Sie sind auf Seite 1von 16

AGORITHM’s

REPRESENTATION

Muzaffar Iqbal Farooqi 23-Sep-19


18
Methods of Specifying
Algorithms
• An algorithm may be expressed in a number of ways,
including:

23-Sep-19
1. Natural language
- usually lengthy and ambiguous.

Muzaffar Iqbal Farooqi


2. Flow chart
- graphical representation
- avoids most (if not all) issues of ambiguity
- difficult to modify w/o specialized tools
- largely standardized

19
Methods of Specifying
Algorithms...
3. Pseudo-code
- a mixture of natural language and programming language-like

23-Sep-19
structures
- precise and brief
- also avoids most issues of ambiguity

Muzaffar Iqbal Farooqi


- no particular agreement on syntax
4. Programming language
- tends to require expressing low-level details that are not
necessary for a high-level understanding

20
Algorithms In Natural
Language
• Easiest type of algorithms
• Written in natural language

23-Sep-19
• Also sometimes called un-structured algorithms
• These type of algorithms may be ambiguous and difficult to

Muzaffar Iqbal Farooqi


understand

21
Example 1
ALGORITHM To convert a decimal integer into binary

1. Write the decimal number

23-Sep-19
2. Divide by 2; write quotient and remainder

Muzaffar Iqbal Farooqi


3. Repeat step 2 on the quotient; keep on repeating until the
quotient becomes zero

4. Write all remainder digits in the reverse order (last remainder


first) to form the final result

22
Example 2
ALGORITHM To mark attendance of students in a class

1. Start

23-Sep-19
2. Open attendance register

Muzaffar Iqbal Farooqi


3. Call student name

4. Check if student is present , mark ‘P’ , else mark the student as ‘A’

5. Repeat steps 3 to 4 until all student names are called

6. Close attendance register

7. Stop
23
Example 3
Algorithm to find grade of a student
1. Read Total_Marks and Marks_Obtained

23-Sep-19
2. Calculate P=(Marks_Obtained/Total_Marks)/100
3. If P is less than 50 then Grade is “F”

Muzaffar Iqbal Farooqi


4. Else if P is between 50 and 60 then Grade is “E”
5. Else if P is between 61 and 70 then Grade is “D”
6. Else if P is between 71 and 80 then Grade is “C”
7. Else if P is between 81 and 90 then Grade is “B”
8. Else if P is between 91 and 100 then Grade is “A”
9. End
24
Another Example
• Another Simple Algorithm to Implement is Designing the Table
of Any Number

23-Sep-19
• Start the Algorithm
• Ask The User to Enter any number
• Perform The Table Statements on each iteration (Multiply

Muzaffar Iqbal Farooqi


number with iteration)
• Write the results of each iteration
• When your iteration count is equal to 10 , then stop the algorithm

25
Flow Chart

• A graphical representation of a process (e.g. an algorithm), in


which graphic objects are used to indicate the steps &
decisions that are taken as the process moves along from
start to finish.

23-Sep-19
• Individual steps are represented by boxes and other shapes
on the flowchart, with arrows between those shapes

Muzaffar Iqbal Farooqi


indicating the order in which the steps are taken.

26
Start or stop

Process
Input or output

23-Sep-19
Decision

Muzaffar Iqbal Farooqi


Flowchart
Flow line
Symbols
Connector

Off-page connector
27
Rules to draw a flowchart
• Every flowchart must have a start and stop symbol
• Symbols in a flowchart must be neat and clear

23-Sep-19
• The flow should be from top to bottom
• Isolated symbols cannot exist in a flowchart

Muzaffar Iqbal Farooqi


• The flow of steps must be clear and unambiguous

28
Example 1

Muzaffar Iqbal Farooqi 23-Sep-19


29
Example 2

Muzaffar Iqbal Farooqi 23-Sep-19


30
Example 3

Muzaffar Iqbal Farooqi 23-Sep-19


31
Example 4

Muzaffar Iqbal Farooqi 23-Sep-19


32
Another Example
• Flowchart to display
integer numbers

23-Sep-19
between 1 to 10

Muzaffar Iqbal Farooqi


33

Das könnte Ihnen auch gefallen