(a) Give the asymptotic running time of BubbleSort and justify your answer. Enter the best-case runtime or the worst-case runtime of BubbleSort.(b) Extend BubbleSort with a premature termination criterion, so that the best-case running time becomes O(n). Justify that the worst-case running time is still Ω(n^2 ) with this modification.
(a) Give the asymptotic running time of BubbleSort and justify your answer. Enter the best-case runtime or the worst-case runtime of BubbleSort.
(b) Extend BubbleSort with a premature termination criterion, so that the best-case running time becomes O(n). Justify that the worst-case running time is still Ω(n^2 ) with this modification.
BubbleSort (A) for i=1 to A.length-1 do for j= A.length downto i+ 1 do if Aj Aj-1] then | exchange A[j] with A[j-1] end end end
(a) Give the asymptotic running time of BubbleSort and justify your answer. Enter the best-case runtime or the worst-cas
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am