1 Pertemuan 19 Leftist Tree Heap Matakuliah: T0026/Struktur Data Tahun: 2005 Versi: 1/1.

Slides:



Advertisements
Similar presentations
Heaps1 Part-D2 Heaps Heaps2 Recall Priority Queue ADT (§ 7.1.3) A priority queue stores a collection of entries Each entry is a pair (key, value)
Advertisements

1 Pertemuan 12 Binary Search Tree Matakuliah: T0026/Struktur Data Tahun: 2005 Versi: 1/1.
Pairing Heaps. Experimental results suggest that pairing heaps are actually faster than Fibonacci heaps.  Simpler to implement.  Smaller runtime overheads.
Leftist Heaps Text Read Weiss, §23.1 (Skew Heaps) Leftist Heap Definition of null path length Definition of leftist heap Building a Leftist Heap Sequence.
1 Pertemuan 20 Binomial Heap Matakuliah: T0026/Struktur Data Tahun: 2005 Versi: 1/1.
1 Pertemuan 14 Object Query Language (Lanjutan bagian 1) Matakuliah: M0174/OBJECT ORIENTED DATABASE Tahun: 2005 Versi: 1/0.
Lec 6 Feb 17, 2011  Section 2.5 of text (review of heap)  Chapter 3.
© 2004 Goodrich, Tamassia Heaps © 2004 Goodrich, Tamassia Heaps2 Priority Queue Sorting (§ 8.1.4) We can use a priority queue to sort a set.
1 Pertemuan 21 Audit Reporting Matakuliah:A0274/Pengelolaan Fungsi Audit Sistem Informasi Tahun: 2005 Versi: 1/1.
Binomial Heaps. Min Binomial Heap Collection of min trees
Initializing A Max Heap input array = [-, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
Instructors: C. Y. Tang and J. S. Roger Jang All the material are integrated from the textbook "Fundamentals of Data Structures in C" and some supplement.
1 Pertemuan 20 Time & Condition Clauses with Future reference Matakuliah: G0134 – Grammar III Tahun: 2005 Versi: revisi 1.
1 Pertemuan 13 AVL Tree Matakuliah: T0026/Struktur Data Tahun: 2005 Versi: 1/1.
Source: Muangsin / Weiss1 Priority Queue (Heap) A kind of queue Dequeue gets element with the highest priority Priority is based on a comparable value.
1 Pertemuan 09 Binary Tree Matakuliah: T0534/Struktur Data Tahun: 2005 Versi: September 2005.
1 Pertemuan #3 Clocks and Realtime Matakuliah: H0232/Sistem Waktu Nyata Tahun: 2005 Versi: 1/5.
Priority Queues1 Part-D1 Priority Queues. Priority Queues2 Priority Queue ADT (§ 7.1.3) A priority queue stores a collection of entries Each entry is.
1 Pertemuan 11 Tree & Binary Tree Matakuliah: T0026/Struktur Data Tahun: 2005 Versi: 1/1.
Heaps and Priority Queues Priority Queue ADT (§ 2.4.1) A priority queue stores a collection of items An item is a pair (key, element) Main.
Priority Queues, Heaps & Leftist Trees
CSC 172 DATA STRUCTURES. Priority Queues Model Set with priorities associatedwith elements Priorities are comparable by a < operator Operations Insert.
Leftist Trees Linked binary tree. Can do everything a heap can do and in the same asymptotic complexity.  insert  remove min (or max)  initialize Can.
ADT Table and Heap Ellen Walker CPSC 201 Data Structures Hiram College.
單元7: Heap 定義 for priority queues Leftist trees Binomial heap
Data Structure & Algorithm II.  Delete-min  Building a heap in O(n) time  Heap Sort.
WEEK 3 Leftist Heaps CE222 Dr. Senem Kumova Metin CE222_Dr. Senem Kumova Metin.
SNU IDB Lab. Ch.13 Priority Queues © copyright 2006 SNU IDB Lab.
Chapter 2: Basic Data Structures. Spring 2003CS 3152 Basic Data Structures Stacks Queues Vectors, Linked Lists Trees (Including Balanced Trees) Priority.
Priority Queues Two kinds of priority queues: Min priority queue. Max priority queue. Nov 4,
Data Structure II So Pak Yeung Outline Review  Array  Sorted Array  Linked List Binary Search Tree Heap Hash Table.
1 Heaps A heap is a binary tree. A heap is best implemented in sequential representation (using an array). Two important uses of heaps are: –(i) efficient.
Initializing A Max Heap input array = [-, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
Dynamic Dictionaries Primary Operations:  get(key) => search  put(key, element) => insert  remove(key) => delete Additional operations:  ascend()
Heaps © 2010 Goodrich, Tamassia. Heaps2 Priority Queue ADT  A priority queue (PQ) stores a collection of entries  Typically, an entry is a.
Leftist Trees Linked binary tree.
Pertemuan 22 The Business Views of the Technology Architecture
Priority Queues © 2010 Goodrich, Tamassia Priority Queues 1
Heaps 8/2/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser,
Hashing Exercises.
Part-D1 Priority Queues
Heaps © 2010 Goodrich, Tamassia Heaps Heaps
Bohyung Han CSE, POSTECH
Heaps 9/13/2018 3:17 PM Heaps Heaps.
Dynamic Dictionaries Primary Operations: Additional operations:
Heaps and Priority Queues
Pairing Heaps Actual Complexity.
Chapter 8 – Binary Search Tree
Initializing A Max Heap
Part-D1 Priority Queues
Heaps 11/27/ :05 PM Heaps Heaps.
Tree Representation Heap.
Heaps A heap is a binary tree.
Heaps and Priority Queues
© 2013 Goodrich, Tamassia, Goldwasser
Heaps 12/4/2018 5:27 AM Heaps /4/2018 5:27 AM Heaps.
Ch. 8 Priority Queues And Heaps
Heaps and Priority Queues
Dr.Surasak Mungsing CSE 221/ICT221 Analysis and Design of Algorithms Lecture 05-2: Analysis of time Complexity of Priority.
Heaps © 2014 Goodrich, Tamassia, Goldwasser Heaps Heaps
Heaps and Priority Queues
CMSC 341 Lecture 19.
Heaps By JJ Shepherd.
Leftist Heaps Text Leftist Heap Building a Leftist Heap
CS 6310 Advanced Data Structure Wei-Shian Wang
Pairing Heaps Actual Complexity
A Heap Is Efficiently Represented As An Array
Heaps 9/29/2019 5:43 PM Heaps Heaps.
CS210- Lecture 13 June 28, 2005 Agenda Heaps Complete Binary Tree
Presentation transcript:

1 Pertemuan 19 Leftist Tree Heap Matakuliah: T0026/Struktur Data Tahun: 2005 Versi: 1/1

2 Learning Outcomes Pada akhir pertemuan ini, diharapkan mahasiswa akan mampu : Mahasiswa dapat menghasilkan program modular untuk mengimplementasikan Letftist tree

3 Outline Materi Pengertian dan kegunaan leftist tree heap contoh leftist tree heap operasi leftist tree heap implementasi program leftist tree heap

Leftist Trees Linked binary tree. Can do everything a heap can do and in the same asymptotic complexity.  insert  remove min (or max)  initialize Can meld two leftist tree priority queues in O(log n) time.

Extended Binary Trees Start with any binary tree and add an external node wherever there is an empty subtree. Result is an extended binary tree.

A Binary Tree

An Extended Binary Tree number of external nodes is n+1

The Function s() For any node x in an extended binary tree, let s(x) be the length of a shortest path from x to an external node in the subtree rooted at x.

s() Values Example

Properties Of s() If x is an external node, then s(x) = 0. Otherwise, s(x) = min {s(leftChild(x)), s(rightChild(x))} + 1

Height Biased Leftist Trees A binary tree is a (height biased) leftist tree iff for every internal node x, s(leftChild(x)) >= s(rightChild(x))

A Leftist Tree

Leftist Trees – Property 1 In a leftist tree, the rightmost path is a shortest root to external node path and the length of this path is s(root).

A Leftist Tree Length of rightmost path is 2.

Leftist Trees—Property 2 The number of internal nodes is at least 2 s(root) - 1 Because levels 1 through s(root) have no external nodes.

A Leftist Tree Levels 1 and 2 have no external nodes.

Leftist Trees—Property 3 Length of rightmost path is O(log n), where n is the number of (internal) nodes in a leftist tree. Follows from Property 2.  n >= 2 s(root) – 1 => s(root) <= log 2 (n+1)

Leftist Trees As Priority Queues Min leftist tree … leftist tree that is a min tree. Used as a min priority queue. Max leftist tree … leftist tree that is a max tree. Used as a max priority queue.

A Min Leftist Tree

Some Min Leftist Tree Operations put removeMin() meld() initialize() put() and removeMin() use meld().

Put Operation put(7) Create a single node min leftist tree. 7 Meld the two min leftist trees.

Remove Min Remove the root.

Remove Min Remove the root. Meld the two subtrees.

Meld Two Min Leftist Trees Traverse only the rightmost paths so as to get logarithmic performance.

Meld Two Min Leftist Trees Meld right subtree of tree with smaller root and all of other tree.

Meld Two Min Leftist Trees Meld right subtree of tree with smaller root and all of other tree.

Meld Two Min Leftist Trees Meld right subtree of tree with smaller root and all of other tree.

Meld Two Min Leftist Trees 8 6 Meld right subtree of tree with smaller root and all of other tree. Right subtree of 6 is empty. So, result of melding right subtree of tree with smaller root and other tree is the other tree.

Meld Two Min Leftist Trees Swap left and right subtree if s(left) < s(right). Make melded subtree right subtree of smaller root

Meld Two Min Leftist Trees Make melded subtree right subtree of smaller root. Swap left and right subtree if s(left) < s(right).

Meld Two Min Leftist Trees Swap left and right subtree if s(left) < s(right). Make melded subtree right subtree of smaller root

Meld Two Min Leftist Trees

Initializing In O(n) Time Create n single-node min leftist trees and place them in a FIFO queue. Repeatedly remove two min leftist trees from the FIFO queue, meld them, and put the resulting min leftist tree into the FIFO queue. The process terminates when only 1 min leftist tree remains in the FIFO queue. Analysis is the same as for heap initialization.

Arbitrary Remove Remove element in node pointed at by x. L x A B R x = root => remove min.

Arbitrary Remove, x != root L x A B R Make L right subtree of p. Adjust s and leftist property on path from p to root. Meld with R. p