Exam Flashcards
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
what kind of runtime complexity do selection sort and bubble sort have?
N (problem size) to the power of 2.
N^2
e.g. if N=20 then the runtime will be 400.
this makes it a very slow algorithm. the graph looks very spiked. like its pointing straight up with a little bit of a slope
What is the runtime complexity of Quicksort?
Quicksort has a runtime complexity of N x Log N
it is much faster than N^2 (selection sort and bubble sort)
What is polynomial runtime complexity?
they are considered the ‘easy’ algorithms to solve.
polynomial runtime complexities are defined by if N is a main factor in the equation.
what are Log N, N, N x Log N, and N^2 all examples of?
polynomial runtime complexities
what is exponential runtime
these are considered ‘hard’ algorithms to solve.
exponential runtimes are defined if N exists only in the power of something in an equation. E.g.. 2^N
what is the nature of exponential runtime complexities?
if the problem size (N) increases by 1, the runtime doubles, triples, quadruples
(the problem size exponentially grows)
What runtime complexity is 2^N an example of?
it is an example of exponential runtime complexity
what is the traveling salesman problem (TSP) an example of?
exponential runtime complexity
What is the equation to figuring out the traveling sales man algorithm?
2^N
what is the quickest algorithm?
Log N (binary search)
What is the longest algortihm?
2^N
Traveling sales man algorithm
what is the order from quickest to slowest algorithms.
TSP, Search algorithm, sorting algorithm, linear algorithm
1) search
2) linear
3) sorting
4) tsp
what is the order from quickest to slowest formula for algorithms…
N^2 N log N 2^N N log N
1) Log N
2) N
3) N log N
4) N^2
5) 2^N
when is the only time that exponential algorithms make sense?
for crypography
what does programming mean?
creating a sequence of instructions for a computer to carry out a task
what is the difference between an algorithm and a program?
an algorithm is an abstract or idealized process.
it might ignore the details, e.g. invalid user input, hardware failure, ect..
a program is like an algorithm (they are both a sequence of detailed instructions)
but…..
a program is more detailed than an algorithm, it implements the algorithm.
Difference between algorithm and program.
an algorithm is the steps that need to be followed in order to solve a problem.
a program is an instruction set for a specific type of machine for the algorithm to function
do algorithms contain bunch of programs…
or
do programs contain a bunch of algorithms?
a program typically contains implementations of a couple of algorithms for different tasks bundled together
what don’t programs have to worry about, that algorithms do…
- insufficient memory
- limited processor speed
- invalid or malicious input
- hardware failure