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. always be evaluated

  2. be evaluated only if the definition is L-attributed

  3. be evaluated only if the definition has synthesized attributes

  4. never be evaluated

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

Every S (synthesized) -attributed definitions is L- attributed. So in a bottom-up evaluation of SDD inherited attributes can be evaluated only if the definition has synthesized attributes.

Multiple choice
  1. O(n log n)

  2. O(n)

  3. O(log n)

  4. O(1)

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

Here we can follow simple procedure, we can rum heap sort for 7 iterations. In each iteration the top most element is smallest, we note & then replace it with the last element, then we run min heapify algorithm, which brings next smallest element on top. This procedure take 0 (log n) time. We need to run it for 7 times. So tight bound O(7 log n) = O(log n)

Multiple choice
  1. X = Y + Z

  2. t1 = Y + Z; X = t1

  3. t1 = Y; t2 = t1 + Z; X = t2

  4. t1 = Y; t2 = Z; t3 = t1 + t2; X = t3

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

In 3-address code we use temporary variables to reduce complex instructions so here $$ t_1 = Y \\ t_2 = Z \\ t_3 = t_1 + t_2 \\ x = t_3 \\ $$

Multiple choice
  1. O(n log n)

  2. O(n)

  3. O(log n)

  4. O(1)

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

Here we can follow simple procedure, we can rum heap sort for 7 iterations. In each iteration the top most element is smallest, we note & then replace it with the last element, then we run min heapify algorithm, which brings next smallest element on top. This procedure take 0 (log n) time. We need to run it for 7 times. So tight bound O(7 log n) = O(log n)

Multiple choice
  1. remain O (n2)

  2. become O (n (log n)2)

  3. become O (n log n)

  4. become O (n)

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

Binary search is efficient when the sorted sequence is there, but the worst case scenario for insertion sort would not be sorted sequence so even using binary search instead of linear search the complexity of comparisons will remain O (n2)

Multiple choice
  1. 115, 220

  2. 25, 220

  3. 25, 15

  4. 115, 105

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

In static scoping the variables are initialized at compile time only So i =100 & j =5 P(i + j) = P(100 + 5) = P(105)

So x =105 x + 10 = 105 + 10 = 115 So 115 and 105 will be printed

Multiple choice
  1. A heap can be used but not a balanced binary search tree

  2. A balanced binary search tree can be used but not a heap

  3. Both balanced binary search tree and heap can be used

  4. Neither balanced binary search tree nor heap can be used

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

Both the tasks can be performed by both the data structures but heap is a data structure where to perform these function every element has to be checked so  O (n) complexity. But the balance binary search tree is efficient data structure since at every decision it selects one of its sub tree to no. of elements to be checked are reduced by a factor of / 1 2 every time. $\dfrac{n}{2!} = x$ x = log n

Multiple choice
  1. n(X + Y)

  2. 3Y + 2X

  3. n(X + Y) - X

  4. Y + 2X

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

Multiple choice
  1. the list is empty or has exactly one element

  2. the elements in the list are sorted in non-decreasing order of data value

  3. the elements in the list are sorted in non-increasing order of data value

  4. not all elements in the list have the same data value

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