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
-
$\Omega$(n2)
-
$\Omega$ (nlogn) and O(n2)
-
$\theta$(n)
-
O (n)
C
Correct answer
Explanation
Here the fragment of code contains for loop which goes from 1 to n. Since due to given conditions m < n. So complexity of code is $\Theta$ 6(n)
-
O (1)
-
O (n)
-
O (n!)
-
O (nn)
B
Correct answer
Explanation
Here we store values in foo(i ) only when they are completed then in every recursion we require space to store 1 double. So overall n calls we require 0(n)
-
Student s[];
-
Student s[]=new Student[4];
-
Student s[][]=new Student[5][];
-
Student s[][]=new Student[5][3];
A
Correct answer
Explanation
The declaration Student s[] is incorrect. All the other array declarations are correct.
-
L is necessarily finite.
-
L is regular but not necessarily finite.
-
L is context free but not necessarily regular.
-
L is recursive but not necessarily context free.
A
Correct answer
Explanation
The strings of a language L can be effectively enumerated means a Turing machine exists for language L which will enumerate all valid strings of the language.If the string is in lexicographic order then TM will accept the string and halt in the final state.
But, if the string is not lexicographic order then TM will reject the string and halt in non-final state.Thus, L is recursive language.We can not construct PDA for language L. So, the given language is not context free.
-
$L_1$ $\in P$ and $L_2$ is finite
-
$L_1$ $\in NP$ and $L_2$ $\in P$
-
$L_1$ is undecidable and $L_2$ is decidable
-
$L_1$ is recursively enumerable and $L_2$ is recursive
C
Correct answer
Explanation
We have one to one mapping for all instances of L1 to L2.
L1 is given to be undecidable. Further L1 is polynomial time reducible to L2. (By given mapping). Now if L2 is decidable then there is algorithm to solve L2 in polytime. But then we can solve every instance of L1 in polytime, making L1 also decidable. Contradiction
-
recursive descent parsing
-
shift reduce parsing
-
operator precedence parsing
-
none of the above
A
Correct answer
Explanation
Top-down parsing is also called recursive descent parsing because it recursively expands non-terminals starting from the root. Shift-reduce and operator precedence are bottom-up techniques.
-
canonical derivation sequence
-
canonical reduction sequence
-
both (1) and (2) above
-
none of the above
B
Correct answer
Explanation
Handle pruning is used in LR parsing to efficiently find the canonical reduction sequence - the unique reverse of rightmost derivation. It helps identify handles without exploring all possibilities.
-
Only A
-
Only B
-
Both A and B
-
Neither A nor B
C
Correct answer
Explanation
Both are the disadvantages of recursion. Recursion always takes more space and time.
-
Array
-
Pointer
-
Structure
-
None of these
C
Correct answer
Explanation
These are user-defined data types in 'C' used to hold different data types and can be accessed by structure variable along with dot operator in the main program.
-
One-dimensional array
-
Two-dimensional array
-
Multi-dimensional array
-
None of these
B
Correct answer
Explanation
Two -dimensional array consists of two subscripts one refers to row & the second refers to column. Hence, it is used for matrix application in 'C'.
-
First-in first-out replacement algorithm
-
Random replacement algorithm
-
Least recently used algorithm
-
None of these
A
Correct answer
Explanation
This replacement algorithm removes the block that has been in the cache for the longest time.
-
Bubble sort
-
Selection sort
-
Quick sort
-
All of the above
C
Correct answer
Explanation
Quick sort choose one element and divide the list into two. It uses divide and conquer method. A key element is chosen then it is compared and the element is placed in such a way that all smaller elements as compared to key are on one side and larger than key are on other side. Then likewise list is broken into two, again algorithm is applied.
-
2H+1 - 1
-
2H-1
-
2H+1 + 1
-
2H+1
A
Correct answer
Explanation
2H+1 - 1, gives total number of nodes present in any binary tree for tree at level 0. 2H gives the total number of nodes at any level. If root is at level zero, 2H+1 will give the same, e.g. at level 3, total no. of nodes will be 8 and total number of nodes at level 2 if root is at level 0, is 7. So this relation works here 2H+1 - 1.
-
Stack
-
Link list
-
Tree
-
Graph
A
Correct answer
Explanation
For static memory location, stack is used. Stack is used because size of memory is known.