- Insertion sort orders animals by weight.
Insertion Sort: The insertion sort builds a sorted list from the start of the unsorted list. It loops through the remaining unsorted items in the list; each time through, it grabs the next unsorted item, and then loops back through the sorted part of the list to find the correct spot for the current unsorted item. After it finds the correct spot, it "inserts" the item into that spot.

By Swfung8 (Own work) [CC BY-SA 3.0 (http://creativecommons.org/licenses/by-sa/3.0) or GFDL (http://www.gnu.org/copyleft/fdl.html)], via Wikimedia Commons
5.3.7 How to Use Insertion Sort
The value is greater than 0 and the second animal in the list's Weight (103.8) is less than the first animal's (128.2) so the loop will execute.
Bobo and Bubbles should swap index positions in the list.
The value of the inner for loop becomes 0 (the beginning of the list) so the condition fails and you should be brought back to the outer loop.
This time the value should be 2 and the second animal in the unsorted list is 41.3 and the first is 128.2.
This time the value is greater than 0 AND the Weight of the second animal (41.3) is less than the first animal (103.8) so the loop executes again and Spot should swap with Bubbles. The loop should break because it reaches the beginning of the list.
The animals should be sorted in ascending order by weight with a swap count of 108.

It is the same as the algorithm for weight, but it compares the name values instead of the weight values.

It should look like the following:
"COMPARE COUNT: " + [SortResult variable].CompareCount
"TIME: " + [SortResult variable].ElapsedMillisecondsStart the stopwatch at the beginning of the method, and stop it at the end of the method. Assign the ElapsedMilliseconds property in the object initialzer to the Stopwatch's Elapsed.TotalMilliseconds property.
5.3.8 How to Use the StopwatchThe swap count should be 108, and the compare count should be 210.
The animals should be sorted by weight in ascending order. The swap count should be 108, and the compare count should be 20.
The swap count should be 16, and the compare count should be 210.

Penjee via https://blog.penjee.com/binary-vs-linear-search-animated-gifs/
5.3.9 How to Use a Binary SearchEach time through, increment the loop counter and check if the current animal's name matches the passed-in name.
Then break. The message should look like the following.
[animal name] found. [number of loops] loops complete.Also, store a copy of the zoo's animals from a SortResult object in a variable, as shown in the code below.
SortResult animals = zoo.SortAnimals("bubble", "name");Type "search linear Ted". Ensure that Ted is found and that it takes 16 loops to complete.
The minPosition should be 0, the maxPosition should be 20, the middlePosition should become 10 and the compare variable should be 1 (indicating it is greater than the animal name at the middle position). The minPosition should become 11 because we now only care about the ranges from 11 to 20.
Now the middle position becomes 15 and the minPosition becomes 16. The range was cut in half again.
The middle position becomes 19 and since the animal at position 19 IS Ted, the string compare will come back as 0 and the else statement will execute.
© 2026 Northcentral Technical College