Exam Flashcards
(108 cards)
What is the definition of an algorithm?
sequence of ordered and precisely described steps to achieve a result/solve a problem.
-each step is expressed in terms of basic operations who’s meaning is completely specified
is there any ambiguity in algorithms?
no.
are algorithms guaranteed to produce a result?
yes, algorithms are guaranteed to produce a result.
do algorithms have to stop eventually.
yes! they have a finite number of steps..
What are the two methods to describe algorithms unambiguously?
flow charts and pseudo code
What is pseudo code?
is describing the steps of an algorithm in plain language.
define flow chart
visual representation of the steps in an algorithm.
In a flow chart, what does —–> the arrow mean?
its called a flow line. it indicates the next operation (the flow of operations) by the connecting symbol.
In a flow chart, what does the oval/circle mean?
it is used to represent the start and end of a flow chart.
in a flow chart, what does the slanted rectangle mean?
it is used for the input and output of operations. such as asking people for their height and name, and calculating the results
In a flow chart, what does the rectangle stand for?
it is used for any kind of operation and or data manipulation. e.g selected = height, or selected = name.
In a flow chart, what does the diamond symbol stand for?
it represents a conditional operation that determines which of the two paths the program will take. e.g. has every person in the room been asked yet?
What is runtime?
how long does it take to compute the results? how much work is it? how many steps/operations are carried out
What does N symbolize?
it symbolizes problem size.
what is runtime complexity?
described the performance of an algorithm, or how much processing power/time is required to run the algorithm.
what is problem size?
the number of elements of the input is the problem size… e.g. how many people are in the room to find the problem size for the tallest person algorithm
how can you tell if something is a linear algorithm?
if the runtime complexity = N (problem size)
this is because the number of steps in an algorithm will increase linearly with the problem size (N)
if N=80, then runtime will be 80
if the pseudo code is:
set sum to 0
for each height on the list add height to sum
set average sum to N
what type of algorithm is this describing?
Linear Algorithm.
because sum = N
How do you tell if an algorithm is Linear?
runtime complexity = N
How does binary search work?
if the list is organized, you identify the middle of the list and split it. again and again until you find your result.
What is the binary search complexity?
with every split necessary, the size of N doubles.
if there is 1 split, the problem size is 2.
if there is 2 splits, the problem size is 4.
if there are 3 splits the problem size is 8
if N increases (the number of splits) then the runtime increases not as much
What is the equation for binary search runtime complexity?
logN
logarithm to the base of 2 N
what kinds of sorting algorithms are there? (4)
binary search
selection sort
bubble sort
and Quicksort.
selection sort and bubble sort are examples of what type of algorithm?
sort algorithm