2.1.3 Searching and Sorting algorithms Flashcards
What are the two searching algorithms?
Binary search
Linear search
What is a Binary search?
looks for a specific value in an ordered or sorted list
What is a Binary search?
looks for a specific value in an ordered or sorted list
How does a binary search take place?
Comparing it with the middle or median value and deciding if it is higher or lower
Taking the half of the list that is higher or lower and once again finding and comparing it with the middle or median value
Repeating this process until the specific value is found
How does a linear search take place?
takes each value in a list, one at a time, and compares it with the value required, this is repeated until the correct value is found
What are the characteristics of a linear search?
process can be very slow, especially with large data sets
How does a bubble sort take place?
The first two values in a list are compared with each other and are swapped if they are in the wrong order. Then the next pair of values is checked and their order in the list is swapped, if required. This process is repeated unto no further swapes are needed and the list is sorted
How does a Merge sort take place?
data is repeatedly split into halves until each list contains only one item. The items are then merged into the order required.
How does an Insertion sort take place?
Each item in an unordered list is examined in turn and compared with the previous items in the list. Higher values than those before them are left in the same position, but lower values are compared with each in turn until they can be inserted into the correct place. This process is repeated until all items have been examined and inserted into their correct position, in ascending order.