Sorting+and+Searching

Sorting and Searching

Topics: 1. Common sorting algorithmns - Bubble Sort, Selection sort, Insertion sort, recursive sorts (Mergesort and Quicksort)

There are three main types of sorts that we should know.

The first major sort is is the Bubble Sort. The bubble sort goes though the list you are trying to sort and compares one item with the next. If it the first item compared is supposed to be later in the list they are switched. It continues doing this for the enitre list until it can go through the list making no changes. These are very easy to implement

The next major sort is the selection sort. The selection sort goes through the list finds the lowest value and puts it first. It then goes on and does the same thing for the second lowest until it has done the entire thing. These are more efficient then the others on a large scale.

The third major sort is the insertion sort. In an insertion sort the program creates a new array and sorts the list into a the new array. This is very similar to how most people sort cards. This is very innefficient on a large scale.

2. Implementing sorts in Java

These websites have good examples: [|bubble] [|insertion] [|selection] To implement a sort you need to have figured out how you are sorting them and what tests to do. You also need to set up an while or for statement to allow you to loop.

3. Sequential search and Binary Search

Sequential search is the most basic type of search. In a sequential search you go through and test every single piece of the array until you find the one you are searching for. It is simple to [|implement] but very inneficient on large lists. A binary search requires the list to have be previously sorted. The program will then try the middle value. If it is greater the then the desired value you guess the middle of the part of the list lower then your last guess. It is harder to [|implement] but is more efficient, especially on larger lists, then a sequential sort assuming it is already sorted