Interval Heaps - Advanced Data Structures - Lecture Slides, Slides of Computer Science

These are the Lecture Slides Advanced Data Structures which includes Actual and Amortized Complexity, Splay Tree Operation, Potential Function, Join and Split Operations, Number of Splay Trees, Splay Step Amortized Cost etc. Key important points are: Interval Heaps, Complete Binary Tree, Define Max Heap, Insert Element, Another Insert, Left End Point, Remove Min Element, Swap End Points, Cache Optimization, Uniformly Distributed Keys

Typology: Slides

2012/2013

Uploaded on 03/19/2013

dharmakeerti
dharmakeerti 🇮🇳

4.2

(27)

89 documents

1 / 14

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
Interval Heaps
Complete binary tree.
Each node (except possibly last one) has 2 elements.
Last node has 1 or 2 elements.
Let a and b be the elements in a node P, a <= b.
[a, b] is the interval represented by P.
The interval represented by a node that has just one
element a is [a, a].
The interval [c, d] is contained in interval [a, b] iff a <=
c <= d <= b.
In an interval heap each node’s (except for root)
interval is contained in that of its parent.
Interval
[c,d] is contained in [a,b]
a <= c
d <= b
a b
c d
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download Interval Heaps - Advanced Data Structures - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

Interval Heaps

• Complete binary tree.

• Each node (except possibly last one) has 2 elements.

• Last node has 1 or 2 elements.

• Let a and b be the elements in a node P, a <= b.

• [a, b] is the interval represented by P.

• The interval represented by a node that has just one

element a is [a, a].

• The interval [c, d] is contained in interval [a, b] iff a <=

c <= d <= b.

• In an interval heap each node’s (except for root)

interval is contained in that of its parent.

Interval

• [c,d] is contained in [a,b]

• a <= c

• d <= b

a b

c d

Example Interval Heap

Left end points define a min heap.

Right end points define a max heap.

Min and max elements are in the root.

Store as an array.

Height is ~log

2

n.

Example Interval Heap

Insert 18.

New element becomes a left end point.

Insert new element into min heap.

Another Insert

Insert 18.

New element becomes a left end point.

Insert new element into min heap.

Another Insert

Yet Another Insert

Insert 82.

New element becomes a right end point.

Insert new element into max heap.

After 82 Inserted

Remove Min Element

• n = 0 => fail.

• n = 1 => heap becomes empty.

• n = 2 => only one node, take out left end point.

• n > 2 => not as simple.

Remove Min Element Example

Remove left end point from root.

Remove left end point from last node.

Reinsert into min heap, begin at root.

Delete last node if now empty.

Swap with right end point if necessary.

Remove Min Element Example

Swap with right end point if necessary.

Remove Min Element Example

Initialize

Examine nodes bottom to top.

Swap end points in current root if needed.

Reinsert right end point into max heap.

Reinsert left end point into min heap.

Cache Optimization

• Heap operations.

 Uniformly distributed keys.

 Insert percolates 1.6 levels up the heap on average.

 Remove min (max) height – 1 levels down the heap.

• Optimize cache utilization for remove min

(max).

Cache Aligned Array

• L1 cache line is 32 bytes.

• L1 cache is 16KB.

• Heap node size is 8 bytes (1 8-byte element).

• 4 nodes/cache line.

• A remove min (max) has ~h L1 cache misses

on average.

 Root and its children are in the same cache line.

 ~log

2

n cache misses.

 Only half of each cache line is used (except root’s).

d-ary Heap

• Complete n node tree whose degree is d.

• Min (max) tree.

• Number nodes in breadth-first manner with

root being numbered 1.

• Parent(i) = ceil((i – 1)/d).

• Children are d(i – 1) + 2, …, min{di + 1, n}.

• Height is log

d

n.

• Height of 4-ary heap is half that of 2-ary heap.

d-ary Heap Performance

• Speedup of about 1.5 to 1.8 when sorting 1

million elements using heapsort and cache-

aligned 4-heap vs. 2-heap that begins at

array position 0.

• Cache-aligned 4-heap generally performs as

well as, or better, than other d-heaps.

• Use degree 4 complete tree for interval

heaps instead of degree 2.

Application Of Interval Heaps

• Complementary range search problem.

 Collection of 1D points (numbers).

 Insert a point.

  • O(log n)

 Remove a point given its location in the structure.

  • O(log n)

 Report all points not in the range [a,b], a <= b.

  • O(k), where k is the number of points not in the range.

Example

[5,100]

[2,65]

Example

[2,65]