0 Course Outline n Abstract data types and algorithm analysis (Ch. 2, 3) n C++ review (Ch. 1) n Sets in general: Balanced search trees (Ch. 4 and 12.2)

Slides:



Advertisements
Similar presentations
Unit-iv.
Advertisements

Chapter 23 Minimum Spanning Tree
CSE 326: Data Structures Part 7: The Dynamic (Equivalence) Duo: Weighted Union & Path Compression Henry Kautz Autumn Quarter 2002 Whack!! ZING POW BAM!
CS203 Lecture 15.
0 Course Outline n Introduction and Algorithm Analysis (Ch. 2) n Hash Tables: dictionary data structure (Ch. 5) n Heaps: priority queue data structures.
Weighted graphs Example Consider the following graph, where nodes represent cities, and edges show if there is a direct flight between each pair of cities.
Graphs CSC 220 Data Structure. Introduction One of the Most versatile data structures like trees. Terminology –Nodes in trees are vertices in graphs.
Minimum Spanning Trees Definition Two properties of MST’s Prim and Kruskal’s Algorithm –Proofs of correctness Boruvka’s algorithm Verifying an MST Randomized.
1 Minimum Spanning Tree Prim-Jarnik algorithm Kruskal algorithm.
Graphs Chapter 12. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different.
©Brooks/Cole, 2003 Chapter 12 Abstract Data Type.
© 2006 Pearson Addison-Wesley. All rights reserved14 A-1 Chapter 14 excerpts Graphs (breadth-first-search)
ITEC200 – Week 12 Graphs. 2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study.
CSCE 210 Data Structures and Algorithms
CS 307 Fundamentals of Computer Science 1 Abstract Data Types many slides taken from Mike Scott, UT Austin.
Disjoint Union / Find CSE 373 Data Structures Lecture 17.
DAST, Spring © L. Joskowicz 1 Data Structures – LECTURE 1 Introduction Motivation: algorithms and abstract data types Easy problems, hard problems.
Spanning Trees.
Spanning Trees. 2 Spanning trees Suppose you have a connected undirected graph Connected: every node is reachable from every other node Undirected: edges.
TDDB57 DALG-C, DALG Exam Requirements Jan Maluszynski - HT 2006DALG-C.1 TDDB57 – DALG-C Examination Requirements.
Data Structures & Algorithms What The Course Is About s Data structures is concerned with the representation and manipulation of data. s All programs.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Spring 2010CS 2251 Graphs Chapter 10. Spring 2010CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs.
Dynamic Sets and Data Structures Over the course of an algorithm’s execution, an algorithm may maintain a dynamic set of objects The algorithm will perform.
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
Data Structures, Spring 2004 © L. Joskowicz 1 DAST – Final Lecture Summary and overview What we have learned. Why it is important. What next.
1 ES 314 Advanced Programming Lec 2 Sept 3 Goals: Complete the discussion of problem Review of C++ Object-oriented design Arrays and pointers.
Spanning Trees. Spanning trees Suppose you have a connected undirected graph –Connected: every node is reachable from every other node –Undirected: edges.
Chapter 9: Graphs Spanning Trees Mark Allen Weiss: Data Structures and Algorithm Analysis in Java Lydia Sinapova, Simpson College.
DAST, Spring © L. Joskowicz 1 Data Structures – LECTURE 1 Introduction Motivation: algorithms and abstract data types Easy problems, hard problems.
Data Structures and Algorithms1 Graphs 3 Adapted From: Data Structures and Their Algorithms, by Harry R. Lewis and Larry Denenberg (Harvard University:
Graphs and Sets Dr. Andrew Wallace PhD BEng(hons) EurIng
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 1. Data Modeling and ADTs.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Chapter 3 List Stacks and Queues. Data Structures Data structure is a representation of data and the operations allowed on that data. Data structure is.
2IL05 Data Structures Fall 2007 Lecture 13: Minimum Spanning Trees.
Spring 2015 Lecture 11: Minimum Spanning Trees
0 Course Outline n Introduction and Algorithm Analysis (Ch. 2) n Hash Tables: dictionary data structure (Ch. 5) n Heaps: priority queue data structures.
CSE373: Data Structures & Algorithms Lecture 10: Disjoint Sets and the Union-Find ADT Lauren Milne Spring 2015.
All-Pairs Shortest Paths & Essential Subgraph 01/25/2005 Jinil Han.
CS Data Structures II Review & Final Exam. 2 Topics Review Final Exam.
Spanning Trees CSIT 402 Data Structures II 1. 2 Two Algorithms Prim: (build tree incrementally) – Pick lower cost edge connected to known (incomplete)
CS 146: Data Structures and Algorithms July 16 Class Meeting Department of Computer Science San Jose State University Summer 2015 Instructor: Ron Mak
Disjoint-sets Abstract Data Type (ADT) that contains nonempty pairwise disjoint sets: For all sets X and Y in the container, – X != ϴ and Y != ϴ – And.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 13. Abstract Data Types (ADT’s)
0 Union-Find data structure. 1 Disjoint set ADT (also Dynamic Equivalence) The universe consists of n elements, named 1, 2, …, n n The ADT is a collection.
Graphs. Graphs Similar to the graphs you’ve known since the 5 th grade: line graphs, bar graphs, etc., but more general. Those mathematical graphs are.
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.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
© 2006 Pearson Addison-Wesley. All rights reserved 14 A-1 Chapter 14 Graphs.
Minimum Spanning Trees CSE 373 Data Structures Lecture 21.
CSE373: Data Structures & Algorithms Lecture 9: Disjoint Sets and the Union-Find ADT Lauren Milne Summer 2015.
Graphs Upon completion you will be able to:
CS6045: Advanced Algorithms Sorting Algorithms. Heap Data Structure A heap (nearly complete binary tree) can be stored as an array A –Root of tree is.
CSE 589 Applied Algorithms Spring 1999 Prim’s Algorithm for MST Load Balance Spanning Tree Hamiltonian Path.
CSCE 210 Data Structures and Algorithms
Set Collection A Bag is a general collection class that implements the Collection interface. A Set is a collection that resembles a Bag with the provision.
Minimum Spanning Trees
Minimum Spanning Trees and Shortest Paths
Map interface Empty() - return true if the map is empty; else return false Size() - return the number of elements in the map Find(key) - if there is an.
CSE373: Data Structures & Algorithms Lecture 10: Disjoint Sets and the Union-Find ADT Linda Shapiro Spring 2016.
Course Outline Introduction and Algorithm Analysis (Ch. 2)
Graphs Chapter 11 Objectives Upon completion you will be able to:
Spanning Trees.
Dynamic Sets (III, Introduction)
Minimum Spanning Trees
Priority Queues Supports the following operations. Insert element x.
Chapter 14 Graphs © 2011 Pearson Addison-Wesley. All rights reserved.
Presentation transcript:

0 Course Outline n Abstract data types and algorithm analysis (Ch. 2, 3) n C++ review (Ch. 1) n Sets in general: Balanced search trees (Ch. 4 and 12.2) n Sets with insert/delete/member: Hashing (Ch. 5) n Sets with priority: Heaps, priority queues (Ch. 6) n Graphs: Shortest-path algorithms (Ch. 9.1 – 9.3.2) n Sets with disjoint union: Union/find trees (Ch. 8.1 – 8.5) n Graphs: Minimum spanning trees (Ch. 9.5)

1 Disjoint set ADT (also Dynamic Equivalence) n The universe consists of n elements, named 1, 2, …, n n The ADT is a collection of sets of elements n Each element is in exactly one set  sets are disjoint  to start, each set contains one element n Each set has a name, which is the name of one of its elements (any one will do)

2 Disjoint set ADT, continued n Setname = find ( elementname )  returns the name of the unique set that contains the given element  not the same as “find” in search trees (lousy terminology, for historical reasons…) n union ( Setname1, Setname2 )  replaces both sets with a new set  the name of the new set is not specified n Analysis: worst-case total running time of a sequence of f finds and u unions

3 Toy application: mazes without loops elements are 1, 2, … 25; sets are connected parts of the maze start with each element in its own set; repeat { pick two adjacent elements p and q (= p ± 1 or p ± 5) at random; if (psetname = find(p)) != (qsetname = find(q)) { erase the wall between p and q; union(psetname, qsetname); } } until 24 walls have been erased

4 Array Implementation n Elements are 1, …, N n Setname[i] = name of the set containing element i n Find : O(1), Union : O(N) n u Union, f Find operations: O(u*N+f ) n N-1 Unions and O(N) Finds: O(N 2 ) total time Initialize(int N) Setname = new int [N+1]; for (int e=1; e<=N; e++) Setname[e] = e; Union (int i, int j) for (int k=1; k<=N; k++) if (Setname[k] == j) Setname[k] = i; int Find (int e) return Setname[e];

5 Union(5,11) Union(12,4)Union(1,5)Union(15,1)

6 Tree implementation n Complexity in the worst case:  Union is O(1) but Find is O(n)  u Union, f Find : O(u + f n)  N-1 Unions and O(N) Finds: still O(N 2 ) total time Initialize (int N) parent = new int [N+1]; for (int e=1; e<=N; e++) parent[e] = 0; int Find (int e) while (parent[e] != 0) e = parent[e]; return e; Union (int i, int j) parent[j] = i; N1N1 N Union (N-1, N); Union (N-2, N-1); Union (N-3, N-2); … Union (1, 2); Find (1); Find (2); … Find (N);

7 Now a tree with height h has at least 2 h nodes Union is O(1) but Find is O(log N) u Unions, f Finds : O(u + f log u) N-1 Unions, O(N) Finds: O  N log N  total time Union by size: link smaller tree to larger one Initialize (int N) setsize = new int[N+1]; parent = new int [N+1]; for (int e=1; e <= N; e++) parent[e] = 0; setsize[e] = 1; int Find (int e) while (parent[e] != 0) e = parent[e]; return e; Union (int i, int j) if setsize[i] < setsize[j] then setsize[j] += setsize[i]; parent[i] = j; else setsize[i] += setsize[j]; parent[j] = i ;

8 Path compression int Find (int e) if (parent[e] == 0) return e else parent[e] = Find (parent[e]) return parent[e] any single find can still be O(log N), but later finds on the same path are faster u Unions, f Finds : O(u + f  (f, u))  (f, u) is a functional inverse of Ackermann’s function N-1 Unions, O(N) Finds:  “almost linear” total time