Final Exam Questions Flashcards
(40 cards)
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
1
What are the max number of nodes in a balanced binary tree?
n = 2^(h+1) - 1
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
The last node of the heap
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?
O(1)
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
Quadratic Probing
-can fail if the table becomes too full because it may not find an empty slot due to clustering
What is the best case time complexity of adding an edge to a graph with n vertices that is implemented using adjacency matrix ?
O(1)
In finding the Fibonacci number recursively, at an index n, what will be the worst case time complexity of the process? Why?
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.
Two algorithms with the same time complexity may not be equally efficient [True or False]
True
-time complexity doesn’t take into account hidden overhead, input sizes, and constant factors
The best-case time complexity of a sequentially searched chain of n number of linked nodes is O(1) [True or False]
True
-Only one comparison is required to find the element
Binary search is impractical when performed on an unsorted data collection [True or False]
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.
The worst-case time complexity in a binary searched sorted-data-collection of size n is O(logn) [True or False]
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))
The max number of Max-Heap trees that can be formed with 3 nodes with unequal entries is:
2
-largest node stays the at the root meanwhile the two smaller nodes can be switched from left and right
For an n-node Binary Search Tree (BST), what will be the worst-case time complexity in removing an entry from the tree?
O(n)
-If the tree is unbalanced
A Red-black tree is preferred over an AVL tree when the application requires frequent insertion and deletion operations [True or False]
True
-less strict balancing requirements which lead to fewer rotations
The root of a red black tree is always black [True or False]
True
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]
True
What are the conditions for a rotation in a Red-Black tree?
-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.
A red-black tree is a self balancing binary search tree [True or False]
True
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
Red and Black Tree
-it guarantees O(logn) time complexity for common operations like insertion, deletion, and search.
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
None
-use a TreeSet<>
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?
31
O(nlogn) is equivalent to O(n) [True or False]
False
-O(nlogn) grows a lot faster than O(n)
O(5n3 + n log n + 106) is equivalent to O(n3) [True or False]
True
-n^3 is a lot faster than nlogn and 106 -the expression is the same as O(n^3)
O(n2 + n log n) is equivalent to O(n2) [True or False]
True
-n^2 is a lot faster than nlogn