0% found this document useful (0 votes)
95 views7 pages

Algorithms Vca II Year

This document discusses algorithms and their analysis. It defines an algorithm as a well-defined set of steps to solve a problem from input to output. Example algorithms are provided to find the area of a rectangle, check voting eligibility, sort values, find average marks, and find roots of a quadratic equation. Top-down design is introduced as a technique to successively refine algorithms into subproblems until simple program statements. Key aspects of analyzing algorithms like correctness, efficiency in terms of time and memory usage, and fundamental notations like Big O notation are covered.

Uploaded by

Vandana Dulani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
95 views7 pages

Algorithms Vca II Year

This document discusses algorithms and their analysis. It defines an algorithm as a well-defined set of steps to solve a problem from input to output. Example algorithms are provided to find the area of a rectangle, check voting eligibility, sort values, find average marks, and find roots of a quadratic equation. Top-down design is introduced as a technique to successively refine algorithms into subproblems until simple program statements. Key aspects of analyzing algorithms like correctness, efficiency in terms of time and memory usage, and fundamental notations like Big O notation are covered.

Uploaded by

Vandana Dulani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Algorithms

An algorithm is any well defined set of instructions that takes some value, or set of values as Input, and produces
some value, or set of values as output. An algorithm is thus a sequence of computational steps that transform the
input into the output.
We can also say that an algorithm is a mechanism for solving a given problem. The statement of the problem
specifies the desired input/output relationship.
Example
Write an algorithm to find area of a rectangle.
Step 1: Start
Step 2: Take length and breadth and store them as L and B?
Step 3: Multiply by L and B and store it in area
Step 4: Print area
Step 5: Stop
Write an algorithm to check whether he is eligible to vote? (More than or equal to 18 years old).
Step 1: Start
Step 2: Take age and store it in age
Step 3: Check age value, if age >= 18 then go to step 4 else step 5
Step 4: Print Eligible to vote and go to step 6
Step 5: Print Not eligible to vote
Step 6: Stop

Write an algorithm to arrange values in ascending order


Step1: Start
Step 2: Take input of 10 values and store in A
Step 3: i=0
Step4: Check I, if I <10 then goto step 5 else step 13
Step 5: j=i+1
Step6: Check j, if j<10 then goto step 7 else step 11
Step 7: Check A[i] and A[j], if A[i]>A[j] then goto step 8 else step 9
Step 8: Interchange A[i] and A[j]
Step 9: j=j+1
Step 10: goto Step 6
Step 11: i=i+1
Step 12: goto Step 4
Step 13: print A
Step 14: Stop
Write an algorithm to find average marks of 10 students
Step 1: Start
Step 2: i=1
Step 3: s=0
Step 4: Check I, if I<=10 then goto step 5 else goto step 9
Step 5: input marks and store in m
Step 6: s=s+m
Step 7: i=i+1
Step 8: goto step 4
Step 9: s=s/10
Step10: Print The average is ,s
Step 11: Stop
Algorithm to find roots of quadratic equation
Step 1: Start
Step 2: Input three values and store in a,b,c
Step 3: r=b*b+4*a*c
Step 4: print r
Step 5: Stop

TOP DOWN DESIGN


The top down design is a technique for stepwise refinement of algorithm design. In this technique, the whole concentration
is on the major problem.
The top down design approach represents a successive refinement of functions and the process of refinement is continued
until the lowest level module can be designed without further analysis.
In this design approach, we take the general statements that we have about the solution, one at a time and break them
down into a set of more precisely defined sub-problems. These sub-problems should more accurately describe how the
final goal is to be reached. It is necessary that the way, in which the sub-problems need to interact with each other, be
precisely defined. Only in this way it is possible to preserve the overall structure of the solution to the problem. The process
of repeatedly breaking down a problem into sub-problems and then each sub-problem into still smaller sub-problems must
continue until we eventually end up with sub-problems, which can be implemented as program statements.
The top down design structure is viewed as tree structure. The module is divided into sub-modules and further submodules.
Characteristics

The term algorithm is believed to derive from the name of a 9th century Arabian mathematician Al-Khowarizmi.
A computer program is simply an implementation of an algorithm on a computer.
Efficiency
The efficiency refers to the ability of an algorithm to solve a given problem keeping in mind the different
constraints. The efficiency depends on the resources that the algorithm requires.
Computational time (CPU consumption)
Memory space (RAM consumption)
Communication bandwidth consumption
The efficiency depends on:
o Memory
o Time
o Number of steps
o Number of particular operations
Number of disk operations
Number of network packets
Example:
Sequential search in a list of size n
Worst-case: n comparisons
Best-case: 1 comparison
Average-case: n/2 comparisons
The algorithm runs in linear time - Linear number of operations
Analysis
Analyzing an algorithm has come to mean predicting the resources that the algorithm requires. Resources such as
memory, communication bandwidth, or computer hardware are of primary concern, but most often it is

computational time that we want to measure. By analyzing several candidate algorithms, a most efficient one can
be easily identified.
The following are the criteria which are used for analyzing algorithms:1.

Correctness:
Before determining an algorithm is correct, we should know what CORRECT means.
Therefore, we need a specific condition, the input on which it is expected to work on (pre-conditions) and what
result it will produce (Post-conditions ). If the pre-conditions are satisfied , the post-conditions will be true.
2.

Amount Of Work Done:


To measure the amount of work done we can use execution time of the algorithm, but it is not a
suitable way to measure because it changes with the computer used.

Fundamental Notations

Notation
This notation bounds a function with constant factor. We say:
F(n) = (g(n))
If there exists positive constants n0, c1and c2 such that the value of f(n) always lies between C1g(n) and
C2g(n).

1.

O Notations

O notation is also called as Upper Bound Notation. This notation gives an


upper bound for a function within a constant factor. We write f(n) = O(g(n)) , if there are positive constants and n
and c such that the value of f(n) always lie below C(g(n)).

2.

Notation

This notation gives a lower bound for a function within a constant factor, we write f(n)=(g(n)) if
there are positive constants such that f(n) always lie above or on g(n).
Note: n here refers to the no. of inputs.

FlowChart

Example
Draw a flowchart to find the simple interest. (Sequence)

Draw a flowchart to find bigger number among two numbers (selective)

Draw a flow chart to find factorial of any number.

You might also like