H Lecture Notes - Lecture 5: Time Complexity, Dspace, Selection Sort

9 views6 pages

Document Summary

The idea behind this algorithm is pretty simple. We divide the array into two parts: sorted and unsorted. The left part is sorted subarray and the right part is unsorted subarray. Initially, sorted subarray is empty and unsorted array is the complete given array. We perform the steps given below until the unsorted subarray becomes empty: Pick the minimum element from the unsorted subarray. Swap it with the leftmost element of the unsorted subarray. Now the leftmost element of unsorted subarray becomes a part (rightmost) of sorted subarray and will not be a part of unsorted subarray. This is our initial array a = [5, 2, 6, 7, 2, 1, 0, 3] We will swap a[0] and a[6] then, make a[0] part of sorted subarray. We will swap a[1] and a[5] then, make a[1] part of sorted subarray. We will swap a[2] and a[4] then, make a[2] part of sorted subarray.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents