# Union-Find Algorithms. network connectivity quick find quick union improvements applications

Save this PDF as:

Size: px
Start display at page:

## Transcription

1 Union-Find Algorithms network connectivity quick find quick union improvements applications 1

2 Subtext of today s lecture (and this course) Steps to developing a usable algorithm. Define the problem. Find an algorithm to solve it. Fast enough? If not, figure out why. Find a way to address the problem. Iterate until satisfied. The scientific method Mathematical models and computational complexity READ Chapter One of Algs in Java 2

3 network connectivity quick find quick union improvements applications 3

4 Network connectivity Basic abstractions set of objects union command: connect two objects find query: is there a path connecting one object to another? 4

5 Objects Union-find applications involve manipulating objects of all types. Computers in a network. Web pages on the Internet. Transistors in a computer chip. Variable name aliases. stay tuned Pixels in a digital photo. Metallic sites in a composite system. When programming, convenient to name them 0 to N-1. Hide details not relevant to union-find. Integers allow quick access to object-related info. Could use symbol table to translate from object names use as array index

6 Union-find abstractions Simple model captures the essential nature of connectivity. Objects grid points Disjoint sets of objects. 0 1 { } { 5 6 } 7 { 4 8 } subsets of connected grid points Find query: are objects 2 and 9 in the same set? 0 1 { } { 5-6 } 7 { 4-8 } are two grid points connected? Union command: merge sets containing 3 and { } { 5-6 } 7 add a connection between two grid points 6

7 Connected components Connected component: set of mutually connected vertices Each union command reduces by 1 the number of components in out = 10-7 components union commands 0 8 7

8 Network connectivity: larger example u find(u, v)? v 8

9 Network connectivity: larger example find(u, v)? true 63 components 9

10 Union-find abstractions Objects. Disjoint sets of objects. Find queries: are two objects in the same set? Union commands: replace sets containing two items by their union Goal. Design efficient data structure for union-find. Find queries and union commands may be intermixed. Number of operations M can be huge. Number of objects N can be huge. 10

11 network connectivity quick find quick union improvements applications 11

12 Quick-find [eager approach] Data structure. Integer array id[] of size N. Interpretation: p and q are connected if they have the same id. i id[i] and 6 are connected 2, 3, 4, and 9 are connected 12

13 Quick-find [eager approach] Data structure. Integer array id[] of size N. Interpretation: p and q are connected if they have the same id. i id[i] and 6 are connected 2, 3, 4, and 9 are connected Find. Check if p and q have the same id. id[3] = 9; id[6] = 6 3 and 6 not connected Union. To merge components containing p and q, change all entries with id[p] to id[q]. i id[i] union of 3 and 6 2, 3, 4, 5, 6, and 9 are connected problem: many values can change 13

14 Quick-find example problem: many values can change 14

15 Quick-find: Java implementation public class QuickFind { private int[] id; } public QuickFind(int N) { id = new int[n]; for (int i = 0; i < N; i++) id[i] = i; } public boolean find(int p, int q) { return id[p] == id[q]; } public void unite(int p, int q) { int pid = id[p]; for (int i = 0; i < id.length; i++) if (id[i] == pid) id[i] = id[q]; } set id of each object to itself 1 operation N operations 15

16 Quick-find is too slow Quick-find algorithm may take ~MN steps to process M union commands on N objects Rough standard (for now). 109 operations per second. 109 words of main memory. Touch all words in approximately 1 second. a truism (roughly) since 1950! Ex. Huge problem for quick-find edges connecting 10 9 nodes. Quick-find takes more than 1019 operations years of computer time! Paradoxically, quadratic algorithms get worse with newer equipment. New computer may be 10x as fast. But, has 10x as much memory so problem may be 10x bigger. With quadratic algorithm, takes 10x as long! 16

17 network connectivity quick find quick union improvements applications 17

18 Quick-union [lazy approach] Data structure. Integer array id[] of size N. Interpretation: id[i] is parent of i. Root of i is id[id[id[...id[i]...]]]. keep going until it doesn t change i id[i] 's root is 9; 5's root is 6 18

19 Quick-union [lazy approach] Data structure. Integer array id[] of size N. Interpretation: id[i] is parent of i. Root of i is id[id[id[...id[i]...]]]. keep going until it doesn t change i id[i] Find. Check if p and q have the same root Union. Set the id of q's root to the id of p's root. 3's root is 9; 5's root is 6 3 and 5 are not connected i id[i] only one value changes p 3 5 q 19

20 Quick-union example problem: trees can get tall 20

