Algorithm Analysis and Design
Algorithm Analysis and Design
DESIGN
(DATA STRUCTUES &
ALGORITHMS II)
COURSE CODE: CS 204
FACILITATOR: SAMUEL
INTRODUCTION ALGORITHMS
• List the data needed to solve the problem and know the end results
• Describe the various steps to process the input to get the desired output
• Finally test algorithms with different data sets.
ALGORITHM FOR ADDING TWO NUMBERS
• Step 1: Start
• Step 2: Get two numbers a&b as input
• Step 3: Add the two numbers a&b and store the in the variable c
• Step 4: Print c
• Step 5: Stop
ALGORITHM SPECIFICATION
• Comment://
• Start: BEGIN
• Stop: END
• Input: COMPUTE, CALCULATE, ADD, SUBTRACT, INITIALIZE
• Output: OUTPUT, PRINT, DISPLAY
• Selection: IF, ELSE, ENDIF
• Iteration: WHILE, ENDWHILE, FOR ENDFOR
EXAMPLE PSEUDOCODE TO ADD TWO
NUMBER
• BEGIN
• GET a,b
• ADD c= a+b
• PRINT c
• END
ALGORITHM FOR ADDITION OF TWO
NUMBERS
• Step 1: Start
• Step 2: Get two numbers a and b as input
• Step 3: Add the numbers and store the results in c
• Step 4: Print c
• Step 5: Stop
PSEUDOCODE USING FOR LOOP
TOPIC 3: PERFORMANCE
ANALYSIS
-TIME COMPLEXITY
-SPACE COMPLEXITY
PERFORMANCE ANALYSIS
• The total time taken for the execution of the program is the sum of the
compilation time and the execution time.
• Compilation time- the time taken for the compilation of the program.
• Run time or Execution time- The time taken for the execution of the
program.
• Time complexity T(P) = c + Tp
• c- Compile time
• Tp – Run time or Execution time
HOW TO CALCULATE TIME COMPLEXITY
• Step count:
• For algorithms heading---0
• For Braces---0
• For expression---1
• For any looping statements---no. of times the loop repeats.
TIME COMPLEXITY
ASYMPTOTIC NOTATIONS
• Asymptotic Notations are the expressions that are used to represent the
complexity of an algorithm.
• There are three types of analysis that can be performed on a particular
algorithm.
• Best Case: in which we analyze the algorithm for the input, for which the
algorithm takes less time or space.
ASYMPTOTIC NOTATION