L feb abhi shelat

Similar documents
Greedy Alg: Huffman abhi shelat

BFS Dijkstra. Oct abhi shelat

Fibonacci Heaps These lecture slides are adapted from CLRS, Chapter 20.

Mon Tue Wed Thurs Fri

Algorithm Design and Analysis

Analysis of Algorithms. Outline 1 Introduction Basic Definitions Ordered Trees. Fibonacci Heaps. Andres Mendez-Vazquez. October 29, Notes.

Chapter 5 Data Structures Algorithm Theory WS 2017/18 Fabian Kuhn

Algorithms Theory. 08 Fibonacci Heaps

25. Minimum Spanning Trees

25. Minimum Spanning Trees

2-INF-237 Vybrané partie z dátových štruktúr 2-INF-237 Selected Topics in Data Structures

Breadth First Search, Dijkstra s Algorithm for Shortest Paths

Algorithm Design and Analysis

Shortest Path Algorithms

FIBONACCI HEAPS. preliminaries insert extract the minimum decrease key bounding the rank meld and delete. Copyright 2013 Kevin Wayne

CS 253: Algorithms. Chapter 24. Shortest Paths. Credit: Dr. George Bebis

Fibonacci (Min-)Heap. (I draw dashed lines in place of of circular lists.) 1 / 17

Introduction to Algorithms

Introduction to Algorithms

Part IA Algorithms Notes

8 Priority Queues. 8 Priority Queues. Prim s Minimum Spanning Tree Algorithm. Dijkstra s Shortest Path Algorithm

Introduction to Algorithms

Analysis of Algorithms. Outline. Single Source Shortest Path. Andres Mendez-Vazquez. November 9, Notes. Notes

CMPS 2200 Fall Carola Wenk Slides courtesy of Charles Leiserson with small changes by Carola Wenk. 10/8/12 CMPS 2200 Intro.

Dijkstra s Single Source Shortest Path Algorithm. Andreas Klappenecker

Single Source Shortest Paths

CS60020: Foundations of Algorithm Design and Machine Learning. Sourangshu Bhattacharya

CS 4407 Algorithms Lecture: Shortest Path Algorithms

Design and Analysis of Algorithms

Data Structures 1 NTIN066

Another way of saying this is that amortized analysis guarantees the average case performance of each operation in the worst case.

CMPS 6610 Fall 2018 Shortest Paths Carola Wenk

Introduction to Algorithms

past balancing schemes require maintenance of balance info at all times, are aggresive use work of searches to pay for work of rebalancing

Single Source Shortest Paths

CS 161: Design and Analysis of Algorithms

ENS Lyon Camp. Day 2. Basic group. Cartesian Tree. 26 October

abhi shelat

Data Structures 1 NTIN066

Chapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Slides credited from Hsueh-I Lu & Hsu-Chun Hsiao

CS 161: Design and Analysis of Algorithms

Assignment 5: Solutions

Objec&ves. Review. Data structure: Heaps Data structure: Graphs. What is a priority queue? What is a heap?

A Simple Implementation Technique for Priority Search Queues

CS 466/666 Course Notes

CPSC 320 Sample Final Examination December 2013

Splay Trees. CMSC 420: Lecture 8

Heaps and Priority Queues

Priority queues implemented via heaps

Divide-and-Conquer Algorithms Part Two

CSE548, AMS542: Analysis of Algorithms, Fall 2017 Date: Oct 26. Homework #2. ( Due: Nov 8 )

General Methods for Algorithm Design

Amortized Analysis. DistributeMoney(n, k) 1 Each of n people gets $1. 2 for i = 1to k 3 do Give a dollar to a random person

Algorithms Booklet. 1 Graph Searching. 1.1 Breadth First Search

4.8 Huffman Codes. These lecture slides are supplied by Mathijs de Weerd

CSE 202: Design and Analysis of Algorithms Lecture 3

AMORTIZED ANALYSIS. binary counter multipop stack dynamic table. Lecture slides by Kevin Wayne. Last updated on 1/24/17 11:31 AM

Fast Inference with Min-Sum Matrix Product

A Tight Lower Bound for Top-Down Skew Heaps

CS 410/584, Algorithm Design & Analysis: Lecture Notes 3

CS Data Structures and Algorithm Analysis

INF2220: algorithms and data structures Series 1

Amortized analysis. Amortized analysis

Partha Sarathi Mandal

Chapter 6. Self-Adjusting Data Structures

CS213d Data Structures and Algorithms

DecreaseKeys are Expensive for External Memory Priority Queues

ICS 252 Introduction to Computer Design

Discrete Wiskunde II. Lecture 5: Shortest Paths & Spanning Trees

