Data Structures and Algorithms MCQs

Data Structures and Algorithms MCQs

These Data Structures and Algorithms multiple-choice questions and their answers will help you strengthen your grip on the subject of Data Structures and Algorithms. You can prepare for an upcoming exam or job interview with these Data Structures and Algorithms MCQs.
So scroll down and start answering.

1: External sorting is a way of

A.   sorting data that is too large to fit into RAM

B.   sorting data without the usage of a recursive implementation

C.   sorting data outside a specific performance bound

2: What compares adjacent elements and exchanges them to put an array in order?

A.   Insertion sort

B.   Selection sort

C.   Quicksort

D.   Bubble sort

3: Which steps through an array sequentially until a match is found?

A.   Hashing

B.   Sequential Search

C.   Fibonacci Search

D.   Binary Search

4: Which represents data as a chain of nodes and provides dynamic growth of data?

A.   Stack

B.   Linked List

C.   Sequence

D.   Array

5: Which of the following data structures is efficient in tree construction?

A.   Queue

B.   Array

C.   Stack

D.   Linked List

6: Which is the most suitable data structure for hierarchical data models?

A.   Priority Queue

B.   Linked List

C.   Tree

D.   Array

7: The smalled element of an array's index is called its:

A.   Lower bound

B.   Upper bound

C.   Midpoint

D.   Range

8: What is the process a procedure goes through when one of the steps of the procedure involves invoking the procedure itself?

A.   Induction

B.   Recursion

C.   Sequencing

D.   Looping

9: Can a binary tree be implemented using an array?

A.   Yes

B.   No

10: What is the most suitable data structure for a situation where tasks must be scheduled for execution on a computer and the tasks include system tasks?

A.   Tree

B.   Array

C.   Linked List

D.   Priority Queue

11: Minimum number of queues needed to implement the priority queue?

A.   One.

B.   Two. One queue is used for actual storing of data and another for storing priorities.

C.   Three.

D.   Four.

12: Which starts with an empty list and adds elements one-by-one to create a sorted list?

A.   Insertion sort

B.   Selection sort

C.   Bubble sort

D.   Quicksort

A.   Sequential Search

B.   Hashing algorithm has been performed

C.   Sorted Array

D.   Unsorted Array

14: What is the difference between the stack and queue data structures?

A.   Stack requires recursive search technique; Queue does not.

B.   Stack uses selection sort; Queue uses bubble sort.

C.   Stack is LIFO; Queue is FIFO.

D.   Stack is FIFO; Queue is LIFO.

15: A(n) ______ is the data structure used more than any other data structure.

A.   Binary Tree

B.   Array

C.   Linked List

D.   B-tree

16: The most common solution to the Towers of Hanoi involves the use of which datastructure

A.   Hashtable

B.   Set

C.   Stack

D.   Queue

17: All binary trees are balanced

A.   True

B.   False

18: BFS and DFS are two types of

A.   Sorting algorithms

B.   Searching algorithms

C.   computational complexity measurements

19: Which is an ordered collection of elements in which insertions are restricted to the rear end and deletions are restricted to the front end?

A.   Stack

B.   Binary tree

C.   Queue

D.   Array

20: What is the running time of finding Nth element in array using quick sort? (For example: Find the 4th smallest element in an unsorted array.)

A.   n!

B.   2 ^ n

C.   n * log(n)

D.   n ^ 3

E.   n ^ 2

21: A stack must always be implemented using an array

A.   False

B.   True

22: Which of the following is NOT a basic function of a linked list?

A.   Deletion of a leaf

B.   Creation of a list

C.   Insertion of a node

D.   Deletion of a node

23: Which is an access mechanism that transforms the search key into a storage address, thereby providing very fast access to stored data?

A.   Pointers

B.   Recursion

C.   Binary Search

D.   Hashing

24: A perfect hash function is

A.   maps each hash value to a different valid input

B.   maps each valid input to a different hash value

C.   not possible

25: What is the data structure used to perform recursion?

A.   Array

B.   Binary Tree

C.   B-tree

D.   Stack

26: What is the data structures used to perform recursion?

A.   Heap

B.   Linked List

C.   Stack

D.   Queue

27: Collision resolution is not required if a hash function is perfect

A.   True

B.   False

28: In which of the following areas is data structures NOT applied extensively?

A.   Compiler design

B.   Simulation

C.   Website design

D.   Graphics

29: Which is a collection of distinct unordered elements with a common type and no duplicates?

A.   Set

B.   Stack

C.   Sequence

D.   Structure

30: What is the time complexity to compute the average of a N×M matrix?

A.   O(N^2)

B.   It depends on how both N and M vary.

