[modified] Exam-2 Flashcards

1
Q

For which of the following sorts does the decision tree model not apply?
a) insertion
b) LSD radix sort
c) merge-sort
d) quicksort

A

b) LSD radix sort

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

In the example of recycling the elements of a list in O(1) time, which situation holds?
a) both lists are circular
b) both lists are not circular
c) the list to be recycled is circular, the garbage list is not
d) the garbage list is circular, the list to be recycled is not

A

c) 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
3
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

Θ(n)

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

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
6
Q

The subset sum problem takes n input values and attempts to find a combination of those values whose sum in 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
7
Q

Which of the following will not be true regarding the decision tree for HEAP-SORT for sorting n input values?
a) every path from the root to a leaf will have O(n log n) decisions
b) the height of the tree is Ω(n log n)
c) there will be a path from the root to a leaf with Ω(n^2) decisions
d) there will be n! leaves

A

c) there will be a path from the root to a leaf with Ω(n^2) decisions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
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
10
Q

Suppose a (singly) linked list is used to implement a queue. Which of the following is true?
a) like a circular queue, the maximum number of items is determined at initialization
b) the head points to the first element and the tail points to the last element
c) the tail points to the first element and the head points to the last element
d) one node is always wasted

A

b) the head points to the first element and the tail points to the last element

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
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 }

A

postorder

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
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

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

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

A

the maximum

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
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

Θ(h)

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

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

A

O(n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
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

Θ(1)

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

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

A

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

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 element becomes the first element of the garbage list?

A

the second element of the circular list

19
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

20
Q

Which of the following may be performed in O(1) worst-case time?
a) Search(L, k) on a sorted, singly linked list
b) Search(L, k) on an unsorted, singly linked list
c) LogicalPredecessor(L, x) on a sorted, singly linked list
d) LogicalPredecessor(L, x) on a sorted, doubly linked list

A

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

21
Q

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

A

return SP==0

22
Q

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

A

Θ(n^2)

23
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

Θ(1)

24
Q

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

A

preorder

25
Q

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

A

Θ(1)

26
Q

Free-Response

The asymptotic number of nodes in the decision tree for any key-comparison sorting algorithm for an input sequence with n unique values is:

A

Θ(2^n)

27
Q

Long Answer

Describe the four phases of counting sort and give the asymptotic complexity for each phase.

A
  1. Clear the count table - one counter for each value in range (i < k) and repeat count[i]=0 [takes Θ(k) time]
  2. Pass through input table - add to appropriate counter for each key (i < n) and repeat count[inp[i]]++ [takes Θ(n) time]
  3. Determine first slot that will receive a record for each range value. Initialize slot[0]=0 and loop (i < k) and repeat slot[i]=slot[i-1]+count[i-1] [takes Θ(k) time]
  4. Copy each record to output, increment index in table from 3rd step (i < n) and repeat out[slot[inp[i]]++]=inp[i] [takes Θ(n) time]
28
Q

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

A

third

29
Q

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

A

the minimum

30
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

31
Q

Which of the following will not be true regarding the decision tree for QUICKSORT for sorting n input values?
a) there will be n! leaves
b) every path from the root to a leaf will have O(n log n) decisions
c) there will be a path from the root to a leaf with Ω(n^2) decisions
d) the height of the tree is Ω(n log n)

A

b) every path from the root to a leaf will have O(n log n) decisions

32
Q

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

A

stack[SP++] = X

33
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 (yi), 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

34
Q

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

A

many more misses than hits are expected

35
Q

Which phase of counting sort actually “counts”?

A

second

36
Q

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

A

Θ(n)

37
Q

Memoization is associated with which technique?

A

top-down dynamic programming

38
Q

Circular linked lists are occasionally useful because

A

some operations may be done in constant time

39
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

Θ(1)

40
Q

Which phase of counting sort clears the count table?

A

first

41
Q

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

A

return tail==head

42
Q

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

A

queues

43
Q

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

A

the index stored for each C(i)