HW #4. (mostly by) Salim Sarımurat. 1) Insert 6 2) Insert 8 3) Insert 30. 4) Insert S a.

Lecture 2 September 4, 2014

Notes on Logarithmic Lower Bounds in the Cell Probe Model

Computing Connected Components Given a graph G = (V; E) compute the connected components of G. Connected-Components(G) 1 for each vertex v 2 V [G] 2 d

Weak Heaps and Friends: Recent Developments

IS 709/809: Computational Methods in IS Research Fall Exam Review

CS781 Lecture 3 January 27, 2011

Binary Search Trees. Lecture 29 Section Robb T. Koether. Hampden-Sydney College. Fri, Apr 8, 2016

A faster algorithm for the single source shortest path problem with few distinct positive lengths

Chapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Matching Residents to Hospitals

Lecture 5: Splay Trees

Binary Search Trees. Motivation

Data Structures and and Algorithm Xiaoqing Zheng

Dictionary: an abstract data type

CSCE 750 Final Exam Answer Key Wednesday December 7, 2005

Lecture Notes for Chapter 25: All-Pairs Shortest Paths

Each internal node v with d(v) children stores d 1 keys. k i 1 < key in i-th sub-tree k i, where we use k 0 = and k d =.

1 Introduction A priority queue is a data structure that maintains a set of elements and supports operations insert, decrease-key, and extract-min. Pr

CS 410/584, Algorithm Design & Analysis, Lecture Notes 4

Lecture VI AMORTIZATION

Slides for CIS 675. Huffman Encoding, 1. Huffman Encoding, 2. Huffman Encoding, 3. Encoding 1. DPV Chapter 5, Part 2. Encoding 2

Greedy Algorithms and Data Compression. Curs 2018

Fundamental Algorithms

(v,w) disconnected? bridge? articulatiion point? Update MST during insertion and deletion

Data Structures and Algorithms

Optimal Color Range Reporting in One Dimension

1 Some loose ends from last time

CS60007 Algorithm Design and Analysis 2018 Assignment 1

Disjoint Sets : ADT. Disjoint-Set : Find-Set

Transcription:

L10 661 feb 17 2009 abhi shelat

General-MST-Strategy(G =(V, E)) 1 A 2 repeat V 1 times: 3 Pick a cut (S, V S) that respects A 4 Let e be min-weight edge over cut (S, V S) 5 A A {e}

prim General-MST-Strategy(G =(V, E)) 1 A 2 repeat V 1 times: 3 Pick a cut (S, V S) that respects A 4 Let e be min-weight edge over cut (S, V S) 5 A A {e} A is a subtree edge e is lightest edge that grows the subtree

prim b 8 d 8 g 10 7 2 a 9 e 5 9 i 12 3 3 11 c 1 f 6 h

prim e d f c b a 10 8 1 3 3 9 12 6 5 9 11 2 i g h 8 7 e d f c b a 10 8 1 3 3 9 12 6 5 9 11 2 i g h 8 7 e d f c b a 10 8 1 3 3 9 12 6 5 9 11 2 i g h 8 7 e d f c b a 10 8 1 3 3 9 12 6 5 9 11 2 i g h 8 7 e d f c b a 10 8 1 3 3 9 12 6 5 9 11 2 i g h 8 7 e d f c b a 10 8 1 3 3 9 12 6 5 9 11 2 i g h 8 7 e d f c b a 10 8 1 3 3 9 12 6 5 9 11 2 i g h 8 7 e d f c b a 10 8 1 3 3 9 12 6 5 9 11 2 i g h 8 7 e d f c b a 10 8 1 3 3 9 12 6 5 9 11 2 i g h 8 7

implementation idea: maintain the set A set key of all nodes not adjacent to A to be

implementation idea: use a priority queue to keep track of light edges makequeue: insert: extractmin: decreasekey:

implementation prim(g =(V, E)) 1 Q Q is a Priority Queue 2 Initialize each v V with key k v, π v nil 3 Pick a starting node r and set k r 0 4 Insert all nodes into Q with key k v. 5 while Q 6 do u extract-min(q) 7 for each v Adj (u) 8 do if v Q and w(u, v) <k v 9 then π v u 10 decrease-key(q, v, w(u, v)) Sets k v w(u, v) A = {(v, π v ) : v V {r} Q}

prim b 8 8 d 0 8 g 8 10 7 2 a 9 e 7 5 9 i 11 12 3 3 11 prim(g =(V, E)) c 1 Q Q is a Priority Queue 2 Initialize each v V with key k v, π v nil 3 Pick a starting node r and set k r 0 4 Insert all nodes into Q with key k v. 5 while Q 6 do u extract-min(q) 7 for each v Adj (u) 8 do if v Q and w(u, v) <k v 9 then π v u 10 decrease-key(q, v, w(u, v)) Sets k v w(u, v) 1 f 6 6 h 5

