Searching and Sorting Flashcards
what is binary search
Start at middle position in the list.
If the value at the midpoint is less than the value to be found, the list is divided in half. The lower half of the list is ignored and the search keeps to the upper half of the list.
Otherwise, if the value at the midpoint is greater than the value to be found, the upper half of the list is ignored and the search keeps to the lower half of the list.
The search moves to the midpoint of the remaining items. Steps 2 through 4 continue until a match is made or there are no more items to be found.
what is linear search
Find out the length of the data set.
Set counter to 0.
Examine value held in the list at the counter position.
Check to see if the value at that position matches the value searched for.
If it matches, the value is found. End the search.
If not, increment the counter by 1 and go back to step 3 until there are no more items to search.
explain the differences of binary and linear search
- linear is much more simpler than binary
- linear is less efficient
- liner is better with small list
- in a ordered list binary list is better as it is suitable for larger lists
what is bubble sort
Start at the beginning of the list.
Compare the first value in the list with the next one up. If the first value is bigger, swap the positions of the two values.
Move to the second value in the list. Again, compare this value with the next and swap if the value is bigger.
Keep going until the there are no more items to compare.
Go back to the start of the list.
what is a pass in binary search
when you get to the end of the list for the first time
what the advantages of bubble sort
- simpler
- efficient to check if in order
- doesn’t use much memory
what are disadvantages of bubble sort
- inefficient to sort
- not good with large lists
what is merge sort
- split the list in half into sub lists
- keep doing till you get individual items
- each time ur merging sort it
- keep merging and sorting till sub list become one
what are advantages of merge sort
- efficient and quicker than bubble sort for large lists
what are disadvantages of merge sort
slower for small lists
not good for checking
use lots of memory
what is insertion sort
look at second item at list if smaller than first insert in position keep going till all inserted properly
what is insertion sort
look at second item at list if smaller than first insert in position keep going till all inserted properly
what are advantages of insertion sort
- easy coded
- good with small list
- not much memory
- quick
- easy to check
what are disadvantages or insertion sort
not good with large lists