Merge K sorted Linked List – Using Priority Queue

Objective: Given, K sorted linked list, Write an algorithm to merge all the linked list into one linked list which will be also be sorted. Example: List 1: –>1–>5 List 2: –>4–>8 List 3: –>4–>6–>9 List 4: –>2–>7–>10 Merged Linked List: –>1–>2–>4–>4–>5–>6–>7–>8–>9–>10 Approach: Use Priority Queue Please read Priority Queue and Linked List if needed. … Read more

Dijkstra’s – Shortest Path Algorithm (SPT) – Adjacency List and Min Heap – Java Implementation

Earlier we have seen the basics of Dijkstra algorithm. In this article, we will see its implementation using the adjacency list and Min Heap. brief: What is Dijkstra’s algorithm? Dijkstra algorithm is a greedy algorithm. It finds a shortest-path tree for a weighted undirected graph. This means it finds the shortest paths between nodes in a graph, … Read more

Graph – Find Cycle in Undirected Graph using Disjoint Set (Union-Find)

Objective: Given a graph, check if the graph contains a cycle using disjoint set. Note: Disjoint-set data structure, also called a union–find data structure or merge–find set. Example: Earlier in Detect Cycle in Undirected Graph using DFS we discussed about how to find cycle in graph using DFS. In this article we will discuss how to find cycle using … Read more

Text Justification Problem (OR Word Wrap Problem)

Objec­tive:  Given a list of words and length L. Format the words so that each line will have only L characters and fully justified (left and right justified). Restrictions- You need to fit as many as words in every line. You are not allowed to split a word and put them in next line. Pad extra … Read more