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
-
BIGINT
-
FLOAT
-
DECIMAL
-
MONEY
-
REAL
-
NUMERIC
A
Correct answer
Explanation
In SQL Server's data type precedence hierarchy, BIGINT has the lowest precedence among the options. The order from lowest to highest is: BIGINT, INT, SMALLINT, TINYINT, DECIMAL/NUMERIC, MONEY, FLOAT, REAL. When different types interact, the lower precedence type converts to the higher one.
A
Correct answer
Explanation
Python lists are heterogeneous data structures that can contain elements of different types within the same list object, such as integers, strings, floats, or even other lists.
-
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 INDEXE BY 10 TIMES
-
01 ARRAYS. 88 ARRAY2 PIC X(6) OCCURS 20 TIMES INDEXED BY WS-INDEX
B
Correct answer
Explanation
Option B shows correct COBOL array syntax: the data name at level 01 with PIC clause, OCCURS clause specifying the count, and INDEXED BY clause for the index variable. Option A unnecessarily nests under a group, Option C has 'INDEXE' typo, and Option D incorrectly uses level 88 (reserved for condition names).
-
arr[n].length();
-
arr.size;
-
arr.size-1;
-
arr[n].length;
-
Serial Search
-
Binary search
-
Tree Search
-
SQL Search
B
Correct answer
Explanation
COBOL's SEARCH ALL verb implements a binary search algorithm. Binary search requires the table to be sorted and repeatedly divides the search interval in half, achieving O(log n) time complexity.
-
SET
-
SEARCH
-
PERFORM
-
All the above
D
Correct answer
Explanation
In COBOL, the INDEX command creates an index for a table that can then be used by the SEARCH statement to efficiently locate specific table entries. The SEARCH operation requires an index to perform optimized lookups through the table.
-
int *ptr = (int *) malloc(10, sizeof(int));
-
int *ptr = (int *) calloc(10, sizeof(int));
-
int *ptr = (int *) malloc(10*sizeof(int));
-
int *ptr = (int *) alloc(10*sizeof(int));
C
Correct answer
Explanation
malloc(10*sizeof(int)) correctly allocates space for 10 integers. Option C is correct - it multiplies the element count by the size of each element. malloc() takes a single byte count argument, while calloc(10, sizeof(int)) initializes to zero but allocates the same size. Option A's malloc(10, sizeof(int)) is incorrect syntax - malloc doesn't take two arguments.
-
2147483647
-
-2147483647
-
0
-
2147483648
-
-1
D
Correct answer
Explanation
The 'nodefault' specifier has an ordinal value of 2147483648, which is $80000000 in hexadecimal (the high bit set in a 32-bit value). This specific value is used to indicate that a property has no default value assigned. The other options are mathematically related but incorrect: 2147483647 is MaxInt, -2147483647 is not special, and 0 is the default for ordinal types.
-
O(n)
-
O(log n)
-
O(n2)
-
O(n log n)
B
Correct answer
Explanation
Binary search works by repeatedly dividing the search interval in half, eliminating half of the remaining elements each time. This logarithmic reduction means time complexity is O(log n), making it much faster than linear O(n) search for sorted data.
-
Arrays
-
Linked lists
-
Both of above
-
None of above
D
Correct answer
Explanation
Both arrays and linked lists store elements in a sequential manner where each element has a clear 'next' relationship, making them linear data structures. The only non-linear data structures among common types are trees and graphs, which aren't listed here.
-
Trees
-
Graphs
-
Arrays
-
None of above
C
Correct answer
Explanation
Arrays store elements sequentially in contiguous memory locations, where each element can be accessed directly by its index. This linear organization distinguishes them from non-linear structures like trees and graphs, where elements have multiple connections and hierarchical relationships.
-
Sorting
-
Merging
-
Inserting
-
Traversal
D
Correct answer
Explanation
Traversal is the process of systematically visiting each element in a data structure exactly once, typically to perform some operation on each element. Unlike searching (which looks for specific values) or sorting (which rearranges elements), traversal focuses on complete, sequential access.
-
Traversal
-
Search
-
Sort
-
None of above
B
Correct answer
Explanation
Search is the operation of locating a specific element with a given value within a data structure. While traversal visits every element, search focuses on finding particular targets, using algorithms like linear search or binary search to efficiently locate the desired value.
-
for relatively permanent collections of data
-
for the size of the structure and the data in the structure are constantly changing
-
for both of above situation
-
for none of above situation
A
Correct answer
Explanation
Arrays have a fixed size determined at creation, making them ideal for relatively permanent collections where the number of elements doesn't change frequently. Their contiguous memory allocation provides efficient random access, but resizing requires copying all elements to a new array.
-
Processor and memory
-
Complexity and capacity
-
Time and space
-
Data and space
C
Correct answer
Explanation
Algorithm efficiency is measured by time complexity (how execution time grows with input size) and space complexity (how memory usage grows with input size). These two metrics provide a complete picture of an algorithm's resource consumption and performance characteristics.