Transcript
Page 1: Design and Analysis of Algorithms Dynamic Set Model Haidong Xue Summer 2012, at GSU

Design and Analysis of AlgorithmsDynamic Set Model

Haidong XueSummer 2012, at GSU

Page 2: Design and Analysis of Algorithms Dynamic Set Model Haidong Xue Summer 2012, at GSU

Motivation

• Programs manipulate datae.g.– Sorting– Wildfire simulation– Computer games– Google search engine

• In many cases, data can be represented as a “dynamic set”

Page 3: Design and Analysis of Algorithms Dynamic Set Model Haidong Xue Summer 2012, at GSU

Elements of a dynamic set

• <Key, Satellite data>– E.g. : • <key, value>; • <key, color>.

• Satellite data– Unused data by set implementation (see page 229

for more details)

2 3 6 1 7 5

Page 4: Design and Analysis of Algorithms Dynamic Set Model Haidong Xue Summer 2012, at GSU

Operations on dynamic set

• SEARCH(S, k) – returns the pointer of

• MINIMUM(S) – returns the pointer of x=<

• MAXIMUM(S)– returns the pointer of x=<

• SUCCESSOR(S, x)– returns the pointer of x=<

• PREDECESSOR(S, x)– returns the pointer of x=<

• INSERT(S, x)• DELETE(S, x)

𝑆={<𝑘1 ,𝑑1>,<𝑘2 ,𝑑2>,…,<𝑘𝑛 ,𝑑𝑛>}

Page 5: Design and Analysis of Algorithms Dynamic Set Model Haidong Xue Summer 2012, at GSU

Operations on dynamic set

• SEARCH(S, k)• MINIMUM(S)• MAXIMUM(S)• SUCCESSOR(S, x)• PREDECESSOR(S, x)• INSERT(S, x)• DELETE(S, x)

Input (S is known) Result2 3 6 1

7

5

6 6

(nothing) 1

(nothing) 7

6 7

6 5

4 2 3 6 1 7 5 4

2 3 6 1 5

7

Page 6: Design and Analysis of Algorithms Dynamic Set Model Haidong Xue Summer 2012, at GSU

Difference among data structures

• MAXIMUM(S)• DELETE(S, x )

Array Linked-List

2 3 6 1 5

Max-heap

Max:

2 3 66

O(n) O(n)

1

5

2

3

6

O(1)

1 52 3 6

3 O(n)

1 52 3 6

O(1)

1

5

2

3

6

O(n)

Build-Max-Heap

Page 7: Design and Analysis of Algorithms Dynamic Set Model Haidong Xue Summer 2012, at GSU

Example: influence in quicksort

2 8 71 3 5 6 4 2 8 71 3 5 6 4

O(1) O(n)

Do it in linked-list:

2 8 71 3 5 6 4

tail

The last step of a partition: swap the pivot with A[tail+1]

Do it in an array:

Page 8: Design and Analysis of Algorithms Dynamic Set Model Haidong Xue Summer 2012, at GSU

Examples

• Dynamic set examples– Webpage search• Key: key words• Satellite data: web page• Frequent operation: SERACH

– Simulation engine• Key: model id• Satellite data: model information• Frequent operation: SEARCH, INSERT, DELETE