In selection sort, how many comparisons are performed in the inner loop in each iteration?
- i
- n
- n - 1
- n - i
In each iteration of the inner loop in selection sort, where 'i' is the current iteration, n - i comparisons are performed. This is because the inner loop looks for the minimum element in the unsorted portion and places it at the beginning, reducing the number of comparisons in subsequent iterations.
Loading...
Related Quiz
- What is the time complexity for inserting an element at the beginning of a singly linked list?
- Can you explain the time complexity of the Ford-Fulkerson algorithm and identify any potential optimization techniques?
- What problem does the Matrix Chain Multiplication algorithm aim to solve?
- In bubble sort, what happens in each pass through the array?
- What does regular expression matching involve?