Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

BIG O Notation

Runtimes of Common Big-O Functions


Here is a table of common Big-O functions:
Big-
Name
O

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.

First create a function and then define that function.


So here str is the type of func, for which we are putting in next line in quotes.
def printme( str ):
"This prints a passed string into this function"
print str
return
def function1 ():
print(“abcd”)
print(“this is outside function”)
O/P: this is outside func because we are not calling the func.
So if you have to call function1. We have to type
function1()
O/P: this is outside function
Next one
Def function2(x): ----------- X is the argument or input of function , function is
function2

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 calling a function?


Algorithm
Go through entire list
Ex: If there are list of ways to reach destination.
Linked list and array. (boxes where list is made is array and linked list is ech box
is linked with a string)

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?

You might also like