Union By Rank Ackermann - PowerPoint PPT Presentation

Loading...

PPT – Union By Rank Ackermann PowerPoint presentation | free to download - id: c2b97-ZDc1Z



Loading


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation
Title:

Union By Rank Ackermann

Description:

1st walk: Find the name of the set . Take a walk until we reach the root. 2nd walk: Retrace the path and join all the elements along the path to the root ... – PowerPoint PPT presentation

Number of Views:81
Avg rating:3.0/5.0
Slides: 33
Provided by: cryst
Learn more at: http://crystal.uta.edu
Category:
Tags: ackermann | rank | union | walk

less

Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: Union By Rank Ackermann


1
Union By Rank Ackermanns Function Graph
Algorithms
  • Rajee S Ramanikanthan
  • Kavya Reddy Musani

2
  • Union by Rank
  • In Union, have parent of shallower tree point to
    other tree.
  • Maintain rank(x) as an upper bound on the depth
    of the tree rooted at x.
  • Consider the following example

x
y
b
d
s
c
m
l
h
a
3
  • Rank of x is 3, and rank of y is 2
  • Union (x,y) results in with the rank of the
    resultant tree greater rank

x
y
b
d
s
c
m
l
h
a
4
  • If the two trees are of same rank then the rank
    of the resultant tree increases by one

x
y
d
s
c
l
h
  • The resultant rank of the union is rank of x 1.

x
d
y
l
s
c
h
5
Algorithm for Path Compression
  • 1st walk Find the name of the set . Take a walk
    until we reach the root.
  • 2nd walk Retrace the path and join all the
    elements along the path to the root using another
    pointer.
  • This enables future finds to take shorter paths.

6
Path Compression
  • Find the root(x) by traversing parent pointers.
  • Set each node traversed to the resulting root(x)

a
c
b
d
e
f
x
7
Path Compression
  • For union by rank,

Best Case
1
Worst Case
Log n
8
Analysis
  • Union by rank only
  • Q (m lgn) where m of operations
  • n MakeSet operations in m
  • Path compression only
  • Q(n f lgn) fltn
  • f FindSet operations
  • n MakeSet operations
  • There are always lt n-1 Unions
  • Union by Rank and Path Compression
  • For n-1 union and m finds the running time is
  • (n m  a (n))
  • a (n) is inverse of Ackermann's function

9
Amortised analysis for Path Compression and Union
by Rank
  • Time for n-1 unions and n finds
  • O(n logn)

logn is a slow growing function
n log n log n
22 2 1
222 4 2
2222 222 3
22222 2222 4
10
Ladder Function
  • This is a very fast growing function,even faster
    than exponential
  • Ladder (n) 222...2

n times
n 2n Ladder(n)
1 2 4
2 4 16
3 8 256
4 16 65536
5 32 4294967296
11
Ackermann's Function
  • Ai (j) is Ackermanns function, it mimics a
    ladder function for higher values of i
  • Ai(j) A i-1 A i-1 A i-1............ A i-1(j)

j1 times
  • Ai (j) j1 if i0
  • 2j1 if i1
  • (j1) 2j1 -1
  • B(j)Aj(j)
  • a(n)Inverse of B

12
Comparisons of functions
F(n)n
Log n
Logn
4
?(n)
13
Graph Algorithms
14
KONIGSBERG BRIDGES

A
B
C
The town of Konigsberg( now kalliningrad) lay on
the banks and on two islands of the Predal
river. The city was connected by 7 bridges. The
puzzle whether it was possible to start walking
from anywhere in town and return to the starting
point by crossing all bridges exactly once.
15
GRAPHS
  • A Graph G(V,E) is a finite nonempty set V of
    objects called vertices together with a set E of
    unordered pairs of distinct vertices of G called
    edges.
  • A directed graph(digraph) G(V,E) is a finite
    nonempty set V of vertices together with a set E
    of ordered pairs of vertices of G called arcs. A
    directed graph is not a symmetric matrix.
  • Weighted Graph A graph having a weight, or
    number, associated with each edge.A weighted
    graph is usually implemented using adjacency
    matrix.

