Midterm Study From Quizes Flashcards

1
Q

Arrange the following expressions from the slowest to fastest growth rate.

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
A

false

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

O(n). When resizing, a new array must be created, and each existing element in the old array is then individually copied into the new array.

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

When do we need to increase the capacity of the underlying data storage array (i.e. data) in order to make space for the new element.

A

When the array is full, the current size equals the capacity. We must then call resize() to increase the array capacity

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

[0, 3, 6, 9, 12, 15]

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

The order in which elements are placed into the Bag ADT is important

A

False, Conceptually, we use the Bag ADT when the insertion order is irrelevant for the problem we’re working on.

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

Which of the following provides better speed for a dynamic array?

A
19
Q

Suppose the size of the dynamic array is n, and we want to insert an element into the array. What is the maximum number of elements we have to move.

A

n,

20
Q
A
21
Q
A
22
Q

What will happen if we attempt to remove a value from an empty queue

A

It will raise an exception when the operation is attempted on an empty queue

23
Q
A
24
Q
A
25
Q

Why is it difficult to implement a deque using the same dynamic array implementation that was used for the dynamic array-based stack?

A

While a stack only has values added to and removed from one end of the array, a deque may have values added to or removed from both the front or the back of the array. The problem is that removing or adding a value located at index 0 (unless it is the only value in the deque) is very difficult. For adding, you must shift all other values up one index in the array, and, for removing, you must shift all other values back one index in the array. Otherwise, it would leave a “hole” in your array. Either operation would have O(n) algorithmic execution time, which is not ideal.

26
Q
A
27
Q

We know that a circular buffer or circular queue is simply an array viewed as a circle instead of a line, where we allow the values to wrap around back to the beginning of the array. When we resize our queue’s underlying physical array, what strategy do we follow?

A

The value at the start index in the old array gets copied to physical index 0 in the new array.

28
Q
A
29
Q
A
30
Q

How many calls to pop() are needed to determine the size of a stack? Answer in terms of n, where n is the number of elements in the stack.

A

n

31
Q
A
32
Q

Why do we need both front and back sentinels when implementing a deque on top of a linked list?

A
33
Q

A _____ binary tree is a binary tree in which every interior node has exactly two children.

A

Full

34
Q

Fill in the following blanks:
If we know a perfect binary tree has height h, then we know:
- it has _____ leaves.
- it has _____ total nodes.

A

2^h
2^(h+1)-1

35
Q

If we know that a perfect binary tree has n nodes, then we know its height is approximately _______.

A

O(log(n))

36
Q

Add the following numbers in the order given to a binary search tree: 45, 67, 22, 100, 75, 13, 11, 64, 30

A
37
Q

What is the height of the tree from the previous question? What is the height of the subtree rooted at the node holding the value 22? What is the depth of the node holding the value 22?

A

3, 2, 1

38
Q

Add the following numbers in the order given to a binary search tree: 3, 14, 15, 20, 25, 30, 33, 62, 200

A
39
Q

Is the following tree balanced? Why or why not? What is the execution time required for searching for a value in this tree?

A

No, it is not balanced because it has all of the child nodes on the right side of the root node and no nodes on the left side. Balanced trees should be able to maintain O(logn) for all operations, however, this tree would yield an execution time of O(n) when searching for a value.

40
Q

Add a new value, 145, to this tree:

A
41
Q

Remove the value 67 from this tree. What value did you replace it with and why?

A
42
Q

For the following binary search tree, list the nodes as they are visited in a pre-order, in-order, and post-order traversal.

A
43
Q

Why is the time required to find a key in a binary search tree O(n) in the worst case?

A

The worst case occurs when the longest path in the tree is followed in search of the target and the longest path is based on the height of the tree. Binary trees come in many shapes and sizes and their heights can vary. We read that a tree of size n can have a minimum height of roughly logn when the tree is complete and a maximum height of n when there is one node per level. If we have no knowledge about the shape of the tree and its height, wwe have to assume the worst and in this case that would be a tree of height n. Thus, the ime required to find a key in a binary search tree is O(n) in the worst case.