C.   O(N*M)

D.   O(N+M)

31: Bubble sort's worst case performance is

A.   O(log n)

B.   O(n^3)

C.   O(n^2)

D.   O(1)

E.   O(n)

32: Which of the following problems has the fastest algorithms?

A.   Find the 2nd largest value in an array

B.   Find the 2nd smallest value in an array

C.   Find the maximum value in an array.

D.   Find the median value in an array

33: A balanced binary search tree search average output is

A.   O(n^2)

B.   O(n * log n)

C.   O(log n)

D.   O(n)

E.   O(1)

34: In tree there may be more than one path from root to leaf node

A.   False

B.   True

35: What is the minimum number of queues needed to implement a priority queue?

A.   Ten

B.   Once

C.   Three

D.   Two

36: What is the time complexity to insert an item into a B-Tree?

A.   O(1)

B.   O(N^2)

C.   O(log N)

D.   O(N)

E.   O(N * log N)

37: Which data structure provides the fastest lookup time

A.   HashMap

B.   Fibonacci heap

C.   Sorted list

D.   B-tree

E.   Doubly-linked list

38: The path length from root to farthest leaf node is the ______ of the tree.

A.   Set

B.   Height

C.   Size

D.   Depth

39: What is the correct order for a in-order binary tree traversal?

A.   Right Child - Parent - Left Child

B.   Left Child - Parent - Right Child

C.   Parent - Left Child - Right Child

D.   Left Child - Right Child - Parent

40: Worst case insert for a dynamic array is

A.   O(n^2)

B.   O(1)

C.   O(log n)

D.   O(n)

41: Heapsort's worst case performance is

A.   O(n^2)

B.   O(n * log n)

C.   O(n)

D.   O(1)

E.   O(n^2 * log n)

42: Which is a way of organizing data that considers not only the items stored, but also their relationship to each other?

A.   Database table

B.   Algorithm

C.   Database

D.   Data Structure

43: A technique for direct search is _______.

A.   Linear search

B.   Tree search

C.   Hashing

D.   Binary search

44: Which is the best possible complexity to sort an array?

A.   O(NlogN)

B.   O(N*N)

C.   O(1)

D.   O(logN)

E.   O(N)

45: Which of the following is NOT a property of a B-Tree?

A.   Root is leaf, or has between 2 & M children.

B.   Data stored only on the leaves.

C.   Data is stored only on the branches.

D.   All leaf nodes are at the same level.

46: Which sort will you use if you want to optimize sorting time?

A.   Insertion sort

B.   Quick sort

C.   Bubble sort

D.   Merge sort

47: Can Dijkstra's be used to find the longest-path in a graph?

A.   No, they can't

B.   Yes, with a slight modification to the algorithm.

C.   Yes, by multiplying each edge in the graph by -1, and finding the shortest-path.

48: If a node having two children is deleted from a binary tree, it is replaced by its:

A.   Preorder predecessor

B.   Inorder successor

C.   Suborder successor

D.   Inorder predecessor

49: The path length from a node to the deepest leaf under it is the _________.

A.   Size

B.   Height

C.   Depth

D.   Set

50: Worst case for a binary search tree is

A.   O(n^2)

B.   O(n)

C.   O(2n)

D.   O(log n)

E.   O(n * log n)

51: What is the worst-case time complexity of finding a maximum cardinality matching in a bipartite graph G = (V,E)?

A.   O(|E||V|)

B.   O(|E| + |V|)

C.   O(|E|*sqrt(|V|))

D.   O(|E|^2|V|^2)

E.   O(|V|)

52: What is the worst-case time complexity of the simple Ford-Fulkerson algorithm for finding the maximum flow in a graph given a source and a sink, and all integer capacities on edges? Assume the graph G = (V,E) has a finite, integer maximum flow value of f.

A.   O(|E|^2|V|)

B.   O(|V|)

C.   O(|E|f)

D.   O(|E||V|)

E.   O(|E|)

53: You have a file with 4 billion 32-bit integers. The distribution of the integers is random but uniform. You are supposed to find a number NOT in the file. If you created a bit array and used the index to that array to determine if a number existed in the file approximately how much memory would you need?

A.   2 Gigabytes

B.   512 Megabytes

C.   16 Gigabytes

D.   1024 Megabytes

E.   128 Gigabytes

54: A full binary tree with 2n+1 nodes contains:

A.   n-1 leaf nodes

B.   n non-leaf nodes

C.   n-1 non-leaf nodes

D.   n leaf nodes

55: Which graph traversal algorithm uses a queue to keep track of the vertices which need to be processed?

A.   Breadth-first search

B.   Depth-first search

56: A simple graph with n vertices and k components can have at the most _______.

