Arrange the following in ascending order of their average case complexity. Selection-sort, Quick-sort, Linear search, Binary search
Binary search, Linear search, Quick-sort, Selection-sort
Algorithm complexity is a measure of the resources (like time or space) an algorithm uses to solve a problem. Average case complexity describes the behavior of an algorithm on a "typical" or "random" input. It's the expected performance over many possible inputs of a given size.
Let's look at the average case time complexities for the algorithms mentioned in the question: Selection Sort, Quick Sort, Linear Search, and Binary Search. We represent the input size as \(n\).
Let's summarize these complexities in a table:
| Algorithm | Average Case Time Complexity |
|---|---|
| Linear Search | \(O(n)\) |
| Binary Search | \(O(\log n)\) |
| Selection Sort | \(O(n^2)\) |
| Quick Sort | \(O(n \log n)\) |
We need to arrange these complexities from smallest to largest. For large values of \(n\), the order of growth is:
Therefore, arranging the algorithms in ascending order of their average case complexity gives us:
Binary Search (\(O(\log n)\)), Linear Search (\(O(n)\)), Quick Sort (\(O(n \log n)\)), Selection Sort (\(O(n^2)\))
Let's compare our derived order with the given options:
The correct ascending order of average case complexities is Binary Search, Linear Search, Quick Sort, Selection Sort.
| Algorithm | Best Case | Average Case | Worst Case | Notes |
|---|---|---|---|---|
| Linear Search | \(O(1)\) | \(O(n)\) | \(O(n)\) | Simple, no prerequisites |
| Binary Search | \(O(1)\) | \(O(\log n)\) | \(O(\log n)\) | Requires sorted data |
| Selection Sort | \(O(n^2)\) | \(O(n^2)\) | \(O(n^2)\) | Simple, in-place, stable |
| Quick Sort | \(O(n \log n)\) | \(O(n \log n)\) | \(O(n^2)\) | Fastest average case, unstable, space depends on recursion stack |
Big O notation (\(O\)) describes the upper bound of the growth rate of a function. In the context of algorithms, it tells us how the running time or space requirements scale with the input size (\(n\)) in the worst-case or average-case scenario (depending on which complexity we are analyzing). Common Big O notations in order of increasing growth rate are:
Understanding Big O notation helps in comparing the efficiency of different algorithms, especially for large inputs.
Match the following :
| List – I | List – II | ||
| a. | Bucket sort | i. | \(O(n^3 \lg n)\) |
| b. | Matrix chain multiplication | ii. | \(O(n^3)\) |
| c. | Huffman codes | iii. | \(O(n \lg n)\) |
| d. | All pairs shortest paths | iv. | \(O(n)\) |
Codes :
a b c d
We can show that the clique problem is NP-hard by proving that
To determine the efficiency of an algorithm the time factor is measured by :
Given the following statements :
\(S_{1}\) : The subgraph-isomorphism problem takes two graphs \(G_{1}\) and \(G_{2}\) and asks whether \(G_{1}\) is a subgraph of \(G_{2}\).
\(S_{2}\) : The set-partition problem takes as input a set S of numbers and asks whether the numbers can be partitioned into two sets A and \(\bar{A} = S - A\) such that
\(\sum_{x \in A} x = \sum_{x \in \bar{A}} x\)
Which of the following is true ?
An algorithm is made up of 2 modules \(M_{1}\) and \(M_{2}\). If time complexity of modules \(M_{1}\) and \(M_{2}\) are h(n) and g(n) respectively, the time complexity of the algorithm is