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
-
By calling ReverseSort()
-
By calling SortReverse()
-
By calling Descend()
-
By calling Sort() and then Reverse() method
D
Correct answer
Explanation
To sort an array in descending order in C#, you first call Sort() to arrange elements in ascending order, then call Reverse() to invert the sequence. There is no built-in ReverseSort() or SortReverse() method in the Array class, and Descend() is not a standard array method.
-
By calling ReverseSort()
-
By calling SortReverse()
-
By calling Descend()
-
By calling Sort() and then Reverse() method
D
Correct answer
Explanation
To sort an array in descending order, you typically first sort the array in ascending order using Sort(), then reverse the sorted array using Reverse(). While some languages may have dedicated methods, this two-step approach is common and reliable.
-
Table
-
Array of Arrays
-
list of arrays
-
both a and b
D
Correct answer
Explanation
A two-dimensional array can be conceptualized in multiple equivalent ways: as a Table (with rows and columns), as an Array of Arrays (where each element is itself an array), or as a list of arrays. All three perspectives are valid and useful in different contexts - the table view is intuitive for data representation, while the array-of-arrays view reflects the underlying memory structure. Since both 'Table' and 'Array of Arrays' are correct interpretations, option D ('both a and b') is the right choice.
B
Correct answer
Explanation
The ternary operator (a>b)?a:b avoids method call overhead and is executed inline by the JVM. Math.max() requires a method invocation, which involves stack frame creation and overhead even if the JIT compiler eventually inlines it. For simple comparisons, the ternary is measurably faster.
-
(1, 5, 10)
-
(1, 10, 5)
-
(10, 5, 1)
-
(5, 10, 1)
B
Correct answer
Explanation
Perl's sort function defaults to lexicographic (string) comparison, not numeric. The strings '10', '5', '1' sort as '1' < '10' < '5' because '1' < '5' alphabetically. So @b becomes (1, 10, 5). Option A is incorrect because it assumes numeric sorting.
B
Correct answer
Explanation
Bitmap indexes are best for columns with LOW cardinality (few distinct values like gender, status, or boolean flags). They use bitmaps to represent which rows have each value. High cardinality columns (many distinct values) are better served by B-tree indexes, which would be more efficient for that data distribution.
-
HASH
-
MODULUS
-
RANGE
-
RANDOM
C
Correct answer
Explanation
INTERVAL partitioning is an extension of RANGE partitioning. It automatically creates new partitions of a specified range (interval) when data is inserted that falls outside existing partition boundaries, making it fundamentally range-based.
-
Range
-
Freelist
-
Hash
-
Index
-
HASH
-
MODULUS
-
RANGE
-
RANDOM
C
Correct answer
Explanation
Interval partitioning is an extension of range partitioning where Oracle automatically creates new partitions at specified intervals when data exceeds existing ranges. It inherits the range-based concept of partitioning data along a continuous spectrum (dates or numbers) but automates the partition boundary creation.
-
sort @a
-
sort {$1 <=> $2} @a
-
sort {$a <=> $b} @a
-
sort {$_[0] <=> $_[1]} @a
C
Correct answer
Explanation
Perl uses the spaceship operator <=> inside a block to perform numerical comparisons for sorting, using the special package variables $a and $b. The default sort function performs ASCII-alphabetical sorting, while using $1 and $2 or $_[0] and $_[1] inside the sort block is syntactically incorrect.
-
set
-
ConcurrentSkipListSet
-
Hashmap
-
Queue
B
Correct answer
Explanation
SortedSet is an interface in Java. ConcurrentSkipListSet is a concrete class that implements the SortedSet interface, providing a thread-safe sorted set implementation based on a skip list data structure. HashMap and Queue are unrelated to SortedSet implementation.
-
bitmap indexes
-
b*-tree indexes
-
composite unique index
-
cluster index
A
Correct answer
Explanation
Bitmap indexes are ideal for columns with low cardinality (non-unique values) because they store bitmaps efficiently for repetitive values. B-tree indexes work better for unique or high-cardinality columns. A composite unique index would require unique values, and cluster index is not the standard term for non-unique column indexing.
B
Correct answer
Explanation
Similar to the previous question, there is no fixed rule that 50000-250000 leaf blocks automatically equals degree 16 parallelism. The degree of parallelism is calculated by the optimizer based on multiple factors including system resources, operation cost, and initialization parameters, not just block count ranges.
-
O(n2)
-
O(log n)
-
O(nlogn)
-
O(n2 logn)
C
Correct answer
Explanation
The average-case time complexity of Quick Sort is O(n log n), which occurs when the pivot consistently divides the array into reasonably balanced partitions. Distractors like O(n^2) represent the worst-case complexity, while O(log n) is too low and O(n^2 log n) is inefficient.
-
O(n)
-
O(log n)
-
O(n^2)
-
O(n log n)
C
Correct answer
Explanation
Bubble Sort has a time complexity of O(n^2) in both average and worst cases because it uses nested loops - each element may need to be compared with every other element. In the best case (already sorted), it can be O(n) with optimization, but its standard complexity is quadratic. Option A is for linear algorithms, B for logarithmic, and D for efficient sorts like merge sort.