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
-
$\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)
-
A – i, B – ii
-
A – ii, B – i
-
A – i, B – i, B – ii
-
A – i, B – ii, A – ii
C
Correct answer
Explanation
In an S – attributed syntax directed translation all attributes are synthesized. In an L – attributed definition attributes may be inherited or synthesized.
-
a + a * (b - c) + (b - c) *d
-
a + a × (b - c) + (b - c) * (e/f)
-
a*a + (b - c) + (b - c) * (e/f)
-
a + a* (b - c) + (b + c) * (e/f)
-
$ ++\*+ABC\*DE\*FG $
-
$ +\*++ABC\*DE\*FG $
-
$AB+C\*DE\*+FG\*+$
-
$ABC+\*DE\*+FD\*+$
A
Correct answer
Explanation
$(+AB)*C+(*DE)+(*FG)$
$= *+ABC+(*DE)+(*FG)$
$=+ + * + ABC * DE * FG$
-
TreeSet
-
ArrayList
-
HashSet
-
AbstractList
-
None of these
B
Correct answer
Explanation
This class implements a dynamic array by extending the AbstractList.
-
AbstractCollection
-
AbstractList
-
LinkedList
-
None of these
C
Correct answer
Explanation
This class in Java implements a linked list by extending AbstractSequentialList class.
-
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.
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.
-
Stack
-
Priority queue
-
Input restricted queue
-
Output restricted queue
C
Correct answer
Explanation
Input restricted queue allows input data from one end, and delete data from both ends.
-
binary trees
-
binary search trees
-
heaps
-
None of the above
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.
-
2H - 1
-
2H+1
-
2H+1 - 1
-
None of the above
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.
-
Queue
-
Stack
-
Tree
-
Linked list
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.