Computer Knowledge

Data Structures and Algorithms

1,518 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 programming languages
  1. arr.length() – 1

  2. arr.length()

  3. arr.length - 1

  4. arr.length

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

The correct way of getting the number of elements in a one-dimensional array is:

A. arr.length

The option A, arr.length, returns the length of the array, which represents the number of elements in the array. This is the correct way to get the number of elements in the array.

The other options are incorrect:

B. arr.length() – 1: This option subtracts 1 from the length of the array, which does not give the correct count of elements in the array.

C. arr.length(): Adding parentheses after length is not necessary and will result in a syntax error.

D. arr.length - 1: This option subtracts 1 from the length of the array, which does not give the correct count of elements in the array.

So, the correct answer is: A. arr.length

Multiple choice technology web technology
  1. set of business elements

  2. phrases ans constants

  3. set of business terms

  4. both 2 & 3

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

Vocabulary in rule management systems defines both phrases and constants (option 2) as well as a set of business terms (option 3). Vocabulary provides the terminology and definitions used in rules, including business terminology, phrases, and constant values that can be referenced throughout the rule set.

Multiple choice technology performance
  1. B*Tree

  2. Bitmap

  3. Bmap

  4. Function Based Indexes

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

B*Tree indexes are the most common index type for equality and range queries. Bitmap indexes are efficient for low-cardinality columns. Function-based indexes store the results of function calls to improve performance of queries using those functions. 'Bmap' is not a standard index type.

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.