0% found this document useful (0 votes)
12 views14 pages

Bank

The document consists of a series of questions related to algorithms, data structures, and their complexities, including sorting algorithms like Bubble Sort, Quick Sort, and Merge Sort. It covers concepts such as best and worst-case scenarios, time complexities, and characteristics of different algorithmic approaches like greedy methods and dynamic programming. Additionally, it includes practical applications and problem-solving scenarios involving these algorithms.

Uploaded by

marwansitten
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views14 pages

Bank

The document consists of a series of questions related to algorithms, data structures, and their complexities, including sorting algorithms like Bubble Sort, Quick Sort, and Merge Sort. It covers concepts such as best and worst-case scenarios, time complexities, and characteristics of different algorithmic approaches like greedy methods and dynamic programming. Additionally, it includes practical applications and problem-solving scenarios involving these algorithms.

Uploaded by

marwansitten
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Assume that we use Bubble Sort to sort n distinct elements in ascending order.

When does the best


case of Bubble Sort occur?

Right?

A )When elements are sorted in ascending order

B )When elements are sorted in descending order

C)When elements are not sorted by any order

D)There is no best case for Bubble Sort. It always takes O(n*n) time

2. In computer science, algorithm refers to a special method usable by a computer for the solution
to a problem.

a) True

b) False

3. Which sorting algorithm repeatedly steps through the list, compares adjacent elements, and
swaps them if they are in the wrong order?

A)Insertion Sort

B)Quick Sort

C)Bubble Sort

D)Merge Sort

4. What is the time complexity of Bubble Sort in the worst case?

A)O(n)

B)O(n^2)

C)O(n log n)

D)O(log n)

5. Which sorting algorithm divides the array into a sorted and an unsorted part and repeatedly picks
the smallest element from the unsorted part?

A)Bubble Sort

B)Selection Sort
C)Insertion Sort

D)Merge Sort

6. The time complexity of Quick Sort in the best case is:

A)O(n^2)

B)O(n log n)

C)O(n)

D)O(log n)

7.Which sorting algorithm works by repeatedly inserting elements into their correct position in the
sorted portion of the array?

A)Insertion Sort

B)Merge Sort

C)Quick Sort

D)Bubble Sort

8.Which sorting algorithm is based on the "divide and conquer" approach?

A)Insertion Sort

B)Merge Sort

C)Bubble Sort

D)Selection Sort

9.In Quick Sort, what is the term for the element used to partition the array?

A)Median

B)Pivot

C)Divider d)Anchor
10. What is the main drawback of empirical analysis in algorithm efficiency?

A.It uses physical units of time

B.It requires implementing the algorithm

C.It assumes all inputs are equal

D.It focuses only on theoretical performance

11. What is the primary purpose of an algorithm?

A.To provide an infinite loop for problem-solving

B.To solve a problem in a finite number of steps

C.To compile code into machine language

D.To design hardware architectures

12.Which efficiency class represents exponential growth?

a. O(log n) )

b. ( O(n^2) )

c. ( O(2^n) )

d. ( O(n log n) )

13. Which of these functions grows the fastest as ( n to infty)?

a. (n^2)

b. (log n)

c. (2^n)

d. (nlog n)

What data structure is typically used in BFS?

A)Stack B)Queue C)Priority Queue D)Linked List


15. What data structure is typically used in DFS?

A)Stack

B)Queue

C)Binary Tree

D)Array

16.Which algorithm traverses a graph level by level?

A)DFS

B)BFS

C)Quick Sort

D)Exhaustive Search

17.The time complexity of BFS is:

O(V + E)

O(V^2)

O(E log V)

O(VE)

18. What does the growth rate of an algorithm measure?

A.The number of iterations in a loop

B.The space needed as the algorithm executes

C.The increase in time or resources as input size grows

D.The amount of input the algorithm can handle


19. What is the goal of recursion’s decomposition step?

a. Combine smaller problems into the final result.

b. Stop the recursion.

c. Break the problem into smaller subproblems.

d. Replace recursion with iteration.

20. What is a significant limitation of binary search?

a. It only works for unsorted arrays.

b. It requires the array to be sorted.

c. It takes more time than linear search.

d. It cannot handle duplicate values.

21. What does (O(nlog n)) commonly describe?

a. Sorting algorithms like merge sort.

b. Matrix multiplication.

c. Simple linear traversal.

d. Searching a sorted array.

22. Which algorithm is an example of greedy approach?

a. Binary search

b. Dijkstra's algorithm

c. Merge sort

d. Backtracking
23. What is the growth rate of all logarithmic functions( log_a(n)) regardless of base (a)?

a. Different for each ( a).

b. (O(log n)).

c. (O(nlog n)).

d. Depends on the input size(n).

24.What is the primary disadvantage of the Exhaustive Search method?

A)It is complex to implement.

B)It does not guarantee a solution.

C)It is computationally expensive.

D)It requires specific data structures.

25.Which sorting algorithm is also referred to as "partition-exchange sort"?

a.Quick Sort

b.Merge Sort

c.Insertion Sort

d.Bubble Sort

