This preview shows pages 1–6. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Efficiency Analysis of Algorithms 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 input size. 4 bits 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: – Everycase time complexity analysis T(n): Basic operation is always done the same number of times for every instance of size n. – Worstcase time complexity analysis W(n) : Maximum number of times the basic operation is ever done for an input of size n. – Averagecase time complexity analysis A(n) : Average number of times the basic operation is done for an input of size n....
View
Full
Document
This note was uploaded on 05/14/2011 for the course CMPS 323 taught by Professor Shaban during the Spring '11 term at Qatar University.
 Spring '11
 Shaban

Click to edit the document details