21 Quick-union: Java implementation public class QuickUnion { private int[] id; public QuickUnion(int N) { id = new int[n]; for (int i = 0; i < N; i++) id[i] = i; } private int root(int i) { while (i!= id[i]) i = id[i]; return i; } time proportional to depth of i } public boolean find(int p, int q) { return root(p) == root(q); } public void unite(int p, int q) { int i = root(p); int j = root(q); id[i] = j; } time proportional to depth of p and q time proportional to depth of p and q 21

22 Quick-union is also too slow Quick-find defect. Union too expensive (N steps). Trees are flat, but too expensive to keep them flat. Quick-union defect. Trees can get tall. Find too expensive (could be N steps) Need to do find to do union algorithm union find Quick-find N 1 Quick-union N* N worst case * includes cost of find 22

23 network connectivity quick find quick union improvements applications 23

24 Improvement 1: Weighting Weighted quick-union. Modify quick-union to avoid tall trees. Keep track of size of each component. Balance by linking small tree below large one. Ex. Union of 5 and 3. Quick union: link 9 to 6. Weighted quick union: link 6 to 9. size q 5 p 24

25 Weighted quick-union example no problem: trees stay flat 25

26 Weighted quick-union: Java implementation Java implementation. Almost identical to quick-union. Maintain extra array sz[] to count number of elements in the tree rooted at i. Find. Identical to quick-union. Union. Modify quick-union to merge smaller tree into larger tree update the sz[] array. 26

27 Weighted quick-union analysis Analysis. Find: takes time proportional to depth of p and q. Union: takes constant time, given roots. Fact: depth is at most lg N. [needs proof] Data Structure Union Find Quick-find N 1 Quick-union N * N Weighted QU lg N * lg N * includes cost of find Stop at guaranteed acceptable performance? No, easy to improve further. 27

28 Improvement 2: Path compression Path compression. Just after computing the root of i, set the id of each examined node to root(i) root(9)

29 Weighted quick-union with path compression Path compression. Standard implementation: add second loop to root() to set the id of each examined node to the root. Simpler one-pass variant: make every other node in path point to its grandparent. public int root(int i) { while (i!= id[i]) { id[i] = id[id[i]]; i = id[i]; } return i; } only one extra line of code! In practice. No reason not to! Keeps tree almost completely flat. 29

30 Weighted quick-union with path compression no problem: trees stay VERY flat 30

31 WQUPC performance Theorem. Starting from an empty data structure, any sequence of M union and find operations on N objects takes O(N + M lg* N) time. Proof is very difficult. But the algorithm is still simple! number of times needed to take the lg of a number until reaching 1 Linear algorithm? Cost within constant factor of reading in the data. In theory, WQUPC is not quite linear. In practice, WQUPC is linear. because lg* N is a constant in this universe N lg* N Amazing fact: In theory, no linear linking strategy exists 31

32 Summary Algorithm Quick-find Quick-union Weighted QU Path compression Weighted + path Worst-case time M N M N N + M log N N + M log N (M + N) lg* N M union-find ops on a set of N objects Ex. Huge practical problem edges connecting 10 9 nodes. WQUPC reduces time from 3,000 years to 1 minute. Supercomputer won't help much. Good algorithm makes solution possible. Bottom line. WQUPC makes it possible to solve problems that could not otherwise be addressed WQUPC on Java cell phone beats QF on supercomputer! 32

33 network connectivity quick find quick union improvements applications 33

34 Union-find applications Network connectivity. Percolation. Image processing. Least common ancestor. Equivalence of finite state automata. Hinley-Milner polymorphic type inference. Kruskal's minimum spanning tree algorithm. Games (Go, Hex) Compiling equivalence statements in Fortran. 34

35 Percolation A model for many physical systems N-by-N grid. Each square is vacant or occupied. Grid percolates if top and bottom are connected by vacant squares. percolates does not percolate model system vacant site occupied site percolates electricity material conductor insulated conducts fluid flow material empty blocked porous social interaction population person empty communicates 35

36 Percolation phase transition Likelihood of percolation depends on site vacancy probability p p low: does not percolate p high: percolates Experiments show a threshold p* p > p*: almost certainly percolates p < p*: almost certainly does not percolate Q. What is the value of p*? p* 36

37 UF solution to find percolation threshold Initialize whole grid to be not vacant Implement make site vacant operation that does union() with adjacent sites Make all sites on top and bottom rows vacant Make random sites vacant until find(top, bottom) Vacancy percentage estimates p* top vacant not vacant bottom 37

38 Percolation Q. What is percolation threshold p*? A. about for large square lattices. percolation constant known only via simulation percolates does not percolate Q. Why is UF solution better than solution in IntroProgramming 2.4? 38

39 Hex Hex. [Piet Hein 1942, John Nash 1948, Parker Brothers 1962] Two players alternate in picking a cell in a hex grid. Black: make a black path from upper left to lower right. White: make a white path from lower left to upper right. Reference: Union-find application. Algorithm to detect when a player has won. 39

