Exam 2 Flashcards

1
Q

Consider an abstraction supporting the operations “allocate”, “allocateAny”, and “freeup” in constant time. How does the “allocateAny” operation detect that all items have already been allocated?

A

The header points at itself

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Which of the following may be performed in O(1) worst-case time?

A

LogicalPredecessor(L, x) on a sorted, doubly linked list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Which binary tree traversal corresponds to the following recursive code?
void traverse(noderef x) {
if (x==null) return;
traverse(x.left);
traverse(x.right);
// process x here }

A

Postorder

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Suppose that only numbers in 1 . . . 100 appear as keys in a binary search tree. While searching for 50, which of the following sequences of keys could not be examined?

A

10, 40, 70, 30, 50

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which phase of counting sort uses this code?
Slot[0]=0;
for (i=1; i<kl i++)
slot[i]=slot[i-1]+count[i-1];

A

Third

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

In a binary search tree, which element does not have a predecessor?

A

The minimum

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Suppose the tree below is a binary search tree whose keys and subtree sizes are NOT SHOWN. Which node will contain the key with rank 10?

A

C

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Why is it common for a circular queue implementation to waste one table element?

A

To avoid confusing an empty queue with a full queue

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Which of the following will NOT BE TRUE regarding the decision tree for QUICKSORT for sorting n input values?

A

Every path from the root to a leaf will have O(n logn) decisions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

The worst-case number of comparisons for finding the kth largest of n keys using PARTITION is in which asymptotic set?

A

O(n^2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

If POP is implemented as return stack[–SP], then PUSH of element X is implemented as:

A

stack[SP++] = X

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Which of the following is a longest common subsequence for 0 1 2 0 1 2 and 0 0 1 2 1 2?

A

0 1 2 1 2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Suppose a value k appears for p entries in the cost function table (C) for an instance of the longest monotonically increasing subsequence problem. Going left-to-right across the corresponding input sequence values (y1), which statement is true?
(Stated formally: For i1 < i2 < . . . < ip, suppose Ci1 = Ci2 = . . . = Cip = k. Which statement is true regarding yi1, yi2, . . ., yip?)

A

They are strictly decreasing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Based on dictionary search performance alone, the best justification for ordering a linked list is:

A

Many more misses than hits are expected.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

The maximum number of rotations while inserting a key into a red-black tree is:

A

2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Suppose the tree below is a binary search tree whose keys and subtree sizes are NOT SHOWN. Which node will contain the key with rank 6?

A

I

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

For which of the following sorts does the decision tree model not apply?

A

LSD Radix Sort

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

In the example of recycling the elements of a list in O(1) time, which situation holds?

A

The list to be recycled is circular, the garbage list is not

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Given a pointer to a node, the worst-case time to delete the node from a singly-linked list with n nodes in ascending order is:

A

O(n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Which of the following binary trees has exactly one legal coloring as a red-black tree?

A

B

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What does counting sort count?

A

The number of occurences for each possible key value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

The subset sum problem takes n input values and attempts to find a combination of those values whose sum is m. The worst-case time to extract the solution from the dynamic programming table is:

A

O(n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Which of the following will NOT BE TRUE regarding the decision tree for HEAP-SORT for sorting n input values?

A

There will be (n logn) leaves.

24
Q

Suppose a node x in an unbalanced binary search tree has two children, each storing one key. What is the first step to delete x?

A

Find the successor of x

25
Q

If POP is implemented as return stack[SP–], then PUSH of element X is implemented as:

A

stack[++SP] = X

26
Q

Suppose a (singly) linked list is used to implement a queue. Which of the following is true?

A

The head points to the first element and the tail points to the last element.

27
Q

The purpose of the binary searches used when solving the longest (monotone) increasing subsequence (LIS) problem is:

A

To determine the longest possible increasing subsequence terminated by a particular input value

28
Q

What is the worst-case time to perform MINIMUM(L ) for a sorted, doubly-lnked list with n nodes?

A

O(1)

29
Q

Suppose a postfix evaluator has already processed 3 2 1 + * 4 5 + (with more to follow). What will be the contents of the stack (shown bottom-to-top going left-to-right)?

A

9 9

30
Q

Which phase of counting sort actually “counts”?

A

Second

31
Q

The most accurate description of the time to perform a deletion in an unbalanced binary search tree with n keys and height h is:

A

O(h)

32
Q

Suppose the tree below is a binary search tree whose keys and subtree sizes are NOT SHOWN. Which node will contain the key with rank 8?

A

A

33
Q

The expected number of comparisons for finding the kth largest of n keys using PARTITION is in which asymptotic set?

A

O(n)

34
Q

The time to fill in the dynamic programming matrix when computing the LCS for sequences of lengths m and n is:

A

O(mn)

35
Q

In the example of recycling the elements of a list in O(1) time, which element becomes the first element of the garbage list?

A

The second element of the circular list

36
Q

Suppose that only numbers in 1 . . . 1000 appear as keys in a binary search tree. While searching for 500, which of the following sequences of keys could not be examined?

A

100, 1000, 200, 800, 300, 900, 500

37
Q

Which of the following would not be used in implementing rat-in-a-maze in a depth-first fashion?

A

Circular Queue

38
Q

Memoization is associated with which technique?

A

Top-Down Dynamic Programming

39
Q

Which phase of counting sort clears the count table?

A

First

40
Q

If POP is implemented as return stack[–SP], then the test for an empty stack is implemented as:

A

return SP==0

41
Q

The minimum number of rotations while inserting a key into a red-black tree is:

A

0

42
Q

Suppose the tree below is a binary search tree whose keys and subtree sizes are NOT SHOWN. Which node will contain the key with rank 5?

A

E

43
Q

Circular linked lists are occasionally useful because

A

Some operations may be done in constant time

44
Q

Given a pointer to a node, the worst-case time to delete the node from an unsorted, doubly-linked list with n nodes is:

A

O(1)

45
Q

How will a circular queue implementation test for an empty queue?

A

return tail==head

46
Q

If POP is implemented as return stack[SP–], then the test for an empty stack is implemented as:

A

return SP==(-1)

47
Q

Which binary tree traversal corresponds to the following recursive code?
Traverse(noderef x) {
if (x==null) return;
traverse(x.left);
// process x here
traverse(x.right); }

A

Inorder

48
Q

Suppose a binary search tree includes each subtree’s size at the subtree’s root. How should the rank for the key stored at the tree’s root be computed?

A

Add 1 to the subtree size for the subtree to the left of the root

49
Q

Assuming the input has been sorted, Huffman coding may use:

A

Queues

50
Q

Which is minimized in the dynamic programming solution to the subset sum problem?

A

The index stored for each C(i)

51
Q

Given a pointer to a node, the worst-case time to insert the node into an unsorted, doubly-linked list with n nodes is:

A

O(1)

52
Q

Suppose the tree below is a binary search tree whose keys and subtree sizes are NOT SHOWN. Which node will contain the key with rank 9?

A

C

53
Q

Given a pointer to a node, the worst-case time to delete the node from a doubly-linked list with n nodes in ascending order is:

A

O(1)

54
Q

Which sort treats keys as several digits and uses a counting sort for each position

A

Radix

55
Q
A