Lecture 2 - Efficiency Analysis of Algorithms

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

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the 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: – 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....
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.

Page1 / 40

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

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online