29-Jan-00 CPSC 212: Data Structures and Algorithms Instructor: Harry Plantinga.

Slides:



Advertisements
Similar presentations
1 Union-find. 2 Maintain a collection of disjoint sets under the following two operations S 3 = Union(S 1,S 2 ) Find(x) : returns the set containing x.
Advertisements

CSE332: Data Abstractions Lecture 14: Beyond Comparison Sorting Dan Grossman Spring 2010.
Razdan with contribution from others 1 Algorithm Analysis What is the Big ‘O Bout? Anshuman Razdan Div of Computing.
ISOM MIS 215 Module 7 – Sorting. ISOM Where are we? 2 Intro to Java, Course Java lang. basics Arrays Introduction NewbieProgrammersDevelopersProfessionalsDesigners.
EECS 311: Chapter 8 Notes Chris Riesbeck EECS Northwestern.
Union-Find: A Data Structure for Disjoint Set Operations
Algorithmic Complexity Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Fall 2006CENG 7071 Algorithm Analysis. Fall 2006CENG 7072 Algorithmic Performance There are two aspects of algorithmic performance: Time Instructions.
CSE 326: Data Structures Disjoint Union/Find Ben Lerner Summer 2007.
Disjoint Union / Find CSE 373 Data Structures Lecture 17.
Introduction to Analysis of Algorithms
CSE 326: Data Structures Disjoint Union/Find. Equivalence Relations Relation R : For every pair of elements (a, b) in a set S, a R b is either true or.
Algorithmic Complexity 2 Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
© 2006 Pearson Addison-Wesley. All rights reserved6-1 More on Recursion.
© 2004 Goodrich, Tamassia Union-Find1 Union-Find Partition Structures.
Algorithm Analysis CS 201 Fundamental Structures of Computer Science.
Chapter 9: Union-Find Algorithms The Design and Analysis of Algorithms.
Computer Science 2 Data Structures and Algorithms V section 2 Intro to “big o” Lists Professor: Evan Korth New York University 1.
Lecture 16: Union and Find for Disjoint Data Sets Shang-Hua Teng.
Analysis of Algorithms 7/2/2015CS202 - Fundamentals of Computer Science II1.
CSE 373, Copyright S. Tanimoto, 2002 Up-trees - 1 Up-Trees Review of the UNION-FIND ADT Straight implementation with Up-Trees Path compression Worst-case.
Elementary Data Structures and Algorithms
Summary of Algo Analysis / Slide 1 Algorithm complexity * Bounds are for the algorithms, rather than programs n programs are just implementations of an.
Analysis of Algorithms COMP171 Fall Analysis of Algorithms / Slide 2 Introduction * What is Algorithm? n a clearly specified set of simple instructions.
© 2006 Pearson Addison-Wesley. All rights reserved10 A-1 Chapter 10 Algorithm Efficiency and Sorting.
CS2420: Lecture 42 Vladimir Kulyukin Computer Science Department Utah State University.
Computer Science 2 Data Structures and Algorithms V Intro to “big o” Lists Professor: Evan Korth New York University 1.
Analysis of Algorithms Spring 2015CS202 - Fundamentals of Computer Science II1.
Week 2 CS 361: Advanced Data Structures and Algorithms
Chapter 12 Recursion, Complexity, and Searching and Sorting
© 2011 Pearson Addison-Wesley. All rights reserved 10 A-1 Chapter 10 Algorithm Efficiency and Sorting.
Chapter 10 A Algorithm Efficiency. © 2004 Pearson Addison-Wesley. All rights reserved 10 A-2 Determining the Efficiency of Algorithms Analysis of algorithms.
Télécom 2A – Algo Complexity (1) Time Complexity and the divide and conquer strategy Or : how to measure algorithm run-time And : design efficient algorithms.
CSE332: Data Abstractions Lecture 14: Beyond Comparison Sorting Dan Grossman Spring 2012.
CSE373: Data Structures & Algorithms Lecture 11: Implementing Union-Find Aaron Bauer Winter 2014.
Introduction to Analysis of Algorithms COMP171 Fall 2005.
Algorithm Analysis CS 400/600 – Data Structures. Algorithm Analysis2 Abstract Data Types Abstract Data Type (ADT): a definition for a data type solely.
Union-find Algorithm Presented by Michael Cassarino.
Union Find ADT Data type for disjoint sets: makeSet(x): Given an element x create a singleton set that contains only this element. Return a locator/handle.
CSE373: Data Structures & Algorithms Lecture 11: Implementing Union-Find Nicki Dell Spring 2014.
CSE373: Data Structures & Algorithms Lecture 10: Implementing Union-Find Dan Grossman Fall 2013.
CSC – 332 Data Structures Generics Analysis of Algorithms Dr. Curry Guinn.
Union-Find  Application in Kruskal’s Algorithm  Optimizing Union and Find Methods.
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.
CHAPTER 8 THE DISJOINT SET ADT §1 Equivalence Relations 【 Definition 】 A relation R is defined on a set S if for every pair of elements (a, b), a, b 
Scalability for Search Scaling means how a system must grow if resources or work grows –Scalability is the ability of a system, network, or process, to.
E.G.M. PetrakisAlgorithm Analysis1  Algorithms that are equally correct can vary in their utilization of computational resources  time and memory  a.
Chapter 8 Searching and Sorting © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
Lecture aid 1 Devon M. Simmonds University of North Carolina, Wilmington CSC231 Data Structures.
1 Asymptotes: Why? How to describe an algorithm’s running time? (or space, …) How does the running time depend on the input? T(x) = running time for instance.
Analysis of Algorithms Spring 2016CS202 - Fundamentals of Computer Science II1.
GC 211:Data Structures Week 2: Algorithm Analysis Tools Slides are borrowed from Mr. Mohammad Alqahtani.
MA/CSSE 473 Day 37 Student Questions Kruskal Data Structures and detailed algorithm Disjoint Set ADT 6,8:15.
CSE 373, Copyright S. Tanimoto, 2001 Up-trees - 1 Up-Trees Review of the UNION-FIND ADT Straight implementation with Up-Trees Path compression Worst-case.
CSE 373: Data Structures and Algorithms
Analysis of Algorithms
Analysis of Algorithms
CMSC 341 Disjoint Sets Based on slides from previous iterations of this course.
CSE373: Data Structures & Algorithms Lecture 11: Implementing Union-Find Linda Shapiro Spring 2016.
CSE 332: Data Structures Disjoint Set Union/Find
Data Structures & Algorithms Union-Find Example
Analysis of Algorithms
CSE 332: Data Abstractions Union/Find II
PAC Intro to “big o” Lists Professor: Evan Korth New York University
CSE373: Data Structures & Algorithms Implementing Union-Find
Disjoint Sets DS.S.1 Chapter 8 Overview Dynamic Equivalence Classes
CSE 373: Data Structures and Algorithms
Analysis of Algorithms
Disjoint Set Operations: “UNION-FIND” Method
Presentation transcript:

