{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture 2 - Efficiency Analysis of Algorithms

# Lecture 2 - Efficiency Analysis of Algorithms - Efficiency...

This preview shows pages 1–7. Sign up to view the full content.

Efficiency Analysis of Algorithms Dr. Khaled Bashir Shaban

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
What is Analysis of Algorithms ? Algorithms devised to solve the same problem often differ dramatically in their efficiency . How do we measure the “efficiency” of an algorithm? Time complexity : How long does it take the algorithm to run. Space complexity : How much storage does the algorithm require. Algorithm analysis should be independent of: The computer on which the algorithm is run. The programming language used in implementing the algorithm. Algorithm analysis depends on: Size of the input called input size Number of times some basic operation is performed
Input Size For many algorithms it is easy to find a simple measure of the input size (use parameters): Sorting, searching, adding members of an array: Number of items in the array. n x n Matrix multiplication: N , Number of rows and columns. Graphs: Number ( i ) of nodes (vertices) and number ( j ) of edges For some other algorithms, parameters are not a good measure of the input size. Example : Fibonacci sequence, parameter n represents an input value not the size. We can use the numbers of symbols used to encode n as a measure of the input size. 13 = ( 1101 ) 2 In this lecture, we will usually consider simple measures of the 4 bits

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Basic Operation There are no rules for choosing the basic operation: Choose based on judgment and experience. Basic operation is an instruction (group of instructions) such that the total work done by the algorithm is roughly proportional to the number of times this instruction (group of instructions) is executed. Operations that should not be considered as basic operations: Increment of loop indices . Control of loop index Setting of pointers. Initialization statements (Overhead instructions). Operations that could be considered as basic operation: One pass through a loop Comparison instruction Control structure instructions
Time Complexity Analysis Algorithms devised to solve the same problem often differ dramatically in their efficiency . How do we measure the “efficiency” of an algorithm ? focus is on time: How long does it take the algorithm to run. That is we focus on Time Complexity Analysis of algorithms. We consider different types of time complexity analysis: Every-case time complexity analysis T(n): Basic operation is always done the same number of times for every instance of size n. Worst-case time complexity analysis W(n) : Maximum number of times the basic operation is ever done for an input of size n. Average-case time complexity analysis A(n) : Average number of times the basic operation is done for an input of size n. Best Case Time Complexity Analysis B(n) : Minimum number of times the basic operation is done for an input of size n.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Every Case Time Complexity -I- Add Array Members number sum ( int n, const number S[ ]) { index i; number result; result = 0; for (i= 1; i <= n; i++) result = result + S[i]; return result; } Basic Operation Number of times this basic operation is executed is the same regardless of the values in the array
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 33

Lecture 2 - Efficiency Analysis of Algorithms - Efficiency...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online