PGT 3033 DATA STRUCTURES NUROL HUSNA CHE ROSE

  • Slides: 25
Download presentation
PGT 303/3 DATA STRUCTURES NUROL HUSNA CHE ROSE ELECTRONIC ENGINEERING TECHNOLOGY DEPARTMENT FACULTY OF

PGT 303/3 DATA STRUCTURES NUROL HUSNA CHE ROSE ELECTRONIC ENGINEERING TECHNOLOGY DEPARTMENT FACULTY OF ENGINEERING TECHNOLOGY Email: husnarose@unimap. edu. my Phone : 013 505 9294 ( Available from Monday to Friday from 9 a. m till 5. 30 p. m ) Kindly, no call or whats app after working hours ya . Thank you

ANALYSIS OF ALGORITHMS (Chapter 2)

ANALYSIS OF ALGORITHMS (Chapter 2)

OUTLINE § Efficiency of algorithms § • Apriori analysis § • Asymptotic notations §

OUTLINE § Efficiency of algorithms § • Apriori analysis § • Asymptotic notations § • Time complexity of an algorithm using O notation § • Polynomial vs Exponential algorithms § • Average, best and worst case complexities § • Analyzing recursive programs

EFFICIENCY OF ALGORITHMS PROBLEM SOLVING VS GOOD ALGORITHM VS APPROPRIATE USE OF DATA STRUCTURE

EFFICIENCY OF ALGORITHMS PROBLEM SOLVING VS GOOD ALGORITHM VS APPROPRIATE USE OF DATA STRUCTURE • The performance of algorithms can be measured on the scales of time and space FASTEST MIN POSSIBLE TIME • The time complexity of an algorithm or a program is a function of the running time of the algorithm or program. • The space complexity of an algorithm or a program is a function of the space needed by the algorithm or program to run to completion. CONSUME LIMITED MEORY SPACE

EFFICIENCY OF ALGORITHMS The time complexity can be computed either empirical Depends on the

EFFICIENCY OF ALGORITHMS The time complexity can be computed either empirical Depends on the observation and experiments • • theoretical The disadvantages of posteriori testing is that it is dependent on various other factor such as the machine, the programming language and even the skills of the programmers. The empirical or posteriori (from the later ) testing approach calls for implementing the complete algorithms and executing them on a computer for various instances of the problem. The theoretical or apriori (from the earlier) approach calls for mathematically determining the resources such as time and space needed by the algorithm, as a function of a parameter related to the instances of the problem considered. The advantage of apriori analysis is that it is entirely machine , language and program independent

APRIORI ANALYSIS Apriori estimation is interested in the following for the computation of effeciency:

APRIORI ANALYSIS Apriori estimation is interested in the following for the computation of effeciency: • the number of times the statement (freq count) is executed in the program, known as the frequency count of the statement, and • the time taken for a single execution of the statement. To consider the second factor, would render the estimation machine : machine instruction set, the machine configuration and so on Hence, apriori analysis only consider the first factor which is the total frequency count

APRIORI ANALYSIS • Program segment A Program statements Frequency count …………… X=X+2; 1 ……………….

APRIORI ANALYSIS • Program segment A Program statements Frequency count …………… X=X+2; 1 ………………. . Total frequency count 1

APRIORI ANALYSIS Program segment B Programs statements Frequency count ………………. For k =1 to

APRIORI ANALYSIS Program segment B Programs statements Frequency count ………………. For k =1 to n do (n+1) x=x+2; n end n …………………. Total frequency count 3 n + 1

APRIORI ANALYSIS Program segment C Big Oh Notation? Programs statements Frequency count ……………. .

APRIORI ANALYSIS Program segment C Big Oh Notation? Programs statements Frequency count ……………. . for j = 1 to n do (n+1) For k =1 to n do n(n+1)= n^2+n X = x + 2; n ^2 end ………………… Total frequency count 3 n ^2 + 3 n + 1

ASYMPTOTIC NOTATIONS Time and space complexity of a program

ASYMPTOTIC NOTATIONS Time and space complexity of a program

ASYMPTOTIC NOTATIONS

ASYMPTOTIC NOTATIONS

TIME COMPLEXITY OF AN ALGORITHM USING O NOTATION

TIME COMPLEXITY OF AN ALGORITHM USING O NOTATION

TIME COMPLEXITY OF AN ALGORITHM USING O NOTATION

TIME COMPLEXITY OF AN ALGORITHM USING O NOTATION

POLYNOMIAL VS EXPONENTIAL ALGORITHMS Consider n is the input size n vs n^2 vs

POLYNOMIAL VS EXPONENTIAL ALGORITHMS Consider n is the input size n vs n^2 vs n^3

POLYNOMIAL VS EXPONENTIAL ALGORITHMS

POLYNOMIAL VS EXPONENTIAL ALGORITHMS

AVERAGE , BEST AND WORST CASE COMPLEXITIES The larger the input size of the

AVERAGE , BEST AND WORST CASE COMPLEXITIES The larger the input size of the problem , the larger its running time But there are problem whose time complexity is dependent not just on the size on the input but the NATURE of the input as well

AVERAGE , BEST AND WORST CASE COMPLEXITIES ACTIVITY : WELCOME ABOARD 3 VOLUNTEERS

AVERAGE , BEST AND WORST CASE COMPLEXITIES ACTIVITY : WELCOME ABOARD 3 VOLUNTEERS

ANALYZING RECURSIVE PROGRAMS If P is a procedure containing a call statement to it

ANALYZING RECURSIVE PROGRAMS If P is a procedure containing a call statement to it self ( dire recursion) or to another procedure that result in a call to itsel indirect recursion), then the procedure is said to be a recursiv procedure In order to prevent infinite loop, it is essential that the recursive procedure have these two criteria 1) There must be base criteria or simply base case (s) , where the procedure does not call itself either directly or indirectly. 2)Ach time the procedure call itself directly or indirectly, it must closer to the base criteria.

ANALYZING RECURSIVE PROGRAMS

ANALYZING RECURSIVE PROGRAMS

ANALYZING RECURSIVE FUNCTIONS

ANALYZING RECURSIVE FUNCTIONS

ANALYZING RECURSIVE PROGRAMS

ANALYZING RECURSIVE PROGRAMS

Application of the recursive function THE TOWER OF HANOI PUZZLE 6 disk-stack resembles like

Application of the recursive function THE TOWER OF HANOI PUZZLE 6 disk-stack resembles like tower, with the largest at the bottom and the smallest at the top Source Intermediate Destination The objective is to transfer the entire tower of disks in Peg S to Peg D, maintaining the same order of the disk. Only one disk can be moved at one time and never can a larger disk be placed on the smaller disk during the transfer.

THE TOWER OF HANOI PUZZLE

THE TOWER OF HANOI PUZZLE

THE TOWER OF HANOI PUZZLE 2^n -1= moves

THE TOWER OF HANOI PUZZLE 2^n -1= moves

THANK YOU

THANK YOU