Analysis of Algorithm Part one analysis.ppt

RAJESHS195 17 views 13 slides Aug 20, 2024
Slide 1
Slide 1 of 13
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13

About This Presentation

basic


Slide Content

Programming Fundamentals --> Ch1.
Problem solving
1
Fundamentals of Algorithms
Problem Solving

Fundamentals of Algorithmic Problem Solving

Programming Fundamentals --> Ch1.
Problem solving
3
Problem Solving
•Algorithm
Step-by-step problem-solving process
Solution achieved in finite amount of time
Problem Solution by computer

Programming Fundamentals --> Ch1.
Problem solving
4
Problem Solving Process
•Phase 1 - Analyze the problem
Outline the problem and its requirements
Design (algorithm) to solve the problem ( Flow chart, pseudo code)
Algorithm tracing
•Phase 2 - Implement the algorithm
Implement the algorithm in code (in Programming Language 
Program)
Verify that the algorithm works
•Phase 3 - Maintenance
Use and modify the program if the requirements changes

Choosing between Exact and Approximate Problem Solving
•The next principal decision is to choose between
solving the problem exactly (exact algorithm) or
solving the problem approximately (approximation
algorithm).
Exact algorithm
Eg. extracting square roots, solving nonlinear
equations, and evaluating definite integrals.
Approximation algorithm
Eg. Vertex Cover, Traveling Salesman Problem

Programming Fundamentals --> Ch1.
Problem solving
6
Analyze the Problem (1)
Design Algorithm
•Pseudocode - is a mixture of a natural language and
programming language constructs. Pseudo code is usually more
precise than natural language.
•Flow chart - a method of expressing an algorithm by a
collection of connected geometric shapes containing
descriptions of the algorithm’s steps

Programming Fundamentals --> Ch1.
Problem solving
7
Flow Chart Symbols
Start and End
Input / output
Selection
Calculation
Data
Flow
•A Flowchart is
An algorithm graphical representation.
Written as a combination of the following graphical
notations:

Programming Fundamentals --> Ch1.
Problem solving
8
•Pseudo-code:
<Algorithm name>
The comment lines “//”
Begin
<data definition>
<actions>
End

Programming Fundamentals --> Ch1.
Problem solving
9
Analyze the Problem (1)
Algorithm Tracing
Draw flowchart
Find all possible paths
Check each path with appropriate input data
Observed Outputs not conform to the expected ones  error in the
algorithm.

Proving an Algorithm’s Correctness/verification
•Once an algorithm has been specified, you have to prove its
correctness. i.e. you have to prove that the algorithm yields a
required result for every legitimate input in a finite amount of
time.
Analyzing an Algorithm
two kinds of analyzing the algorithm efficiency:
• time efficiency- indicating how fast the algorithm runs
• space efficiency-indicating how much extra memory it uses.
•Range of inputs-These factors are not satisfactory then redesign
the algorithm.

Programming Fundamentals --> Ch1.
Problem solving
11
 Computer Stage: after completing the program, the
computer must do the following:
1.Compilation:
2.Execution: when the program become don’t has errors, the
computer execute it to produce the output

Programming Fundamentals --> Ch1.
Problem solving
12
Implement the algorithm
• Errors are of three types:
. syntax errors
. run-time errors
. logic errors
• Syntax errors: detected by the C compiler
. source code does not conform to one or more of C’s grammar
rules
. examples of syntax errors: undeclared variable, …
• Often one mistake leads to multiple error messages – can
be confusing

Programming Fundamentals --> Ch1.
Problem solving
13
Implement the algorithm
• Run-time errors. detected and displayed by computer during
execution.
-Occur when program directs computer to perform illegal
operation.
- will stop program execution and display message
• Logic errors.
- caused by faulty algorithm
-sign of error: incorrect program output
-cure: thorough testing and comparison with expected results
A logic error is also referred to as a bug, so finding logic errors is
called debugging.
Tags