16
CONNECTIVITY PROBLEMS
  • BICONNECTIVITY PROBLEMS In a biconnected graph
    if a path fails , then we have another path. A
    biconnected graph is a graph from which at least
    two nodes have to be deleted to break it up into
    disconnected pieces.
  • REACHABILITY/COVERING PROBLEMS Given a graph,
    then we need to find the whether we can cover
    the required path.
  • REPRESENTATION PROBLEM Representing graphs in
    computer.

17
GRAPH TERMINOLOGIES
M
A
D
N
E
O
B
C
P
Q
DIRECTED GRAPH
UNDIRECTED GRAPH
18
PATHS AND CYCLES
  • A path from vertex v1 to vk is a sequence of
    vertices v1,v2, , vk that are connected by edges
    (v1,v2), (v2,v3), , (vk-1,vk).
  • A path is simple if each vertex in it appears
    only once.
  • Vertex u is said to be reachable from v if there
    is a path from v to u.
  • A circuit is a path whose first and last vertices
    are the same.
  • A simple circuit is a cycle if except for the
    first (and last) vertex, no other vertex appears
    more than once.
  • A Hamiltonian cycle of a graph G is a cycle that
    contains all the vertices of G

19
GRAPH REPRESENTATIONS ADJACENCY MATRIX
  • The adjacency matrix for a finite graph G on n
    vertices
  • is an nn matrix where the nondiagonal entry
    a(i,j) is the
  • number of edges joining vertex i and vertex
    j, and the
  • diagonal entry a(i,i) is either twice the
    number of loops at
  • vertex i or just the number of loops. There
    exists a
  • unique adjacency matrix for each graph. If
    the graph is
  • undirected, the adjacency matrix is
    symmetric. For
  • dense graphs, that is graph with more edges,
    an
  • adjacency matrix is often preferred.

20
ADJACENCY LIST
  • An adjacency list is the representation of all
    edges or
  • arcs in a graph as a list. If a graph is
    undirected, every
  • entry is a set of two nodes containing the
    two ends of the
  • corresponding edge if it is directed, every
    entry is a
  • tuple of two nodes, one denoting the source
    node and
  • the other denoting the destination node of
    the
  • corresponding arc. Adjacency lists are
    unordered. For a
  • graph with a sparse adjacency matrix an
    adjacency list
  • representation of the graph occupies less
    space,
  • because it does not use any space to
    represent edges
  • which are not present.

21
GRAPH REPRESENTATIONS
22
DEPTH FIRST SEARCH
  • DFS is an uninformed search that progresses by
    expanding the first child node of the search tree
    that appears and thus going deeper and deeper
    until a goal state is found, or until it hits a
    node that has no children.
  • Then the search backtracks and starts off on the
    next node.
  • In a non-recursive implementation, all freshly
    expanded nodes are added to a stack for
    expansion.
  • Time complexity is equal to the number of
    vertices plus the number of edges in the graphs
    they traverse.
  • When searching large graphs that can not be fully
    contained in memory, DFS suffers from
    non-termination when the length of a path in the
    search tree is infinite. This can be solved by
    maintaining an increasing limit on the depth of
    the tree, which is called iterative deepening
    depth first search.

23
(No Transcript)
24
(No Transcript)
25
(No Transcript)
26
(No Transcript)
27
BREADTH FIRST SEARCH
  • BFS is an uninformed search method that aims to
    expand and examine all nodes of a tree
    systematically in search of a search of a
    solution. In other words, it exhaustively
    searches the entire tree without considering the
    goal until it finds it. It does not use a
    heuristic.
  • All child nodes obtained by expanding a node are
    added to a FIFO queue. In typical
    implementations, nodes that have not yet been
    examined for their neighbors are placed in some
    container called open and then once examined
    are placed in the container closed.
  • Time complexity is equal to the number of
    vertices plus the number of edges in the graphs
    they traverse.
  • BFS has space complexity linear in size of the
    tree/graph searched as it needs to store all
    expanded nodes in memory.

28
(No Transcript)
29
(No Transcript)
30
C
B
31
(No Transcript)
32
REFERENCES
  • Dr.Kumars notes
  • Dr.Cooks notes
  • Fall 2004 notes
  • www.mathworld.com
  • en.wikipedia.org
About PowerShow.com