Data Structures and Algorithms Fundamentals
Comprehensive quiz covering arrays, trees, graphs, hashing, complexity analysis, and searching algorithms
Questions
If n is even, and assuming that all A[i] are distinct, what what will be the result of the execution of the code given below:
for (i = 0; i < n; i++)
A[i] = A[n+1-i]?
- It results in 2 copies of each value data.
- The values remain unchanged.
- The array reverses.
- None of the above.
In a binary tree, an edge is the one which joins two nodes of two adjacent levels. Maximum possible edges of a tree with height h is
- h – 1
- h
- 2h
- none of the above
A set of values (23, 18, 29, 28, 39, 13, 16, 42, 17) are stored in an array having 11 locations (array indexes starts from 0) using quadratic probing and primary hashing function of key modulus number of locations is used. Possible locations of 17 and 29 are:
- 1, 8
- 4, 8
- 2, 8
- 3, 9
The least integer k such that f (n) = (n3 + 5 log n) / (n4 + 1) is O(nk)
- 1
- 0
- – 1
- 3
Which of the following is not a limitation of binary search algorithm?
- Must use a sorted array
- Requirement of sorted array is expensive when a lot of insertion and deletions are needed
- There must be a mechanism to access middle element directly
- Binary search algorithm is not efficient when the data elements are more than 1000
Which of the following data structure stores the homogeneous data elements?
- Arrays
- Records
- Pointers
- None of the above
A graph’s adjacency matrix is as follows. Then the graph
0100
0010
0001
1000 is:
- directed
- all nodes are a cycle
- one connected component
- all of the above
A 2 - 3 tree is a type of
- binary search tree
- search tree
- binary tree
- AVL tree
The number of distinct strings of length 3 that can be obtained using a, a, b, b, c is
- 7
- 6
- 12
- 15
A graph has adjacency matrix of all 1’s then
- it is fully connected
- its path matrix is same is adjacency matrix
- contains cycles
- all of the above
A Binany Search Tree search complexity is log2N, where N is the number of elements that are maintained as Binany Search Tree. If we change number of childs of the nodes to c instead of 2 in Binany Search Tree, then search complexity becomes
- (log2N)/c
- log2(N/c)
- logcN
- none of the above
Number of data items in a leaf node of a 2-3 tree is:
- 1
- 1 or 2
- 2
- 2 or 3
The indirect change of the values of a variable in one module by another module is called
- internal change
- inter-module change
- side effect
- side-module update
Find the correct statement
- In an undirected graph with positive edge weights, the shortest edge in the graph always belongs to any tree of shortest paths, provided the edge weights are distinct.
- To find the longest path between 2 given vertices in a graph G with positive weights, we can change the weight of every edge e from w(e) to k – w(e), where k is a value larger than any edge weight in G, and then find the shortest path in the resultant graph.
- If T is a tree of shortest paths from vertex s in a graph G, then T is also a tree of shortest paths from vertex s in a graph G’ obtained by increasing the weight of every edge by same value C.
- None of the above
What is the order of growth of the running time of an algorithm, if its running time is:
T(n) = [n(n log n + n2 + 3) + log(0.5n)] / n2 + 3.14
- 3.14n
- 3.14n
- n
- none of the above
The worst case behavior of linear search algorithm is seen when
- item is somewhere in the middle of the array
- item is not in the array at all
- item is the last element in the array
- item is the last element in the array or is not there at all
_______ is a technique that determines the solution by systematically searching the solution space for the given problem.
- Dynamic
- Backtracking
- Greedy
- None of the above
In a heap, element with the greatest key is always in the ___________ node.
- leaf
- root
- first node of left sub tree
- first node of right sub tree
Possible number of spanning trees with 4 vertexes are:
- 4
- 1
- 16
- None of the above
We have a chocolate of rectangular size with mxn rectangular pieces. We need to divide into pieces along the grooves. You are not allowed to split two or more stacked pieces at a time. The approach which divides into individual pieces has
- best case complexity
- worse case complexity
- average complexity
- any trail needs same number of splits
What is the worst case big-oh (asymptotic) cost of searching an element in a Binany Search Tree of depth d?
- O(logn)
- O(d)
- O(2d)
- None of the above
Time complexity of finding middle node of a single linked list is:
- O(1)
- O(log(n))
- O(n)
- O(n/2)
Given two arrays of numbers a1,..........., an and b1,............, bn where each number is 0 or 1, the fastest algorithm to find the largest span (i, j ) such that ai + ai+1 + .........+ aj = bi + bi + 1 +...........+ bj is:
- O(n2)
- O(n3)
- O(nlogn)
- O(2n)
Assume we have coins of denomination 1, 5, 10, 21 and 25 paisa, then the minimum and maximum number of coins needed to make 63 paisa is
- 5, 3
- 7, 3
- 6, 3
- None of these
Number of data items in a leaf node of a 2 - 3 tree are:
- 1
- 1 or 2
- 2
- 2 or 3