CS 357 Exam 4
Fall 2007
Solution
1. Begin with an empty hash table of size 11 and use the hash function h(x) = x %11. Insert keys 18, 17, 39, 51, 34, 73, 50, 22, 79, 45, 66 (in that order), and resolve collisions using each of the techniques specified bel
CS 357 Exam 3
Name _
1. Draw a tree (not necessarily binary) whose nodes are visited in the specified order
during preorder and postorder traversals.
Preorder
Postorder
MCOFXRKWAQTGHLZDUEJVPSIYNB
FXROKCQGTAWZDLUJVPEHNYBISM
2. Beginning with an empty min-o
CS 357 Exam 21
Fall 2002
Solutions
1. Show a circular array representation of the deque d as it would appear at the end
of this code fragment. Also specify the final values of d.first and d.last.
ArrayDeque d(10);
/ array of size 10
for (k=20; k<=44; k+)
CS 357 Exam 22
Fall 2002
Name _
1. Show a circular array representation of the deque d as it would appear at the end
of this code fragment. Also specify the final values of d.first and d.last.
ArrayDeque d(10);
/ array of size 10
for (k=10; k<=34; k+)
if
CS 357 Exam 21 Fall 2002
Name _
1. Show a circular array representation of the deque d as it would appear at the end of this code fragment. Also specify the final values of d.first and d.last.
ArrayDeque d(10); / array of size 10 for (k=20; k<=44; k+) if
CS 357 Exam 1
Name _
Using either C+ or Java, write 4 classes Rectangle, Square, Box, and Cube. A rectangle
is specified by length and width. A square is a rectangle such that length = width. A box
is specified by length, width, and height. A cube is a bo
CS 357 Exam 2
Solutions
1. Express the running time of each code fragment as the simplest function of n.
a) for (i=0; i<=n*n*n; i+=n)
x+;
(n2)
b) for (i=1; i<=n*n*n; i*=n)
x+;
(1)
c) for (j=1; j<=n; j+=j)
x+;
(lg n)
d) for (j=2; j<=n; j*=j)
x+;
(lg lg n)
CS 357 Exam 11
Fall 2002
Name _
Using either C+ or Java, write a class Vector that provides all the operations specified
below. Make each operation reasonably efficient, and state the worstcase running time
of each operation as a function of n. Do not wri
CS 357 Exam 2
Name _
1. Express the running time of each code fragment as the simplest function of n.
a) for (i=0; i<=n*n*n; i+=n)
x+;
b) for (i=1; i<=n*n*n; i*=n)
x+;
c) for (j=1; j<=n; j+=j)
x+;
d) for (j=2; j<=n; j*=j)
x+;
e) for (k=1; k<=n; k+)
if (k*
CS 357 Exam 12
Fall 2002
Name _
Using either C+ or Java, write a class Matrix that provides all the operations specified
below. Make each operation reasonably efficient, and state the worstcase running time of
each operation as a function of n. Do not wri
Solution to Exercise 24.1
k 1
6 8
7
The event T KT H occurs with probability
1/2k-11/2 = 1/2k.
and when this event has occurred we have tossed the coin k times. So the expected number of times we need
to toss the coin until it comes up heads is
11/2 [once
Data Structures CS357 Second Midterm Tuesday, October 23, 2003 12:15 pm 2:00pm
Student name . Student number . The maximum number of points that you can earn is 89. If you earn x points, your credit will be x/74 (so 74 points is enough for full credit). Y
Solution to Project 23.1
void SkipList:remove(int key) cfw_ Node *u,*v; u=search(key); / check if the key actually exists in the skip list if( u->key != key ) return; / so the key exists, and u is the leftmost in list S_0 / we need to delete the tower bas
Solution to Exercise 22.1 Recall that in B-tree, the root contains at least one key, and each other node contains at least t-1 keys; each node can contain at most 2t-1 keys; all leaves have the same depth; and any node, that is not a leaf, has the number
Solution to Project 25.1
main() cfw_ / costruct the graph G given on page 609 of the textbook const int n=16; Graph G(n); G.setEdge(0,1); G.setEdge(1,2); G.setEdge(2,3); G.setEdge(0,4); G.setEdge(0,5); G.setEdge(1,5); G.setEdge(3,7); G.setEdge(4,5); G.set
Solution to Exercise 20.1 We know that each node of a B-tree can have at most 2t-1 keys. Therefore each node can have at most 2t children subtrees. Let us look at the maximum number of nodes at consecutive depths. At depth 0, we can have at most 1 node; a
Solution to Exercise 17.1 Any uppercase latter is smaller than its lowercase counterpart. Aphrodite < Apollo < Artemis < Athena < alabama < all = all < data < datagram < structures < university
CS 357 Exam 31
Fall 2002
Name _
1. Start with an empty hash table of size 11 and use a hash function h(k) = k%11.
Insert keys 17, 18, 28, 19, 29, 30, 24, 23, 22, 21, 33 in that order, and resolve
collisions using each of the techniques specified below.
a.
CS 357 Exam 32
Fall 2002
Name _
1. Start with an empty hash table of size 11 and use a hash function h(k) = k%11.
Insert keys 17, 18, 28, 19, 29, 30, 24, 23, 22, 21, 33 in that order, and resolve
collisions using each of the techniques specified below.
a.
CS 357 Exam 5
Fall 2007
Solution
1. Given the red-black tree shown below, insert keys C, J, Q, X (in that order), and draw the final red-black tree that results. The external nodes (dummy leaves) are not shown. The red nodes are indicated, and all other n
CS 357 Exam 5
Fall 2007
Name _
1. Given the red-black tree shown below, insert keys C, J, Q, X (in that order), and draw the final red-black tree that results. The external nodes (dummy leaves) are not shown. The red nodes are indicated, and all other nod
CS 357 Exam 3
Fall 2007
Solution
1. Beginning with an empty min-ordered heap, draw the heap after each operation as follows: first insert keys 7, 6, 3, 1, 2, 5, 4 in that order, and then perform six removeMin operations. Also, show the vector representati
CS 357 Exam 4
Fall 2007
Name _
1. Begin with an empty hash table of size 11 and use the hash function h(x) = x %11. Insert keys 18, 17, 39, 51, 34, 73, 50, 22, 79, 45, 66 (in that order), and resolve collisions using each of the techniques specified below
CS 357 Exam 3
Fall 2007
Name _
1. Beginning with an empty min-ordered heap, draw the heap after each operation as follows: first insert keys 7, 6, 3, 1, 2, 5, 4 in that order, and then perform six removeMin operations. Also, show the vector representation
CS 357 Exam 3 Extra Problem
Fall 2007
Solution
5. You are given this prefix arithmetic expression: -/+-ab*cde*f-+gh/ij a. Write a postfix expression that is equivalent to the given prefix expression. [6 points] ab-cd*+e/fgh+ij/-*b. Write a parenthesized i
CS 357 Exam 3 Extra Problem
Fall 2007
Name _
5. You are given this prefix arithmetic expression: -/+-ab*cde*f-+gh/ij a. Write a postfix expression that is equivalent to the given prefix expression. [6 points]
b. Write a parenthesized infix expression that
CS 357 Exam 1
Fall 2007
Solution
1. Arrange these running times in order from best (most efficient) to worst (least efficient): (1000n), (n), (3n), (n3), (nn), (lg n), (n2), (n lg n), (2n), (3n), (1n). Assume n is very large. [20 points] (1n), (lg n), (3n
CS 357 Exam 2
Fall 2007
Name _
1. Implement each stack and queue operation below by invoking an appropriate deck or sequence operation. Assume that Stack and Queue are subclasses of either a Deck or a Sequence class. [10 points] void Stack:push (int x) cf
CS 357 Exam 1
Fall 2007
Name _
1. Arrange these running times in order from best (most efficient) to worst (least efficient): (1000n), (n), (3n), (n3), (nn), (lg n), (n2), (n lg n), (2n), (3n), (1n). Assume n is very large.
2. Suppose we run some programs