Big O Notation

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Recursion

A function that calls itself is called recursive.

Constant time O(1)

No matter the size of your input, the algorithm will take the same amount of time to complete. Examples of O(1) algorithms are accessing an array item or performing basic arithmetic operations (e.g., adding two numbers).

Logarithmic time O(log(n))

While logarithmic complexity algorithms do take longer with larger inputs, run time increases slowly. they cut the problem size in half each round through so huge inputs are not a problem.

big O notation

a way of describing the run-time complexity of an algorithm - how much time is needed for an algorithm to complete its work with a given input

algorithm

defined set of instructions to solve a problem

Linear time O(n)

have run times that are directly proportional to the size (n) of the input. Given input a and input b, where b is twice as large as a, it will take a linear algorithm twice as long to process b compared to a. Some examples of linear run time algorithms are summing the elements in an array and finding the minimum or maximum value in an array.

Polynomial time O(n^k)

run time would be input size n raised to some constant power, k. So n^2 or n^3. The easiest way to understand polynomial time complexity is with nested loops. An algorithm that requires two levels of looping over an input would be O(n^2) while one requiring three levels of looping would be O(n^3). In both cases, we have polynomial time complexity.

Exponential time O(2^n)

run times that grow rapidly with increases in input size. For an input of size 2, an exponential time algorithm will take 2^2 = 4 time. With an input of size 10, the same algorithm will take 2^10=1024 time

Space complexity

the amount of physical memory that an algorithm requires to complete

run-time complexity or time complexity

the number of operations an algorithm requires to complete


Kaugnay na mga set ng pag-aaral

Interest Groups: Organizing for Influence

View Set

Management Skills Exam - Rutgers

View Set

Health and Illness II - Mobility

View Set

Genetica y evolución primer bloque

View Set