2.1.3 Flashcards
what are the different searching algorithms?
-linear search
-binary search
linear search
starts with the first item in a list and compares them to the search criteria one after the other
pros of linear search
-good on small lists
-simple to code
-doesn’t need to be ordered
cons of linear search
-takes a while on large lists
-has to go through entire list
binary search
values in the list have to be ordered and compares the middle value to the data
pros of binary search
-good on large lists
-doesn’t have many loops
cons of binary search
-only works on ordered lists
-more complicated to code
-lists need reordering every time a new item is added
what are the different sorting algorithms?
-bubble sort
-insertion sort
-merge sort
bubble sort
goes through a list repeatedly, making comparisons between pairs of adjacent items and then swapping elements in the wrong order
pros of bubble sort
-simple to write the code for
-simple to understand
-doesn’t need much memory
cons of bubbles sort
-slowest way to sort a list
insertion sort
each item is taken in turn, compared to the items in a sorted list and placed in the correct position
pros of insertion sort
-simpler to code than merge sort
-useful for small lists
-faster than bubble sort
cons of insertion sort
-not effective with large lists
merge sort
splits large lists into individual lists by breaking them down, sorting them and then merging them back together in one large list