40 Subtext of today s lecture (and this course) Steps to developing an usable algorithm. Define the problem. Find an algorithm to solve it. Fast enough? If not, figure out why. Find a way to address the problem. Iterate until satisfied. The scientific method Mathematical models and computational complexity READ Chapter One of Algs in Java 40

### Algorithms. Algorithms 1.5 UNION-FIND. dynamic connectivity quick find quick union improvements applications ROBERT SEDGEWICK KEVIN WAYNE

Algorithms ROBERT SEDGEWICK KEVIN WAYNE 1.5 UNION-FIND Algorithms F O U R T H E D I T I O N ROBERT SEDGEWICK KEVIN WAYNE dynamic connectivity quick find quick union improvements applications http://algs4.cs.princeton.edu

### The Union-Find Problem Kruskal s algorithm for finding an MST presented us with a problem in data-structure design. As we looked at each edge,

The Union-Find Problem Kruskal s algorithm for finding an MST presented us with a problem in data-structure design. As we looked at each edge, cheapest first, we had to determine whether its two endpoints

### Merge Sort. 2004 Goodrich, Tamassia. Merge Sort 1

Merge Sort 7 2 9 4 2 4 7 9 7 2 2 7 9 4 4 9 7 7 2 2 9 9 4 4 Merge Sort 1 Divide-and-Conquer Divide-and conquer is a general algorithm design paradigm: Divide: divide the input data S in two disjoint subsets

### Union-Find Problem. Using Arrays And Chains

Union-Find Problem Given a set {,,, n} of n elements. Initially each element is in a different set. ƒ {}, {},, {n} An intermixed sequence of union and find operations is performed. A union operation combines

### CSE 326, Data Structures. Sample Final Exam. Problem Max Points Score 1 14 (2x7) 2 18 (3x6) 3 4 4 7 5 9 6 16 7 8 8 4 9 8 10 4 Total 92.

Name: Email ID: CSE 326, Data Structures Section: Sample Final Exam Instructions: The exam is closed book, closed notes. Unless otherwise stated, N denotes the number of elements in the data structure

Lecture 10 Union-Find The union-nd data structure is motivated by Kruskal's minimum spanning tree algorithm (Algorithm 2.6), in which we needed two operations on disjoint sets of vertices: determine whether

### State Spaces Graph Search Searching. Graph Search. CPSC 322 Search 2. Textbook 3.4. Graph Search CPSC 322 Search 2, Slide 1

Graph Search CPSC 322 Search 2 Textbook 3.4 Graph Search CPSC 322 Search 2, Slide 1 Lecture Overview 1 State Spaces 2 Graph Search 3 Searching Graph Search CPSC 322 Search 2, Slide 2 State Spaces Idea:

### Priority Queues. Client, Implementation, Interface. Priority Queues. Abstract Data Types

Client, Implementation, Interface Priority Queues Priority Queue ADT Binary heaps Heapsort Reference: Chapter 6, Algorithms in Java, 3 rd Edition, Robert Sedgewick. Separate interface and implementation

### Data Structures Fibonacci Heaps, Amortized Analysis

Chapter 4 Data Structures Fibonacci Heaps, Amortized Analysis Algorithm Theory WS 2012/13 Fabian Kuhn Fibonacci Heaps Lacy merge variant of binomial heaps: Do not merge trees as long as possible Structure:

### 4.2 Sorting and Searching

