Final Exam Questions Flashcards

(40 cards)

1
Q

What will be the minimum height of a binary search tree (BST) that contains 3 different data items? Note that the height of a tree at the root node is 0

A

1

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

What are the max number of nodes in a balanced binary tree?

A

n = 2^(h+1) - 1

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

To remove the root from a heap structure, you need to start a process by first placing ______ to the place of the root and re-heap it to maintain the heap property

A

The last node of the heap

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

What would be the best case time complexity in finding the presence of an edge between two vertices of a graph when the graph is implemented using adjacency list?

A

O(1)

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

Which probing methods in hashing might fail to insert a next data item in the table, if the load factor is set to be 70%?
-Separate chaining
-Quadratic Probing
-Double Hashing
-None of the above will fail

A

Quadratic Probing
-can fail if the table becomes too full because it may not find an empty slot due to clustering

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

What is the best case time complexity of adding an edge to a graph with n vertices that is implemented using adjacency matrix ?

A

O(1)

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

In finding the Fibonacci number recursively, at an index n, what will be the worst case time complexity of the process? Why?

A

It is proportional to n^2
-The function “branches out” at each step, like a tree splitting into two parts at every level, with overlapping (repeated) calculations.

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

Two algorithms with the same time complexity may not be equally efficient [True or False]

A

True
-time complexity doesn’t take into account hidden overhead, input sizes, and constant factors

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

The best-case time complexity of a sequentially searched chain of n number of linked nodes is O(1) [True or False]

A

True
-Only one comparison is required to find the element

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

Binary search is impractical when performed on an unsorted data collection [True or False]

A

True
-Binary search relies on the data being sorted to function properly
-The algorithm works by repeatedly dividing the search interval in half, which assumes the elements are in order.

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

The worst-case time complexity in a binary searched sorted-data-collection of size n is O(logn) [True or False]

A

True
-The worst-case occurs when the search continues until the collection is reduced to a single element, requiring the maximum number of divisions (which is proportional to the height of the tree Log2(n))

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

The max number of Max-Heap trees that can be formed with 3 nodes with unequal entries is:

A

2
-largest node stays the at the root meanwhile the two smaller nodes can be switched from left and right

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

For an n-node Binary Search Tree (BST), what will be the worst-case time complexity in removing an entry from the tree?

A

O(n)
-If the tree is unbalanced

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

A Red-black tree is preferred over an AVL tree when the application requires frequent insertion and deletion operations [True or False]

A

True
-less strict balancing requirements which lead to fewer rotations

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

The root of a red black tree is always black [True or False]

A

True

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

In ensuring the balance of a red black tree, when a newly inserted node has a red parent and a black ‘uncle’, the rotation must be done before recolouring [True or False]

A

True

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

What are the conditions for a rotation in a Red-Black tree?

A

-The newly inserted node is red
-Its parent is also red
-The “uncle” of the newly inserted node (the sibling of its parent) is black.

17
Q

A red-black tree is a self balancing binary search tree [True or False]

18
Q

Which of the following trees is used to implement the sorting algorithm in TreeSet<>class in Java?
(a) Red and Black Tree
(b) Minheap Tree
(c) Maxheap Tree
(d) AVL Tree
(e) None of the above

A

Red and Black Tree
-it guarantees O(logn) time complexity for common operations like insertion, deletion, and search.

19
Q

Which of the following built-in classes in Java stores elements in their natural order?
(a) HashSet<>
(b) LinkedHashSet<>
(c) ArrayList<>
(d) Vector<>
(e) None of the above

A

None
-use a TreeSet<>

20
Q

If open addressing with linear probing resolves collisions with a maximum of 50% load
factor, what will be minimum required size of the hash table, when 15 different search
keys need to be inserted into an initially empty table?

21
Q

O(nlogn) is equivalent to O(n) [True or False]

A

False
-O(nlogn) grows a lot faster than O(n)

22
Q

O(5n3 + n log n + 106) is equivalent to O(n3) [True or False]

A

True
-n^3 is a lot faster than nlogn and 106 -the expression is the same as O(n^3)

23
Q

O(n2 + n log n) is equivalent to O(n2) [True or False]

A

True
-n^2 is a lot faster than nlogn

24
O(n/22) is equivalent to O(n) [True or False]
True -both grow linearly
25
Which of the following trees can be used to realize the boarding of airplane-passengers with special need who get priority in boarding the airplane (a) AVL tree (b) Red-Black tree (c) Binary Search Tree (d) None of the above.
(d) None of the above -The trees do not give priority to nodes
26
If you need to insert a data item into a max heap-tree, what will be the worst-case time- complexity?
O(logn) -the inserted element is swapped up until the root (the height)
27
Let’s assume that we’ve accommodated 6 hash-keys in a hash table of size 13. If the table uses a load factor of 50%, and open addressing with linear probing method is used to resolve collisions, how many more hash-keys can be inserted into the table before rehashing it?
Already reached max load factor limit of 6 so can't add any more keys
28
Which of the following trees might be an unbalanced and/or a incomplete tree? (a) Binary Search Tree (b) Heap Tree (c) 2-3 Tree (d) 2-4 Tree (e) None of the above
Binary Search Tree -Does not guarantee completeness because there is no requirement for nodes to be filled level by level
29
Given a complete binary search tree, what would be the worst-case time efficiency, in terms of big-Oh, to search for an item from this tree?
O(logn) -The target value is either not present in the tree or located at the lowest level, requiring traversal down the full height
30
Where can you locate the largest element in a Max-Heap tree? (a) It is located amongst the leaf nodes of the tree. (b) It is the rightmost leaf node of the tree. (c) It is the leftmost leaf node of the tree. (d) It is the median of the leaf nodes of the tree. (e) It is the root of the tree.
It is the root of the tree -guaranteed to be greater than or equal to its children
31
What does a Hash Function do?
maps a key with any arbitrary size of data to fixed sized integer data called hash / hash code / hash sum
32
What is a collision?
When a hash function allows more than one search key to map into a single index
33
What makes a good hash function?
-Minimize collisions -Distribute entries uniformly throughout the hash table -Be fast to compute
34
What are the two ways of resolving collisions?
-Use another location in the table -Change the structure of the hash table
35
List the collision handling schemes
-Open addressing -Separate Chaining
36
What is open addressing?
Finding an unused, or open location in the hash table
37
What does the load factor have to be for open addressing with quadratic probing to be successful?
-load factor should be less than 50%
38
Why does probing with open addressing fail?
A hash table may not have a null location -better to increase the size of the hash table
39