26.In BFS, what happens when the queue becomes empty?

The algorithm terminates.

The algorithm starts over.

The algorithm uses a stack.


The algorithm restarts from the root.

27.What is the primary role of the pivot in Quick Sort?

To act as the smallest element

To divide the array into two halves

To sort the entire array

To find the median

28. Why are nested loops often inefficient?

a. They require recursion.

b. They involve repeated comparisons.

c. They increase time complexity exponentially.

d. They increase time complexity quadratically.

29.Quick Sort always has better performance than Merge Sort ?

True

False

30.Breadth-First Search (BFS) can be implemented using a queue.

A)True

B) False

31)Insertion Sort has a time complexity of O(n^2) in the worst case.

True

False
32.Analyze the time complexity of this nested loop:

for i in range(n):
N^2
for j in range(i + 1):

print(i, j)

33.Analyze the time complexity .

<Fuction> factorial(n):

if n == 0:

return 1
(N)
return n * factorial(n - 1)

34.

<Function> factorial_reduce(n):

if n <= 1:

return 1

return n * factorial_reduce(n // 2)

35.function exponentialLoop(n):

i=1

while i <= n:

if i % 2 == 0:

print(i)

i=i*2
36. static int MaxSubarraySum(int[] arr)

int maxSum = arr[0];

int currentSum = arr[0];

for (int i = 1; i < arr.Length; i++)

currentSum = Math.Max(arr[i], currentSum + arr[i]);

maxSum = Math.Max(maxSum, currentSum);

return maxSum;

37.Which of the following is a characteristic of Dynamic Programming?

A) It requires solving problems sequentially from start to finish.

B) It stores subproblem solutions to avoid repeated computation.

C) It only uses recursion.

D) It cannot be applied to overlapping subproblems

38.Dynamic Programming does not require storing subproblem solutions.

A)True

B)False
39.Which of the following problems is not typically solved using Dynamic Programming?

A) Longest Common Subsequence.

B) Knapsack Problem.

C) Prime Number Calculation.

D) Coin Change Problem

40.Dynamic Programming is only suitable for problems that can be broken down into subproblems.

True

False

41.Greedy algorithms rely on:

A) Making the optimal choice at each step without considering future consequences.

B) Trying to explore all possible solutions.

C) Storing all subproblem solutions.

D) Applying recursion to all inputs.

42.Greedy algorithms do not always guarantee an optimal solution to a problem.

True

False

43.Which of the following problems can be solved using a greedy algorithm?

A) Nearest Neighbor Problem.

B) 0/1 Knapsack Problem.

C) Subset Sum Problem.

D) Shortest Path in a graph (e.g., Dijkstra’s Algorithm).


44.In the Fractional Knapsack Problem, what should the greedy algorithm prioritize?

A) Items with the least weight.

B) Items with the least value.

C) Items with the highest value-to-weight ratio.

D) Items based on their order of appearance.

45.Backtracking is typically used in:

A) Problems that have a limited number of possible solutions.

B) Searching for an optimal solution among all possible configurations.

C) Problems relying on Dynamic Programming.

D) Problems requiring greedy decisions.

46.In backtracking, when a solution path reaches an invalid state, it backtracks to the previous step
and tries a different path.

True/False:

47.Which of the following is a typical application of backtracking?

A) Solving the Traveling Salesman Problem.

B) Solving Sudoku.

C) Finding the shortest path in a graph.

D) Sorting an array.

48.if an algorithm has a complexity of O(N+M), what does this indicate?

A.The algorithm's complexity depends only on N.


B.The algorithm's performance is the product of N and M.

C.The algorithm runs in linear time relative to N and M.

D.The algorithm runs in quadratic time

49.In an if-then-else statement, the worst-case time complexity is determined by the faster of the
two sequences of statements.

True

False

50.ow does Merge Sort merge two sorted arrays?

A.By comparing all elements simultaneously

B.By sorting both arrays again

C.By repeatedly comparing the smallest elements of the two arrays

D.By appending one array to the other

B) Compare

a- Between DFS , BFS

b- difference between Recursive , Backtracking

c-Binary search , Sequential (Linear ) Search

d- Top-down , bottom up approach of Dynamic Programming

e – merge sort , Quick Sort – bubble Sort

d- compare the time complexity of merge sort , Quick Sort , bubble Sort

f- Dynamic Programming , Recursive


C) Problesm if You have List of integer Numbers

[ 200 , 7 , 60 ,65 ,40 ,100 , 30 ]

Apply

1- Merge Sort
2- Quick sort Assume that Pivot first element in List
3- Bubble Sort

D) List the stemps of how

1 – Binary search work

2- Dynamic Programming

3- Back Tracking

4-Bubble, Quick sort

5- linear search

6- DFS , BFS
Solve Knapsak Problem by Gready Algorthim (capacity W=9)

Let’s say you have a set of coins with values [1, 2, 5, 10] and you need to give minimum number of
coin to someone change for 39.

Nth Fibonacci number by Dynamic Programming

Apply :

1- Greedy Algorithm
2- Dynamic Programming

You might also like