Skip to main content

C++ and Algorithms

1).Which of the following is a commonly used algorithm for searching in C++?

1) Binary Search
2) Linear Search
3) Depth First Search
4) All of the above

2).Which C++ Standard Library class provides a way to store and manipulate sequences of elements?

1) vector
2) map
3) set
4) deque

3).Which algorithm is typically used for sorting in C++?

1) Quick Sort
2) Merge Sort
3) Bubble Sort
4) All of the above

4).What is the time complexity of the `std::sort()` algorithm in the worst case?

1) O(n log n)
2) O(n^2)
3) O(n)
4) O(log n)

5).Which algorithm is best suited for finding the shortest path in a graph?

1) Dijkstra's Algorithm
2) Binary Search
3) Breadth-First Search
4) None of the above

6).What is the purpose of a hash table in C++?

1) To store data with unique keys for fast lookup
2) To store ordered data
3) To optimize sorting algorithms
4) None of the above

7).Which of the following algorithms is used to solve the Traveling Salesman Problem (TSP)?

1) Dynamic Programming
2) Greedy Algorithm
3) Branch and Bound
4) All of the above

8).Which data structure is typically used in a breadth-first search (BFS) algorithm?

1) Queue
2) Stack
3) Priority Queue
4) Array

9).What is the time complexity of inserting an element into an unordered_map in C++?

1) O(1)
2) O(log n)
3) O(n)
4) O(n^2)

10).Which C++ algorithm is used for merging two sorted ranges?

1) std::merge
2) std::sort
3) std::partition
4) std::reverse