Sequential Search: Java Implementation 4.2 Sorting and Searching Scan through array, looking for key. search hit: return array index search miss: return -1 public static int search(string key, String[]

### Lecture 7: Approximation via Randomized Rounding

Lecture 7: Approximation via Randomized Rounding Often LPs return a fractional solution where the solution x, which is supposed to be in {0, } n, is in [0, ] n instead. There is a generic way of obtaining

### Binary Heap Algorithms

CS Data Structures and Algorithms Lecture Slides Wednesday, April 5, 2009 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks CHAPPELLG@member.ams.org 2005 2009 Glenn G. Chappell

### Binary Search Trees. A Generic Tree. Binary Trees. Nodes in a binary search tree ( B-S-T) are of the form. P parent. Key. Satellite data L R

Binary Search Trees A Generic Tree Nodes in a binary search tree ( B-S-T) are of the form P parent Key A Satellite data L R B C D E F G H I J The B-S-T has a root node which is the only node whose parent

### Lecture Notes on Spanning Trees

Lecture Notes on Spanning Trees 15-122: Principles of Imperative Computation Frank Pfenning Lecture 26 April 26, 2011 1 Introduction In this lecture we introduce graphs. Graphs provide a uniform model

### Sorting revisited. Build the binary search tree: O(n^2) Traverse the binary tree: O(n) Total: O(n^2) + O(n) = O(n^2)

Sorting revisited How did we use a binary search tree to sort an array of elements? Tree Sort Algorithm Given: An array of elements to sort 1. Build a binary search tree out of the elements 2. Traverse

### Find-The-Number. 1 Find-The-Number With Comps

Find-The-Number 1 Find-The-Number With Comps Consider the following two-person game, which we call Find-The-Number with Comps. Player A (for answerer) has a number x between 1 and 1000. Player Q (for questioner)

### Motivation Suppose we have a database of people We want to gure out who is related to whom Initially, we only have a list of people, and information a

CSE 220: Handout 29 Disjoint Sets 1 Motivation Suppose we have a database of people We want to gure out who is related to whom Initially, we only have a list of people, and information about relations

### Parallelization: Binary Tree Traversal

By Aaron Weeden and Patrick Royal Shodor Education Foundation, Inc. August 2012 Introduction: According to Moore s law, the number of transistors on a computer chip doubles roughly every two years. First

### Discrete Mathematics (2009 Spring) Induction and Recursion (Chapter 4, 3 hours)

Discrete Mathematics (2009 Spring) Induction and Recursion (Chapter 4, 3 hours) Chih-Wei Yi Dept. of Computer Science National Chiao Tung University April 17, 2009 4.1 Mathematical Induction 4.1 Mathematical

### A binary heap is a complete binary tree, where each node has a higher priority than its children. This is called heap-order property

CmSc 250 Intro to Algorithms Chapter 6. Transform and Conquer Binary Heaps 1. Definition A binary heap is a complete binary tree, where each node has a higher priority than its children. This is called

### Sorting algorithms. Mergesort and Quicksort. Merge Sort. Partitioning Choice 1. Partitioning Choice 3. Partitioning Choice 2 2/5/2015

Sorting algorithms Mergesort and Quicksort Insertion, selection and bubble sort have quadratic worst case performance The faster comparison based algorithm? O(nlogn) Mergesort and Quicksort Merge Sort

### Persistent Data Structures

6.854 Advanced Algorithms Lecture 2: September 9, 2005 Scribes: Sommer Gentry, Eddie Kohler Lecturer: David Karger Persistent Data Structures 2.1 Introduction and motivation So far, we ve seen only ephemeral

### Symbol Tables. IE 496 Lecture 13

Symbol Tables IE 496 Lecture 13 Reading for This Lecture Horowitz and Sahni, Chapter 2 Symbol Tables and Dictionaries A symbol table is a data structure for storing a list of items, each with a key and

### (Refer Slide Time: 01:35)

Artificial Intelligence Prof. Sudeshna Sarkar Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture - 6 Informed Search -2 Today we start our 6 th lecture. This

### Algorithms 2/17/2015. Double Summations. Enough Mathematical Appetizers! Algorithms. Algorithms. Algorithm Examples. Algorithm Examples

Double Summations Table 2 in 4 th Edition: Section 1.7 5 th Edition: Section.2 6 th and 7 th Edition: Section 2.4 contains some very useful formulas for calculating sums. Enough Mathematical Appetizers!

### Parallelization of a "Masyu" Puzzle solver

John Lilley Parallelization of a "Masyu" Puzzle solver The "Masyu" (aka "Pearls") puzzle consists of a rectangular board divided into rows and columns, on which a number of white and black "pearls" are

### Cpt S 223. School of EECS, WSU

Priority Queues (Heaps) 1 Motivation Queues are a standard mechanism for ordering tasks on a first-come, first-served basis However, some tasks may be more important or timely than others (higher priority)

### Picture Maze Generation by Successive Insertion of Path Segment

1 2 3 Picture Maze Generation by Successive Insertion of Path Segment 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32. ABSTRACT Tomio Kurokawa 1* 1 Aichi Institute of Technology,

### Data Structure. Lecture 3

Data Structure Lecture 3 Data Structure Formally define Data structure as: DS describes not only set of objects but the ways they are related, the set of operations which may be applied to the elements

### Binary Trees and Huffman Encoding Binary Search Trees

Binary Trees and Huffman Encoding Binary Search Trees Computer Science E119 Harvard Extension School Fall 2012 David G. Sullivan, Ph.D. Motivation: Maintaining a Sorted Collection of Data A data dictionary

### 6.080 / 6.089 Great Ideas in Theoretical Computer Science Spring 2008

MIT OpenCourseWare http://ocw.mit.edu 6.080 / 6.089 Great Ideas in Theoretical Computer Science Spring 2008 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.

### Faster deterministic integer factorisation

David Harvey (joint work with Edgar Costa, NYU) University of New South Wales 25th October 2011 The obvious mathematical breakthrough would be the development of an easy way to factor large prime numbers

### Small Maximal Independent Sets and Faster Exact Graph Coloring

Small Maximal Independent Sets and Faster Exact Graph Coloring David Eppstein Univ. of California, Irvine Dept. of Information and Computer Science The Exact Graph Coloring Problem: Given an undirected

### CSC 143. Two important problems. Searching and Sorting. Review: Linear Search. Example. Review: Binary Search. How Efficient Is Linear Search?

CSC 43 Searching and Sorting [Chapter 9, pp. 402-432] Two important problems Search: finding something in a set of data Sorting: putting a set of data in order Both very common, very useful operations

### Notes on Matrix Multiplication and the Transitive Closure

ICS 6D Due: Wednesday, February 25, 2015 Instructor: Sandy Irani Notes on Matrix Multiplication and the Transitive Closure An n m matrix over a set S is an array of elements from S with n rows and m columns.

### Guessing Game: NP-Complete?

Guessing Game: NP-Complete? 1. LONGEST-PATH: Given a graph G = (V, E), does there exists a simple path of length at least k edges? YES 2. SHORTEST-PATH: Given a graph G = (V, E), does there exists a simple

### Balanced Trees Part One

Balanced Trees Part One Balanced Trees Balanced trees are surprisingly versatile data structures. Many programming languages ship with a balanced tree library. C++: std::map / std::set Java: TreeMap /

### Lecture 15 An Arithmetic Circuit Lowerbound and Flows in Graphs

CSE599s: Extremal Combinatorics November 21, 2011 Lecture 15 An Arithmetic Circuit Lowerbound and Flows in Graphs Lecturer: Anup Rao 1 An Arithmetic Circuit Lower Bound An arithmetic circuit is just like

### Introduction to Algorithms. Part 3: P, NP Hard Problems

Introduction to Algorithms Part 3: P, NP Hard Problems 1) Polynomial Time: P and NP 2) NP-Completeness 3) Dealing with Hard Problems 4) Lower Bounds 5) Books c Wayne Goddard, Clemson University, 2004 Chapter

