Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Unit-I

1. Define algorithm.

o The sequence of steps to be performed in order to solve a problem.


o Algorithm is a step by step procedure for solving a problem

Program=algorithm +data

2. Define Pseudo code

It is another way to describe the algorithm. Pseudo means false or imitation and code is
the programming language. Pseudo code consists of short, readable and formally styled English
languages used for explain an algorithm.
3. Define flowchart.

It is a graphical or symbolic representation of an algorithm. The purpose of flowchart is


making the logic of the program clear in a visual representation.

4.Notation Of Algorithm

 Pseudo code
 Flowchart
 Programming Language

5. Characteristics of algorithm:

 Uniqueness
 Finiteness
 Input
 Output
 generality

6. Algorithmic Problem Solving Steps:

 Understanding the Problem


 Determining the capabilities of computational device
 Exact/approximate solution
 Select the appropriate data structure
 Algorithm design techniques
 Methods for specifying an algorithm
 Proving the correctness
 Analysis the performance of an algorithm

7. Properties of Algorithms

1
 Should be written in simple English
 Each and every instruction should be precise and unambiguous.
 Instructions in an algorithm should not be repeated infinitely.
 Algorithm should conclude after a finite number of steps.
 Should have an end point.Derived results should be obtained only after the algorithm
terminates.

8. Advantages of flowchart:

 Communication
 Effective analysis
 Proper documentation
 Efficient Coding
 Proper Debugging
 Efficient Program Maintenance

9. Disadvantages of flowchart:

 Complex logic
 Alterations and Modifications
 Reproduction
 Cost

10. Rules for drawing a flowchart:

 The flowchart should be clear, neat and easy to follow.


 The flowchart must have a logical start and finish.
 Only one flow line should come out from a process symbol.
 Only one flow line is used with a terminal symbol.
 Only one flow line should enter a decision symbol. However, two or three flow lines may
leave the decision symbol.

11. Guidelines for writing pseudo code:


 Write one statement per line
 Capitalize initial keyword
 Indent to hierarchy
 End multiline structure
 Keep statements language independent

12. Common keywords used in pseudocode:

 BEGIN,END: Begin is the first statement and end is the last statement.
 INPUT, GET, READ: The keyword is used to inputting data.
 COMPUTE, CALCULATE: used for calculation of the result of the given expression.
2
 ADD, SUBTRACT, INITIALIZE used for addition, subtraction and initialization.
 OUTPUT, PRINT, DISPLAY: It is used to display the output of the program.
 IF, ELSE, ENDIF: used to make decision.
 WHILE, ENDWHILE: used for iterative statements.
 FOR, ENDFOR: Another iterative incremented/decremented tested automatically

13. Advantages of Pseudo code:


 Pseudo is independent of any language; it can be used by most programmers.
 It is easy to translate pseudo code into a programming language.
 It can be easily modified as compared to flowchart.
 Converting a pseudo code to programming language is very easy as compared with
converting a flowchart to programming language.

14. Disadvantages of Pseudo code :


 It does not provide visual representation of the program’s logic.
 There are no accepted standards for writing pseudo codes.
 It cannot be compiled nor executed.
 For a beginner, It is more difficult to follow the logic or write pseudo code as compared
to flowchart.
15. Categories of Programming language:
1. Interpreted programming languages
2. Functional programming languages
3. Compiled programming languages
4. Procedural programming languages
5. Scripting programming language
6. Markup programming language
7. Concurrent programming language
8. Object oriented programming language

16. Recursion:
 A function that calls itself is known as recursion.
 Recursion is a process by which a function calls itself repeatedly until some specified
condition has been satisfied.

17. Iteration or repetition:

It involves executing one or more steps for a number of times and it can be implemented using
while and for loop. These loops execute one or more steps until some condition is true.

18. Write the algorithm, pseudo code and flowchart for the following :

 Addition of two numbers


 Subtraction of two numbers
