Max Flow Problem – Ford-Fulkerson Algorithm

Objective: Given a directed graph that represents a flow network involving source(S) vertex and Sink (T) vertex.  Each edge in the graph has an individual capacity which is the maximum flow that edge allows. Flow in the network has the following restrictions- Input flow must match to output flow for each node in the graph, … Read more Max Flow Problem – Ford-Fulkerson Algorithm

Least Recently Used (LRU) Cache – Using LinkedHashSet and Deque | Set 2

Objective: Design and Implement a data structure Least Recently Used (LRU) Cache. Earlier we had seen Least Recently Used (LRU) Cache – Using HashMap and Doubly Linked List. In this article, we will see the implementation using LinkedHashSet and Deque. Lets first brief about LRU- Given a cache (or memory) with capacity. The cache will … Read more Least Recently Used (LRU) Cache – Using LinkedHashSet and Deque | Set 2

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 Merge K sorted Linked List – Using Priority Queue

Least Recently Used (LRU) Cache – Using HashMap and Doubly Linked List | Set 1

Objective: Design and Implement a data structure Least Recently Used (LRU) Cache. Least Recently Used (LRU) Cache: You have given a cache (or memory) capacity. The cache will be filled with items you will access or look for it. The most recently accessed item will be at the top of the cache whereas the least … Read more Least Recently Used (LRU) Cache – Using HashMap and Doubly Linked List | Set 1

Find the nearest building which has bike | Find nearest specific vertex from source in a graph.

Objective: Given a matrix (NxN) which represents the buildings in community. You are in a building and you need a bike to travel.  There are few buildings in community which has bikes which you can take for your ride. Write an algorithm to find the nearest building which has bike and distance from your building. … Read more Find the nearest building which has bike | Find nearest specific vertex from source in a graph.

Max Flow Problem – Introduction

Max Flow Problem- Maximum flow problems find a feasible flow through a single-source, single-sink flow network that is maximum. This problem is useful for solving complex network flow problems such as the circulation problem. The maximum value of the flow (say the source is s and sink is t) is equal to the minimum capacity of an s-t … Read more Max Flow Problem – Introduction

Dijkstra Algorithm Implementation – TreeSet and Pair Class

Earlier we have seen what Dijkstra algorithm is and how it works. In this article, we will see its implementation using adjacency list and TreeSet. 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 … Read more Dijkstra Algorithm Implementation – TreeSet and Pair Class

Find no of reverse pairs in an array which is sorted in two parts in O(N)

Objective: Given an array of integers A[] which is sorted in two parts (both parts are individually sorted), find no of reverse pairs means no of (i, j) pairs where i belongs to the part one and j belongs to part 2 and A[i]>A[j]. Example: A[] = {4, 6, 8, 9, 1, 5, 10, 11} … Read more Find no of reverse pairs in an array which is sorted in two parts in O(N)

Dijkstra’s – Shortest Path Algorithm (SPT) – Adjacency List and Priority Queue – Java Implementation

Earlier we have seen what Dijkstra’s algorithm is and how it works. In this article, we will see its implementation using the adjacency list and Priority Queue. 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 … Read more Dijkstra’s – Shortest Path Algorithm (SPT) – Adjacency List and Priority Queue – Java Implementation

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 Dijkstra’s – Shortest Path Algorithm (SPT) – Adjacency List and Min Heap – Java Implementation

Dijkstra’s – Shortest Path Algorithm (SPT) – Adjacency Matrix – Java Implementation

Earlier we have seen what Dijkstra’s algorithm is and how it works. In this article, we will see its implementation using the adjacency matrix. 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 Dijkstra’s – Shortest Path Algorithm (SPT) – Adjacency Matrix – Java Implementation

Dijkstra’s – Shortest Path Algorithm (SPT)

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 a shortest paths between nodes in a graph, which may represent, for example, road networks For a given source node in the graph, the algorithm finds the shortest path between source node and every other node. This algorithm also … Read more Dijkstra’s – Shortest Path Algorithm (SPT)

Kruskal’s Algorithm – Minimum Spanning Tree (MST) – Complete Java Implementation

What is Kruskal Algorithm? Kruskal’s algorithm for finding the Minimum Spanning Tree(MST), which finds an edge of the least possible weight that connects any two trees in the forest It is a greedy algorithm. It finds a subset of the edges that forms a tree that includes every vertex, where the total weight of all the edges in the … Read more Kruskal’s Algorithm – Minimum Spanning Tree (MST) – Complete Java Implementation

Prim’s – Minimum Spanning Tree (MST) |using Adjacency List and Priority Queue without decrease key in O(ElogV)

Earlier we have seen the implementation of prim’s algorithm using priority queue with decrease key and how decrease key has increased the time complexity. In this article we will improve the implementation(without decrease key) and reduce the complexity from O(EVlogV) to O(ElogV). If you are reading prim’s algorithm for the first time then we recommend … Read more Prim’s – Minimum Spanning Tree (MST) |using Adjacency List and Priority Queue without decrease key in O(ElogV)