Lecture 025

Definition of Tree and Forest

Definition of Cycles

Cycle: a path from a vertex to itself

Simple Cycle: with at least one edge and without repeated edges

Definition of Trees

Tree: a connected graph without simple cycles

Definitions:

Definition of Forests

Forest: a graph where each connected component is a tree (notice a tree is a forest)

Complexity

DFS, BSF complexity of a tree: O(v) reduced from O(v+e) unlike graph

Spanning Tree

Binary Search Tree

BST: a tree where every vertex has at most 3 edges

Spanning Tree

Superimposing a tree

Superimposing a tree

subgraph: a subgraph of graph G is a graph with the same vertices and a subset of its edges

spannning tree: a spannning tree for G is a subgraph that

spanning forest: a spanning forest for G is a subgraph that (a bunch of spanning trees)

Computing a Spanning Tree

Edge-Centric algorithm (O(ev)?O(elog(v)))

Start with a spanning forest of singleton trees and add edges from the graph as long as they don't form a cycles (def.B)

Adding Edges

Adding Edges

Initialize T with isolated vertices of G (O(1)=graph_new)
For each edge (u, v) in G: (O(e))
  if connected(u, v): (O(v) where v=v_in_tree_so_far by DFS/BFS)
    discard the edge
  else:
    add it to T (O(1))
  stop once T has v-1 edges

costs O(ev)

- O(v^2) for sparse graphs

(it can create spanning forests) (Edge-Centric algorithm is greedy, DFS/BFS is not since they have worklist)

Making a Maze

Using graph

Using graph

Vertex-Centric algorithm (O(e))

Start with a single vertex in the tree and add edges to vertices not in the tree (def.C)

Adding Vertex

Adding Vertex

Actual Algorithm

Actual Algorithm
(Complexity: O(e) as DFS/BFS)

Minimum Spanning Tree

Minimum spanning tree: one with the least total weight of its edges.

Kruskal's Algorithm (O(ev)->O(elog(e)))

We sort first

We sort first

Visualization

Visualization

Finished Visualization

Finished Visualization

Union Find: A way to check connectivity by grouping O(ev)

Union Find Concept: checking connectivity and connect

Union Find Concept: checking connectivity and connect

Thinking in terms of relation

Thinking in terms of relation

Building Graph using list

Building Graph using list
O(ev)

Height Tracking: Trying to build balanced tree by tracking height (O(elog(e)))

Height Tracking Array

Height Tracking Array

Visualization

Visualization

Complexity

Complexity

Sample Code

Sample Code

Path Compression (O(eAck^{-1}(v)) amortized)

Path Compression: Ackermann Function

Path Compression: Ackermann Function

Prim's Algorithm (O(e log e))

Using priority queue

Using priority queue

Complexity Summary

Complexity Summary

Table of Content