ENGR 101 Lecture Notes - Lecture 21: Ex-Gay Movement, Insertion Sort, Bubble Sort
Document Summary
Engr 101: introduction to computers and algorithms - lecture 21: common algorithms. Often sequences of data are more useful if the elements are in order. Rearranges a data sequence so that the elements are in order. Is a very common and useful category of algorithms. Go through the list, swapping adjacent places when out of order. Ensures that the highest gets to the end. Then go through the list again, swapping as we go . Ensures that the second highest is second to the end. Create new sorted list by going through input list one-by-one. For each input item, go through new list in order, stop and insert in place that would maintain order. Suppose we are looking for a value in a sorted vector, a. Compare the value against the middle element of a and there are three possibilities. Value is equal, greater, or less than the element. If value is equal, the index was found.