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
-
internal nodes on extended tree
-
external nodes on extended tree
-
vanished on extended tree
-
None of above
A
Correct answer
Explanation
When extending a binary tree by adding external nodes for missing children, all original nodes become internal nodes of the extended tree. This is by definition: internal nodes have children (original or null placeholders), while new external nodes are the added leaf placeholders.
-
ABFCDE
-
ADBFEC
-
ABDECF
-
ABDCEF
C
Correct answer
Explanation
Given post-order DEBFCA of a binary tree, the root is A (last visited). From preorder ABDECF, A's left subtree is B-D-E and right is F-C. Post-order shows left subtree post-order is D-E-B, meaning B is root of left subtree with D and E as children. This uniquely determines the structure yielding preorder ABDECF.
-
Values in a node is greater than every value in left sub tree and smaller than right sub tree
-
Values in a node is greater than every value in children of it
-
Both of above conditions applies
-
None of above conditions applies
B
Correct answer
Explanation
In a min-heap or max-heap, the key property is that each node's value is greater than (max-heap) or less than (min-heap) all values in its subtree. This parent-child relationship must hold down the entire tree, not just comparing with one subtree or sibling.
-
Stacks
-
Queues
-
Deques
-
Binary search tree
B
Correct answer
Explanation
A queue is a FIFO (First-In-First-Out) data structure where deletions occur only at the front and insertions only at the rear. This is fundamental to queue behavior - elements are processed in arrival order. Stacks use LIFO, deques allow operations at both ends, and BSTs don't enforce positional insertion/deletion.
-
Input-restricted deque
-
Output-restricted deque
-
Priority queues
-
None of above
A
Correct answer
Explanation
An input-restricted deque allows deletions from both ends but restricts insertions to only one end. This is a specialized deque variant - unlike standard deques (full operations at both ends) or output-restricted deques (opposite restriction). Priority queues use different ordering principles entirely.
-
Deque
-
Priority
-
Tree
-
All of above
C
Correct answer
Explanation
Trees are the standard data structure for representing hierarchical relationships because each node can have multiple children, forming a parent-child hierarchy. Deques (double-ended queues) are linear structures for adding/removing from both ends, not hierarchies. Priority queues are for ordered access by priority, not hierarchy. Option C is correct.
-
Complete binary tree
-
Binary search tree
-
Extended binary tree
-
None of above
C
Correct answer
Explanation
An extended binary tree (also called a full binary tree or proper binary tree) is defined as a binary tree where every node has either 0 or 2 children - never just 1 child. A complete binary tree fills all levels except possibly the last, which must be left-filled. A binary search tree is ordered by key values, not by child count. Option C is correct.
-
Arrays
-
Records
-
Pointers
-
None
A
Correct answer
Explanation
Arrays are designed to store homogeneous data elements - all elements must be of the same type. Records can store heterogeneous data (different types), pointers store addresses (not data elements per se), and 'None' is incorrect. Therefore Arrays is the correct answer.
-
Arrays
-
Records
-
Pointers
-
None
B
Correct answer
Explanation
Records are designed to store heterogeneous data elements - fields can be of different types (e.g., name:string, age:integer, salary:decimal). Arrays require homogeneous elements. Pointers store addresses. Therefore Records is the correct answer.
-
linear arrays
-
linked lists
-
both of above
-
none of above
A
Correct answer
Explanation
Linear arrays are indexed structures because they allow direct access to any element using its index in constant time O(1). The index is used to calculate the memory address directly. Linked lists are sequential structures that require traversal from the head to access a specific element, making them non-indexed.
-
The list must be sorted
-
there should be the direct access to the middle element in any sublist
-
There must be mechanism to delete and/or insert elements in list
-
none of above
C
Correct answer
Explanation
Binary search requires the search space/list to be sorted and allows random access to the middle element to achieve logarithmic time complexity. It does not require a mechanism to insert or delete elements; in fact, binary search is often performed on static arrays.
-
must use a sorted array
-
requirement of sorted array is expensive when a lot of insertion and deletions are needed
-
there must be a mechanism to access middle element directly
-
binary search algorithm is not efficient when the data elements are more than 1000.
D
Correct answer
Explanation
Binary search has O(log n) time complexity, which remains efficient even for large datasets. The efficiency depends on the logarithmic growth rate, not on a fixed number like 1000. Options A, B, and C are actual limitations: binary search requires sorted data and direct access to the middle element, which can be expensive to maintain with frequent insertions/deletions.
-
tables arrays
-
matrix arrays
-
both of above
-
none of above
C
Correct answer
Explanation
Two-dimensional arrays are commonly referred to as both tables (for tabular data representation) and matrices (especially in mathematical contexts involving rows and columns). Both terms describe the same conceptual structure of data arranged in a grid format with rows and columns.
-
LOC(Array[5]=Base(Array)+w(5-lower bound), where w is the number of words per memory cell for the array
-
LOC(Array[5])=Base(Array[5])+(5-lower bound), where w is the number of words per memory cell for the array
-
LOC(Array[5])=Base(Array[4])+(5-Upper bound), where w is the number of words per memory cell for the array
-
None of above
A
Correct answer
Explanation
The address of any array element is calculated as: Base Address + (Index - Lower Bound) × Word Size. For the 5th element, this is LOC(Array[5]) = Base(Array) + w(5 - lower bound), where w represents bytes per memory cell. Options B and C are incorrect because they omit the word size multiplier or use wrong bounds.
-
Linked lists
-
Stacks
-
Queues
-
Deque
D
Correct answer
Explanation
A deque (double-ended queue) specifically allows insertion and deletion at both ends. Stacks only allow operations at one end (LIFO), queues restrict insertion to rear and deletion to front (FIFO), and linked lists allow insertion/deletion anywhere but not with the same efficiency at both ends as a deque.