CSE 548: Analysis of Algorithms. Lectures 14 & 15 ( Dijkstra s SSSP & Fibonacci Heaps )

Size: px
Start display at page:

Download "CSE 548: Analysis of Algorithms. Lectures 14 & 15 ( Dijkstra s SSSP & Fibonacci Heaps )"

Transcription

1 CSE 548: Analysis of Algorithms Lectures 14 & 15 ( Dijkstra s SSSP & Fibonacci Heaps ) Rezaul A. Chowdhury Department of Computer Science SUNY Stony Brook Fall 2012

2 Fibonacci Heaps ( Fredman & Tarjan, 1984 ) A Fibonacci heapcan be viewed as an extension of Binomial heaps which supports DECREASE-KEY and DELETE operations efficiently. Heap Operation Binary Heap ( worst-case ) Binomial Heap ( amortized) MAKE-HEAP Θ 1 Θ 1 INSERT Ο log Θ 1 MINIMUM Θ 1 Θ 1 EXTRACT-MIN Ο log Ο log UNION Θ Θ 1 DECREASE-KEY Ο log DELETE Ο log

3 Fibonacci Heaps ( Fredman & Tarjan, 1984 ) A Fibonacci heapcan be viewed as an extension of Binomial heaps which supports DECREASE-KEY and DELETE operations efficiently. Heap Operation Binary Heap ( worst-case ) Binomial Heap ( amortized) MAKE-HEAP Θ 1 Θ 1 INSERT Ο log Θ 1 MINIMUM Θ 1 Θ 1 EXTRACT-MIN Ο log Ο log UNION Θ Θ 1 DECREASE-KEY DELETE Ο log Ο log Ο log ( worst case ) Ο log ( worst case )

4 Fibonacci Heaps ( Fredman & Tarjan, 1984 ) A Fibonacci heapcan be viewed as an extension of Binomial heaps which supports DECREASE-KEY and DELETE operations efficiently. Heap Operation Binary Heap ( worst-case ) Binomial Heap ( amortized) Fibonacci Heap ( amortized ) MAKE-HEAP Θ 1 Θ 1 Θ 1 INSERT Ο log Θ 1 Θ 1 MINIMUM Θ 1 Θ 1 Θ 1 EXTRACT-MIN Ο log Ο log Ο log UNION Θ Θ 1 Θ 1 DECREASE-KEY Ο log Ο log ( worst case ) Θ 1 DELETE Ο log Ο log ( worst case ) Ο log

5 Dijkstra s SSSP Algorithm with a Min-Heap ( SSSP: Single-Source Shortest Paths ) Input:Weighted graph, with vertex set and edge set, a weight function, and a source vertex. Output: For all,. is set to the shortest distance from to. Dijkstra-SSSP (,,, ) 1. for each do { empty min-heap } 4. for each do INSERT(, ) 5. while do 6. EXTRACT-MIN( ) 7. for each do 8. if.., then 9. DECREASE-KEY(,,., ) 10...,

6 Dijkstra s SSSP Algorithm with a Min-Heap ( SSSP: Single-Source Shortest Paths ) Input:Weighted graph, with vertex set and edge set, a weight function, and a source vertex. Output: For all,. is set to the shortest distance from to. Dijkstra-SSSP (,,, ) 1. for each do { empty min-heap } 4. for each do INSERT(, ) 5. while do 6. EXTRACT-MIN( ) 7. for each do 8. if.., then 9. DECREASE-KEY(,,., ) 10..., Let and # INSERTS # EXTRACT-MINS # DECREASE-KEYS Total cost

7 Dijkstra s SSSP Algorithm with a Min-Heap ( SSSP: Single-Source Shortest Paths ) Input:Weighted graph, with vertex set and edge set, a weight function, and a source vertex. Output: For all,. is set to the shortest distance from to. Dijkstra-SSSP (,,, ) 1. for each do { empty min-heap } 4. for each do INSERT(, ) 5. while do 6. EXTRACT-MIN( ) 7. for each do 8. if.., then 9. DECREASE-KEY(,,., ) 10..., Let and For Binary Heap ( worst-case costs ): Ο log Ο log Ο log Total cost ( worst-case ) Ο log

8 Dijkstra s SSSP Algorithm with a Min-Heap ( SSSP: Single-Source Shortest Paths ) Input:Weighted graph, with vertex set and edge set, a weight function, and a source vertex. Output: For all,. is set to the shortest distance from to. Dijkstra-SSSP (,,, ) 1. for each do { empty min-heap } 4. for each do INSERT(, ) 5. while do 6. EXTRACT-MIN( ) 7. for each do 8. if.., then 9. DECREASE-KEY(,,., ) 10..., Let and For Binomial Heap ( amortized costs ): Ο 1 Ο log Ο log ( worst-case ) Total cost ( worst-case ) Ο log

9 Dijkstra s SSSP Algorithm with a Min-Heap ( SSSP: Single-Source Shortest Paths ) Input:Weighted graph, with vertex set and edge set, a weight function, and a source vertex. Output: For all,. is set to the shortest distance from to. Dijkstra-SSSP (,,, ) 1. for each do { empty min-heap } 4. for each do INSERT(, ) 5. while do 6. EXTRACT-MIN( ) 7. for each do 8. if.., then 9. DECREASE-KEY(,,., ) 10..., Let and Total cost Observation: Obtaining a worst-case bound for a sequence of INSERTS, EXTRACT-MINS and DECREASE-KEYSis enough. Amortized bound per operation is sufficient.

10 Dijkstra s SSSP Algorithm with a Min-Heap ( SSSP: Single-Source Shortest Paths ) Input:Weighted graph, with vertex set and edge set, a weight function, and a source vertex. Output: For all,. is set to the shortest distance from to. Dijkstra-SSSP (,,, ) 1. for each do { empty min-heap } 4. for each do INSERT(, ) 5. while do 6. EXTRACT-MIN( ) 7. for each do 8. if.., then 9. DECREASE-KEY(,,., ) 10..., Let and Total cost Observation: For the best possible bound is Θ log. ( else violates sorting lower bound ) Perhaps can be improved to o log.