3
 Multiplication of two numbers
 Division of two numbers
 Check whether the given year is leap year or not.
 Check whether the given number is positive or not.
 Greatest of two numbers
 Calculate simple interest
 Find the area of circle
 Find the circumference of the circle
 Find the area of triangle
 Convert the given Celsius to Fahrenheit
 Convert the Fahrenheit value to Celsius

Greatest among three numbers:

c=int(input(“enter third number:”))


a=int(input(“enter first number:”))
if((a>b)&&(a>c)):
b=int(input(“enter second number:”))
print(“The first number is bigger”)
elif(b>c):
print(“The second number is bigger”)
else:
print(“The third number is bigger”)
Output:
Enter first number:10
Enter second number:20
Enter third number:30
The third number is bigger
Part-B

1. Building blocks of an algorithm:

Building block common name

Instruction action/sequence
State/selection decision
Control flow/iteration repetition/loop
Functions
Instruction/ Sequence:

Sequence is the specific order in which the instructions are performed in an algorithm.

Step 1

4
Step 2
Step n

State/Selection:

Selection is a decision or question . state is the result of selection either true or false.

condition
false true
Action y Action x

Iteration: Repeat a set of instructions.(refer diagram in note)

 Count controlled iteration


 Condition controlled iteration
Functions:
 Function is a sub program which consists of block of code that performs a particular task.
 For complex problems, splitting a larger problem into smaller ones.
Advantages of functions:
 Reduction in line of code
 code reuse
 Better readability
 Information hiding
 Easy to debug and test
 Improved maintainability

2. Simple Strategies for developing an algorithm:


 Iteration
 Recursion
Iteration:
 It involves executing one or more steps for a number of times and it can be implemented
using while and for loop. These loops execute one or more steps until some condition is
true.

Recursion:

A function that calls itself is known as recursion. Recursion is a process by which a


function calls itself repeatedly until some specified condition has been satisfied.

Basis for comparison Recursion Iteration


Applied Recursion is always applied for It is applied using loops
function
Speed Slow in execution Faster
Format Only termination condition is It includes initialization, condition
5
specified and execution of statement within
loop
Example def factorial(n): n=int(input("Enter number:"))
Factorial if n == 0: fact=1
return 1 while(n>0):
else: fact=fact*n
return n * factorial(n-1) n=n-1
n=int(input("Input a number: ")) print("Factorial of the number is: ")
print(factorial(n)) print(fact)

3.Algorithmic Problem Solving:


 Understanding the Problem: the problem should be clearly and completely understood.
 Determining the capabilities of computational device :the capabilities of the
computation devices should be known .ex: speed, memory
 Exact/approximate solution: Next develop the algorithm. The algorithm should give
correct output for the proper inputs.
 Select the appropriate data structure: the data structure should be proper in order for
storing and organizing the data.
List: fast access of data
Dictionary: collection of key-value pairs
Tuple: immutable data structure
 Algorithm design techniques: new algorithms should be developed for the same
problem. Example dynamic programming.
 Methods for specifying an algorithm: after the algorithm is written, it is specified either
by pseudo code or flowchart.
 Proving the correctness: once the algorithm is written it is check for the valid inputs
which is called algorithm validation.
 Analysis the performance of an algorithm: while executing the algorithm time
complexity and space complexity are compared with the different algorithms for the
same problem

6
4. Tower of Hanoi: (refer page number:19,20,21)

Rules:

 Only one disk can be moved among the towers at any given time
 Only top disk can be moved
 No Larger disk can sit over smaller disk
Draw the diagram one by one
Write the algorithm(refer pg no:20) algorithm 1.4
Draw flowchart(refer pg no:21) flowchart1.4

5. Define flowchart? Explain the rules with its advantages and disadvantages.
6. Write the algorithm and pseudo code for finding the minimum in a list.
7. Write the algorithm and pseudo code for inserting a card into a list of sorted cards.
8. Write the algorithm and pseudo code for find the random number in a given range.

You might also like