### Lecture 6 Online and streaming algorithms for clustering

CSE 291: Unsupervised learning Spring 2008 Lecture 6 Online and streaming algorithms for clustering 6.1 On-line k-clustering To the extent that clustering takes place in the brain, it happens in an on-line

### Random-Turn Hex and Other Selection Games

Random-Turn Hex and Other Selection Games Yu-Han Lyu March 10, 2011 Abstract In this report, we summarize the results in [6]. We define a mathematical formulation for all selection games. When considering

### CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis. Linda Shapiro Winter 2015

CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis Linda Shapiro Today Registration should be done. Homework 1 due 11:59 pm next Wednesday, January 14 Review math essential

### ! Insert a value with specified key. ! Search for value given key. ! Delete value with given key. ! O(log N) time per op.

Symbol Table Review 4.4 Balanced Trees Symbol table: key-value pair abstraction.! a value with specified key.! for value given key.! value with given key. Randomized BST.! O(log ) time per op. unless you

### A. V. Gerbessiotis CS Spring 2014 PS 3 Mar 24, 2014 No points

A. V. Gerbessiotis CS 610-102 Spring 2014 PS 3 Mar 24, 2014 No points Problem 1. Suppose that we insert n keys into a hash table of size m using open addressing and uniform hashing. Let p(n, m) be the

### Discrete Mathematics Lecture 5. Harper Langston New York University

Discrete Mathematics Lecture 5 Harper Langston New York University Empty Set S = {x R, x 2 = -1} X = {1, 3}, Y = {2, 4}, C = X Y (X and Y are disjoint) Empty set has no elements Empty set is a subset of

### Euclidean Minimum Spanning Trees Based on Well Separated Pair Decompositions Chaojun Li. Advised by: Dave Mount. May 22, 2014

Euclidean Minimum Spanning Trees Based on Well Separated Pair Decompositions Chaojun Li Advised by: Dave Mount May 22, 2014 1 INTRODUCTION In this report we consider the implementation of an efficient

### Minimum Spanning Trees

Minimum Spanning Trees Algorithms and 18.304 Presentation Outline 1 Graph Terminology Minimum Spanning Trees 2 3 Outline Graph Terminology Minimum Spanning Trees 1 Graph Terminology Minimum Spanning Trees

### Binary Heaps * * * * * * * / / \ / \ / \ / \ / \ * * * * * * * * * * * / / \ / \ / / \ / \ * * * * * * * * * *

