Computer Knowledge

Data Structures and Algorithms

1,256 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. 15

  2. 14

  3. 13

  4. 16

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

While inserting the element make sure the difference of height of  left subtree and right sub tree must be -1, 0 and +1. Insert 10 as a root, then 11 as right child. Here, tree is balanced. Now Insert 12, tree became unbalanced as the height of left sub tree from root and right sub tree is -2, 0 = -2. So do RR rotation on tree. Now 11 is as root and 10 as left child and 12 as right child. Again insert 13 as left child of 12, then 14 right child of 13 again it unbalanced. So do again RR rotation and so on.

Multiple choice
  1. binary trees

  2. binary search trees

  3. heaps

  4. None of the above

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

Binary search tree has all the small data in left and all big data in right. So, when inorder traversal is made, it gives sorted list. Suppose tree is having data 1, 2, 3, 4 and 5, if 3 is the root element then 4 and 5 will be on right side of the root. 1 and 2 will get place in left side of 3. So, inorder traversel of BST will give sorted elements.

Multiple choice
  1. 2H - 1

  2. 2H+1

  3. 2H+1 - 1

  4. None of the above

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

2H - 1, gives total number of nodes present in any binary tree. 2H gives the total number of nodes at any level. So for height H, total number of nodes will be one less than next level. For example at level 3, the number of nodes is 8, for height 3 the total number of nodes is 7. This is the way how this expression works.

Multiple choice
  1. Queue

  2. Stack

  3. Tree

  4. Linked list

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

Stack is used to perform recursion. It stores the function call in stack. then call each function in LIFO order. Let a function is called from its own body then for to track the function call, each call is pushed into stack till the end of counter then one by one each function call is executed. So, stack is a correct answer.

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.