Searching And Sorting Algorithms Y9 Flashcards
(19 cards)
What is linear search
The computer checks each individual item on the list, and compares it to the value being looked for, it then moves on to the next value if not found.
Why is linear search inefficient
Large lists mean that the search would take a while to finish
What is binary search
List has to be in order(number or alphabetical order)
Computer checks middle value and compares it-if the number/alphabet is higher than it finds the middle of the second half
Keeps doing this until value found
Wha has to happen before binary search can take place
List needs to be in order
What happens if there is an even number for binary search(which ones the middle)
The one on the left
Why is binary search more efficient than linear search
Binary search looks at significantly less values than linear. Making the process quicker
Why do we use sorting algorithms
To put a list of items in order (alphabetically or numerically)
What is the bubble sort algorithm
Compares first two numbers and will swap them if needed (if the value on the one on the right is lower than the one on the left)
Then repeats with second and third number.
This repeats until end of list
Then goes to start of list and redoes it all(ordering again)
Keeps going from start until all in order (there will be one check)
How efficient is bubble sort
Very inefficient
What is merge sort
Divide the list in half
And in half again
Keep dividing in half until values are separated
Then start merging them back together
Ordering the values as you go along
Which one is more efficient merge or insertion sort
Merge
Which sort is most complicated
Merge
What is insertion sort
Takes first number of list and adds it to the sorted list
Takes the second and puts it in the sorted list (placing it in order)
Keep going from doing this one at a time until all are sorted
Advantages of bubble sort
Simple and easiest to code
Disadvantages of bubble sort
Slowest
Advantages of insertion sort
Simple and easy to code
Disadvantages of insertion sort
Twice as fast as bubble but slower than merge
Advantages of merge sort
Fastest.
Disadvantages of merge sort
More difficult to code than the other two and it requires more memory