1 Flashcards
what is a binary search?
looks for items in an ordered list
how does binary search work?
compare your number to the middle one
if it comes before the middle, get rid of the second half
if it comes after, get rid of the first half
repeat until you get your number
what is a linear search?
used to find items in an unsorted list
how does a linear search work?
checks each item to see if it is the correct one
if it is, it stops
if it isn’t, it continues checking until it finds it or has checked the entire list
what is a search algorithm?
computers use them to find items in a list
examples of search algorithms
binary search
linear search
what is a sorting algorithm?
used to order lists of values
examples of sorting algorithms?
bubble sort
merge sort
insertion sort
what is bubble sort?
used to sort an unordered list
how does bubble sort work?
compares two values at a time, keeps going through the list even after swapping two values
pros of bubble sort?
simple algorithm
efficient way check numbers are in order, only has to check once
doesn’t use much memory as it is done using the original list
cons of bubble sort?
inefficient way to sort a long list
what is merge sort?
divide and conquer algorithm
splits the list apart then merges it back together
how does merge sort work?
split the list in half into sub-lists until each sub list contains one item
merge pairs of sub lists and order them
repeat until you’ve merged all the sub lists together
pros of merge sort?
much more efficient and quicker than bubble
consistent running time regardless of amount of numbers
cons of merge sort?
slower than others on small lists
even if the list is sorted it goes through the whole process - taking a long time
uses more memory to create separate lists
what is insertion sort?
orders items by following one item through the list until it is in the correct place
how does insertion sort work?
follows one item until it is in the correct place then goes back to the start and follows the next number
pros of insertion sort?
can be easily coded
good with small lists
doesn’t need much additional memory
quick to check an already sorted list
integar
code, characteristics, example
int
whole number
6, 204, -987
real/float
code, characteristics, example
real
decimal number
1.00, 4.5, -7.8
boolean
code, characteristics, example
bool
either true or false
true/false, yes/no, 1/0
character
code, characteristics, example
char
a single letter, number or symbol
A, 8, !
string
code, characteristics, example
string
a collection of characters
isla!, pizzaisready, 7Azo59!?