Developing Efficient Algorithms
General requirements for a computer program
-must produce correct results -should be maintainable -should run efficiently
factors that influence the time it takes for a program to execute
-the size and content of the input data -the hardware specifications of a particular system -the nature and volume of "other programs" which may be sharing the system at the time of the test
what is the Big O performance of a nested loop (one outer and one inner loop)
O(N^2)
Ignore constant multiples: if C is constant, then O(C*f(N)) is the same as O(f(N)) and O(f(C*N)) is the same as
O(f(N))
if O(f(N)) > O(g(N)) for large values of N, then O(f(N)) + O(g(N)) can be simplified to
O(f(N))
if an algorithm performs a certain sequence of steps f(N) times for a function f, then the time complexity for that sequence is
O(f(N))
if an algorithm performs an operation which requires O(f(N)) and for every step in that operation it also performs a second operation which requires O(g(N)), then the total time complexity is
O(f(N)) * O(g(N))
if an algorithm performs one operation which requires O(f(N)) and then performs a second operation which requires O(g(n)), then the total time complexity is
O(f(N)) + (O(g(N))
an algorithm with O(2^N) is called
an exponential algorithm
constant time
an operation that will always take the same amount of time to execute (i.e. returning the first element of an array)
Why don't we use an average case analysis
because average case analysis is difficult to achieve
what does Big O notation do?
it estimates the execution time of an algorithm in relation to the input size. If the time if not related to the input size, the algorithm is said to take constant time with the notation O(1)
sequential search
searching through a data structure that isn't sorted, searching one value after another until you either find the value you are looking for or don't find it at all
true of false for 0(logN) the time required to search is only doubled if the input data is squared
true
true or false Big O notation is a "worst case" scenario notation
true
true or false the multiplicative constants in algorithm efficiency analysis don't effect growth rates
true
true or false the time required for a sequential search will grow proportionally to the size of an array
true