Union By Rank Ackermann’s Function Graph Algorithms Rajee S Ramanikanthan Kavya Reddy Musani.

Slides:



Advertisements
Similar presentations
C++ Programming: Program Design Including Data Structures, Fifth Edition Chapter 21: Graphs.
Advertisements

Lecture 15. Graph Algorithms
Uninformed search strategies
Introduction to Algorithms Lecture 12 Prof. Constantinos Daskalakis CLRS
Traveling Salesperson Problem
Review Binary Search Trees Operations on Binary Search Tree
Chapter 8, Part I Graph Algorithms.
Introduction This chapter explores graphs and their applications in computer science This chapter explores graphs and their applications in computer science.
© 2006 Pearson Addison-Wesley. All rights reserved14 A-1 Chapter 14 excerpts Graphs (breadth-first-search)
Data Structures Using C++
Graphs.
Graph.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
Graph & BFS.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
Structures and Strategies for State Space Search
Graph COMP171 Fall Graph / Slide 2 Graphs * Extremely useful tool in modeling problems * Consist of: n Vertices n Edges D E A C F B Vertex Edge.
Graph & BFS Lecture 22 COMP171 Fall Graph & BFS / Slide 2 Graphs * Extremely useful tool in modeling problems * Consist of: n Vertices n Edges D.
1 Data Structures and Algorithms Graphs I: Representation and Search Gal A. Kaminka Computer Science Department.
Graphs. Graphs Many interesting situations can be modeled by a graph. Many interesting situations can be modeled by a graph. Ex. Mass transportation system,
Using Search in Problem Solving
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
1 Structures and Strategies for State Space Search 3 3.0Introduction 3.1Graph Theory 3.2Strategies for State Space Search 3.3Using the State Space to Represent.
Review of Graphs A graph is composed of edges E and vertices V that link the nodes together. A graph G is often denoted G=(V,E) where V is the set of vertices.
C o n f i d e n t i a l HOME NEXT Subject Name: Data Structure Using C Unit Title: Graphs.
GRAPHS Education is what remains after one has forgotten what one has learned in school. Albert Einstein Albert Einstein Smitha N Pai.
GRAPH Learning Outcomes Students should be able to:
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Chapter 2 Graph Algorithms.
Representing and Using Graphs
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Computer Algorithms Submitted by: Rishi Jethwa Suvarna Angal.
1 CS104 : Discrete Structures Chapter V Graph Theory.
D ESIGN & A NALYSIS OF A LGORITHM 03 – G RAPH T HEORY Informatics Department Parahyangan Catholic University.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Elementary Graph Algorithms CLRS Chapter 22. Graph A graph is a structure that consists of a set of vertices and a set of edges between pairs of vertices.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Graphs. Definitions A graph is two sets. A graph is two sets. –A set of nodes or vertices V –A set of edges E Edges connect nodes. Edges connect nodes.
10 Copyright © William C. Cheng Data Structures - CSCI 102 Graph Terminology A graph consists of a set of Vertices and a set of Edges C A B D a c b d e.
CISC 235: Topic 9 Introduction to Graphs. CISC 235 Topic 92 Outline Graph Definition Terminology Representations Traversals.
1 Chapter 22 Elementary Graph Algorithms. 2 Introduction G=(V, E) –V = vertex set –E = edge set Graph representation –Adjacency list –Adjacency matrix.
Trees : Part 1 Section 4.1 (1) Theory and Terminology (2) Preorder, Postorder and Levelorder Traversals.
Unit – V Graph theory. Representation of Graphs Graph G (V, E,  ) V Set of vertices ESet of edges  Function that assigns vertices {v, w} to each edge.
Graphs A graphs is an abstract representation of a set of objects, called vertices or nodes, where some pairs of the objects are connected by links, called.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 13: Graphs Data Abstraction & Problem Solving with C++
1 Directed Graphs Chapter 8. 2 Objectives You will be able to: Say what a directed graph is. Describe two ways to represent a directed graph: Adjacency.
COSC 2007 Data Structures II
© 2006 Pearson Addison-Wesley. All rights reserved 14 A-1 Chapter 14 Graphs.
Discrete Structures CISC 2315 FALL 2010 Graphs & Trees.
Graphs Upon completion you will be able to:
Graphs & Paths Presentation : Part II. Graph representation Given graph G = (V, E). May be either directed or undirected. Two common ways to represent.
Shahed University Dr. Shahriar Bijani May  A path is a sequence of vertices P = (v 0, v 1, …, v k ) such that, for 1 ≤ i ≤ k, edge (v i – 1, v.
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
Chapter 05 Introduction to Graph And Search Algorithms.
Graph Representations And Traversals. Graphs Graph : – Set of Vertices (Nodes) – Set of Edges connecting vertices (u, v) : edge connecting Origin: u Destination:
Graph Theory Def: A graph is a set of vertices and edges G={V,E} Ex. V = {a,b,c,d,e} E = {ab,bd,ad,ed,ce,cd} Note: above is a purely mathematical definition.
1 GRAPH Learning Outcomes Students should be able to: Explain basic terminology of a graph Identify Euler and Hamiltonian cycle Represent graphs using.
Lecture 20. Graphs and network models 1. Recap Binary search tree is a special binary tree which is designed to make the search of elements or keys in.
Code: BCA302 Data Structures with C Prof. (Dr.) Monalisa Banerjee By.
Csc 2720 Instructor: Zhuojun Duan
Graph & BFS.
Graphs Chapter 13.
Graphs Chapter 11 Objectives Upon completion you will be able to:
Chapter 11 Graphs.
Graphs Chapter 7 Visit for more Learning Resources.
Graphs G = (V, E) V are the vertices; E are the edges.
Important Problem Types and Fundamental Data Structures
Search Strategies CMPT 420 / CMPG 720.
INTRODUCTION A graph G=(V,E) consists of a finite non empty set of vertices V , and a finite set of edges E which connect pairs of vertices .
Presentation transcript:

Union By Rank Ackermann’s Function Graph Algorithms Rajee S Ramanikanthan Kavya Reddy Musani

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 m h sc y b a l d x

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 m h sc y b a l d x

If the two trees are of same rank then the rank of the resultant tree increases by one h sc y l d x The resultant rank of the union is rank of x + 1. h sc y l d x

Algorithm for Path Compression 1 st walk: Find the name of the set. Take a walk until we reach the root. 2 nd 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.

a b c def x Path Compression Find the root(x) by traversing parent pointers. Set each node traversed to the resulting root(x)

Path Compression For union by rank, Best Case Worst Case 1 Log n

Analysis Union by rank only  (m lgn) where m = # of operations n = # MakeSet operations in m Path compression only  (n+ f lgn) f<n f = # FindSet operations n = # MakeSet operations There are always <= n-1 Unions Union by Rank and Path Compression For n-1 union and m finds the running time is (n + m *  (n))  (n) is inverse of Ackermann's function

Amortised analysis for Path Compression and Union by Rank Time for n-1 unions and n finds O(n log*n) n log n log * n ^2^ ^2^2^2 2 ^2^2 3 2 ^2^2^2^2 2 ^2^2^2 4 log*n is a slow growing function

Ladder Function This is a very fast growing function,even faster than exponential Ladder (n) = n times n 2n2n Ladder(n)

Ackermann's Function A i (j) is Ackermann’s function, it mimics a ladder function for higher values of i Ai(j) = A i-1 A i-1 A i A i-1 (j) A i (j) = j+1 if i=0 = 2j+1 if i=1 =(j+1) 2 j+1 -1 B(j)=A j (j)  (n)=Inverse of B j+1 times

Comparisons of functions 4 F(n)=n Log n Log*n  (n)

Graph Algorithms

KONIGSBERG BRIDGES C B A 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.

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.

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.

A B E C D M N O P Q UNDIRECTED GRAPH DIRECTED GRAPH GRAPH TERMINOLOGIES

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

GRAPH REPRESENTATIONS ADJACENCY MATRIX The adjacency matrix for a finite graph G on ‘n’ vertices is an n*n 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.

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.

GRAPH REPRESENTATIONS

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.

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.

C B

REFERENCES Dr.Kumar’s notes Dr.Cook’s notes Fall 2004 notes en.wikipedia.org