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
-
FAEKCDBHG
-
FAEKCDHGB
-
EAFKHDCBG
-
FEAKDCHBG
B
Correct answer
Explanation
The inorder sequence E A C K F H D B G and preorder F A E K C D H G B correspond to a specific binary tree structure. Preorder traversal always visits root first, then left subtree, then right subtree. Option B is the correct preorder for this tree configuration.
-
grounded header list
-
circular header list
-
linked list with header and trailer nodes
-
none of above
D
Correct answer
Explanation
A two-way list (doubly linked list) has nodes with pointers to both next and previous nodes. None of the given options (grounded header list, circular header list, linked list with header and trailer) specifically describe a doubly linked list. These are variations of singly linked lists or specific implementations, not two-way lists.
-
Arrays are dense lists and static data structure
-
data elements in linked list need not be stored in adjecent space in memory
-
pointers store the next data element of a list
-
linked lists are collection of the nodes that contain information part and next pointer
C
Correct answer
Explanation
Option C is false because pointers store the ADDRESS of the next node, not the data element itself. Options A, B, and D are true: arrays are dense static structures, linked list elements need not be adjacent in memory (linked by pointers), and linked lists are collections of nodes with data and pointer fields.
-
sorted linked list
-
sorted binary trees
-
sorted linear array
-
pointer array
A
Correct answer
Explanation
Binary search requires O(1) direct access to the middle element, which is not possible in linked lists as they require sequential traversal. Binary search CAN be applied to sorted linear arrays (direct index access), sorted binary trees (balanced BSTs allow O(log n) access), and pointer arrays (also support direct access).
-
FIFO lists
-
LIFO list
-
Piles
-
Push-down lists
A
Correct answer
Explanation
Stacks operate on LIFO (Last In First Out) principle, meaning the last element added is the first one removed. FIFO (First In First Out) is the characteristic of queues, not stacks. LIFO, piles, and push-down lists are all names associated with stack data structures, while FIFO specifically describes queue behavior.
-
array
-
lists
-
stacks
-
all of above
C
Correct answer
Explanation
Push and pop are the fundamental operations of stack data structures. Push adds an element to the top of the stack, while pop removes the top element. While stacks can be implemented using arrays or linked lists, the terms push and pop specifically refer to stack operations and are standard terminology for this abstract data type.
-
for (var i = 0; i < arr.length; i++) { // some code here }
-
for (var i = 0, len = arr.length; i < len; i++) { // some code here }
-
for (var i = arr.length; i--; ) { // some code here }
-
for ( i = 0; i < arr.length; i++) { // some code here }
C
Correct answer
Explanation
A decrementing loop checking against zero (i--) is historically the fastest in JavaScript because the termination check does not require querying a property (arr.length) or comparing variables on every iteration. Other options perform redundant length lookups or property evaluations inside the loop condition.
-
Round Robin
-
Same
-
Hash
-
Modulus
A,B
Correct answer
Explanation
Keyless partitioning methods distribute or maintain data flow without requiring a key column value. Round Robin rotates rows sequentially across partitions without reading any field. Same partitioning preserves the existing partitioning from the previous stage without applying any key-based logic. In contrast, Hash and Modulus both require a key column to calculate partition assignments.
-
Vector
-
Array List
-
Linked List
-
None of the above
C
Correct answer
Explanation
LinkedList is theoretically the fastest for inserting into the middle of a list because it only requires updating the pointers of neighboring nodes, which is an O(1) operation once located. Array-based structures like ArrayList and Vector require shifting all subsequent elements, which is an O(N) operation and significantly slower.
-
01 ARRAYS. 05 ARRAY2 PIC X(6) OCCURS 20 TIMES INDEXED BY WS-INDEX
-
01 ARRAY2 PIC X(6) OCCURS 20 TIMES INDEXED BY WS-INDEX
-
01 ARRAYS. 05 ARRAY1 PIC X(9) OCCURS INDEX BY 10 TIMES
-
01 ARRAYS. 88 ARRAY2 PIC X(6) OCCURS 20 TIMES INDEXED BY WS-INDEX
A
Correct answer
Explanation
In COBOL, the OCCURS clause cannot be defined at the 01 level (ruling out the second option) or with level 88 condition names (ruling out the fourth). The third option uses incorrect syntax order. The first option correctly defines the table at level 05 with INDEXED BY.
-
uksort()
-
arsort()
-
ksort()
-
All of the above
D
Correct answer
Explanation
PHP provides multiple sorting functions for different sorting needs. uksort() sorts by keys with a custom comparison, arsort() sorts by values in descending order, and ksort() sorts by keys in ascending order. All three are valid array sorting functions in PHP, making All of the above the correct choice.
-
Round Robin
-
Same
-
Hash
-
Modulus
A,B
Correct answer
Explanation
Round Robin distributes rows sequentially without using any key, and Same keeps data on the same partition (no key needed for repartitioning). Hash and Modulus both require a key column to calculate partition destinations.
-
key
-
minor-key
-
major-key
-
max-core
C
Correct answer
Explanation
Sort within Group is used when data is already sorted by a major key and you need to sort within each group of that major key. The major-key parameter specifies the key that the input is already pre-sorted on, allowing the component to perform secondary sorting within each group efficiently.
-
int *array1 = (int *)malloc(nrows * sizeof(int *));
-
int *array2 = (int *)malloc(nrows * sizeof(int *));
-
int *array3 = (int *)malloc(nrows * ncolumns * sizeof(int));
-
Any of the above.
D
Correct answer
Explanation
All three methods are valid approaches to allocate 2D arrays dynamically. Option A allocates an array of pointers then each row separately (pointer-to-pointer). Option B appears identical to A in the garbled text but represents the same approach. Option C allocates a single contiguous block and uses arithmetic to index (flattened 2D array). Each has trade-offs in syntax and memory layout.