01/06/2016 – Data Structure

Graph

A graph data structure consists of a finite (and possibly mutable) set of vertices or nodes or points, together with a set of unordered pairs of these vertices for an undirected graph or a set of ordered pairs for a directed graph.

Minimum Spanning Tree

Prim’s Algorithm

de4be1a72501ffb2708b8231e75a5d7b

Kruskal Algorithm

d5e0259133761d4896024354a5cd4185

Dijkstra Algorithm

Dijkstra Algorithm is the only algorithm to find the shortest path. The way to find the shortest path is as follow:

  1. Insert first node to the priority queue, then place node in the priority queue.
  2. If the next node’s is the final destination, then that node is the shortest path. If not, choose the next node that has the smallest distance then update the distance of the node.
  3. Repeat until priority queue is not empty.