This action might not be possible to undo. Are you sure you want to continue?

Welcome to Scribd! Start your free trial and access books, documents and more.Find out more

Dr. Mohammed Gulam Ahamad

1

• Two aspects of the algorithm efficiency are: 1.Time Complexity • The subject of the analysis of algorithms consists of the study of their efficiency. • In this chapter we introduce the basic techniques for calculating time efficiency (Time complexity). The memory space it consumes. 2 . The amount of time required to execute the algorithm 2.

or. ÷) Logical operations(and. ≤. ≠. ≥) Arithmetic operation(+.while other operations are slower. >. Multiplication and division are often slower than addition and subtraction. -. <. assignments are very fast . not) How long does each of these operations take to execute? In general. ×. 3 .Dominant Operations • • • • • The following main operations are used in the algorithms Assignment(⃪) Comparison(=.

We call T(n) the time complexity function of the algorithm. • Let T(n) be a measure of the time required to execute an algorithm of problem size n. • If n is sufficiently small then the algorithm will not have a long running time.Time Complexity • The running time of an algorithm is defined to be an estimate of the number of operations performed by it given a particular number of input values. 4 .

that is. the longest running time for any input of size n.Time Complexity • How fast T(n) increases for large n? This is called the asymptotic behavior of the time complexity function. 5 . • In our time analysis we will restrict ourselves to the worst case behavior of an algorithm. basically we will be focusing on the leading term of T(n).

• We say that one algorithm is more efficient then another if its worse case running time has a lower order of growth.Example • If T(n) = 4n3 + 2n2 + n + 5 then 2 1 5 3 T(n) = n (4 + ) n n n and for large n we have T(n) ≃ 4n3. • We say that T(n) has a growth of order n3. 2 3 6 .

7 . is also executed n times.1 for j = 1 to n do 1.1 A(i.1. T(n) = n2 so that the growth is of order n2.Exercise What is the run-time complexity based on n for the following algorithm segment: 1. Hence.1 is executed n times and the outer loop 1.j) ⃪ x Solution The inner loop 1. for i = 1 to n do 1.

is executed n times. .1 p ⃪ p × i 3. • The loop 3. the time complexity of the algorithm is given by 8 T(n) = 4n + 2 so the growth is of order n. for j = 1 to n do 3. and each time it executes two assignment statements and two arithmetic operations 3. and 2.2 i ⃪ i + 1 Solution It takes two assignment statements 1.Exercise Estimate the time complexity of the following algorithm: 1. to initialize the variables i and p. i ⃪ 1 2. • Thus.2. p ⃪ 1 3.1 and 3.

Remark • In the latest algorithm. the dominant operation is the multiplication of 3. so T(n) would be the number of dominant operations to accomplish the task. we only count in this case the number of multiplications.1. Thus T(n) = n (multiplications) • In an algorithm. certain operations are usually dominant. 9 . • Because multiplication takes more computer time to execute.

What usually interests us is the order of growth. • Let g : ℕ ⟶ℕ . 10 . We say that a function f is order at most g or f “big O” of g if and only if there exists positive constant C and n0 ∈ ℕ such that |f(n)| ≤ C|g(n)|.Order of Growth-O(g) notation • In the latest two problems we found a precise expression for the time complexity of the algorithm. for n ≥ n0 We write f(n) = O(g(n)).

Example Find the minimum number of multiplications needed to calculate x13? Solution • suppose x13 is expressed as x13 = x × x ×…× x. 11 . x4 = x2 × x2. x8 = x4 × x4. 2 + 2 + 1 = 5 multiplications needed.Hence x13 = x8 × x4 × x. 12 multiplications needed • If it is expressed as x13 = x8 × x4 × x then x2 = x × x.

1)(n . A and B . find the value of n such that f(n)=g(n).Example Two algorithms.3n + 1 and g(n)=n2.3n + 1 2 n2 .Thus n2 = 3 n2 .1) = 0 n = 1/2 or n = 1 12 . Solution First. where f(n) = 3 n2 .Determine which algorithm is faster.3n + 1 = 0 (2n .have time complexities f and g respectively.

3(2) + 1 = 7 and g(2) = 22 = 4 Thus g(n) < f(n) for all n > 1.Hence g(n) is faster. so algorithm B is faster 13 . that is for n > 1. suppose n = 2.then f(2) = 3(2)2 .Example Take the larger value of n.

- Control Systems1
- Control Systems1
- Semiconductors
- Examples OfzTransform
- Donors and Acceptors in Semiconductors
- Intro Signals
- Distributed System Architeture
- Client Server 1
- Graph Theory
- Microprocessor Begning
- 8086 Chip Evalution
- Functions
- Introtocomputer.ppt
- m6-game.ppt
- m5-csp.ppt
- m4-heuristics.ppt
- m3-search.ppt
- m2-agents.ppt
- AI-ppt.ppt
- Imageenhancement.pdf
- Intro to Amplifiers.pdf
- _ch1_lecture1.pdf
- History Lecture Notes - S2004.ppt
- Hashing.ppt
- AlgorithmAnalysis.ppt

Algorithm complexity

Algorithm complexity

- 13 White Box Symbolic
- Assembly Line
- Complexity (1)
- Iñigo Quilez - fractals, computer graphics, mathematics, demoscene and more 1
- Simplicity Alip
- Complexity
- DAA
- Sierpinski Karpet
- Class Tabu Search
- Lect6 Divide Conquer Mergesort
- Path-Based Static Analysis
- Data Structure
- Dynamic Programming Lecture
- introduction to computing
- Commands
- ImpofAlgorithms_Topcoder
- L-02 Complexity Analysis.ppt
- Lec01 Stable
- Random Number Generators - A Brief Assessment of Those Available
- AOA Course Contents
- Week5 Lab Report
- Lecture 01236
- Lesson 25
- TreeMap
- Data Structure Lecture 2
- Abs Int Tutorial
- Compare K,Fcm Imp
- Problem Set 1
- Tutorial

Are you sure?

This action might not be possible to undo. Are you sure you want to continue?

We've moved you to where you read on your other device.

Get the full title to continue

Get the full title to continue listening from where you left off, or restart the preview.

scribd