11 Fibonacci Heaps from Binomial Heaps A Fibonacci heapcan be viewed as an extension of Binomial heaps which supports DECREASE-KEY and DELETE operations efficiently. But the trees in a Fibonacci heap are no longer binomial trees as we will be cutting subtrees out of them. However, all operations ( except DECREASE-KEYand DELETE) are still performed in the same way as in binomial heaps. The rankof a tree is still defined as the number of children of the root, and we still link two trees if they have the same rank.

12 Implementing DECREASE-KEY,, DECREASE-KEY(,, ): One possible approach is to cut out the subtreerooted at from, reduce the value of to, and insert that subtreeinto the root list of. Problem: If we cut out a lot of subtreesfrom a tree its size will no longer be exponential in its rank. Since our analysis of EXTRACT-MINin binomial heaps was highly dependent on this exponential relationship, that analysis will no longer hold. Solution: Limit #cuts among the children of any node to 2. We will show that the size of each tree will still remain exponential in its rank. When a 2nd child is cut from a node, we also cut from its parent leading to a possible sequence of cuts moving up towards the root.

13 Analysis of Fibonacci Heap Operations Recurrence for Fibonacci numbers: 0 0, 1 1,. We showed in a pervious lecture:, where and are the roots 1 0.

14 Analysis of Fibonacci Heap Operations Lemma 1:For all integers 0, 1. Proof:By induction on. Base case: Inductive hypothesis: 1 for 0 1. Then 1 1.

15 Analysis of Fibonacci Heap Operations Lemma 2:For all integers 0,. Proof:By induction on. Base case: 1 and 2. Inductive hypothesis: for 0 1. Then 1

16 Analysis of Fibonacci Heap Operations Lemma 3:Let be any node in a Fibonacci heap, and suppose that. Let,,, be the children of in the order in which they were linked to, from the earliest to the latest. Then max 0, 2 for 1. Proof:Obviously, 0. For 1, when was linked to, all of,,, were children of. So, 1. Because is linked to only if, we must have had 1at that time. Since then, has lost at most one child, and hence 2.

17 Analysis of Fibonacci Heap Operations Lemma 4:Let be any node in a Fibonacci heap with and. Then log. Proof:Let be the minimum possible size of any node of rank in any Fibonacci heap. Trivially, 1and 2. Since adding children to a node cannot decrease its size, increases monotonically with. Let be a node in any Fibonacci heap with and.

18 Analysis of Fibonacci Heap Operations Lemma 4:Let be any node in a Fibonacci heap with and. Then log. Proof ( continued ):Let,,, be the children of in the order in which they were linked to, from the earliest to the latest. Then 1 1, 2 We now show by induction on that for all integer 0. Base case: 1 and 2. Inductive hypothesis: for 0 1. Then 2 Hence log. 2 1.

19 Analysis of Fibonacci Heap Operations Corollary:The maximum degree of any node in an node Fibonacci heap is Ο log. Proof:Let be any node in the heap. Then from Lemma 4, log log Ο log.

20 Analysis of Fibonacci Heap Operations All nodes are initially unmarked. We mark a node when it loses its first child We unmark a node when it loses its second child, or becomes the child of another node ( e.g., LINKed ) We extend the potential function used for binomial heaps: Φ 2 3, where is the state of the data structure after the operation, is the number of trees in the root list, and is the number of marked nodes.

21 Analysis of Fibonacci Heap Operations We extend the potential function used for binomial heaps: Φ 2 3, where is the state of the data structure after the operation, is the number of trees in the root list, and is the number of marked nodes. DECREASE-KEY(,, ):Let #cascading cuts performed. Then the actual cost of cutting the tree rooted at is 1, and the actual cost of each of the cascading cuts is also 1. overall actual cost, 1

22 Fibonacci Heaps from Binomial Heaps Potential function: Φ 2 3 DECREASE-KEY(,, ): New trees: 1 tree rooted at, and 1 tree produced by each of the cascading cuts. 1 Marked nodes: 1 node unmarked by each cascading cut, and at most 1 node marked by the last cut/cascading cut. 1 Potential drop, Δ Φ Φ

23 Fibonacci Heaps from Binomial Heaps Potential function: Φ 2 3 DECREASE-KEY(,, ): Amortized cost, Δ Ο 1

24 Fibonacci Heaps from Binomial Heaps Potential function: Φ 2 3 EXTRACT-MIN( ): Let be the max degree of any node in an -node Fibonacci heap. Cost of creating the array of pointers is 1. Suppose we start with trees in the doubly linked list, and perform link operations during the conversion from linked list to array version. So we perform work, and end up with trees. Cost of converting to the linked list version is. actual cost, Since no node is marked, and each link reduces the #trees by 1, potential change, Δ Φ Φ 2

25 Fibonacci Heaps from Binomial Heaps Potential function: Φ 2 3 EXTRACT-MIN( ): actual cost, potential change, Δ Φ Φ 2 amortized cost, Δ 2 1 But 1 ( as we have at most one tree of each rank ) So, 3 3 Ο log.

26 Fibonacci Heaps from Binomial Heaps Potential function: Φ 2 3 DELETE(, ): STEP1:DECREASE-KEY(,, ) STEP2:EXTRACT-MIN( ) amortized cost, amortized cost of DECREASE-KEY amortized cost of EXTRACT-MIN Ο 1 Ο log Ο log

Fibonacci Heaps. Structure. Implementation. Implementation. Delete Min. Delete Min. Set of min-heap ordered trees min

Fibonacci Heaps. Structure. Implementation. Implementation. Delete Min. Delete Min. Set of min-heap ordered trees min Algorithms Fibonacci Heaps -2 Structure Set of -heap ordered trees Fibonacci Heaps 1 Some nodes marked. H Data Structures and Algorithms Andrei Bulatov Algorithms Fibonacci Heaps - Algorithms Fibonacci

More information

W4231: Analysis of Algorithms

W4231: Analysis of Algorithms W4231: Analysis of Algorithms From Binomial Heaps to Fibonacci Heaps Fibonacci Heaps 10/7/1999 We first prove that in Binomial Heaps insert and find-min take amortized O(1) time, while still having insert,

More information

