Augmenting Data Structures - Introduction to Algorithms - Lecture Slides, Slides of Computer Science

These are the Lecture Slides of Introduction to Algorithms which includes Expensive Operations, Sort Edges, Running Time, Upshot, Union, Makeset, Disjoint Set, Disjoint Set Union, Naïve Implementation etc. Key important points are: Augmenting Data Structures, Interval Trees, Dynamic Order Statistics, Unordered, Support Finding, Dynamic Set, Statistic Operations, Trees Augment, Red Black Trees, Order Statistic Trees

Typology: Slides

2012/2013

Uploaded on 03/23/2013

dhruv
dhruv 🇮🇳

4.3

(12)

194 documents

1 / 37

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Algorithms
Augmenting Data Structures:
Interval Trees
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25

Partial preview of the text

Download Augmenting Data Structures - Introduction to Algorithms - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

Algorithms

Augmenting Data Structures:

Interval Trees

Review: Dynamic Order Statistics

● We’ve seen algorithms for finding the i th

element of an unordered set in O( n ) time

● OS-Trees : a structure to support finding the i th

element of a dynamic set in O(lg n ) time

■ Support standard dynamic set operations

(Insert(), Delete(), Min(), Max(),

Succ(), Pred())

■ Also support these order statistic operations:

void OS-Select(root, i );
int OS-Rank( x );

Review: OS-Select

● Example: show OS-Select( root , 5):

M 8

C 5

P 2

Q 1

A 1

F 3

D 1

H 1

OS-Select(x, i)

{

r = x->left->size + 1; if (i == r) return x; else if (i < r) return OS-Select(x->left, i); else return OS-Select(x->right, i-r);

}

Review: OS-Select

● Example: show OS-Select( root , 5):

M 8

C 5

P 2

Q 1

A 1

F 3

D 1

H 1

OS-Select(x, i)

{

r = x->left->size + 1; if (i == r) return x; else if (i < r) return OS-Select(x->left, i); else return OS-Select(x->right, i-r);

}

i = 5 r = 6

Review: OS-Select

● Example: show OS-Select( root , 5):

M 8

C 5

P 2

Q 1

A 1

F 3

D 1

H 1

OS-Select(x, i)

{

r = x->left->size + 1; if (i == r) return x; else if (i < r) return OS-Select(x->left, i); else return OS-Select(x->right, i-r);

}

i = 5 r = 6

i = 5 r = 2

i = 3 r = 2

Review: OS-Select

● Example: show OS-Select( root , 5):

M 8

C 5

P 2

Q 1

A 1

F 3

D 1

H 1

OS-Select(x, i)

{

r = x->left->size + 1; if (i == r) return x; else if (i < r) return OS-Select(x->left, i); else return OS-Select(x->right, i-r);

}

i = 5 r = 6

i = 5 r = 2

i = 3 r = 2

i = 1 r = 1

Review: Determining The

Rank Of An Element

M
C
P
Q
A
F
D
H

OS-Rank(T, x)

{

r = x->left->size + 1;

y = x; while (y != T->root)

if (y == y->p->right)

r = r + y->p->left->size + 1;

y = y->p;

return r;

}

Idea: rank of right child x is one

more than its parent’s rank, plus

the size of x ’s left subtree

Review: Determining The

Rank Of An Element

M
C
P
Q
A
F
D
H

OS-Rank(T, x)

{

r = x->left->size + 1;

y = x; while (y != T->root)

if (y == y->p->right)

r = r + y->p->left->size + 1;

y = y->p;

return r;

}

Example 1:

find rank of element with key H

y
r = 1

Review: Determining The

Rank Of An Element

M
C
P
Q
A
F
D
H

OS-Rank(T, x)

{

r = x->left->size + 1;

y = x; while (y != T->root)

if (y == y->p->right)

r = r + y->p->left->size + 1;

y = y->p;

return r;

}

Example 1:

find rank of element with key H

r = 1
r = 3
y
r = 3+1+1 = 5

Review: Determining The

Rank Of An Element

M
C
P
Q
A
F
D
H

OS-Rank(T, x)

{

r = x->left->size + 1;

y = x; while (y != T->root)

if (y == y->p->right)

r = r + y->p->left->size + 1;

y = y->p;

return r;

}

Example 1:

find rank of element with key H

r = 1
r = 3
r = 5
y
r = 5

Review: Determining The

Rank Of An Element

M
C
P
Q
A
F
D
H

OS-Rank(T, x)

{

r = x->left->size + 1;

y = x; while (y != T->root)

if (y == y->p->right)

r = r + y->p->left->size + 1;

y = y->p;

return r;

}

Example 2:

find rank of element with key P

r = 1
y
r = 1 + 5 + 1 = 7

Review: Maintaining Subtree Sizes

● So by keeping subtree sizes, order statistic

operations can be done in O(lg n) time

● Next: maintain sizes during Insert() and

Delete() operations

■ Insert(): Increment size fields of nodes traversed

during search down the tree

■ Delete(): Decrement sizes along a path from the

deleted node to the root

■ Both: Update sizes correctly during rotations

Review: Methodology For

Augmenting Data Structures

● Choose underlying data structure

● Determine additional information to maintain

● Verify that information can be maintained for

operations that modify the structure

● Develop new operations

Interval Trees

● The problem: maintain a set of intervals

■ E.g., time intervals for a scheduling program:

7 10

5 11

4 8 15 18 21 23

17 19

i = [7,10]; ilow = 7; ihigh = 10