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
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.
-
Stack
-
Queue
-
Heap
-
Link list
C
Correct answer
Explanation
For run time memory location, heap is used. As we don't know the size of memory required to allocate. So, heap is used to allocate memory.
-
Link list
-
Graph
-
Tree
-
Stack
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.
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.
-
C B F E D A
-
C B E F A D
-
B C F E D A
-
C B E F D A
D
Correct answer
Explanation
- 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.
-
Ascending order
-
Random order
-
Descending order
-
None of the above
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.
-
strictly binary tree
-
binary tree
-
AVL tree
-
none of the above
A
Correct answer
Explanation
If a binary tree contains either zero or two child, then it is called as strict binary tree.
-
O(n2)
-
O(nlogn)
-
O(logn)
-
O(n)
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.
-
O(n2)
-
O(nlogn)
-
O(logn)
-
O(n)
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.
-
O(n2)
-
O(nlogn)
-
O(logn)
-
O(n)
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.
-
O(n2)
-
O(nlogn)
-
O(logn)
-
O(n)
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.