A.   n edges

B.   n-k edges

C.   (n-k)(n-k-1)/2 edges

D.   (n-k)(n-k+1)/2 edges

57: What is the minimum number of edges which must be removed from a complete bipartite graph of six nodes K(6) so that the remaining graph is a planar?

A.   2

B.   3

C.   4

D.   6

58: Which feature of heaps allows them to be efficiently implemented using a partially filled array?

A.   Heaps are binary search trees

B.   Heaps are complete binary trees

C.   Heaps are full binary trees

D.   Heaps contain only integer data

59: What happens if you make a recursive call without making the problem smaller?

A.   The operating system detects the infinite recursion because of the "repeated state"

B.   The program keeps running until you press Ctrl-C

C.   The results are non-deterministic

D.   The run-time stack overflows, halting the program

60: Tree algorithms typically run in time O(d) . What is d?

A.   The depth of the tree

B.   The number of divisions at each level

C.   The number of nodes in the tree

D.   The total number of entries in all the nodes of the tree

61:

Here is a code for an integer variable n

   while (n > 0)

   {

     n = n/10; // Use integer division

   }

What is the worst case scenario analysis for the above loop?

A.  

O(1)

B.   O(log n)

C.  

O(n)

D.  

O(n2)

62:

Suppose we have a circular array implementation of a queue, with ten items in the queue stored at data[2] through data[11]. The CAPACITY is 42. Where does the push member function place the new entry in the array?

A.  

data[1]

B.  

data[2]

C.  

data[11]

D.   data[12]

63: Which of the following sorting algorithms yield approximately the same worst-case and average-case running time behavior in O(n*log(n))?

A.   Bubble sort and selection sort

B.   Heap sort and merge sort

C.   Quick sort and radix sort

D.   Tree sort and Median-of-3 quicksort

64: The operation for adding an entry to a stack is traditionally called ________.

A.   add

B.   append

C.   insert

D.   push

65: For a complete binary tree with depth d, the total number of nodes is:

A.   2d+1

B.   2d

C.   2d+1-1

D.   2d2

66: Which of the following is false?

A.   A binary search begins with the middle element in the array

B.   A binary search continues halving the array either until a match is found or until there are no more elements to search

C.   If the search argument is greater than the value located in the middle of the binary, the binary search continues in the lower half of the array

67: Which of the following applications may use a stack?

A.   A parentheses balancing program

B.   Keeping track of local variables at run time

C.   Syntax analyzer for a compiler

D.   All of the above

68: What is the value of the post-fix expression 6 3 2 4 + - *?

A.   Something between -15 and -100

B.   Something between -5 and -15

C.   Something between 5 and 15

D.   Something between 15 and 100

69: The minimum number of interchanges needed to convert the array 89,19,14,40,17,12,10,2,5,7,11,6,9,70 into a heap with the maximum element at the root is:

A.   0

B.   1

C.   2

D.   3

70: Suppose T is a complete binary tree with 14 nodes. What would be the minimum possible depth of T?

A.   3

B.   4

C.   5

71: In which data structure do the insertion and deletion take place at the same end?

A.   Linked list

B.   Tree

C.   Stack

D.   Linked list of stack

72: What is the formulae to find maximum number of nodes n in a perfect binary tree?

A.   2h + 1 - 1

B.   2h + 1

C.   2h

D.   2h + 1 + 1

73: A chained hash table has an array size of 512. What is the maximum number of entries that can be placed in the table?

A.   511

B.   512

C.   1024

D.   There is no maximum limit

74: In which dynamically created linked list can the first node be recovered after moving to the second node?

A.   Simple linked list

B.   Circular linked list

C.   Doubly linked list

D.   Both b and c

75: What is the best definition of a collision in a hash table?

A.   Two entries are identical except for their keys

B.   Two entries with different data have exactly the same key

C.   Two entries with different keys have exactly the same hash value

D.   Two entries with exactly the same key have different hash values

76: What is the pre-order traversal equivalent of the following algebraic expression? [a+(b-c)]*[(d-e)/(f+g-h)]

