COMP 3.1.2

Ace your homework & exams now with Quizwiz!

Example of a CUBIC time complexity

-

Exponential time algorithm

an algorithm whose execution time grows exponentially with input size

4 ideas about Algorithms

1) Each step in any algorithm must be unambiguous 2) The range of inputs for which an algorithm works has to be specified carefully 3) Several algorithms for solving the same problem may exist 4) Algorithms for the same problem can be based on very different ideas and can solve the problem with dramatically different speeds.

How much longer will it take to run C(n) = 2n if the input size n is doubled?

2^n times as long

Linear time algorithm

A polynomial time algorithm that executes in O(n) time. A programmer should aim for this.

Why are algorithms studies?

Algorithms are considered to be procedural solutions to problems and problem solving is a human activity. Designing algorithms is a problem solving activity that can be useful regardless of whether a computer is involved. Computer programs would not exist without algorithms. Therefore, a study of algorithms is considered to be a cornerstone of computer science. There may be more than one algorithm for solving a particular problem and algorithms for solving a particular problem may do so with dramatically different speeds and also with different memory requirements.

What is an Algorithm?

An Algorithm is a sequence of unambiguous instructions for solving a problem, i.e for obtaining a required output for any legitimate input in a finite amount of time. It can be represented a a Turing Machine program.

O(g)

Big O of g, represents the class of functions that grow no faster than g

Example of a LOGARITHMIC time complexity.

Binary Search - list split in half, one half rejected. Does not grow as fast as linear time.

Example of a QUADRATIC time complexity

Bubble Sort - Two items looked at together and swapped or not. Each pass features n-1 swaps. Total of n- 1 = quadratic

What is Average-case complexity?

Calculated by averaging the times for every possible input.

What is Worst-case complexity?

Complexity requires the longest time or greatest workload. Eg searching for the value 90, in which every item in a list has to be examined.

What is Best-case complexity?

Complexity requires the shortest time or the smallest workload. Eg searching for the value 25 in a list where only one comparison is required.

What is Computational Complexity of an algorithm?

Computational complexity of an algorithm measures how economical the algorithm is with time and space.

How do we estimate the running time of an algorithm?

Compute the number of times the basic operation is executed on inputs of size n. The basic operation is the operation in the algorithm contributing the most to the total running time.

What happens if the input size of an algorithm is doubled?

Doubling the input size of the input will quadruple the execution time.

How much longer will it take to run C(n) = 1/4n^3 if the input size n is doubled?

Eight times as long

Order of complexity

FASTEST 1) f = O(n^0) CONSTANT TIME 2) f = O(log n) LOGARITHMIC TIME 3) f = O(n) LINEAR TIME 4) f = O(n log n) LINEARITHMIC TIME 5) f = O(n^2) QUADRATIC TIME 6) f = O(n^3) CUBIC TIME 7) f = O (2^n) EXPONENTIAL TIME 8) f = O(n!) FACTORIAL TIME SLOWEST

Example of an EXPONENTIAL time complexity

Fibonacci algorithm. Recursive. Has roughly this level of time complexity

Exponential growth

Growth that has the form k^n EG 2^n where k = 2 and n = 1,2,3

Polynomial growth

Growth that has the form n^k where k = 3 and n = 1,2,3,4

Example of a CONSTANT time complexity.

Is a number odd or even ?

Example of a LINEAR time complexity.

Linear Search - Each item checked. Time complexity grows with list size.

Example of a LINEARITHMIC time complexity

Quick Sort - Splits a list and sorts it recursively. Best-case scenario = linearithmic. (GRAPH IS LIKE LNEAR WITH A CURVE AT START)

What is Space Complexity of an Algorithm?

Space Complexity of an algorithm indicates how much memory an algorithm needs.

Polynomial time algorithm

an algorithm whose execution size grows as a polynomial of input size.

Formula for the Order of Growth

T(n) = bopC(n) bop = execution time of an algorithm's basic operation on a particular computer C(n) number of times the operation needs to be executed for input n for the algorithm T(n) = Estimated running time of a program implementing tihs algorithm on this computer. Estimated time for implementation of this algorithm on this computer = Execution time of basic operation on a particular computer X the number of times the operation needs to be executed for input n for the algorithm.

Asymptotic behaviour of f

The behavior of the function f(n) for very large values of n

What is Basic Operation?

The operation contributing the most to the total running time.

What is the Order of complexity of a problem?

The order of complexity of a problem is its Big O Complexity. Taken to be the growth rate of the most efficient algorithm which solves the problem. This complexity can be expressed by stating its order of growth in big O notation.

What is the Order of Growth?

The order of growth assesses by what factor execution time increases when the size of the input is increased.

What is the complexity of a problem?

The worst-case complexity of the mot efficient algorithm which solves the problem.

What is Time Complexity of an Algorithm?

Time complexity of an algorithm indicates how fast an algorithm runs.

Example of a FACTORIAL time complextiy

Travelling Salesman Problem. Optimal tour between finite number of n nodes. As n grows, problem becomes increasingly more difficult.

How much longer will it take to run C(n) = 1/2n if the input size n is doubled?

Twice as long

Why are estimated running times of algorithms not measured in seconds or milliseconds?

Using a standard unit of time measurement, such as a second, to estimate the running time of a program implementing the algorithm, would not be sensible. The estimate would be dependent on the speed of the computer, the quality of the program implementing the algorithm and the compiler used in generating the machine code.

Polynomial

x ^ y where x = 1,2,3,4,5

Exponential

x ^ y where y = 1,2,3,4,5


Related study sets

Transformations of Quadratic Functions Instruction

View Set

Lesson 4: Basic Life Support for Children and Infants

View Set

n-clex level questions test 3 RNUR 1070

View Set

Competency 1 - Chapter 2 - Input, Processing, and Output

View Set

CH20-21 Assignment #24-30, 28-34

View Set

Chapter 8: Appendicular Skeleton

View Set

5.2.2 Quiz: Public Policy and Your Safety

View Set

GEOM A, U7L3: Proving That a Quadrilateral Is a Parallelogram

View Set

anatomy - heart and blood vessels

View Set

mastering A&P ch. 23 group 1 modules 23.1-23.5 DSM

View Set

KINE 307 Chapter 14: Sociocultural Influences on Motor Development

View Set