COMP 250 Lecture Notes - Lecture 6: Sorting Algorithm, Heapsort, Merge Sort

101 views5 pages

Document Summary

Lecture 6 - sept 19 sorting algorithms: bubble, selection, & insertion. We are talking about a list of elements. Any time you compare things, you can talk about a sorting algorithm. Another example -- you can sort through exams by last name. N * log(n) is waaaay less than n. As we walk through the list, if we see that an element and its neighbor are in the wrong order, then we swap them (put them in the right order). To do this, you need to swap elements. Remember that if you try to swap two things, you can"t do: As soon as you say x=y, you lost the previous value of x. Rather, you need to use a temporary variable : The first time you go through, if the smallest element is in the back, at some point it will be swapped with the 2nd to last element in the list.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents