Dijkstra’s Algorithm Shortest Path

Dijkstra’s algorithm is the most popular algorithm to find the shortest paths from a certain vertex in a weighted graph.In fact, the algorithm will find the shortest paths to every vertex from the start vertex.The algorithm takes both greedy and dynamic programming approach that it will try to find local optimum paths first and use READ MORE

Python – best practices using else block

Typical use case of else block is with if in many programming languages.It usually serves as branch control such if it doesn’t meet certain conditions in if block it will just execute else block instead of if block.And it is the same case for python else block too. However, python extended else block usage more READ MORE

Intro to Union-Find Data Structure

Union-Find is a data structure that mimics tree data structure except that nodes point to their parent instead of children. The union-find is very useful for set operations such as the following.1. find – find the root of the current node2. same component – check if two trees have the same root node. (belongs to READ MORE

C++ Standard Library C-string Functions

C-string is a char array terminated with a null byte(‘\0’), which is the original string that was used since C and early C++.C/C++ standard library provides useful C-string functions.The header you need to include to use C-string functions is <cstring>.In this post, I am going to explain some popular C-string functions with example codes. Before READ MORE

How to detect a loop (cycle) in a linked list

Traversing linked list is easy but what would happen if there is a cycle in the linked list?It will just fall into an infinity loop if traversing is implemented without a cycle prevention code.Thankfully, there is already a known algorithm for this kind of problem. How to detect if a cycle exists? Suppose there is READ MORE

Intro to Depth First Search (DFS)

Depth first search is one of the popular graph traversal algorithms that work well for certain purposes.As you can infer from the name DFS is quite different from BFS – breadth first search.Therefore the applications of DFS are different from BFS.In this post, I am going to discuss how DFS works with examples.Please refer to READ MORE

Intro to Breadth First Search (BFS)

When dealing with a graph it might be necessary to traverse the graph.Graph traversal is a systemic method to traverse the graph.Breadth first search is one of the most popular graph traversal algorithms that work very well for certain purposes.Today, I am going to introduce breadth first search in this post. How does breadth first READ MORE