Data Structures and Algorithms

Description: This quiz covers fundamental concepts and algorithms in Data Structures and Algorithms.
Number of Questions: 15
Created by:
Tags: data structures algorithms complexity searching sorting
Attempted 0/15 Correct 0 Score 0

Which data structure is used to store a collection of unique elements in no particular order?

  1. Array

  2. Linked List

  3. Stack

  4. Set


Correct Option: D
Explanation:

A set is a data structure that stores a collection of unique elements. It does not maintain any specific order for the elements.

What is the time complexity of searching for an element in a sorted array using binary search?

  1. O(n)

  2. O(log n)

  3. O(n^2)

  4. O(1)


Correct Option: B
Explanation:

Binary search repeatedly divides the search interval in half until the element is found or the interval becomes empty. This results in a time complexity of O(log n).

Which sorting algorithm is known for its divide-and-conquer approach?

  1. Bubble Sort

  2. Selection Sort

  3. Merge Sort

  4. Insertion Sort


Correct Option: C
Explanation:

Merge sort follows a divide-and-conquer approach, where the array is recursively divided into smaller subarrays, sorted, and then merged back together to obtain the sorted array.

What is the worst-case time complexity of the insertion sort algorithm?

  1. O(n)

  2. O(n^2)

  3. O(log n)

  4. O(1)


Correct Option: B
Explanation:

Insertion sort has a worst-case time complexity of O(n^2) because it compares each element with all the elements to its left before inserting it in the correct position.

Which data structure is used to implement a queue, where elements are added at one end (rear) and removed from the other end (front)?

  1. Array

  2. Linked List

  3. Stack

  4. Queue


Correct Option: D
Explanation:

A queue is a data structure that follows the first-in-first-out (FIFO) principle, where elements are added at the rear and removed from the front.

What is the time complexity of finding the minimum element in a binary heap?

  1. O(n)

  2. O(log n)

  3. O(n^2)

  4. O(1)


Correct Option: D
Explanation:

In a binary heap, the minimum element is always stored at the root node. Therefore, finding the minimum element has a time complexity of O(1).

Which data structure is used to represent a collection of nodes connected by edges, where each node has a unique identifier?

  1. Array

  2. Linked List

  3. Graph

  4. Tree


Correct Option: C
Explanation:

A graph is a data structure that consists of a set of nodes and a set of edges connecting these nodes. Each node has a unique identifier.

What is the time complexity of the depth-first search (DFS) algorithm on a graph with V vertices and E edges?

  1. O(V)

  2. O(E)

  3. O(V + E)

  4. O(V * E)


Correct Option: C
Explanation:

The time complexity of DFS on a graph is O(V + E) because it visits each vertex and edge once.

Which sorting algorithm is known for its ability to sort a list of numbers in place?

  1. Bubble Sort

  2. Selection Sort

  3. Merge Sort

  4. Quick Sort


Correct Option: D
Explanation:

Quick sort is an in-place sorting algorithm that partitions the array into smaller subarrays and recursively sorts them.

What is the time complexity of finding an element in a hash table with n key-value pairs using the linear probing collision resolution strategy?

  1. O(1)

  2. O(log n)

  3. O(n)

  4. O(n^2)


Correct Option: C
Explanation:

In linear probing, the time complexity of finding an element in a hash table is O(n) in the worst case, as it may have to search through the entire table.

Which data structure is used to implement a stack, where elements are added and removed from the same end?

  1. Array

  2. Linked List

  3. Stack

  4. Queue


Correct Option: C
Explanation:

A stack is a data structure that follows the last-in-first-out (LIFO) principle, where elements are added and removed from the same end.

What is the time complexity of the breadth-first search (BFS) algorithm on a graph with V vertices and E edges?

  1. O(V)

  2. O(E)

  3. O(V + E)

  4. O(V * E)


Correct Option: C
Explanation:

The time complexity of BFS on a graph is O(V + E) because it visits each vertex and edge once.

Which sorting algorithm is known for its ability to sort a list of numbers in a stable manner?

  1. Bubble Sort

  2. Selection Sort

  3. Merge Sort

  4. Quick Sort


Correct Option: C
Explanation:

Merge sort is a stable sorting algorithm, meaning that the relative order of equal elements in the input is preserved in the sorted output.

What is the time complexity of finding an element in a balanced binary search tree with n nodes?

  1. O(n)

  2. O(log n)

  3. O(n^2)

  4. O(1)


Correct Option: B
Explanation:

In a balanced binary search tree, the time complexity of finding an element is O(log n) because the tree is height-balanced.

Which data structure is used to implement a priority queue, where elements are served based on their priority?

  1. Array

  2. Linked List

  3. Stack

  4. Priority Queue


Correct Option: D
Explanation:

A priority queue is a data structure that stores elements with associated priorities. Elements with higher priorities are served before elements with lower priorities.

- Hide questions