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

Multiple choice technology performance
  1. Doubly Linked list

  2. Singly linked list

  3. Pointers

  4. Structures

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

In B*Trees, leaf nodes are connected via a doubly linked list to allow efficient range queries and sequential traversal in both directions. Singly linked lists only support unidirectional traversal, and generic pointers or structures do not define the specific list traversal pattern.

Multiple choice technology programming languages
  1. 8

  2. 10

  3. none

  4. 0

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

When you create an ArrayList using the no-argument constructor new ArrayList(), Java initializes it with a default capacity of 10. This is an implementation detail of the ArrayList class designed to balance memory usage and performance for common use cases. The capacity is not 0, 8, or unlimited.

Multiple choice technology programming languages
  1. The point3d is represented as struct . change it to a class and it will run better

  2. The point3d struct is not byte aligned.

  3. The in the function point3d struct parameters are passed by value, Which will cause additional overhead.

  4. The point3d struct has 3 members of type int . Change it to short ,the program will run faster.

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

The function passes point3d structs by value, meaning the entire struct (12 bytes for 3 ints) is copied for each parameter, every time the function is called. With 2 million objects and 1 million function calls, this results in copying 24 million bytes (2 parameters x 12 bytes x 1 million calls) - a significant performance overhead. Passing by reference (const point3d&) would avoid this copying.

Multiple choice technology programming languages
  1. Hashtable.

  2. ListDictionary.

  3. Hybrid Dictionary

  4. ArrayList.

  5. StringDictionary.

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

HybridDictionary is the most efficient choice for storing name/value pairs when the quantity is unknown. It automatically uses a ListDictionary for small collections (which is efficient for few items) and switches to a Hashtable when the collection grows (which is efficient for larger collections). Hashtable is always a hash table (overhead for small collections), ListDictionary is always a linked list (slow for large collections), and ArrayList stores only values not key-value pairs.

Multiple choice technology
  1. Adjacency List, 2D array, Stack

  2. Heap, Adjacency List, Queue

  3. Binary tree, Hash table

  4. 2D array, Queue

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Dijkstra's algorithm needs: (1) a graph representation via Adjacency List for efficient neighbor access, (2) a Heap (typically min-heap) to efficiently extract the vertex with minimum distance in O(log V), and (3) a structure to manage visited/unvisited vertices or frontier, typically implemented via Queue or priority queue. Option B has all essential components.

Multiple choice technology
  1. O(n+k)

  2. O(lgk+n)

  3. O(klgn+n)

  4. O(nlgk+n)

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

When the maximum value k in the list is known, we can use counting sort which runs in O(n+k) time - O(n) to count occurrences and O(k) to output sorted values. This is better than comparison-based sorts like merge/quick sort which require O(n log n) in the best case.

Multiple choice technology
  1. O(n^3) Brute Force

  2. O(2^n) Recursion

  3. O(n^2) DP

  4. O(n) Divide & Conquer

Reveal answer Fill a bubble to check yourself
B,C Correct answer
Explanation

This minimum path sum problem can be solved by recursion (exponential O(2^n) by exploring all paths) or optimally by dynamic programming (O(n^2) using memoization). Brute force would be O(n^3) or worse, and divide & conquer doesn't apply to this DP structure.

Multiple choice technology
  1. O(2^n) Recursion

  2. O(n^3) Brute Force

  3. O(n) Divide & Conquer

  4. O(n^2) DP

Reveal answer Fill a bubble to check yourself
A,D Correct answer
Explanation

This is the same minimum path sum problem - recursion explores all possible paths giving O(2^n) complexity, while dynamic programming with memoization achieves O(n^2) by avoiding recomputation. Divide & conquer is not applicable to this DP-optimized structure.

Multiple choice technology mainframe
  1. True

  2. False

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

When a COBOL program performs sorting operations (via SORT verb), it typically invokes external sort utilities provided by the operating system or runtime environment rather than implementing the sort algorithm internally. This external sorting leverages optimized system utilities for efficient data processing, making the statement True.

Multiple choice technology programming languages
  1. name.length

  2. name.size

  3. size(name)

  4. length(name)

Reveal answer Fill a bubble to check yourself
A,B Correct answer
Explanation

In Ruby, both length and size are valid methods to get the number of elements in an array. They are aliases and return the same result. Options C and D are incorrect because size(name) and length(name) are not valid Ruby syntax - these methods must be called on the array object itself, not with the array as an argument.