Basic operations Implementation options

Vergelijkbare documenten
SAMPLE 11 = + 11 = + + Exploring Combinations of Ten + + = = + + = + = = + = = 11. Step Up. Step Ahead

Engels op Niveau A2 Workshops Woordkennis 1

(1) De hoofdfunctie van ons gezelschap is het aanbieden van onderwijs. (2) Ons gezelschap is er om kunsteducatie te verbeteren

Preschool Kindergarten

B1 Woordkennis: Spelling

L.Net s88sd16-n aansluitingen en programmering.

RECEPTEERKUNDE: PRODUCTZORG EN BEREIDING VAN GENEESMIDDELEN (DUTCH EDITION) FROM BOHN STAFLEU VAN LOGHUM

L.Net s88sd16-n aansluitingen en programmering.

ANGSTSTOORNISSEN EN HYPOCHONDRIE: DIAGNOSTIEK EN BEHANDELING (DUTCH EDITION) FROM BOHN STAFLEU VAN LOGHUM

Introductie in flowcharts

ALGORITMIEK: answers exercise class 7

Voorbeelden van machtigingsformulieren Nederlands Engels. Examples of authorisation forms (mandates) Dutch English. Juli 2012 Versie 2.

Bin packing and scheduling

8+ 60 MIN Alleen te spelen in combinatie met het RIFUGIO basisspel. Only to be played in combination with the RIFUGIO basicgame.

Add the standing fingers to get the tens and multiply the closed fingers to get the units.

Luister alsjeblieft naar een opname als je de vragen beantwoordt of speel de stukken zelf!

LONDEN MET 21 GEVARIEERDE STADSWANDELINGEN 480 PAGINAS WAARDEVOLE INFORMATIE RUIM 300 FOTOS KAARTEN EN PLATTEGRONDEN

Datastructuren en Algoritmen voor CKI

2019 SUNEXCHANGE USER GUIDE LAST UPDATED

LDA Topic Modeling. Informa5ekunde als hulpwetenschap. 9 maart 2015

MyDHL+ Van Non-Corporate naar Corporate

Chromosomal crossover

Classification of triangles

Concept of Feedback. P.S. Gandhi Mechanical Engineering IIT Bombay

z x 1 x 2 x 3 x 4 s 1 s 2 s 3 rij rij rij rij

Comics FILE 4 COMICS BK 2

Group work to study a new subject.

Firewall van de Speedtouch 789wl volledig uitschakelen?

Opgave 2 Geef een korte uitleg van elk van de volgende concepten: De Yield-to-Maturity of a coupon bond.

ETS 4.1 Beveiliging & ETS app concept

Online Resource 1. Title: Implementing the flipped classroom: An exploration of study behaviour and student performance

MyDHL+ ProView activeren in MyDHL+

CS 202 Fundamental Structures of Computer Science II Bilkent University Computer Engineering Department

9 daagse Mindful-leSs 3 stappen plan training

CTI SUITE TSP DETAILS

Graphic Design. Keuzevak GD1. Raul Martinez-Orozco / raul@thecombine.nl)

Installatie van Windows 10 op laptops. Windows 10 installation on laptops

THE WORK HET WERK HARALD BERKHOUT

Meetkunde en Lineaire Algebra

Read this story in English. My personal story

Ik kom er soms tijdens de les achter dat ik mijn schoolspullen niet bij mij heb of niet compleet

General info on using shopping carts with Ingenico epayments

BE Nanoregistry Annual Public Report

Handleiding Zuludesk Parent

Value based healthcare door een quality improvement bril

EU keurt nieuw Programma veiliger internet goed: 55 miljoen euro om het internet veiliger te maken voor kinderen

COGNITIEVE DISSONANTIE EN ROKERS COGNITIVE DISSONANCE AND SMOKERS

Settings for the C100BRS4 MAC Address Spoofing with cable Internet.

FOR DUTCH STUDENTS! ENGLISH VERSION NEXT PAGE. Toets Inleiding Kansrekening 1 8 februari 2010

