fundamentals of algorithms Flashcards
define the term algorithm
a sequence of steps that can be followed to complete a task
define the term decomposition
breaking a problem into a number of sub-problems, so that each sub- problem accomplishes an identifiable task ( which might itself be further subdivided )
define the term abstraction
the process of removing unnecessary detail from a problem
what shape is a decision in a flowchart?
diamond
what shape is a process in a flowchart?
rectangle
what shape is a input/output in a flowchart?
parallelogram
what shape is a subroutine in a flowchart?
rectangle with a line at each side
explain linear search
a linear search checks each item of the list in turn to see if it’s the correct one and stops when it either finds the item or has checked every item
explain binary search
a binary search finds the middle item in the list (if this is the right item then it stops)
if not it compares the requested item with the middle item and gets rid of the half which the item isn’t in
this will repeat until the number is found
( in an odd list ( e.g 7 ) round down so ( item 3 would be half )
what are the advantages of linear search over binary search?
works in an unordered list
for small lists the run time of both algorithms will be similar
what are the advantages of binary search over linear search?
is much quicker at searching big lists
run time is similar for small lists
( but doesn’t work in an unordered list )
explain the merge sort
split the list in half ( into sublists )
repeat until each sublist has one item
merge the sublists and sort the order each time
repeat until all the sublists are merged
explain the bubble sort
the bubble sort looks at the first two items and swaps them if they are in the wrong order
this continues until the end of the list ( called a pass ( now the final number is in the correct place )
repeat until a pass has no swaps
what are the advantages for a bubble sort over a merge sort?
much quicker for longer lists
very consistent run time no matter how unordered the list is
what are the advantages of a merge sort over a bubble sort?
little memory is used
simple and can be easily implemented
efficient - for a list of n you only need to do n-1 comparisons to check if the list is ordered