prim b 8 8 d 0 8 g 8 10 7 2 a 9 e 7 5 9 i 11 12 3 3 11 prim(g =(V, E)) c 1 Q Q is a Priority Queue 2 Initialize each v V with key k v, π v nil 3 Pick a starting node r and set k r 0 4 Insert all nodes into Q with key k v. 5 while Q 6 do u extract-min(q) 7 for each v Adj (u) 8 do if v Q and w(u, v) <k v 9 then π v u 10 decrease-key(q, v, w(u, v)) Sets k v w(u, v) 1 f 6 6 h 5

implementation prim(g =(V, E)) 1 Q Q is a Priority Queue 2 Initialize each v V with key k v, π v nil 3 Pick a starting node r and set k r 0 4 Insert all nodes into Q with key k v. 5 while Q 6 do u extract-min(q) 7 for each v Adj (u) 8 do if v Q and w(u, v) <k v 9 then π v u 10 decrease-key(q, v, w(u, v)) Sets k v w(u, v)

implementation prim(g =(V, E)) 1 Q Q is a Priority Queue 2 Initialize each v V with key k v, π v nil 3 Pick a starting node r and set k r 0 4 Insert all nodes into Q with key k v. 5 while Q 6 do u extract-min(q) 7 for each v Adj (u) 8 do if v Q and w(u, v) <k v 9 then π v u 10 decrease-key(q, v, w(u, v)) Sets k v w(u, v) O(V log V + E log V) =O(E log V)

faster implementation prim(g =(V, E)) 1 Q Q is a Priority Queue 2 Initialize each v V with key k v, π v nil 3 Pick a starting node r and set k r 0 4 Insert all nodes into Q with key k v. 5 while Q 6 do u extract-min(q) 7 for each v Adj (u) 8 do if v Q and w(u, v) <k v 9 then π v u 10 decrease-key(q, v, w(u, v)) Sets k v w(u, v) O(E + V log V)

fibonacci heaps insert: findmin: extractmin: decreasekey:

amortized analysis

binary counter

binary counter Increment(A) 1 i 0 2 while i < len(a) and A i =1 3 do A i 0 4 i i +1 5 if i < len(a) 6 then A i 1

binary counter better analysis Increment(A) 1 i 0 2 while i < len(a) and A i =1 3 do A i 0 4 i i +1 5 if i < len(a) 6 then A i 1

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 1

potential method data structure A

potential method data structure A ĉ i = c i + Φ(A i ) Φ(A i 1 )

image: edupics.com

amortized cost of n ops: n i=1 ĉ i =

binary counter 0 0 0 0 0 0 0 0 let let! b i " t i be the... be the... Φ(A i )= ĉ i =

heaps

binomial heaps B 4 B 4 B 5

fibonacci heap min picture courtesy of jeff erickson

each node has 4 pointers 2 fields: degree marked D(n)

fibonacci heap min

fibheap potential min Φ(H) =

key idea: be lazy put off the work until last minute

create new heap

insert node min

findmin min

extractmin min two steps: split consolidate

extractmin example min[h] - -----

min[h] Q Q@ (d)~~~~~ @-t--------t A~

0 1 2 3 A// ),x4 -- I

0 1 2 3 A 30 e,' AN -- ----- -- -

A/ We) X 0-- xw30@ R 3544 5--

x 7 ---- 21*-I 41 46 17 23w 0 1 2 3 A// / : 38 2 :32

48 0 1 2 3 17 A I

0 1 2 3 A-- l 10ltf0l 9 ----- 24 17 2

3 1 2 3 )-.-...-- -- -----lb 38 41

min[h] -- ---- ---- 7 38

analysis min cost 1. extract 2. add children 3. consolidate potential before: potential after: amortized cost:

decrease key operation what changes in the heap: 0 1 2 3 A 30 e,' AN -- ----- -- -

decrease key decreasekey(v) promote node v to the root list update min of heap if necessary if 2 children of a node have been promoted, promote parent as well (recursively)

min[h] W~tgW decreasekey(46, 15)

min[hm - --- decreasekey(35,5)

-- - 4

min[h] Mt @

min[h] V--- 0 -- ----- --------- 7

analysis decreasekey(v) promote node v to the root list update min of heap if necessary if 2 children of a node have been promoted, promote parent as well (recursively) actual cost: potential before: potential after:

finally prove: D(n) = log φ n size(x) =

lemma: for node x, consider children (degrees)

lemma: F k+2 = 1 + k i=0 F i

lemma: size(x) F deg(x)+2 s i :

thm: D(n) log φ n