DALISOFT. 33. Configuring DALI ballasts with the TDS20620V2 DALI Tool. Connect the TDS20620V2. Start DALISOFT

Vergaderen in het Engels

NMOZTMKUDLVDKECVLKBVESBKHWIDKPDF-WWUS Page File Size 9,952 KB 29 May, 2016

20 twenty. test. This is a list of things that you can find in a house. Circle the things that you can find in the tree house in the text.

3e Mirror meeting pren April :00 Session T, NVvA Symposium

Buy Me FILE 5 BUY ME BK 2

TOEGANG VOOR NL / ENTRANCE FOR DUTCH : lator=c&camp=24759

FOR DUTCH STUDENTS! ENGLISH VERSION NEXT PAGE

Win a meet and greet with Adam Young from the band Owl City!

1a. We werken het geval voor het tandenpoetsen uit. De concepten zijn (we gebruiken Engelse termen en afkortingen):

News: Tours this season!

EM7680 Firmware Update by OTA

OPEN TRAINING. Onderhandelingen met leveranciers voor aankopers. Zeker stellen dat je goed voorbereid aan de onderhandelingstafel komt.

Chapter 4 Understanding Families. In this chapter, you will learn

Yes/No (if not you pay an additional EUR 75 fee to be a member in 2020

Vertaling Engels Gedicht / songteksten

NCTS - INFORMATIE INZAKE NIEUWIGHEDEN VOOR 2010

FOR DUTCH STUDENTS! ENGLISH VERSION NEXT PAGE

Puzzle. Fais ft. Afrojack Niveau 3a Song 6 Lesson A Worksheet. a Lees de omschrijvingen. Zet de Engelse woorden in de puzzel.

Maillijsten voor medewerkers van de Universiteit van Amsterdam

MyDHL+ Uw accountnummer(s) delen

Calculator spelling. Assignment

A2 Workshops Grammatica Heden

EM7680 Firmware Update by Micro SD card

i(i + 1) = xy + y = x + 1, y(1) = 2.

Elementary Data Structures 3

Lists of words from the books, and feedback from the sessions, are on

Registratie- en activeringsproces voor de Factuurstatus Service NL 1 Registration and activation process for the Invoice Status Service EN 10

After that, the digits are written after each other: first the row numbers, followed by the column numbers.

Issues in PET Drug Manufacturing Steve Zigler PETNET Solutions April 14, 2010

Bijlage 2: Informatie met betrekking tot goede praktijkvoorbeelden in Londen, het Verenigd Koninkrijk en Queensland

Cambridge Assessment International Education Cambridge International General Certificate of Secondary Education. Published

een kopie van je paspoort, een kopie van je diploma voortgezet onderwijs (hoogst genoten opleiding), twee pasfoto s, naam op de achterkant

Stars FILE 7 STARS BK 2

Travel Survey Questionnaires

Daylight saving time. Assignment

Hoe met Windows 8 te verbinden met NDI Remote Office (NDIRO) How to connect With Windows 8 to NDI Remote Office (NDIRO

Four-card problem. Input

Japanse duizendknoop Help mee deze plant te bestrijden

Meetkunde en Lineaire Algebra

Esther Lee-Varisco Matt Zhang

Shipment Centre EU Quick Print Client handleiding [NL]

It s all about the money Group work

EM7580 Firmware Update by Micro SD card

BISL EEN FRAMEWORK VOOR BUSINESS INFORMATIEMANAGEMENT (DUTCH LANGUAGE) (GERMAN EDITION) (DUTCH EDITION) BY REMKO VAN DER POLS, RALPH DONA

MyDHL+ Dangerous Goods

FOR DUTCH STUDENTS! ENGLISH VERSION NEXT PAGE. Toets Inleiding Kansrekening 1 7 februari 2011

Global TV Canada s Pulse 2011

REIN kast. eiken standaard iepen. gebakken iepen. gerookt. licht iepen. bijzonderheden. staanders/achterwand/deur. ontwerp: Gjalt Pilat, 2005

Davide's Crown Caps Forum

Op het potje Potty training

Transcriptie:

Priority Queues Heaps Heapsort Student questions EditorTrees WA 6 File Compression Graphs Hashing Anything else Written Assignments 7 and 8 have been updated for this term. Each of them is smaller than many of the written assignments have been. No programming problems in either assignment. Agenda Priority Queues Heaps Heapsort 1

Basic operations Implementation options Each element in the PQ has an associated priority, which is a value from a comparable type (in our examples, an integer). Operations (may have other names): findmin() insert(item, priority) deletemin( ) 2

How could we implement it using data structures that we already know about? Array? Queue? List? BinarySearchTree? One efficient approach uses a binary heap A somewhat-sorted complete binary tree Questions we'll ask: How can we efficiently represent a complete binary tree? Can we add and remove items efficiently without destroying the "heapness" of the structure? Storage (an array) Algorithms for insertion and deletemin 3

Notice the lack of explicit pointers in the array Figure 21.1 A complete binary tree and its array representation complete is not a completely standard term 1 Array: How to find the children or the parent of a node? One "wasted" array position (0) 2-3 A Binary (min) Heap is a complete Binary Tree (using the array implementation, as on the previous slide) that has the heap-order property everywhere. In a binary heap, where do we find The smallest element? 2 nd smallest? 3 rd smallest? 4

Figure 21.7 Attempt to insert 14, creating the hole and bubbling the hole up Recall that the actual data movement is done by array manipulation Create a "hole" where 14 can be inserted. Percolate up! Figure 21.8 The remaining two steps required to insert 14 in the original heap shown in Figure 21.7 Analysis of insertion Your turn: Insert into an initially empty heap: 6 4 8 1 5 3 2 7 5

4-5 The min is at the root. Delete it, then use the percolatedown algorithm to find the correct place for its replacement. We must decide which child to promote, to make room for 31. Figure 21.10 Creation of the hole at the root 6

Figure 21.11 The next two steps in the deletemin operation Figure 21.12 The last two steps in the deletemin operation 7

6-7 Compare node to its children, moving root down and promoting the smaller child until proper place is found. Analysis 8 Worst case times: findmin: O(1) insert: O(log n) deletemin O(log n) big-oh times for insert/delete are the same as in the balanced BST implementation, but.. Heap operations are much simpler, A heap doesn t require additional space for pointers or balance codes. 8

Use a binary heap to sort an array. Start with empty heap Insert each array element into heap Repeatedly do deletemin, copying elements back into array. http://nova.umuc.edu/~jarc/idsv/lesson3.html Can be run in demo mode or practice mode. We can save space by doing the whole sort in place, using a "maxheap" (i.e. a heap where the maximum element is at the root instead of the minimum) Analysis? Next slide 9

10 Add the elements to the heap Repeatedly call insert Remove the elements and place into the array Repeatedly call DeleteMin Use Stirling's approximation: http://en.wikipedia.org /wiki/stirling%27s_appr oximation Can we do better for the insertion part? Yes, use BuildHeap (next) BuildHeap takes a complete tree that is not a heap and exhanges elements to get it into heap form At each stage it takes a root plus two heaps and "percolates down" the root to restore "heapness" to the entire subtree Why this starting point? 10

Figure 21.17 Implementation of the linear-time buildheap method Figure 21.18 (a) After percolatedown(6); (b) after percolatedown(5) 11

Figure 21.19 (a) After percolatedown(4); (b) after percolatedown(3) Figure 21.20 (a)after percolatedown(2); (b) after percolatedown(1) and buildheap terminates 12

Find a summation that represents the maximum number of comparisons required to rearrange an array into a heap Can you find a summation and its value? Find a summation that represents the maximum number of comparisons required to rearrange an array of N=2 H+1-1 elements into a heap The summation is and the sum is N H - 1 Good practice: prove this formula by induction Can do it strictly by the numbers Simpler: Do it based on the trees. 13

9-10 Add the elements to the heap Use buildheap Remove the elements and place into the array Repeatedly call deletemin 14