Computer Knowledge

Data Structures and Algorithms

1,518 Questions

Data Structures and Algorithms form the core of computer science, focusing on arrays, linked lists, trees, and sorting mechanisms. These concepts are essential for solving complex computational problems efficiently. Test takers preparing for technical and administrative IT exams will find these questions highly relevant.

Array OperationsLinked List ApplicationsSorting AlgorithmsTree Data StructuresMultilevel IndexingAlgorithm Time Complexity

Data Structures and Algorithms Questions

Multiple choice
  1. Link list

  2. Graph

  3. Tree

  4. Stack

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The data structure which is used to manipulate data is called self referential structure. Graph is a self referential structure. So answer is correct as in Graph structure, we cannot refer all the vertices in some order.

Multiple choice
  1. C

  2. A

  3. D

  4. E

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

In link list, when value is assigned, its link part is updated. As after step 2, P is pointing to C, after third step, B is pointing to D, after 4th step, D's link is updated with C and in 5th step, P is pointing to C, so C will be printed. In linklist when value is assigned, Its link part is updated.

As After step 2 P is pointing to C.After third step B is pointing to DAfter 4th step D's link is updated with CAnd 5th step P is pointing to C So C is printed.

Multiple choice
  1. C B F E D A

  2. C B E F A D

  3. B C F E D A

  4. C B E F D A

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation
  1. In POST order traversal, first traverse left, then right and then print node. 2. If the sequence to traversal is given then it is easy to predict the tree. In preorder, the node which is traversed first is the root of the tree. So, here A is the root. Now take each node from preorder list and now from list in order the node which is right side of A is right and the node which is on left will come in left. Now traverse one by one each element from the list and make a tree and then find post order traversal from first step. On traversing the tree, we get following sequence for post order: C B E F D A. So the option C B E F D A is correct.
Multiple choice
  1. Ascending order

  2. Random order

  3. Descending order

  4. None of the above

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

 It will be printed in ascending order as a root node has all the smaller elements in its left side and all the larger elements in its right side. Likewise it is arranged for each node, always left child is smaller and right child is larger. So, it will arrange all elements in ascending order. So it is correct option.

Multiple choice
  1. O(n2)

  2. O(nlogn)

  3. O(logn)

  4. O(n)

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Selection sort makes n-1 passes, each time scanning remaining unsorted elements to find the minimum. This always requires roughly n²/2 comparisons, giving O(n²) in all cases.

Multiple choice
  1. O(n2)

  2. O(nlogn)

  3. O(logn)

  4. O(n)

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Insertion sort's average case involves shifting roughly half the sorted portion on average per insertion, leading to O(n²) comparisons and shifts overall.

Multiple choice
  1. O(n2)

  2. O(nlogn)

  3. O(logn)

  4. O(n)

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Insertion sort's worst case occurs with reverse-sorted input, where each new element must shift through all existing sorted elements, requiring O(n²) comparisons and shifts.

Multiple choice
  1. O(n2)

  2. O(nlogn)

  3. O(logn)

  4. O(n)

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Bubble sort's worst case occurs with reverse-sorted input, requiring maximum passes (n-1) and maximum comparisons/swaps per pass, resulting in O(n²) total operations.

Multiple choice
  1. O(n2)

  2. O(nlogn)

  3. O(logn)

  4. O(n)

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Quick sort's average case achieves O(n log n) when pivots consistently create roughly balanced partitions, dividing the problem size logarithmically.

Multiple choice
  1. O

  2. O(n)

  3. O(logn)

  4. None of these

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Merge sort requires O(n) auxiliary space for the temporary arrays used during the merge phase of each recursive call, regardless of time complexity.

Multiple choice
  1. O(n2)

  2. O(nlogn)

  3. O(logn)

  4. O(n)

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Merge sort always divides input in half and recursively merges, requiring n comparisons per level across log n levels, giving O(n log n) in all cases.

Multiple choice
  1. 0

  2. O(n)

  3. O(logn)

  4. None of these

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Quick sort's worst-case space complexity is O(n) for recursive implementations when poor pivots create maximum recursion depth, causing stack frames proportional to input size. (Note: optimized implementations using tail recursion or iteration can achieve O(log n)).