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
A
Correct answer
Explanation
In C, array indexing starts at 0. The 3rd element is at index 2, which is accessed via *(s+2).
-
Linear list
-
Queue
-
Tree
-
Stack
D
Correct answer
Explanation
The Shunting-yard algorithm, which converts infix to postfix, uses a stack to hold operators until they can be placed in the output string.
B
Correct answer
Explanation
A deque (double-ended queue) is a linear data structure that allows insertion and deletion at both ends.
-
queues
-
stacks
-
strings
-
none of these
B
Correct answer
Explanation
Recursive procedures rely on the call stack to store return addresses, local variables, and parameters for each active function call.
-
stack
-
memory
-
linked list
-
heap
A
Correct answer
Explanation
A stack is a LIFO structure where elements are added and removed from the same end, known as the top.
-
First In First Out (FIFO)
-
Last In Last Out (LILO)
-
Last In First Out (LIFO)
-
None of the above
C
Correct answer
Explanation
Stacks follow the Last In First Out (LIFO) principle, where the most recently added item is the first one removed.
-
2, 2, 1, 1, 2
-
2, 2, 1, 2, 2
-
2, 1, 2, 2, 1
-
2, 1, 2, 2, 2
A
Correct answer
Explanation
Sequence: push(1) [1], push(2) [1,2], pop [1](val 2), push(1) [1,1], push(2) [1,1,2], pop [1,1](val 2), pop [1](val 1), pop [](val 1), push(2) [2], pop [](val 2). Popped values: 2, 2, 1, 1, 2.
-
non-increasing order
-
non-decreasing order
-
strictly increasing order
-
strictly decreasing order
D
Correct answer
Explanation
To simulate a stack (LIFO) using a priority queue (which returns the smallest key), we need to assign keys such that the most recently added item has the smallest key. Therefore, keys must be strictly decreasing.
-
radix sort
-
breadth first search
-
recursion
-
none of these
C
Correct answer
Explanation
A stack operates on a Last In, First Out (LIFO) basis, which is the exact mechanism used to manage function calls, activation records, and return addresses in recursion.
-
O (n2)
-
O (nlogn)
-
O (logn)
-
O (n)
A
Correct answer
Explanation
Selection sort has a nested loop structure, resulting in a time complexity of O(n^2) for all cases.
-
O(n2)
-
O(nlogn)
-
O(logn)
-
O(n)
A
Correct answer
Explanation
Bubble sort uses nested loops to compare adjacent elements, leading to an average time complexity of O(n^2).
-
O(n2)
-
O(nlogn)
-
O(logn)
-
O(n)
A
Correct answer
Explanation
Insertion sort has an average time complexity of O(n^2) because, on average, each element must be compared and shifted against half of the already sorted elements.
-
O(n2)
-
O(nlogn)
-
O(logn)
-
O(n)
B
Correct answer
Explanation
Merge sort uses a divide and conquer approach, splitting the array into halves recursively and merging them, resulting in a consistent O(n log n) complexity.
-
O(n2)
-
O(nlogn)
-
O(logn)
-
O(n)
B
Correct answer
Explanation
Quick sort's average performance is O(n log n) because the partitioning process effectively divides the array into roughly equal halves on average.