29-Jan-00 CPSC 212: Data Structures and Algorithms Instructor: Harry Plantinga

29-Jan-00 Computer Science 212 Data Structures and Algorithms The Heart of Computer Science Data structures Study of important algorithms Algorithm analysis Algorithm design techniques Plus GUIs and a GUI toolkit Intelligent systems Course Information:

29-Jan-00 Why study DS & Algorithms? Some problems are difficult to solve and good solutions are known Some “solutions” don’t always work Some simple algorithms don’t scale well Data structures and algorithms make good tools for addressing new problems Why not just get a faster computer? Esthetic beauty!

29-Jan-00 Asymptotic Analysis What does it mean to say that an algorithm has runtime O(n log n)? n: Problem size Big-O: upper bound over all inputs of size n “Ignore constant factor” (why?) Most algorithms we study will have runtimes of O(1), O(log n), O(n), O(n log n), O(n 2 ), O(n 3 ), O(2 n ) g(n) is said to be O(f(n)) if there exist constants c 0 and n 0 such that g(n) n 0 “as n grows large”

29-Jan-00 Connectivity Building railroads across America Dutch Bingo IC connectivity Telephone network Given an edge from A to B, print it out unless previous edges already connect A and B n edges are added

29-Jan-00 Example [ ] [5-6] 0-2[ ]6-1

29-Jan-00 Abstract Data Types What is an abstract data type? A collection of data A set of operations on that data What abstract data type do we need? Data: Operations: Sets of elements Find(x) – what set is x in? Union(A,B) – merge sets A and B

29-Jan-00 Algorithm How to solve the railroads problem? How to implement the Union-Find ADT? For road (x,y) if find(x) != find(y) union(find(x),find(y)) print “x – y”

29-Jan-00 Quick Find For each city, keep a pointer to the “capital” of the set Find(x): return the set name for x Runtime: Union(A,B): change all sets named A (=Find(x)) in the array to B (=Find(y)) Runtime: Can we do faster unions? O(1) O(n) 10^8 items, 10^9 unions, 100 mips: 10sec 10^8 items, 10^9 unions, 31 yrs

29-Jan-00 Quick Union To do a Unite(X,Y) (where X and Y are sets), just point X to Y Union runtime: Find runtime: Total time for adding n roads? Can we do better? O(1) O(n)

29-Jan-00 Weighted Union Keep track of the number of cities in each set Insert the smaller set into the larger Runtime for Unite(A,B): Runtime for Find(x): What’s the worst-case tree height? O(1) O(?)

29-Jan-00 Weighted Union Worst case What sequence of inputs gives the tallest trees? How tall are the trees? What is the runtime for find? What is the runtime for n unions? <= log n (prove by induction) O(log n) O(n log n) Better still: average O(1) per union!

29-Jan-00 Path Compression When you do a find, make every city on the path to the “capital” point to the capital Runtime? O(n log* n)

29-Jan-00 What difference does it make? Small problem: use the simplest algorithm Large problem: use the best algorithm! N M qf qu wqu pc A better algorithm is much more advantageous than a faster computer.

29-Jan-00 Lessons Start with simple algorithm Need a good algorithm for big problems Higher level of abstraction (tree) is helpful Strive for worst-case performance guarantees Average-case is better than nothing Identify fundamental abstraction Show me your code—you’ll have to explain your DS Show me your DS—I don’t need to see your code