Rangkuman Materi Struktur Data pert-9

GRAPH

Picture1

the elements of graph are vertices, edges and degree.

Vertices are the dots that connected by the line, the line that connect vertices is called edge -> many line = edges.

Every vertices have degree, to count degree simply sum all of the edges of a vertices. Example : the degree for A is 2.

There are 2 types of graph, undirected graph and directed graph.

Undirected graph has no direction in the edges, but directed graph have direction in the edges

Minimum Spanning Tree

one of the way to find MST is using kruskal algorithm

  1. Create an array with name is T.
  2. Sort all the edges using heap (priority queue)
  3. Take the most minimum value of the edge
  4. If there is loop, continue to the next edge
  5. Else add the edge to T
  6. Repeat step 3 to 5 until all vertexes are visited

or prim’s algorithm

  1. Create an array with name is T.
  2. Choose starting vertex.
  3. Whenever each vertex is pointed, the edge which connected to it will be signed as active.
  4. Compare all the active edges value, find the smallest number.
  5. Add the node with smallest active edge to T.
  6. Do step 3 to 5 while the node in T is fewer the total node exist.

The other one is to use Dijkstra’s algorithm

the algorithm for Dijkstra is trying every node by developing a route from initial node. then eleminating the biggest cost.