CS 6310 Advanced Data Structure Wei-Shian Wang

Slides:



Advertisements
Similar presentations
§6 Leftist Heaps CHAPTER 5 Graph Algorithms  Heap: Structure Property + Order Property Target : Speed up merging in O(N). Leftist Heap: Order Property.
Advertisements

DATA STRUCTURES AND ALGORITHMS Lecture Notes 9 Prepared by İnanç TAHRALI.
COL 106 Shweta Agrawal and Amit Kumar
CMSC 341 Binary Heaps Priority Queues. 8/3/2007 UMBC CSMC 341 PQueue 2 Priority Queues Priority: some property of an object that allows it to be prioritized.
Priority Queues  MakeQueuecreate new empty queue  Insert(Q,k,p)insert key k with priority p  Delete(Q,k)delete key k (given a pointer)  DeleteMin(Q)delete.
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 19 Leftist Tree Heap Matakuliah: T0026/Struktur Data Tahun: 2005 Versi: 1/1.
Binary Heaps CSE 373 Data Structures Lecture 11. 2/5/03Binary Heaps - Lecture 112 Readings Reading ›Sections
Heaps and heapsort COMP171 Fall Sorting III / Slide 2 Motivating Example 3 jobs have been submitted to a printer in the order A, B, C. Sizes: Job.
B-Tree B-Tree is an m-way search tree with the following properties:
CSE 373 Data Structures Lecture 12
DEAPS By: Michael Gresenz Austin Forrest. Deaps A deap is a double-ended heap that supports the double-ended priority operations of insert, delete-min,
Initializing A Max Heap input array = [-, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
Source: Muangsin / Weiss1 Priority Queue (Heap) A kind of queue Dequeue gets element with the highest priority Priority is based on a comparable value.
AVL trees. AVL Trees We have seen that all operations depend on the depth of the tree. We don’t want trees with nodes which have large height This can.
Heap: A Special Kind of Tree
5.9 Heaps of optimal complexity
Heaps and heapsort COMP171 Fall 2005 Part 2. Sorting III / Slide 2 Heap: array implementation Is it a good idea to store arbitrary.
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.
PRIORITY QUEUES (HEAPS). Queues are a standard mechanism for ordering tasks on a first-come, first-served basis However, some tasks may be more important.
The Binary Heap. Binary Heap Looks similar to a binary search tree BUT all the values stored in the subtree rooted at a node are greater than or equal.
Data Structure & Algorithm II.  Delete-min  Building a heap in O(n) time  Heap Sort.
Data Structures Week 8 Further Data Structures The story so far  Saw some fundamental operations as well as advanced operations on arrays, stacks, and.
Balanced Search Trees Problem: Efficiency of BST is related to tree’s height.  search, insert and remove follow a path from root to desired location 
WEEK 3 Leftist Heaps CE222 Dr. Senem Kumova Metin CE222_Dr. Senem Kumova Metin.
Data Structure & Algorithm II.  In a multiuser computer system, multiple users submit jobs to run on a single processor.  We assume that the time required.
Change Keys in heaps Fibonacci heap Zhao Xiaobin.
CHAPTER 5 PRIORITY QUEUES (HEAPS) §1 ADT Model Objects: A finite ordered list with zero or more elements. Operations:  PriorityQueue Initialize( int.
1 Binomial Tree Binomial tree. n Recursive definition: B k-1 B0B0 BkBk B0B0 B1B1 B2B2 B3B3 B4B4.
Data Structure II So Pak Yeung Outline Review  Array  Sorted Array  Linked List Binary Search Tree Heap Hash Table.
Review for Exam 2 Topics covered (since exam 1): –Splay Tree –K-D Trees –RB Tree –Priority Queue and Binary Heap –B-Tree For each of these data structures.
CS223 Advanced Data Structures and Algorithms 1 Priority Queue and Binary Heap Neil Tang 02/09/2010.
8 January Heap Sort CSE 2011 Winter Heap Sort Consider a priority queue with n items implemented by means of a heap  the space used is.
AVL Trees and Heaps. AVL Trees So far balancing the tree was done globally Basically every node was involved in the balance operation Tree balancing can.
Initializing A Max Heap input array = [-, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
Exam 3 Review Data structures covered: –Hashing and Extensible hashing –Priority queues and binary heaps –Skip lists –B-Tree –Disjoint sets For each of.
Leftist Trees Linked binary tree.
Priority Queue A Priority Queue Set S is made up of n elements: x0 x1 x2 x3 … xn-1 Functions: createEmptySet() returns a newly created empty priority.
CS 201 Data Structures and Algorithms
Binary search tree. Removing a node
Topics covered (since exam 1):
Splay Trees Binary search trees.
Binary Search Tree Neil Tang 01/28/2010
SNS COLLEGE OF TECHNOLOGY (Autonomous ) COIMBATORE-35
Lecture 22 Binary Search Trees Chapter 10 of textbook
Hashing Exercises.
Source: Muangsin / Weiss
CMSC 341 Lecture 13 Leftist Heaps
O(lg n) Search Tree Tree T is a search tree made up of n elements: x0 x1 x2 x3 … xn-1 No function (except transverse) takes more than O(lg n) in the.
Splay Trees Binary search trees.
Binary Trees, Binary Search Trees
Initializing A Max Heap
Topics covered (since exam 1):
Priority Queue and Binary Heap Neil Tang 02/12/2008
Fundamental Structures of Computer Science
CE 221 Data Structures and Algorithms
Heap Sort CSE 2011 Winter January 2019.
Binary Search Tree Neil Tang 01/31/2008
Definition Applications Implementations Heap Comparison
CMSC 341 Lecture 19.
Priority Queues CSE 373 Data Structures.
Heaps By JJ Shepherd.
Leftist Heaps Text Leftist Heap Building a Leftist Heap
Priority Queues Supports the following operations. Insert element x.
Topics covered (since exam 1):
Fibonacci Heaps & Doubled-Ended Heap Structures
Fundamental Structures of Computer Science II
CSE 373 Data Structures Lecture 12
A Heap Is Efficiently Represented As An Array
CS210- Lecture 13 June 28, 2005 Agenda Heaps Complete Binary Tree
Presentation transcript:

CS 6310 Advanced Data Structure Wei-Shian Wang Heaps CS 6310 Advanced Data Structure Wei-Shian Wang

Also called priority queues Support operations: insert, find_min, delete_min Min-heap and max-heap

5.1 Balanced Search Trees as Heaps

insert : O(log n) find_min : O(log n)  O(1) delete_min : O(log n)

Make find_min in O(1) Store the current minimum in a variable Look up the new current minimum in O(log n) time when we perform the next delete_min

delete_min – O(1) Delete the object current_min->object Move current_min to the next list position If current_min->key is now larger than the key in the root of the balanced tree, add the left subtree of the balanced search tree to the invalid nodes structure; take the right subtree as new search tree; and return the node of the old root to the free list Return several nodes from the invalid nodes structure to the free list

insert – O(log n) find_min – O(1) Split the search tree at current_min->key, and add the lower tree to the invalid nodes structure Insert the new key in search tree If the key is below current_min->key, set current_min to the new key and object find_min – O(1) Return current_min->key and current_min->object

Theorem. The heap structure can be realized using a balanced search tree with lazy deletion in time O(log n) for insert and O(1) for find_min and delete_min operations if the heap contains n element.

5.4 Leftist Heaps

Leftist Heap Properties Each node contains an additional field, the rank, which is defined by n->rank = 1 if n->left = NULL or n->right = NULL n->rank = 1 + Min(n->left->rank, n->right->rank) if n->left ≠ NULL and n->right ≠ NULL Heap is empty if root->rank = 0

Most nodes are on the left All the merging work is done on the right Each node in a leftist heap has the shortest path on the left side is at least as long as that on the right side: n->left->rank ≧ n->right->rank If they are not both defined, then if one of them exists, it is the left one: n->left = NULL only if n->right = NULL Most nodes are on the left All the merging work is done on the right

insert O(log n)

delete_min and merge O(log n)

Theorem. The leftist heap structure supports the operation find_min in O(1) time and insert, merge, and delete_min in O(log n) time

Leftist Heap Visualization https://www.cs.usfca.edu/~galles/visualization/LeftistHeap.html

Thank you !