Time complexity MCQs

By: Prof. Dr. Fazal Rehman Shamil | Last updated: September 20, 2024

What is the time complexity of accessing an element in an array by index?

a) O(n)
b) O(log n)
c) O(1)
d) O(n^2)
Answer: c) O(1)
What is the time complexity of inserting an element at the beginning of a linked list?

a) O(n)
b) O(log n)
c) O(1)
d) O(n^2)
Answer: c) O(1)
What is the best-case time complexity of quicksort?

a) O(n)
b) O(n log n)
c) O(n^2)
d) O(log n)
Answer: b) O(n log n)
What is the worst-case time complexity of quicksort?

a) O(n log n)
b) O(n)
c) O(n^2)
d) O(log n)
Answer: c) O(n^2)
What is the time complexity of searching for an element in a balanced binary search tree (BST)?

a) O(n)
b) O(log n)
c) O(1)
d) O(n log n)
Answer: b) O(log n)
What is the time complexity of merging two sorted arrays of size n?

a) O(n log n)
b) O(n)
c) O(log n)
d) O(n^2)
Answer: b) O(n)
What is the time complexity of deleting an element from a linked list given a pointer to that element?

a) O(1)
b) O(n)
c) O(log n)
d) O(n^2)
Answer: a) O(1)
What is the average-case time complexity of binary search?

a) O(n)
b) O(log n)
c) O(1)
d) O(n log n)
Answer: b) O(log n)
What is the time complexity of finding the maximum element in an unsorted array?

a) O(n log n)
b) O(n)
c) O(log n)
d) O(1)
Answer: b) O(n)
What is the time complexity of the bubble sort algorithm in the worst case?

a) O(n)
b) O(n log n)
c) O(n^2)
d) O(log n)
Answer: c) O(n^2)
What is the time complexity of inserting an element into a max-heap?

a) O(n)
b) O(log n)
c) O(1)
d) O(n log n)
Answer: b) O(log n)
What is the time complexity of deleting the minimum element from a min-heap?

a) O(n)
b) O(log n)
c) O(1)
d) O(n log n)
Answer: b) O(log n)
What is the time complexity of traversing a binary tree?

a) O(n log n)
b) O(n)
c) O(log n)
d) O(n^2)
Answer: b) O(n)
What is the time complexity of the merge sort algorithm?

a) O(n log n)
b) O(n)
c) O(log n)
d) O(n^2)
Answer: a) O(n log n)
What is the time complexity of the selection sort algorithm?

a) O(n log n)
b) O(n)
c) O(log n)
d) O(n^2)
Answer: d) O(n^2)
What is the time complexity of searching for an element in an unbalanced binary search tree (BST)?

a) O(n)
b) O(log n)
c) O(1)
d) O(n log n)
Answer: a) O(n)
What is the time complexity of checking if an element exists in a hash table with n elements?

a) O(n)
b) O(log n)
c) O(1)
d) O(n^2)
Answer: c) O(1)
What is the time complexity of the insertion sort algorithm in the best case?

a) O(n log n)
b) O(n)
c) O(log n)
d) O(n^2)
Answer: b) O(n)
What is the time complexity of deleting an element from an array, given its index?

a) O(1)
b) O(n)
c) O(log n)
d) O(n log n)
Answer: b) O(n)
What is the time complexity of the Fibonacci sequence using dynamic programming?

a) O(n)
b) O(log n)
c) O(1)
d) O(n^2)
Answer: a) O(n)

Data Structures MCQs

Basic Concepts

  1. Introduction to Data Structures
  2. Complexity Analysis MCQs

Linear Data Structures MCQs

  1. Arrays MCQs
  2. Linked Lists MCQs
  3. Stacks MCQs
  4. Queues MCQs

Non-Linear Data Structures MCQs

  1. Trees MCQs
  2. Heaps MCQs
  3. Graphs MCQs

Hashing MCQs MCQs

  1. Hash Tables

Sorting and Searching Algorithms MCQs 

  1. Sorting Algorithms MCQs
  2. Searching Algorithms MCQs

Miscellaneous

  1. Memory Management in data structures MCQs
  2. String Manipulation Algorithms MCQs
  1. Data Structures MCQs 1
  2. Data Structures MCQs 2
  3. Data Structures MCQs 3
  4. Data Structures MCQs 4
  5. Data Structures MCQs 5
  6. Stacks Solved MCQs
  7. Queues MCQs
  8. pointer mcqs
  9. Array MCQs