Josephus problem using circular linked list

last men standing

“Josephus problem” or “circle of death problem”. Given a number n people standing in a circle, eliminate every kth one until the last one remain. This problem can be solved with a circular linked list. First, we build a circular Linked List by adding n nodes. The number starts from …

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

Implement graph as adjacency list

graph feature

A graph is a data structure that consists of a set of nodes connected by edges. Graphs are used to simulate many real-world problems, such as paths in cities, circuit networks, and social networks. This post is to implement a graph as an adjacency list. Table of Content Terminology Add node and …

Continue reading