Category Archives: Source Code
Prefix to postfix (2 solutions) – stack and recursion

In mathematics expressions, there are infix, prefix and postfix notations. Infix notation is characterized by the placement of operators between operands. For example, the plus sign in 2 + 2. Prefix notation is a notation in which operators precede their operands, such as + 3 4. Postfix notation is a …
Huffman coding and decoding – Step by step

Huffman coding is an algorithm to generate the binary code based on the frequencies of corresponding characters in the input string. Huffman decoding is to recover the original text from the binary code generated from the huffman coding process. By applying huffman algorithms, we compress the input string by using …
Autocomplete with trie – Code

Autocomplete is a feature that search box returns the suggestions based on what you have typed. Autocomplete with trie provides an implementation of auto-complete by using data structure trie. A trie is a tree-like data structure in which every node stores a character. After building the trie, strings or substrings …
Web scraping in Java – Jsoup and selenium
Shortest path and 2nd shortest path using Dijkstra – code

Dijkstra’s algorithm is an algorithm to find the shortest paths between vertices in a graph. It uses greedy technique by picking the un-visited vertex with the lowest distance. When all vertices have been evaluated, the result is the shortest path. This post provides code to find shortest path and second …
Get suggested friends (2 solutions) – DFS and Union Find

Get suggested friends is one of a coding question in social network applications. The data structures for social network is usually a graph. In the graph, you can use depth first search(DFS) or breadth first search(BFS) to find the connections between people. Alternatively, you can also use Union find to …