A.   abc-+de-fg+h-/*

B.   *+a-bc/-de-+f-gh

C.   a+*b-/c-d-e+fgh

D.   *+a-bc-/d+e-fgh

77: A sparse matrix can be a lower-triangular matrix when____.

A.   all the non-zero elements lie only on the leading diagonal

B.   all the non-zero elements lie above the leading diagonal

C.   all the non-zero elements lie below the leading diagonal

D.   None of the above

78: A graph in which all nodes are of an equal degree is known as:

A.   Multigraph

B.   Non - regular graph

C.   Regular graph

D.   Complete graph

79: What is the maximum number of statements that may be recursive calls in a single function declaration?

A.   1

B.   2

C.   n (n is the argument)

D.   There is no fixed maximum

80: Which additional requirement is placed on an array so that binary search may be used to locate an entry?

A.   The array elements must form a heap

B.   The array must have at least 2 entries

C.   The array must be sorted

D.   The array's size must be a power of two

81: What is the worst-case scenario for heapsort to sort an array of n elements?

A.   O(log n)

B.   O(n)

C.   O(n log n)

D.   O(n2)

82: The recurrence relation T(n)=mT(n/2)+an2 is satisfied by___

A.   T(n)=O(nm)

B.   T(n)=O(m*log(m))

C.   T(n)=O(n*log(m))

D.   T(n)=O(m*log(n))

83: Consider the node of a complete binary tree whose value is stored in data[i] for an array implementation. If this node has a right child, where will the right child's value be stored (the array's first index is 0)?

A.   data[i+1]

B.   data[i+2]

C.   data[2*i + 1]

D.   data[2*i + 2]

84: In a complete binary tree, the parent of any node k can be determined by ________.

A.   2k

B.   2k+1

C.   K/2

D.   2K-1

85: Consider a linked list of n elements which is pointed by an external pointer. What is the time taken to delete the element which is a successor of the pointed element by a given pointer?

A.   O(1)

B.   O(log2n)

C.   O(n)

D.   O(n*log2n)

86: Suppose X is a B-tree leaf containing 41 entries and has at least one sibling. Which of the statements would be true in this case?

A.   Any sibling of X is also a leaf

B.   Any sibling of X contains at least 41 entries

C.   The parent of X has exactly 42 entries

D.   X has at least 41 siblings

87: In a complete binary tree of n nodes, how far are the most distant two nodes? Assume each in the path counts 1. Assume log(n) is log base 2.

A.   about log(n)

B.   about 2*log(n)

C.   about 3*log(n)

D.   about 4*log(n)

88:

In a graph G, F is a spanning forest of G if

 

(i)F is a subgraph of G containing all the nodes of G

(ii)F is an order forest containing trees T1,T2,...Tn

(iii)Ti contains all the nodes that are reachable in G from the root Ti and are contained in Tj for some j

 

Which of the above conditions is/are true?

A.   (i),(ii)

B.   (ii),(iii)

C.   (i),(iii)

D.   (i),(ii) and (iii)

89: Which information is not saved in the activation record when a function call is executed?

A.   Current depth of recursion

B.   Formal parameters

C.   Location where the function should return when done

D.   Local variables

90: The linked list implementation of sparse matrices is superior to the generalized dope vector method because it is __________.

A.   conceptually easier and completely dynamic

B.   efficient if the sparse matrix is a band matrix

C.   efficient in accessing an entry

D.   all of these

91: Which situation occurs frequently if the selected hash function is poor?

A.   Overflow

B.   Underflow

C.   Collision

D.   None of the above

92: The post-order traversal of a binary tree starts with:

A.   Post-order traversal of the left sub tree

B.   Post-order traversal of the right sub tree

C.   Post-order traversal of the root

D.   Post-order traversal of the lowest node

93: One difference between a queue and a stack is:

A.   Queues require dynamic memory but stacks do not

B.   Stacks require dynamic memory but queues do not

C.   Queues use two ends of the structure but stacks use only one

D.   Stacks use two ends of the structure but queues use only one

94: Using which traversal in a sorted binary insertion tree can a sorted array of numbers be obtained?

A.   Pre-order traversal

B.   Post-order traversal

C.   In order traversal

D.   Top-down traversal

95: Where does the push member function place the new entry on the linked list in the linked list implementation of a queue?

A.   At the head

B.   At the tail

C.   After all other entries that are greater than the new entry

D.   After all other entries that are smaller than the new entry

96: Which term is used to describe an O(n) algorithm?

A.   Constant

B.   Linear

C.   Logarithmic

D.   Quadratic

97: What is the minimum number of nodes in a complete binary tree with depth 3?

A.   4

B.   8

C.   11

D.   15

98: What is true of the complete bipartite graphs K(3,3) and K(2,4)?

A.   Both are planar

B.   Neither is a planar

C.   Both are isomorphic

D.   None of these

99: If X is the adjacency matrix of a graph G with no self loops, the entries along the principle diagonal of X are ______.

A.   all zeros

B.   all ones

C.   both zeros and ones

D.   different

100: Consider a linked list implementation of a queue with two pointers: front and rear. The time needed to insert element in a queue of length n is:

A.   O(1)

B.   O(log2n)

C.   O(n)

D.   O(n*log2n)