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
  1. Ascending priority queue - Min Heap

  2. Descending priority queue - Max Heap

  3. Binary Search Tree - Sorting

  4. B-Tree - Index Sequential Search

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

The other options pair a data structure with its primary application or property (Priority Queues with Heaps, B-Trees with indexing). A Binary Search Tree is a data structure, not a sorting algorithm itself, though it can be used for sorting.

Multiple choice
  1. 6

  2. 5

  3. 4

  4. 3

  5. 2

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

This is the correct answer because there are four constructors in the LinkedHashSet. These are :-LinkedHashSet () LinkedHashSet (c : Collection) LinkedHashSet (initialcapacity : int) LinkedHashSet (initialcapacity : int , loadfactor : float). So, this is the correct answer.

Multiple choice
  1. n = d1d2... dm-i....and rev = dmdm-1..dm-i+1

  2. n = dm-i+1...dm-1dm (or) rev = dm-i...d2d1

  3. n ¹ rev

  4. n = d1d2...dm (or) rev = dm...d2d1

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

The loop reverses the integer. After i iterations, the last i digits of n have been moved to the front of rev in reverse order. Thus, n contains the remaining digits and rev contains the reversed prefix.

Multiple choice
  1. 2

  2. 3

  3. 4

  4. 6

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

Inserting 10, 1, 3, 5, 15, 12, 16 into a BST creates a tree where 10 is the root, 1 is the left child, 3 is the right child of 1, 5 is the right child of 3, 15 is the right child of 10, 12 is the left child of 15, and 16 is the right child of 15. The longest path from the root (10) to a leaf (5 or 16) has 3 edges (10-1-3-5).

Multiple choice
  1. 9, 10, 15, 22, 23, 25, 27, 29, 40, 50, 60, 95

  2. 9, 10, 15, 22, 40, 50, 60, 95, 23, 25, 27, 29

  3. 29, 15, 9, 10, 25, 22, 23, 27, 40, 60, 50, 95

  4. 95, 50, 60, 40, 27, 23, 22, 25, 10, 9, 15, 29

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

Option (1) is correct.

Multiple choice
  1. the number of leaf nodes in the tree

  2. the number of nodes in the tree

  3. the number of internal nodes in the tree

  4. the height of the tree

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

The function recursively calculates the maximum depth of the tree. For each node, it returns 1 plus the maximum of the heights of its left and right subtrees, which is the definition of tree height.

Multiple choice
  1. By accessing the last element of the list.

  2. By accessing any element from the list.

  3. By traversing the list in left or right direction from node.

  4. None of these

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

When a linked list is connected doubly, i.e doubly linked list in which each node contains the address of next as well as previous node is very efficient other than we transverse the list from any direction of side of any node. 

Multiple choice
  1. 4

  2. 5

  3. 8

  4. 2

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

Quadratic probing uses the sequence (h(k) + i^2) mod m. Starting at 4 with m=8, the sequence is 4, (4+1) mod 8 = 5, (4+4) mod 8 = 0 (or 8 if 1-indexed), (4+9) mod 8 = 5, (4+16) mod 8 = 4. Since the probe sequence repeats, locations like 2, 3, 6, and 7 are never reached.