Professional Documents
Culture Documents
BIG O Notation
BIG O Notation
1 Constant
Logarithm
log(n)
ic
N Linear
nlog( Log
n) Linear
n^2 Quadratic
n^3 Cubic
Exponenti
2^n
al
BIG O constant
def func_constant(values):
'''
Prints first item in a list of values.
'''
print values[0]
func_constant([1,2,3])
Output- 1
O(n) Linear
def func_lin(lst):
'''
Takes in list and prints out all values
'''
for val in lst:
print val
func_lin([1,2,3])
O\P : 1,2,3
Basics
What is func?
You can define functions to provide the required functionality. Here are simple rules
to define a function in Python.
Function blocks begin with the keyword def followed by the function name
and parentheses ( ( ) ).
Any input parameters or arguments should be placed within these
parentheses. You can also define parameters inside these parentheses.
The first statement of a function can be an optional statement - the
documentation string of the function or docstring.
The code block within every function starts with a colon (:) and is indented.
The statement return [expression] exits a function, optionally passing back an
expression to the caller. A return statement with no arguments is the same
as return None.
Return 2*x ---- here we are giving x value which is 2*x(whatever number)
A = function2(2)
Print(a)
O/P = 6
You can put multiple arguments/output for a function,
Ex : def function(x , y):
Return x+y
So with the arguments in the function, we can make any rule:
Ex : x+y, x-y , x*y , x/y.
What is class?
What is array? list?
What is argument?
What is return?
What is def?
What is Init?
What is self?
What is object?
What is tupple?
What is dictionary?