Find Path

Find Path
Below is the code for solving the above problem:

Prims Algorithm

Like Kruskal’s algorithm, Prim’s algorithm is used for finding minimum spanning tree. The idea is to maintain two sets of vertices. The first set contains the vertices already included in the MST, the other set contains the vertices not yet included. At every step, it considers all the edges that connect the two sets, and ...

Kruskals Algorithm

Kruskals Algorithm
Kruskals algorithm is used for calculating minimum spanning tree. Minimum spanning tree is a spanning tree of a connected, undirected graph. It connects all the vertices together with the minimal total weighting for its edges. Approach for calculating the minimum spanning tree is described as below: 1. Sort all edges by their distance in non ...

Merge Sort, Quick Sort and finding Kth largest element in an unsorted array

Let’s begin with Merge Sort. Running Time : Average Case : O(n log n) Worst Case : O(n log n) Here is the implementation in java:   Now lets check quick sort: Running time: Average case : O(n log n) Worst Case : O(n2) Here is the implementation in java: Now lets solve finding kth ...

Implementing Producer-Consumer by making own implementation of blocking queue.

Lets implement Producer, Consumer by making own implementation of blocking queue. Lets make own interface which will be having two methods: 1. enqueue // for put 2. dequeue // for take Here is our interface: Now lets make one implementation of above interface. Above implementation behaves as blocking queue, i.e. according to javadoc: ” A ...