Combinations of adding parentheses – code

generate valid parentheses

To find number of possible combinations of valid parentheses, we have to know Catalan number. Catalan numbers are a sequence of natural numbers that follow the formula showing below. The first few Catalan numbers for n = 0, 1, 2, 3, 4, 5 … Cn = 1, 1, 2, 5, …

Continue reading

Hierholzer’s algorithm to find Euler path – undirected graph

longest path

An Euler path  is a trail in a graph that visits every edge exactly once. Here we use graph data structure to simulate the set of linked porker cards and find the Euler path between them. In a porker game, if two poker cards have matched suites and figures, they can be link together. Given …

Continue reading

Topological sort using DFS and BFS

Tournamnet ranking

Topological sort is a graph traversal in which node v is visited only after all its dependencies are visited. The graph has to be directed and has no cycles, i.e. directed acyclic graph (DAG). Once the graph is built, you can use the algorithms to find the order. The result …

Continue reading

Domino Eulerian path problem using backtracking

dominoes euler path

A Euler path (Eulerian path) is a path in a graph that you visit each edge exactly once. You can visit the same vertex multiple times though. Dominoes is one example of finding Euler path problem. A domino is a game piece that has 2 numbers on it, one number …

Continue reading

Flow network and min cut

mini cut feature

A flow network is a directed graph where each edge has a capacity and each edge receives a flow. The amount of flow on an edge cannot exceed the capacity of the edge. A flow network has designated source and sink nodes s and t. A flow must satisfy the …

Continue reading

Implement binary search tree with parent pointer

Binary search tree with parent feature

A binary search tree is a type of ordered binary tree, where the left child has a value smaller than its parent, and the right child has a value greater than or equal to its parent. In a binary search tree, a node has two references, the left child and …

Continue reading

Implement circular queue using an array

circular queue

A circular queue is a queue in which all elements are connected to form a circular. A circular queue can be implemented with an array or a linked list. In the array implementation, the index of the rear element wraps around to the beginning of the array. In this post, …

Continue reading

Implement priority queue using an array

A priority queue is a queue in which you insert an element at the back (enqueue) and remove an element from the front (dequeue). Meanwhile, a priority queue is a special queue, the element with the highest priority shall be dequeued first. You can implement a priority queue using an …

Continue reading

Web scraping in Java – Jsoup and selenium

web scraping feature

Web scraping is a great way to retrieve data and save the information. with a simple Java web scraping setup, you can download content using Jsoup and selenium. Download the source code from the GitHub. Table of Content Web scraping and parsing in HTML – Jsoup Download images – Jsoup …

Continue reading

Autocorrect with trie and edit distance in Java

autocorrect java

Google provides a powerful autocorrect for validating the keywords we type into the input text box. It checks against a dictionary. If it doesn’t find the keyword in the dictionary, it suggests a most likely replacement. To do this it associates with every word in the dictionary a frequency, the …

Continue reading