Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Dynamic Trees - Advanced Data Structures and Algorithms - Exam, Exams of Data Structures and Algorithms

Main points of this exam paper are: Advanced Data Structures, Dynamic Trees Data Structure, Alphabetically, Individual Weight Function, Total Weight Function, Data Structure Operation, Essential Properties, Balanced Binary, Implementation, Self-Adjusting Binary

Typology: Exams

2012/2013

Uploaded on 03/23/2013

saruy
saruy ๐Ÿ‡ฎ๐Ÿ‡ณ

4.5

(114)

132 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
- 1 -
1. (10 points) The figure below represents one of the trees in a dynamic trees data structure.
Show the underlying representation of this tree (what Tarjan calls the virtual tree). Be sure
to show the cost of each vertex using the differential form. Arrange each of the binary search
trees so that the label of the node at the root of the BST comes first alphabetically, among all
nodes in the BST.
In the analysis of dynamic trees, we defined an individual weight function on the vertices and
a total weight function. What is the individual weight of c? What is the total weight of e?
CS 541 โ€“ Algorithms and Programs
Problem Set 2 Solutions
J
onathan Turne
r
Exam 2
- 10/28/03
CS 542 โ€“ Advanced Data Structures and Algorithms
Exam 3
J
onathan Turne
r
12/6/05
3
4
3
2
2
5
1
32
6
3
c
e
b
h
j
a
i
g
k
f
d
3
4
3
2
2
5
1
32
6
3
c
e
b
h
j
a
i
g
k
f
d
pf3
pf4
pf5

Partial preview of the text

Download Dynamic Trees - Advanced Data Structures and Algorithms - Exam and more Exams Data Structures and Algorithms in PDF only on Docsity!

  1. (10 points) The figure below represents one of the trees in a dynamic trees data structure.

Show the underlying representation of this tree (what Tarjan calls the virtual tree). Be sure

to show the cost of each vertex using the differential form. Arrange each of the binary search

trees so that the label of the node at the root of the BST comes first alphabetically, among all

nodes in the BST.

In the analysis of dynamic trees, we defined an individual weight function on the vertices and

a total weight function. What is the individual weight of c? What is the total weight of e?

CS 541 โ€“ Algorithms and Programs

Problem Set 2 Solutions

Jonathan Turner Exam 2 - 10/28/

CS 542 โ€“ Advanced Data Structures and Algorithms

Exam 3

Jonathan Turner 12/6/

c

e

b

h

j

a

i

g

k

f

3 d

c

e

b

h

j

a

i

g

k

f

d

  1. (10 points) The correctness of any data structure operation depends on its maintaining

certain essential properties of the data structure. The data portion of the class declaration

for the C++ implementation of the balanced binary search tree data structure is shown

below. What properties of the data must be maintained by programs that operate on it? List

as many properties as you can.

class bbsts {

int n; // trees defined on nodes {1,...,n}

struct node { // tree node structure

int lchild, rchild, parent;

int rank;

keytyp keyfield;

} *vec;

...

};

How does your answer change if t is an ancestor of s , initially? Explain.

Do you think that it would be worthwhile modifying the implementation of self-adjusting

binary search trees to allow the use of these larger splay steps? Why or why not?

  1. (15 points) The differential cost representation used by the path sets data structure requires

that โˆ† min and โˆ† cost be updated during a rotation operation. Show that the two equations

below are correct.

โˆ† cost'(z) =

โˆ† cost(z)

  • โˆ† min(z)

โˆ† min'(c) =

โˆ† min(c) +

โˆ† min(z)

cost,

min

z

x

b c

a

x

z

a b

c

cost

min

โˆ† cost'(z) =

โˆ† cost(z)

  • โˆ† min(z)

โˆ† min'(c) =

โˆ† min(c) +

โˆ† min(z)

cost,

min

z

x

b c

a

x

z

a b

c

cost

min

cost,

min

z

x

b c

a

x

z

a b

c

cost

min

cost,

min

z

x

b c

a

cost,

min

z

x

b c

a

z

x

b c

aa

x

z

a b

c

cost

min

x

z

a b

c

x

z

a b

c

cost

min

โˆ† cost'(z) =

โˆ† cost(z)

  • โˆ† min(z)

โˆ† min'(c) =

โˆ† min(c) +

โˆ† min(z)

cost,

min

z

x

b c

a

x

z

a b

c

cost

min

โˆ† cost'(z) =

โˆ† cost(z)

  • โˆ† min(z)

โˆ† min'(c) =

โˆ† min(c) +

โˆ† min(z)

cost,

min

z

x

b c

a

x

z

a b

c

cost

min

cost,

min

z

x

b c

a

x

z

a b

c

cost

min

cost,

min

z

x

b c

a

cost,

min

z

x

b c

a

c

a

x

z

a b

c

cost

min

cost,

min

z

x

b c

a

x

z

a b

c

cost

min

cost,

min

z

x

b c

a

cost,

min

z

x

b c

a

z

x

b c

aa

x

z

a b

c

cost

min

x

z

a b

c

x

z

a b

c

cost

min

  1. (10 points) The figure below shows an intermediate state in the execution of the minimum

cost augmenting path algorithm for the min-cost max-flow algorithm, using vertex labels to

represent transformed costs.

Draw the residual graph corresponding to this flow, and for each vertex, determine its

distance from s using the transformed costs. Write the distances by the vertices and mark

the edges that are in the shortest path tree from s. Identify a minimum cost augmenting path

in the graph. What is its cost, using the transformed costs?

What is the new value of the vertex label for e when this step is finished? For t?

s

b

a

e

d

t

capacity, cost, flow

label

s c

b

a

e

d

t

capacity, cost, flow

label

c