Binary Heaps A binary heap is another data structure. It implements a priority queue. Priority Queue has the following operations: isempty add (with priority) remove (highest priority) peek (at highest

### Why Use Binary Trees?

Binary Search Trees Why Use Binary Trees? Searches are an important application. What other searches have we considered? brute force search (with array or linked list) O(N) binarysearch with a pre-sorted

### Balanced Trees trees red-black trees B-trees. References: Algorithms in Java, Chapter 13.

Balanced Trees 2-3-4 trees red-black trees B-trees References: Algorithms in Java, Chapter 13 http://www.cs.princeton.edu/introalgsds/44balanced 1 Symbol Table Review Symbol table: key-value pair abstraction.

### String Search. Brute force Rabin-Karp Knuth-Morris-Pratt Right-Left scan

String Search Brute force Rabin-Karp Knuth-Morris-Pratt Right-Left scan String Searching Text with N characters Pattern with M characters match existence: any occurence of pattern in text? enumerate: how

### 1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

Answer the following 1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++ 2) Which data structure is needed to convert infix notations to postfix notations? Stack 3) The

### CS112 Lecture: Searching and Sorting

CS112 Lecture: Searching and Sorting Objectives: 1. To introduce the linear search algorithm. 2. To introduce the binary search algorithm. 3. To show superiority of O(log n) vs O(n) 4. To take note of

### SAMPLES OF HIGHER RATED WRITING: LAB 5

SAMPLES OF HIGHER RATED WRITING: LAB 5 1. Task Description Lab report 5. (April 14) Graph Coloring. Following the guidelines, and keeping in mind the assessment criteria, using where appropriate experimental

### Introduction to Algorithms Review information for Prelim 1 CS 4820, Spring 2010 Distributed Wednesday, February 24

Introduction to Algorithms Review information for Prelim 1 CS 4820, Spring 2010 Distributed Wednesday, February 24 The final exam will cover seven topics. 1. greedy algorithms 2. divide-and-conquer algorithms

### Computing basics. Ruurd Kuiper

Computing basics Ruurd Kuiper October 29, 2009 Overview (cf Schaum Chapter 1) Basic computing science is about using computers to do things for us. These things amount to processing data. The way a computer

### Data Structures. Jaehyun Park. CS 97SI Stanford University. June 29, 2015