Priority Queues. Meld(Q 1,Q 2 ) merge two sets

Priority Queues. Meld(Q 1,Q 2 ) merge two sets Priority Queues MakeQueue Insert(Q,k,p) Delete(Q,k) DeleteMin(Q) Meld(Q 1,Q 2 ) Empty(Q) Size(Q) FindMin(Q) create new empty queue insert key k with priority p delete key k (given a pointer) delete key

More information

Chapter 5 Data Structures Algorithm Theory WS 2016/17 Fabian Kuhn

Chapter 5 Data Structures Algorithm Theory WS 2016/17 Fabian Kuhn Chapter 5 Data Structures Algorithm Theory WS 06/ Fabian Kuhn Examples Dictionary: Operations: insert(key,value), delete(key), find(key) Implementations: Linked list: all operations take O(n) time (n:

More information

Analysis of Algorithms

Analysis of Algorithms Analysis of Algorithms Concept Exam Code: 16 All questions are weighted equally. Assume worst case behavior and sufficiently large input sizes unless otherwise specified. Strong induction Consider this

More information

Algorithm Theory, Winter Term 2015/16 Problem Set 5 - Sample Solution

Algorithm Theory, Winter Term 2015/16 Problem Set 5 - Sample Solution Albert-Ludwigs-Universität, Inst. für Informatik Prof. Dr. Fabian Kuhn M. Ahmadi, O. Saukh, A. R. Molla November, 20 Algorithm Theory, Winter Term 20/6 Problem Set - Sample Solution Exercise : Amortized

More information

CS711008Z Algorithm Design and Analysis

CS711008Z Algorithm Design and Analysis CS711008Z Algorithm Design and Analysis Lecture 7. Binary heap, binomial heap, and Fibonacci heap Dongbo Bu Institute of Computing Technology Chinese Academy of Sciences, Beijing, China 1 / 108 Outline

More information

CS711008Z Algorithm Design and Analysis

CS711008Z Algorithm Design and Analysis CS700Z Algorithm Design and Analysis Lecture 7 Binary heap, binomial heap, and Fibonacci heap Dongbo Bu Institute of Computing Technology Chinese Academy of Sciences, Beijing, China 1 / Outline Introduction

More information

Hollow Heaps. Aarhus University, Denmark. Tel Aviv University, Israel. Princeton University, USA. July 7, 2015

Hollow Heaps. Aarhus University, Denmark. Tel Aviv University, Israel. Princeton University, USA. July 7, 2015 Hollow Heaps Thomas Dueholm Hansen 1 Haim Kaplan 2 Robert E. Tarjan 3 Uri Zwick 2 1 Department of Computer Science, Aarhus University, Denmark. 2 School of Computer Science, Tel Aviv University, Israel.

More information

Sorting and Searching

Sorting and Searching Sorting and Searching Lecture 2: Priority Queues, Heaps, and Heapsort Lecture 2: Priority Queues, Heaps, and Heapsort Sorting and Searching 1 / 24 Priority Queue: Motivating Example 3 jobs have been submitted

More information

Binary Heaps in Dynamic Arrays

Binary Heaps in Dynamic Arrays Yufei Tao ITEE University of Queensland We have already learned that the binary heap serves as an efficient implementation of a priority queue. Our previous discussion was based on pointers (for getting

More information

18.3 Deleting a key from a B-tree

18.3 Deleting a key from a B-tree 18.3 Deleting a key from a B-tree B-TREE-DELETE deletes the key from the subtree rooted at We design it to guarantee that whenever it calls itself recursively on a node, the number of keys in is at least

More information

Sorting and Searching

Sorting and Searching Sorting and Searching Lecture 2: Priority Queues, Heaps, and Heapsort Lecture 2: Priority Queues, Heaps, and Heapsort Sorting and Searching 1 / 24 Priority Queue: Motivating Example 3 jobs have been submitted

More information

CSE 613: Parallel Programming. Lecture 11 ( Graph Algorithms: Connected Components )

CSE 613: Parallel Programming. Lecture 11 ( Graph Algorithms: Connected Components ) CSE 61: Parallel Programming Lecture ( Graph Algorithms: Connected Components ) Rezaul A. Chowdhury Department of Computer Science SUNY Stony Brook Spring 01 Graph Connectivity 1 1 1 6 5 Connected Components:

More information

CLRS 19 Fibonacci Heaps

CLRS 19 Fibonacci Heaps CLRS 19 Fibonacci Heaps Mergeable Heaps A mergeable heap is any data structure that supports the following five operations, (each element has a key): MAKE-HEAP() creates and returns a new heap containing

More information

Rank-Pairing Heaps. Bernard Haeupler Siddhartha Sen Robert E. Tarjan. SIAM JOURNAL ON COMPUTING Vol. 40, No. 6 (2011), pp.

Rank-Pairing Heaps. Bernard Haeupler Siddhartha Sen Robert E. Tarjan. SIAM JOURNAL ON COMPUTING Vol. 40, No. 6 (2011), pp. Rank-Pairing Heaps Bernard Haeupler Siddhartha Sen Robert E. Tarjan Presentation by Alexander Pokluda Cheriton School of Computer Science, University of Waterloo, Canada SIAM JOURNAL ON COMPUTING Vol.

More information

Algorithms and Theory of Computation. Lecture 7: Priority Queue

Algorithms and Theory of Computation. Lecture 7: Priority Queue Algorithms and Theory of Computation Lecture 7: Priority Queue Xiaohui Bei MAS 714 September 5, 2017 Nanyang Technological University MAS 714 September 5, 2017 1 / 15 Priority Queues Priority Queues Store

More information

Chapter 6 Heapsort 1

Chapter 6 Heapsort 1 Chapter 6 Heapsort 1 Introduce Heap About this lecture Shape Property and Heap Property Heap Operations Heapsort: Use Heap to Sort Fixing heap property for all nodes Use Array to represent Heap Introduce

More information

CSE 638: Advanced Algorithms. Lectures 10 & 11 ( Parallel Connected Components )

CSE 638: Advanced Algorithms. Lectures 10 & 11 ( Parallel Connected Components ) CSE 6: Advanced Algorithms Lectures & ( Parallel Connected Components ) Rezaul A. Chowdhury Department of Computer Science SUNY Stony Brook Spring 01 Symmetry Breaking: List Ranking break symmetry: t h

More information

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Priority Queues / Heaps Date: 9/27/17

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Priority Queues / Heaps Date: 9/27/17 01.433/33 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Priority Queues / Heaps Date: 9/2/1.1 Introduction In this lecture we ll talk about a useful abstraction, priority queues, which are

More information

Priority queue. Advanced Algorithmics (6EAP) MTAT Heaps. Binary heap. Heap/Priority queue. Binomial heaps:

Priority queue. Advanced Algorithmics (6EAP) MTAT Heaps. Binary heap. Heap/Priority queue. Binomial heaps: Priority queue Advanced Algorithmics (EAP) MTAT.03.38 Heaps Jaak Vilo 0 Fall Insert Q, x Retrieve x from Q s.t. x.value is min (or max) Sorted linked list: O(n) to insert x into right place O() access-min,

More information

V Advanced Data Structures

V Advanced Data Structures V Advanced Data Structures B-Trees Fibonacci Heaps 18 B-Trees B-trees are similar to RBTs, but they are better at minimizing disk I/O operations Many database systems use B-trees, or variants of them,

More information

CSE548, AMS542: Analysis of Algorithms, Fall 2012 Date: October 16. In-Class Midterm. ( 11:35 AM 12:50 PM : 75 Minutes )

CSE548, AMS542: Analysis of Algorithms, Fall 2012 Date: October 16. In-Class Midterm. ( 11:35 AM 12:50 PM : 75 Minutes ) CSE548, AMS542: Analysis of Algorithms, Fall 2012 Date: October 16 In-Class Midterm ( 11:35 AM 12:50 PM : 75 Minutes ) This exam will account for either 15% or 30% of your overall grade depending on your

More information

CSE 613: Parallel Programming. Lecture 6 ( Basic Parallel Algorithmic Techniques )

CSE 613: Parallel Programming. Lecture 6 ( Basic Parallel Algorithmic Techniques ) CSE 613: Parallel Programming Lecture 6 ( Basic Parallel Algorithmic Techniques ) Rezaul A. Chowdhury Department of Computer Science SUNY Stony Brook Spring 2017 Some Basic Techniques 1. Divide-and-Conquer

More information

RANK-PAIRING HEAPS BERNHARD HAEUPLER 1, SIDDHARTHA SEN 2,4, AND ROBERT E. TARJAN 3,4

RANK-PAIRING HEAPS BERNHARD HAEUPLER 1, SIDDHARTHA SEN 2,4, AND ROBERT E. TARJAN 3,4 RANK-PAIRING HEAPS BERNHARD HAEUPLER 1, SIDDHARTHA SEN 2,4, AND ROBERT E. TARJAN 3,4 Abstract. We introduce the rank-pairing heap, an implementation of heaps that combines the asymptotic efficiency of

More information

Are Fibonacci Heaps Optimal? Diab Abuaiadh and Jeffrey H. Kingston ABSTRACT

Are Fibonacci Heaps Optimal? Diab Abuaiadh and Jeffrey H. Kingston ABSTRACT Are Fibonacci Heaps Optimal? Diab Abuaiadh and Jeffrey H. Kingston ABSTRACT In this paper we investigate the inherent complexity of the priority queue abstract data type. We show that, under reasonable

More information

Let the dynamic table support the operations TABLE-INSERT and TABLE-DELETE It is convenient to use the load factor ( )

Let the dynamic table support the operations TABLE-INSERT and TABLE-DELETE It is convenient to use the load factor ( ) 17.4 Dynamic tables Let us now study the problem of dynamically expanding and contracting a table We show that the amortized cost of insertion/ deletion is only (1) Though the actual cost of an operation

More information

CSCE750 Analysis of Algorithms Fall 2018 Fibonacci Heaps

CSCE750 Analysis of Algorithms Fall 2018 Fibonacci Heaps CSCE750 Analysis of Algorithms Fall 2018 Fibonacci Heaps This document contains slides from the lecture, formatted to be suitable for printing or individual reading, and with some supplemental explanations

More information

V Advanced Data Structures

V Advanced Data Structures V Advanced Data Structures B-Trees Fibonacci Heaps 18 B-Trees B-trees are similar to RBTs, but they are better at minimizing disk I/O operations Many database systems use B-trees, or variants of them,

More information

A Comparison of Data Structures for Dijkstra's Single Source Shortest Path Algorithm. Shane Saunders

A Comparison of Data Structures for Dijkstra's Single Source Shortest Path Algorithm. Shane Saunders A Comparison of Data Structures for Dijkstra's Single Source Shortest Path Algorithm Shane Saunders November 5, 1999 Abstract Dijkstra's algorithm computes the shortest paths between a starting vertex

More information

FIBONACCI HEAPS. preliminaries insert extract the minimum decrease key bounding the rank meld and delete. Lecture slides by Kevin Wayne

FIBONACCI HEAPS. preliminaries insert extract the minimum decrease key bounding the rank meld and delete. Lecture slides by Kevin Wayne FIBONACCI HEAPS preliminaries insert extract the minimum decrease key bounding the rank meld and delete Lecture slides by Kevin Wayne http://www.cs.princeton.edu/~wayne/kleinberg-tardos Last updated on

More information

Decreasing a key FIB-HEAP-DECREASE-KEY(,, ) 3.. NIL. 2. error new key is greater than current key 6. CASCADING-CUT(, )

Decreasing a key FIB-HEAP-DECREASE-KEY(,, ) 3.. NIL. 2. error new key is greater than current key 6. CASCADING-CUT(, ) Decreasing a key FIB-HEAP-DECREASE-KEY(,, ) 1. if >. 2. error new key is greater than current key 3.. 4.. 5. if NIL and.

More information

On the power of structural violations in priority queues

On the power of structural violations in priority queues On the power of structural violations in priority queues Jyrki Katajainen (University of Copenhagen) Joint work with Amr Elmasry (Alexandria University) and Claus Jensen (University of Copenhagen) These

More information

l Heaps very popular abstract data structure, where each object has a key value (the priority), and the operations are:

l Heaps very popular abstract data structure, where each object has a key value (the priority), and the operations are: DDS-Heaps 1 Heaps - basics l Heaps very popular abstract data structure, where each object has a key value (the priority), and the operations are: l insert an object, find the object of minimum key (find

More information

CSE 5311 Notes 4a: Priority Queues

CSE 5311 Notes 4a: Priority Queues Chart on p., CLRS (binary, Fibonacci heaps) CSE Notes a: Priority Queues (Last updated 9// : AM) MAKE-HEAP INSERT MINIMUM EXTRACT-MIN UNION (MELD/MERGE) DECREASE-KEY DELETE Applications - sorting (?),

More information

Test 1 - Closed Book Last 4 Digits of Student ID # Multiple Choice. Write your answer to the LEFT of each problem. 3 points each

Test 1 - Closed Book Last 4 Digits of Student ID # Multiple Choice. Write your answer to the LEFT of each problem. 3 points each CSE 5311 Test 1 - Closed Book Summer 2009 Name Last 4 Digits of Student ID # Multiple Choice. Write your answer to the LEFT of each problem. 3 points each 1. Which of the following statements is true?

More information

Advanced algorithms. binary heap, d-ary heap, binomial heap, amortized analysis, Fibonacci heap. Jiří Vyskočil, Radek Mařík 2013

Advanced algorithms. binary heap, d-ary heap, binomial heap, amortized analysis, Fibonacci heap. Jiří Vyskočil, Radek Mařík 2013 binary heap, d-ary heap, binomial heap, amortized analysis, Fibonacci heap Jiří Vyskočil, Radek Mařík 2013 heap Heaps [haldy] a heap is a specialized data structure (usually tree-based) that satisfies

More information

Midterm solutions. n f 3 (n) = 3

Midterm solutions. n f 3 (n) = 3 Introduction to Computer Science 1, SE361 DGIST April 20, 2016 Professors Min-Soo Kim and Taesup Moon Midterm solutions Midterm solutions The midterm is a 1.5 hour exam (4:30pm 6:00pm). This is a closed

More information

Quake Heaps: A Simple Alternative to Fibonacci Heaps

Quake Heaps: A Simple Alternative to Fibonacci Heaps Quake Heaps: A Simple Alternative to Fibonacci Heaps Timothy M. Chan Cheriton School of Computer Science, University of Waterloo, Waterloo, Ontario N2L G, Canada, tmchan@uwaterloo.ca Abstract. This note

More information

Priority Queues and Binary Heaps

Priority Queues and Binary Heaps Yufei Tao ITEE University of Queensland In this lecture, we will learn our first tree data structure called the binary heap which serves as an implementation of the priority queue. Priority Queue A priority

More information

These are not polished as solutions, but ought to give a correct idea of solutions that work. Note that most problems have multiple good solutions.

These are not polished as solutions, but ought to give a correct idea of solutions that work. Note that most problems have multiple good solutions. CSE 591 HW Sketch Sample Solutions These are not polished as solutions, but ought to give a correct idea of solutions that work. Note that most problems have multiple good solutions. Problem 1 (a) Any

More information

EECS 477: Introduction to algorithms. Lecture 10

EECS 477: Introduction to algorithms. Lecture 10 EECS 477: Introduction to algorithms. Lecture 10 Prof. Igor Guskov guskov@eecs.umich.edu October 8, 2002 1 Lecture outline: data structures (chapter 5) Heaps, binomial heaps Disjoint subsets (union-find)

More information

9. Which situation is true regarding a cascading cut that produces c trees for a Fibonacci heap?

9. Which situation is true regarding a cascading cut that produces c trees for a Fibonacci heap? 1 1 Name Test 1 - Closed Book Student ID # Multiple Choice. Write your answer to the LEFT of each problem. points each 1. During which operation on a leftist heap may subtree swaps be needed? A. DECREASE-KEY

More information

arxiv: v2 [cs.ds] 9 Apr 2009

arxiv: v2 [cs.ds] 9 Apr 2009 Pairing Heaps with Costless Meld arxiv:09034130v2 [csds] 9 Apr 2009 Amr Elmasry Max-Planck Institut für Informatik Saarbrücken, Germany elmasry@mpi-infmpgde Abstract Improving the structure and analysis

More information

l So unlike the search trees, there are neither arbitrary find operations nor arbitrary delete operations possible.

l So unlike the search trees, there are neither arbitrary find operations nor arbitrary delete operations possible. DDS-Heaps 1 Heaps - basics l Heaps an abstract structure where each object has a key value (the priority), and the operations are: insert an object, find the object of minimum key (find min), and delete

More information

Hollow Heaps. Thomas Dueholm Hansen Haim Kaplan Robert E. Tarjan Uri Zwick

Hollow Heaps. Thomas Dueholm Hansen Haim Kaplan Robert E. Tarjan Uri Zwick Hollow Heaps Thomas Dueholm Hansen Haim Kaplan Robert E. Tarjan Uri Zwick Abstract We introduce the hollow heap, a very simple data structure with the same amortized efficiency as the classical Fibonacci

More information

CSci 231 Final Review

CSci 231 Final Review CSci 231 Final Review Here is a list of topics for the final. Generally you are responsible for anything discussed in class (except topics that appear italicized), and anything appearing on the homeworks.

More information

Breadth-First Search, 1. Slides for CIS 675 DPV Chapter 4. Breadth-First Search, 3. Breadth-First Search, 2

Breadth-First Search, 1. Slides for CIS 675 DPV Chapter 4. Breadth-First Search, 3. Breadth-First Search, 2 Breadth-First Search, Slides for CIS DPV Chapter Jim Royer EECS October, 00 Definition In an undirected graph, the distance between two vertices is the length of the shortest path between them. (If there

More information

CSE 638: Advanced Algorithms. Lectures 18 & 19 ( Cache-efficient Searching and Sorting )

CSE 638: Advanced Algorithms. Lectures 18 & 19 ( Cache-efficient Searching and Sorting ) CSE 638: Advanced Algorithms Lectures 18 & 19 ( Cache-efficient Searching and Sorting ) Rezaul A. Chowdhury Department of Computer Science SUNY Stony Brook Spring 2013 Searching ( Static B-Trees ) A Static

More information

CS 6783 (Applied Algorithms) Lecture 5

CS 6783 (Applied Algorithms) Lecture 5 CS 6783 (Applied Algorithms) Lecture 5 Antonina Kolokolova January 19, 2012 1 Minimum Spanning Trees An undirected graph G is a pair (V, E); V is a set (of vertices or nodes); E is a set of (undirected)

More information

Dictionaries. Priority Queues

Dictionaries. Priority Queues Red-Black-Trees.1 Dictionaries Sets and Multisets; Opers: (Ins., Del., Mem.) Sequential sorted or unsorted lists. Linked sorted or unsorted lists. Tries and Hash Tables. Binary Search Trees. Priority Queues

More information

Algorithms for Minimum Spanning Trees

Algorithms for Minimum Spanning Trees Algorithms & Models of Computation CS/ECE, Fall Algorithms for Minimum Spanning Trees Lecture Thursday, November, Part I Algorithms for Minimum Spanning Tree Sariel Har-Peled (UIUC) CS Fall / 6 Sariel

More information

Review of 4 comparison-based priority queues: Binary, Binomial, Fibonacci and Weak heap : Technical report LUSY-2012/01

Review of 4 comparison-based priority queues: Binary, Binomial, Fibonacci and Weak heap : Technical report LUSY-2012/01 Review of 4 comparison-based priority queues: Binary, Binomial, Fibonacci and Weak heap : Technical report LUSY-2012/01 Matevž Jekovec, Andrej Brodnik University of Ljubljana, Faculty of Computer and Information

More information

Priority Queue: Heap Structures

Priority Queue: Heap Structures Priority Queue: Heap Structures Definition: A max-heap (min-heap) is a complete BT with the property that the value (priority) of each node is at least as large (small) as the values at its children (if

More information

D. Θ nlogn ( ) D. Ο. ). Which of the following is not necessarily true? . Which of the following cannot be shown as an improvement? D.

D. Θ nlogn ( ) D. Ο. ). Which of the following is not necessarily true? . Which of the following cannot be shown as an improvement? D. CSE 0 Name Test Fall 00 Last Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to convert an array, with priorities stored at subscripts through n,

More information

How many leaves on the decision tree? There are n! leaves, because every permutation appears at least once.

How many leaves on the decision tree? There are n! leaves, because every permutation appears at least once. Chapter 8. Sorting in Linear Time Types of Sort Algorithms The only operation that may be used to gain order information about a sequence is comparison of pairs of elements. Quick Sort -- comparison-based

More information

Self-Adjusting Heaps

Self-Adjusting Heaps Heaps-0 Self-Adjusting Heaps No explicit structure. Adjust the structure in a simple, uniform way, so that the efficiency of future operations is improved. Amortized Time Complexity Total time for operations

More information

Rank-Pairing Heaps. Some applications of heaps need either or both of the following additional operations.

Rank-Pairing Heaps. Some applications of heaps need either or both of the following additional operations. Rank-Pairing Heaps Bernhard Haeupler 1, Siddhartha Sen 2,4, and Robert E. Tarjan 2,3,4 1 Massachusetts Institute of Technology, haeupler@mit.edu 2 Princeton University, {sssix,ret}@cs.princeton.edu 3 HP

More information

Lecture 4: Advanced Data Structures

Lecture 4: Advanced Data Structures Lecture 4: Advanced Data Structures Prakash Gautam https://prakashgautam.com.np/6cs008 info@prakashgautam.com.np Agenda Heaps Binomial Heap Fibonacci Heap Hash Tables Bloom Filters Amortized Analysis 2

More information

Lecture 6: Analysis of Algorithms (CS )

Lecture 6: Analysis of Algorithms (CS ) Lecture 6: Analysis of Algorithms (CS583-002) Amarda Shehu October 08, 2014 1 Outline of Today s Class 2 Traversals Querying Insertion and Deletion Sorting with BSTs 3 Red-black Trees Height of a Red-black

More information

Course Review for Finals. Cpt S 223 Fall 2008

Course Review for Finals. Cpt S 223 Fall 2008 Course Review for Finals Cpt S 223 Fall 2008 1 Course Overview Introduction to advanced data structures Algorithmic asymptotic analysis Programming data structures Program design based on performance i.e.,

More information

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators)

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators) Name: Email address: Quiz Section: CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators) Instructions: Read the directions for each question carefully before answering. We will

More information

Representations of Weighted Graphs (as Matrices) Algorithms and Data Structures: Minimum Spanning Trees. Weighted Graphs

Representations of Weighted Graphs (as Matrices) Algorithms and Data Structures: Minimum Spanning Trees. Weighted Graphs Representations of Weighted Graphs (as Matrices) A B Algorithms and Data Structures: Minimum Spanning Trees 9.0 F 1.0 6.0 5.0 6.0 G 5.0 I H 3.0 1.0 C 5.0 E 1.0 D 28th Oct, 1st & 4th Nov, 2011 ADS: lects

More information

Lecture Notes for Advanced Algorithms

Lecture Notes for Advanced Algorithms Lecture Notes for Advanced Algorithms Prof. Bernard Moret September 29, 2011 Notes prepared by Blanc, Eberle, and Jonnalagedda. 1 Average Case Analysis 1.1 Reminders on quicksort and tree sort We start

More information

Lecture 5 Using Data Structures to Improve Dijkstra s Algorithm. (AM&O Sections and Appendix A)

Lecture 5 Using Data Structures to Improve Dijkstra s Algorithm. (AM&O Sections and Appendix A) Lecture Using Data Structures to Improve Dijkstra s Algorithm (AM&O Sections 4.6 4.8 and Appendix A) Manipulating the Data in Dijkstra s Algorithm The bottleneck operation in Dijkstra s Algorithm is that

More information

Multi-Way Search Trees

Multi-Way Search Trees Multi-Way Search Trees Manolis Koubarakis 1 Multi-Way Search Trees Multi-way trees are trees such that each internal node can have many children. Let us assume that the entries we store in a search tree

More information

( ) n 3. n 2 ( ) D. Ο

( ) n 3. n 2 ( ) D. Ο CSE 0 Name Test Summer 0 Last Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to multiply two n n matrices is: A. Θ( n) B. Θ( max( m,n, p) ) C.

More information

CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators)

CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators) Name: Email address: Quiz Section: CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators) Instructions: Read the directions for each question carefully before answering. We will

More information

CSC 505, Fall 2000: Week 7. In which our discussion of Minimum Spanning Tree Algorithms and their data Structures is brought to a happy Conclusion.

CSC 505, Fall 2000: Week 7. In which our discussion of Minimum Spanning Tree Algorithms and their data Structures is brought to a happy Conclusion. CSC 505, Fall 2000: Week 7 In which our discussion of Minimum Spanning Tree Algorithms and their data Structures is brought to a happy Conclusion. Page 1 of 18 Prim s algorithm without data structures

More information

logn D. Θ C. Θ n 2 ( ) ( ) f n B. nlogn Ο n2 n 2 D. Ο & % ( C. Θ # ( D. Θ n ( ) Ω f ( n)

logn D. Θ C. Θ n 2 ( ) ( ) f n B. nlogn Ο n2 n 2 D. Ο & % ( C. Θ # ( D. Θ n ( ) Ω f ( n) CSE 0 Test Your name as it appears on your UTA ID Card Fall 0 Multiple Choice:. Write the letter of your answer on the line ) to the LEFT of each problem.. CIRCLED ANSWERS DO NOT COUNT.. points each. The

More information

( ) D. Θ ( ) ( ) Ο f ( n) ( ) Ω. C. T n C. Θ. B. n logn Ο

( ) D. Θ ( ) ( ) Ο f ( n) ( ) Ω. C. T n C. Θ. B. n logn Ο CSE 0 Name Test Fall 0 Multiple Choice. Write your answer to the LEFT of each problem. points each. The expected time for insertion sort for n keys is in which set? (All n! input permutations are equally

More information

16 Greedy Algorithms

16 Greedy Algorithms 16 Greedy Algorithms Optimization algorithms typically go through a sequence of steps, with a set of choices at each For many optimization problems, using dynamic programming to determine the best choices

More information

CS 380 ALGORITHM DESIGN AND ANALYSIS

CS 380 ALGORITHM DESIGN AND ANALYSIS CS 380 ALGORITHM DESIGN AND ANALYSIS Lecture 12: Red-Black Trees Text Reference: Chapters 12, 13 Binary Search Trees (BST): Review Each node in tree T is a object x Contains attributes: Data Pointers to

More information

) $ f ( n) " %( g( n)

) $ f ( n)  %( g( n) CSE 0 Name Test Spring 008 Last Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to compute the sum of the n elements of an integer array is: # A.

More information

Fundamental Algorithms

Fundamental Algorithms WS 2007/2008 Fundamental Algorithms Dmytro Chibisov, Jens Ernst Fakultät für Informatik TU München http://www14.in.tum.de/lehre/2007ws/fa-cse/ Fall Semester 2007 1. AVL Trees As we saw in the previous

More information

Minimum Spanning Trees

Minimum Spanning Trees CSMPS 2200 Fall Minimum Spanning Trees Carola Wenk Slides courtesy of Charles Leiserson with changes and additions by Carola Wenk 11/6/ CMPS 2200 Intro. to Algorithms 1 Minimum spanning trees Input: A

More information

Properties of red-black trees

Properties of red-black trees Red-Black Trees Introduction We have seen that a binary search tree is a useful tool. I.e., if its height is h, then we can implement any basic operation on it in O(h) units of time. The problem: given

More information

Lecture Summary CSC 263H. August 5, 2016

Lecture Summary CSC 263H. August 5, 2016 Lecture Summary CSC 263H August 5, 2016 This document is a very brief overview of what we did in each lecture, it is by no means a replacement for attending lecture or doing the readings. 1. Week 1 2.

More information

22 Elementary Graph Algorithms. There are two standard ways to represent a

22 Elementary Graph Algorithms. There are two standard ways to represent a VI Graph Algorithms Elementary Graph Algorithms Minimum Spanning Trees Single-Source Shortest Paths All-Pairs Shortest Paths 22 Elementary Graph Algorithms There are two standard ways to represent a graph

More information

n 2 C. Θ n ( ) Ο f ( n) B. n 2 Ω( n logn)

n 2 C. Θ n ( ) Ο f ( n) B. n 2 Ω( n logn) CSE 0 Name Test Fall 0 Last Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to find the maximum of the n elements of an integer array is in: A.

More information

CSE 214 Computer Science II Heaps and Priority Queues

CSE 214 Computer Science II Heaps and Priority Queues CSE 214 Computer Science II Heaps and Priority Queues Spring 2018 Stony Brook University Instructor: Shebuti Rayana shebuti.rayana@stonybrook.edu http://www3.cs.stonybrook.edu/~cse214/sec02/ Introduction

More information

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture 20 Priority Queues Today we are going to look at the priority

More information

COL351: Analysis and Design of Algorithms (CSE, IITD, Semester-I ) Name: Entry number:

COL351: Analysis and Design of Algorithms (CSE, IITD, Semester-I ) Name: Entry number: Name: Entry number: There are 6 questions for a total of 75 points. 1. Consider functions f(n) = 10n2 n + 3 n and g(n) = n3 n. Answer the following: (a) ( 1 / 2 point) State true or false: f(n) is O(g(n)).

More information

How much space does this routine use in the worst case for a given n? public static void use_space(int n) { int b; int [] A;

How much space does this routine use in the worst case for a given n? public static void use_space(int n) { int b; int [] A; How much space does this routine use in the worst case for a given n? public static void use_space(int n) { int b; int [] A; } if (n

More information

2.1 Greedy Algorithms. 2.2 Minimum Spanning Trees. CS125 Lecture 2 Fall 2016

2.1 Greedy Algorithms. 2.2 Minimum Spanning Trees. CS125 Lecture 2 Fall 2016 CS125 Lecture 2 Fall 2016 2.1 Greedy Algorithms We will start talking about methods high-level plans for constructing algorithms. One of the simplest is just to have your algorithm be greedy. Being greedy,

More information

COP 4531 Complexity & Analysis of Data Structures & Algorithms

COP 4531 Complexity & Analysis of Data Structures & Algorithms COP 4531 Complexity & Analysis of Data Structures & Algorithms Lecture 8 Data Structures for Disjoint Sets Thanks to the text authors who contributed to these slides Data Structures for Disjoint Sets Also

More information

CSE 502 Class 16. Jeremy Buhler Steve Cole. March A while back, we introduced the idea of collections to put hash tables in context.

CSE 502 Class 16. Jeremy Buhler Steve Cole. March A while back, we introduced the idea of collections to put hash tables in context. CSE 502 Class 16 Jeremy Buhler Steve Cole March 17 2015 Onwards to trees! 1 Collection Types Revisited A while back, we introduced the idea of collections to put hash tables in context. abstract data types

More information

CSE 5311 Notes 10: Medians/Selection

CSE 5311 Notes 10: Medians/Selection CSE Notes 0: Medians/Selection (Last updated 7/8/ :0 PM) MINIMUM AND MAXIMUM IN NO MORE THAN " n # COMPARISONS (CLRS 9.) Ordinary method takes n - comparisons:. Find minimum with n - comparisons.. Remove

More information

Greedy Algorithms CSE 6331

Greedy Algorithms CSE 6331 Greedy Algorithms CSE 6331 Reading: Sections 16.1, 16.2, 16.3, Chapter 23. 1 Introduction Optimization Problem: Construct a sequence or a set of elements {x 1,..., x k } that satisfies given constraints

More information

Dijkstra s Single Source Shortest Path Algorithm. Andreas Klappenecker

Dijkstra s Single Source Shortest Path Algorithm. Andreas Klappenecker Dijkstra s Single Source Shortest Path Algorithm Andreas Klappenecker Single Source Shortest Path Given: a directed or undirected graph G = (V,E) a source node s in V a weight function w: E -> R. Problem:!!

More information

CSCI2100B Data Structures Heaps

CSCI2100B Data Structures Heaps CSCI2100B Data Structures Heaps Irwin King king@cse.cuhk.edu.hk http://www.cse.cuhk.edu.hk/~king Department of Computer Science & Engineering The Chinese University of Hong Kong Introduction In some applications,

More information

Outline. Computer Science 331. Heap Shape. Binary Heaps. Heap Sort. Insertion Deletion. Mike Jacobson. HeapSort Priority Queues.

Outline. Computer Science 331. Heap Shape. Binary Heaps. Heap Sort. Insertion Deletion. Mike Jacobson. HeapSort Priority Queues. Outline Computer Science 33 Heap Sort Mike Jacobson Department of Computer Science University of Calgary Lectures #5- Definition Representation 3 5 References Mike Jacobson (University of Calgary) Computer

More information

22 Elementary Graph Algorithms. There are two standard ways to represent a

22 Elementary Graph Algorithms. There are two standard ways to represent a VI Graph Algorithms Elementary Graph Algorithms Minimum Spanning Trees Single-Source Shortest Paths All-Pairs Shortest Paths 22 Elementary Graph Algorithms There are two standard ways to represent a graph

More information

Outline. Definition. 2 Height-Balance. 3 Searches. 4 Rotations. 5 Insertion. 6 Deletions. 7 Reference. 1 Every node is either red or black.

Outline. Definition. 2 Height-Balance. 3 Searches. 4 Rotations. 5 Insertion. 6 Deletions. 7 Reference. 1 Every node is either red or black. Outline 1 Definition Computer Science 331 Red-Black rees Mike Jacobson Department of Computer Science University of Calgary Lectures #20-22 2 Height-Balance 3 Searches 4 Rotations 5 s: Main Case 6 Partial

More information

CSE 100: GRAPH ALGORITHMS

CSE 100: GRAPH ALGORITHMS CSE 100: GRAPH ALGORITHMS Dijkstra s Algorithm: Questions Initialize the graph: Give all vertices a dist of INFINITY, set all done flags to false Start at s; give s dist = 0 and set prev field to -1 Enqueue

More information

SFU CMPT Lecture: Week 9

SFU CMPT Lecture: Week 9 SFU CMPT-307 2008-2 1 Lecture: Week 9 SFU CMPT-307 2008-2 Lecture: Week 9 Ján Maňuch E-mail: jmanuch@sfu.ca Lecture on July 8, 2008, 5.30pm-8.20pm SFU CMPT-307 2008-2 2 Lecture: Week 9 Binary search trees

More information

Priority Queues. T. M. Murali. January 29, 2009

Priority Queues. T. M. Murali. January 29, 2009 Priority Queues T. M. Murali January 29, 2009 Motivation: Sort a List of Numbers Sort INSTANCE: Nonempty list x 1, x 2,..., x n of integers. SOLUTION: A permutation y 1, y 2,..., y n of x 1, x 2,..., x

More information

CSE 431/531: Analysis of Algorithms. Greedy Algorithms. Lecturer: Shi Li. Department of Computer Science and Engineering University at Buffalo

CSE 431/531: Analysis of Algorithms. Greedy Algorithms. Lecturer: Shi Li. Department of Computer Science and Engineering University at Buffalo CSE 431/531: Analysis of Algorithms Greedy Algorithms Lecturer: Shi Li Department of Computer Science and Engineering University at Buffalo Main Goal of Algorithm Design Design fast algorithms to solve

More information

LECTURE 18 AVL TREES

LECTURE 18 AVL TREES DATA STRUCTURES AND ALGORITHMS LECTURE 18 AVL TREES IMRAN IHSAN ASSISTANT PROFESSOR AIR UNIVERSITY, ISLAMABAD PROTOTYPICAL EXAMPLES These two examples demonstrate how we can correct for imbalances: starting

More information

SKEW HEAPS: Self-Adjusting Heaps

SKEW HEAPS: Self-Adjusting Heaps Lecture Note 05 CSE40/50 SKEW HEAPS: Self-Adjusting Heaps In this handout we describe the skew heap data structure, a self-adjusting form of heap related to the leftist heap of Crane and Knuth. Skew heaps,

More information