What are the missing data structures in java collections?

Java node data structures diagram

Java collections provides APIs for many data structures such as ArrayList, Linkedlist, HashMap. They are very handy for us to use. But there are missing data structures in Java collections that are widely used, but not provided. The developers have to write their own implementations for these data structures. What …

Continue reading

Permutation of multiple arrays and iterator – code

permutation of multiple arrays java

Permutation of multiple arrays and iterator has two tasks. First is the permutation of multiple arrays and output as one single array. The second is to implement the iterator of this new array. Permutation is an important topic in the fields of combinatorics. It is usually implemented using recursion. The …

Continue reading

Initialize game board in matrix – Code

initialize game board in matrix java

Initialize game board in matrix is to populate one digit number into a NxN matrix. The digit can be generated randomly. However, no 3 adjacent cells shall be the same, horizontal, vertical, diagonal and L shape. If you find invalid digit, replace with a different one in that cell. What …

Continue reading

Build hierarchy from Stack-like log

process log with stack java

When the input data is a flat list, you may notice sometimes they contains the data consists of “start” and “end” pairs. Every “start” has a corresponding “stop” message, which is in a stack-like fashion. When analyzing this kind of data, it will be helpful to build hierarchy from stack-like …

Continue reading

Clean directories with recursion – Code

Clean Directories with recursion java

Clean directories with recursion is to uses Java File class and methods to remove files in a file system. What is recursion? Recursion is a technique that a function or an algorithm calls itself. It is powerful tool to solve math, and data structures problems. It solves sub and repetitive …

Continue reading

Selection sort (2 solutions) – Code

selection sort

Selection Sort is one of three well-known simple sorting algorithms (ie bubble sort, insertion sort and selection sort). It is intuitive. Starting from the first element of the array, find the smallest one in each iteration, and put it at the front. As other two simple sorting algorithms, we can …

Continue reading