Data Structures Jaehyun Park CS 97SI Stanford University June 29, 2015 Typical Quarter at Stanford void quarter() { while(true) { // no break :( task x = GetNextTask(tasks); process(x); // new tasks may

### Efficiency of algorithms. Algorithms. Efficiency of algorithms. Binary search and linear search. Best, worst and average case.

Algorithms Efficiency of algorithms Computational resources: time and space Best, worst and average case performance How to compare algorithms: machine-independent measure of efficiency Growth rate Complexity

### A COOL AND PRACTICAL ALTERNATIVE TO TRADITIONAL HASH TABLES

A COOL AND PRACTICAL ALTERNATIVE TO TRADITIONAL HASH TABLES ULFAR ERLINGSSON, MARK MANASSE, FRANK MCSHERRY MICROSOFT RESEARCH SILICON VALLEY MOUNTAIN VIEW, CALIFORNIA, USA ABSTRACT Recent advances in the

### Cost Model: Work, Span and Parallelism. 1 The RAM model for sequential computation:

CSE341T 08/31/2015 Lecture 3 Cost Model: Work, Span and Parallelism In this lecture, we will look at how one analyze a parallel program written using Cilk Plus. When we analyze the cost of an algorithm

### Analysis of Computer Algorithms. Algorithm. Algorithm, Data Structure, Program

Analysis of Computer Algorithms Hiroaki Kobayashi Input Algorithm Output 12/13/02 Algorithm Theory 1 Algorithm, Data Structure, Program Algorithm Well-defined, a finite step-by-step computational procedure

### Chapter 6: Programming Languages

Chapter 6: Programming Languages Computer Science: An Overview Eleventh Edition by J. Glenn Brookshear Copyright 2012 Pearson Education, Inc. Chapter 6: Programming Languages 6.1 Historical Perspective

### root node level: internal node edge leaf node CS@VT Data Structures & Algorithms 2000-2009 McQuain

inary Trees 1 A binary tree is either empty, or it consists of a node called the root together with two binary trees called the left subtree and the right subtree of the root, which are disjoint from each

### Pseudocode Analysis. COMP3600/6466 Algorithms Lecture 5. Recursive Algorithms. Asymptotic Bounds for Recursions

COMP600/6466 Algorithms Lecture 5 Pseudocode Analysis Iterative Recursive S 0 Dr. Hassan Hijazi Prof. Weifa Liang Recursive Algorithms Asymptotic Bounds for Recursions Total running time = Sum of times

### Data Structure with C

Subject: Data Structure with C Topic : Tree Tree A tree is a set of nodes that either:is empty or has a designated node, called the root, from which hierarchically descend zero or more subtrees, which

### 5.1 Bipartite Matching

CS787: Advanced Algorithms Lecture 5: Applications of Network Flow In the last lecture, we looked at the problem of finding the maximum flow in a graph, and how it can be efficiently solved using the Ford-Fulkerson

### 12 Abstract Data Types

12 Abstract Data Types 12.1 Source: Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: Define the concept of an abstract data type (ADT).

### Labworks 1: Binary Search Trees and Red-Black trees

Labworks 1: Binary Search Trees and Red-Black trees October 12, 2016 Deadline for these labworks: October 26 2016 How? Make an archive with the source files of your implementation, and send it by email

### 2 Exercises and Solutions

2 Exercises and Solutions Most of the exercises below have solutions but you should try first to solve them. Each subsection with solutions is after the corresponding subsection with exercises. 2.1 Sorting

### Why? A central concept in Computer Science. Algorithms are ubiquitous.

Analysis of Algorithms: A Brief Introduction Why? A central concept in Computer Science. Algorithms are ubiquitous. Using the Internet (sending email, transferring files, use of search engines, online

### Vector storage and access; algorithms in GIS. This is lecture 6

Vector storage and access; algorithms in GIS This is lecture 6 Vector data storage and access Vectors are built from points, line and areas. (x,y) Surface: (x,y,z) Vector data access Access to vector

### 1. What s wrong with the following proofs by induction?

ArsDigita University Month : Discrete Mathematics - Professor Shai Simonson Problem Set 4 Induction and Recurrence Equations Thanks to Jeffrey Radcliffe and Joe Rizzo for many of the solutions. Pasted

### Outline. NP-completeness. When is a problem easy? When is a problem hard? Today. Euler Circuits

Outline NP-completeness Examples of Easy vs. Hard problems Euler circuit vs. Hamiltonian circuit Shortest Path vs. Longest Path 2-pairs sum vs. general Subset Sum Reducing one problem to another Clique

### CS/COE 1501 http://cs.pitt.edu/~bill/1501/

CS/COE 1501 http://cs.pitt.edu/~bill/1501/ Lecture 01 Course Introduction Meta-notes These notes are intended for use by students in CS1501 at the University of Pittsburgh. They are provided free of charge

### Binary Search Trees. basic implementations randomized BSTs deletion in BSTs

Binary Search Trees basic implementations randomized BSTs deletion in BSTs eferences: Algorithms in Java, Chapter 12 Intro to Programming, Section 4.4 http://www.cs.princeton.edu/introalgsds/43bst 1 Elementary

### HY345 Operating Systems

HY345 Operating Systems Recitation 2 - Memory Management Solutions Panagiotis Papadopoulos panpap@csd.uoc.gr Problem 7 Consider the following C program: int X[N]; int step = M; //M is some predefined constant

### 1.4 Arrays Introduction to Programming in Java: An Interdisciplinary Approach Robert Sedgewick and Kevin Wayne Copyright 2002 2010 2/6/11 12:33 PM!

1.4 Arrays Introduction to Programming in Java: An Interdisciplinary Approach Robert Sedgewick and Kevin Wayne Copyright 2002 2010 2/6/11 12:33 PM! A Foundation for Programming any program you might want

### Announcements. CSE332: Data Abstractions. Lecture 9: B Trees. Today. Our goal. M-ary Search Tree. M-ary Search Tree. Ruth Anderson Winter 2011

Announcements CSE2: Data Abstractions Project 2 posted! Partner selection due by 11pm Tues 1/25 at the latest. Homework due Friday Jan 28 st at the BEGINNING of lecture Lecture 9: B Trees Ruth Anderson

### Data Structures. Algorithm Performance and Big O Analysis

Data Structures Algorithm Performance and Big O Analysis What s an Algorithm? a clearly specified set of instructions to be followed to solve a problem. In essence: A computer program. In detail: Defined

### CMPS 102 Solutions to Homework 1

CMPS 0 Solutions to Homework Lindsay Brown, lbrown@soe.ucsc.edu September 9, 005 Problem..- p. 3 For inputs of size n insertion sort runs in 8n steps, while merge sort runs in 64n lg n steps. For which

### Minimum Spanning Trees

Minimum Spanning Trees weighted graph API cycles and cuts Kruskal s algorithm Prim s algorithm advanced topics References: Algorithms in Java, Chapter 20 http://www.cs.princeton.edu/introalgsds/54mst 1

### A GUI Crawling-based technique for Android Mobile Application Testing

3th International Workshop on TESTing Techniques & Experimentation Benchmarks for Event-Driven Software Berlin, Germany March 21, 2011 A GUI Crawling-based technique for Android Mobile Application Testing

### 1. Sorting (assuming sorting into ascending order) a) BUBBLE SORT

DECISION 1 Revision Notes 1. Sorting (assuming sorting into ascending order) a) BUBBLE SORT Make sure you show comparisons clearly and label each pass First Pass 8 4 3 6 1 4 8 3 6 1 4 3 8 6 1 4 3 6 8 1

### Notes on Complexity Theory Last updated: August, 2011. Lecture 1

Notes on Complexity Theory Last updated: August, 2011 Jonathan Katz Lecture 1 1 Turing Machines I assume that most students have encountered Turing machines before. (Students who have not may want to look

### COLORED GRAPHS AND THEIR PROPERTIES

COLORED GRAPHS AND THEIR PROPERTIES BEN STEVENS 1. Introduction This paper is concerned with the upper bound on the chromatic number for graphs of maximum vertex degree under three different sets of coloring

### Compiler Construction

Compiler Construction Regular expressions Scanning Görel Hedin Reviderad 2013 01 23.a 2013 Compiler Construction 2013 F02-1 Compiler overview source code lexical analysis tokens intermediate code generation

### More Mathematical Induction. October 27, 2016

More Mathematical Induction October 7, 016 In these slides... Review of ordinary induction. Remark about exponential and polynomial growth. Example a second proof that P(A) = A. Strong induction. Least

### Advice Complexity of Online Coloring for Paths

Advice Complexity of Online Coloring for Paths Michal Forišek 1, Lucia Keller 2, and Monika Steinová 2 1 Comenius University, Bratislava, Slovakia 2 ETH Zürich, Switzerland LATA 2012, A Coruña, Spain Definition

### Data Warehousing und Data Mining

Data Warehousing und Data Mining Multidimensionale Indexstrukturen Ulf Leser Wissensmanagement in der Bioinformatik Content of this Lecture Multidimensional Indexing Grid-Files Kd-trees Ulf Leser: Data

### Algorithms. Theresa Migler-VonDollen CMPS 5P

Algorithms Theresa Migler-VonDollen CMPS 5P 1 / 32 Algorithms Write a Python function that accepts a list of numbers and a number, x. If x is in the list, the function returns the position in the list

### Full and Complete Binary Trees

Full and Complete Binary Trees Binary Tree Theorems 1 Here are two important types of binary trees. Note that the definitions, while similar, are logically independent. Definition: a binary tree T is full

### Graph. Consider a graph, G in Fig Then the vertex V and edge E can be represented as:

Graph A graph G consist of 1. Set of vertices V (called nodes), (V = {v1, v2, v3, v4...}) and 2. Set of edges E (i.e., E {e1, e2, e3...cm} A graph can be represents as G = (V, E), where V is a finite and

### School of Informatics, University of Edinburgh Computer Science 1 Ah [03 04]

School of Informatics, University of Edinburgh Computer Science 1 Ah [03 04] CS1Ah Lecture Note 25 Binary Search Trees This lecture studies binary trees in more detail, in particular their application

### Ordered Lists and Binary Trees

Data Structures and Algorithms Ordered Lists and Binary Trees Chris Brooks Department of Computer Science University of San Francisco Department of Computer Science University of San Francisco p.1/62 6-0:

### CS473 - Algorithms I

CS473 - Algorithms I Lecture 4 The Divide-and-Conquer Design Paradigm View in slide-show mode 1 Reminder: Merge Sort Input array A sort this half sort this half Divide Conquer merge two sorted halves Combine

### ! Overview! Measures of Query Cost! Selection Operation! Sorting! Join Operation! Other Operations! Evaluation of Expressions

Chapter 13: Query Processing Chapter 13: Query Processing! Overview! Measures of Query Cost! Selection Operation! Sorting! Join Operation! Other Operations! Evaluation of Expressions Basic Steps in Query

### 6 March 2007 1. Array Implementation of Binary Trees

Heaps CSE 0 Winter 00 March 00 1 Array Implementation of Binary Trees Each node v is stored at index i defined as follows: If v is the root, i = 1 The left child of v is in position i The right child of

### The Selection Problem

The Selection Problem The selection problem: given an integer k and a list x 1,..., x n of n elements find the k-th smallest element in the list Example: the 3rd smallest element of the following list

### COS 226 Algorithms and Data Structures Fall Final

COS 22 Algorithms and Data Structures Fall 200 Final This test has 4 questions worth a total of 00 points. You have 80 minutes. The exam is closed book, except that you are allowed to use a one page cheatsheet

### Lecture 4: BK inequality 27th August and 6th September, 2007

CSL866: Percolation and Random Graphs IIT Delhi Amitabha Bagchi Scribe: Arindam Pal Lecture 4: BK inequality 27th August and 6th September, 2007 4. Preliminaries The FKG inequality allows us to lower bound