Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

PSP Unit 1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 25

Problem solving is the systematic approach to define the problem and creating number of

solutions. The problem solving process starts with the problem specifications and ends with a
Correct program.

PROBLEM SOLVING TECHNIQUES


Problem solving technique is a set of techniques that helps in providing logic for solving a
problem.
Problem Solving Techniques:
Problem solving can be expressed in the form of
1.Algorithms.
2.Flowcharts.
3.Pseudo codes.
4.programs

ALGORITHM
It is defined as a sequence of instructions that describe a method for solving a problem. In
other words it is a step by step procedure for solving a problem.

Properties of Algorithms

❖▪▪ 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.

Qualities of a good algorithm


The following are the primary factors that are often used to judge the quality of the
algorithms.
Time – To execute a program, the computer system takes some amount of time. The lesser is
the time required, the better is the algorithm.
Memory – To execute a program, computer system takes some amount of memory space. The
lesser is the memory required, the better is the algorithm.
Accuracy – Multiple algorithms may provide suitable or correct solutions to a given problem,
some of these may provide more accurate results than others, and such algorithms may be
suitable.
Example
Write an algorithm to print „Good Morning”
Step 1: Start
Step 2: Print “Good Morning”
Step 3: Stop

Building blocks of algorithms (statements, state, control flow, functions)


Algorithms can be constructed from basic building blocks namely, sequence, selection and
iteration.

Statements:
Statement is a single action in a computer.
In a computer statements might include some of the following actions

⮚▪▪ input data-information given to the program

⮚▪▪ process data-perform operation on a given input

⮚▪▪ output data-processed result

State:
Transition from one process to another process under specified condition with in a time is
called state.

Control flow:
The process of executing the individual statements in a given order is called control flow.
The control can be executed in three ways
1. sequence
2. selection
3. iteration
Sequence:
All the instructions are executed one after another is called sequence execution.
Example:

Add two numbers:


Step 1: Start
Step 2: get a,b
Step 3: calculate c=a+b
Step 4: Display c
Step 5: Stop

Selection:
A selection statement causes the program control to be transferred to a specific part of the
program based upon the condition.
If the conditional test is true, one part of the program will be executed, otherwise it will
execute the other part of the program.

Example
Write an algorithm to check whether he is eligible to vote?
Step 1: Start
Step 2: Get age
Step 3: if age >= 18 print “Eligible to vote”
Step 4: else print “Not eligible to vote”
Step 6: Stop

Iteration:
In some programs, certain set of statements are executed again and again based upon
conditional test. i.e. executed more than one time. This type of execution is called looping or
iteration.

Example
Write an algorithm to print all natural numbers up to n
Step 1: Start
Step 2: get n value.
Step 3: initialize i=1
Step 4: if (i<=n) go to step 5 else go to step 7
Step 5: Print i value and increment i value by 1
Step 6: go to step 4
Step 7: Stop

Functions:

❖▪▪ Function is a sub program which consists of block of code(set of instructions) that

performs a particular task.

❖▪▪ For complex problems, the problem is been divided into smaller and simpler tasks during

algorithm design.

Benefits of Using Functions

❖▪▪ Reduction in line of code

❖▪▪ code reuse

❖▪▪ Better readability

❖▪▪ Information hiding

❖▪▪ Easy to debug and test

❖▪▪ Improved maintainability

Example:

Algorithm for addition of two numbers using function


Main function()
Step 1: Start
Step 2: Call the function add()
Step 3: Stop
sub function add()
Step 1: Function start
Step 2: Get a, b Values
Step 3: add c=a+b
Step 4: Print c
Step 5: Return
FLOW CHART
Flow chart is defined as graphical representation of the logic for problem solving.
The purpose of flowchart is making the logic of the program clear in a visual representation.

Rules for drawing a flowchart


1. The flowchart should be clear, neat and easy to follow.
2. The flowchart must have a logical start and finish.
3. Only one flow line should come out from a process symbol.
4. Only one flow line should enter a decision symbol. However, two or three flow lines may
leave the decision symbol.
5. Only one flow line is used with a terminal symbol.
6. Within standard symbols, write briefly and precisely.
7. Intersection of flow lines should be avoided.

Advantages of flowchart:
1. Communication: - Flowcharts are better way of communicating the logic of a system to all
concerned.
2. Effective analysis: - With the help of flowchart, problem can be analyzed in more effective
way.
3. Proper documentation: - Program flowcharts serve as a good program documentation,
which is needed for various purposes.
4. Efficient Coding: - The flowcharts act as a guide or blueprint during the systems analysis
and program development phase.
5. Proper Debugging: - The flowchart helps in debugging process.
6. Efficient Program Maintenance: - The maintenance of operating program becomes easy
with the help of flowchart. It helps the programmer to put efforts more efficiently on that part.

Disadvantages of flow chart:


1. Complex logic: - Sometimes, the program logic is quite complicated. In that case, flowchart
becomes complex and clumsy.
2. Alterations and Modifications: - If alterations are required the flowchart may require
re-drawing completely.
3. Reproduction: - As the flowchart symbols cannot be typed, reproduction of flowchart
becomes a problem.
4. Cost: For large application the time and cost of flowchart drawing becomes costly.
PSEUDO CODE:

❖▪▪ Pseudo code consists of short, readable and formally styled English languages used for

explain an algorithm.

❖▪▪ It does not include details like variable declaration, subroutines.

❖▪▪ It is easier to understand for the programmer or non programmer to understand the

general working of the program, because it is not based on any programming language.

❖▪▪ It gives us the sketch of the program before actual coding.

❖▪▪ It is not a machine readable

❖▪▪ Pseudo code can’t be compiled and executed.

❖▪▪ There is no standard syntax for pseudo code.

Guidelines for writing pseudo code:

❖▪▪ Write one statement per line

❖▪▪ Capitalize initial keyword

❖▪▪ Indent to hierarchy

❖▪▪ End multiline structure

❖▪▪ Keep statements language independent

Common keywords used in pseudocode


The following gives common keywords used in pseudocodes.
1. //: This keyword used to represent a comment.
2. BEGIN,END: Begin is the first statement and end is the last statement.
3. INPUT, GET, READ: The keyword is used to inputting data.
4. COMPUTE, CALCULATE: used for calculation of the result of the given expression. 5. ADD,
SUBTRACT, INITIALIZE used for addition, subtraction and initialization.
6. OUTPUT, PRINT, DISPLAY: It is used to display the output of the program.
7. IF, ELSE, ENDIF: used to make decision.
8. WHILE, ENDWHILE: used for iterative statements.
9. FOR, ENDFOR: Another iterative incremented/decremented tested automatically.

Syntax for if else:


IF (condition)THEN
statement
...
ELSE
statement
...
ENDIF
Example: Greates of two numbers
BEGIN
READ a,b
IF (a>b) THEN
DISPLAY a is greater
ELSE
DISPLAY b is greater
END IF
END

Syntax for For:


FOR( start-value to end-value) DO
statement
...
ENDFOR
Example: Print n natural numbers
BEGIN
GET n
INITIALIZE i=1
FOR (i<=n) DO
PRINT i
i=i+1
ENDFOR
END

Syntax for While:


WHILE (condition) DO
statement
...
ENDWHILE
Example: Print n natural numbers
BEGIN
GET n
INITIALIZE i=1
WHILE(i<=n) DO
PRINT i
i=i+1
ENDWHILE
END

Advantages:

❖▪▪ 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.

Disadvantages:

❖▪▪ 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.
Example:
Addition of two numbers:
BEGIN
GET a,b
ADD c=a+b
PRINT c
END

PROGRAMMING LANGUAGE
A programming language is a set of symbols and rules for instructing a computer to perform
specific tasks. The programmers have to follow all the specified rules before writing program
using programming language. The user has to communicate with the computer using language
which it can understand.

Types of programming language


1. Machine language
2. Assembly language
3. High level language

Machine language:
The computer can understand only machine language which uses 0’s and 1’s. In machine
language the different instructions are formed by taking different combinations of 0’s and 1’s.

Advantages:
Translation free:
Machine language is the only language which the computer understands. For executing any
program written in any programming language, the conversion to machine language is
necessary. The program written in machine language can be executed directly on computer. In
this case any conversion process is not required.
High speed
The machine language program is translation free. Since the conversion time is saved, the
execution of machine language program is extremely fast.
Disadvantage:

⮚▪▪ It is hard to find errors in a program written in the machine language.

⮚▪▪ Writhing program in machine language is a time consuming process.

Machine dependent: According to architecture used, the computer differs from each other. So
machine language differs from computer to computer. So a program developed for a particular
type of computer may not run on other type of computer.

Assembly language:
To overcome the issues in programming language and make the programming process easier,
an assembly language is developed which is logically equivalent to machine language but it is
easier for people to read, write and understand.

⮚▪▪ Assembly language is symbolic representation of machine language. Assembly languages

are symbolic programming language that uses symbolic notation to represent machine
language instructions. They are called low level language because they are so closely related to
the machines.

Assembler
Assembler is the program which translates assembly language instruction in to a machine
language.

⮚▪▪ Easy to understand and use.

⮚▪▪ It is easy to locate and correct errors.

Disadvantage
Machine dependent
The assembly language program which can be executed on the machine depends on the
architecture of that computer.
Hard to learn
It is machine dependent, so the programmer should have the hardware knowledge to create
applications using assembly language.
Less efficient

⮚▪▪ Execution time of assembly language program is more than machine language program.
⮚▪▪ Because assembler is needed to convert from assembly language to machine language.

High level language


High level language contains English words and symbols. The specified rules are to be
followed while writing program in high level language. The interpreter or compilers are used
for converting these programs in to machine readable form.

Translating high level language to machine language


The programs that translate high level language in to machine language are called interpreter
or compiler.

Compiler:
A compiler is a program which translates the source code written in a high level language in to
object code which is in machine language program. Compiler reads the whole program written
in high level language and translates it to machine language. If any error is found it display
error message on the screen.

Interpreter
Interpreter translates the high level language program in line by line manner. The interpreter
translates a high level language statement in a source program to a machine code and executes
it immediately before translating the next statement. When an error is found the execution of
the program is halted and error message is displayed on the screen.

Advantages
Readability
High level language is closer to natural language so they are easier to learn and understand
Machine independent
High level language program have the advantage of being portable between machines.
Easy debugging
Easy to find and correct error in high level language

Disadvantages
Less efficient
The translation process increases the execution time of the program. Programs in high level
language require more memory and take more execution time to execute.
They are divided into following categories:
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

Interpreted programming languages:


An interpreted language is a programming language for which most of its implementation
executes instructions directly, without previously compiling a program into machine language
instructions. The interpreter executes the program directly translating each statement into a
sequence of one or more subroutines already compiled into machine code.
Examples:
Pascal
Python

Functional programming language:


Functional programming language defines every computation as a mathematical evaluation.
They focus on the programming languages are bound to mathematical calculations
Examples:
Clean
Haskell

Compiled Programming language:


A compiled programming is a programming language whose implementation are typically
compilers and not interpreters.
It will produce a machine code from source code.
Examples:
C
C++
C#
JAVA
Procedural programming language:
Procedural (imperative) programming implies specifying the steps that the programs should
take to reach to an intended state.
A procedure is a group of statements that can be referred through a procedure call.
Procedures help in the reuse of code. Procedural programming makes the programs
structured and easily traceable for program flow.
Examples:
Hyper talk
MATLAB

Scripting language:
Scripting language are programming languages that control an application. Scripts can execute
independent of any other application. They are mostly embedded in the application that they
control and are used to automate frequently executed tasks like communicating with external
program.
Examples:
Apple script
VB script

Markup languages:
A markup language is an artificial language that uses annotations to text that define hoe the
text is to be displayed.
Examples:
HTML
XML

Concurrent programming language:


Concurrent programming is a computer programming technique that provides for the
execution of operation concurrently, either with in a single computer or across a number of
systems.
Examples:
Joule
Limbo

Object oriented programming language:


Object oriented programming is a programming paradigm based on the concept of objects
which may contain data in the form of procedures often known as methods.
Examples:
Lava
Moto

PSEUDO CODE:

❖▪▪ Pseudo code consists of short, readable and formally styled English languages used for

explain an algorithm.

❖▪▪ It does not include details like variable declaration, subroutines.

❖▪▪ It is easier to understand for the programmer or non programmer to understand the

general working of the program, because it is not based on any programming language.

❖▪▪ It gives us the sketch of the program before actual coding.

❖▪▪ It is not a machine readable

❖▪▪ Pseudo code can’t be compiled and executed.

❖▪▪ There is no standard syntax for pseudo code.

Guidelines for writing pseudo code:

❖▪▪ Write one statement per line

❖▪▪ Capitalize initial keyword

❖▪▪ Indent to hierarchy

❖▪▪ End multiline structure

❖▪▪ Keep statements language independent

Common keywords used in pseudocode


The following gives common keywords used in pseudocodes.
1. //: This keyword used to represent a comment.
2. BEGIN,END: Begin is the first statement and end is the last statement.
3. INPUT, GET, READ: The keyword is used to inputting data.
4. COMPUTE, CALCULATE: used for calculation of the result of the given expression. 5. ADD,
SUBTRACT, INITIALIZE used for addition, subtraction and initialization.
6. OUTPUT, PRINT, DISPLAY: It is used to display the output of the program.
7. IF, ELSE, ENDIF: used to make decision.
8. WHILE, ENDWHILE: used for iterative statements.
9. FOR, ENDFOR: Another iterative incremented/decremented tested automatically.
Syntax for if else:
IF (condition)THEN
statement
...
ELSE
statement
...
ENDIF

Example: Greates of two numbers


BEGIN
READ a,b
IF (a>b) THEN
DISPLAY a is greater
ELSE
DISPLAY b is greater
END IF
END

Syntax for For:


FOR( start-value to end-value) DO
statement
...
ENDFOR

Example: Print n natural numbers


BEGIN
GET n
INITIALIZE i=1
FOR (i<=n) DO
PRINT i
i=i+1
ENDFOR
END
Syntax for While:
WHILE (condition) DO
statement
...
ENDWHILE

Example: Print n natural numbers


BEGIN
GET n
INITIALIZE i=1
WHILE(i<=n) DO
PRINT i
i=i+1
ENDWHILE
END

Advantages:

❖▪▪ Pseudo is independent of any language; it can be used by most programmers.

❖▪▪ It is easy to translate pseudo code into a programming language.

1. What is an algorithm?
Algorithm is an ordered sequence of finite, well defined, unambiguous instructions for completing a
task. It is an English-like representation of the logic which is used to solve the problem. It is a step-
by-step procedure for solving a task or a problem. The steps must be ordered, unambiguous and
finite in number.
2. Write an algorithm to find minimum of 3 numbers in a list. ALGORITHM : Find
Minimum of 3 numbers in a list
Step 1: Start
Step 2: Read the three numbers A, B, C
Step 3: Compare A and B.
If A is minimum, go to step 4 else go to step 5. Step 4: Compare A and C.
If A is minimum, output “A is minimum” else output “C is minimum”. Go to step 6.
Step 5: Compare B and C.
If B is minimum, output “B is minimum” else output “C is minimum”.
Step 6: Stop
3. List the building blocks of an algorithm.
The building blocks of an algorithm are
∙€€€€€€€€€€€€€€€€€Statements

∙€€€€€€€€€€€€€€€€€Sequence

∙€€€€€€€€€€€€€€€€€Selection or Conditional

∙€€€€€€€€€€€€€€€€€Repetition or Control flow

∙€€€€€€€€€€€€€€€€€Functions
4. Define statement. List its types.
Statements are instructions in Python designed as components for algorithmic problem solving,
rather than as one-to-one translations of the underlying machine language instruction set of the
computer.
There are three types of high-level programming language statements Input/output statements make
up one type of statement. An input statement collects a specific value from the user for a variable
within the program. An output statement writes a message or the value of a program variable to the
user’s screen.
5. Write the pseudo code to calculate the sum and product of two numbers and display it.
INITIALIZE variables sum, product, number1, number2 of type real
PRINT “Input two numbers”
READ number1, number2
sum = number1 + number2
PRINT “The sum is “, sum
COMPUTE product = number1 * number2
PRINT “The Product is “, product
END program
6. How does flow of control work?
Control flow (or flow of control) is the order in which individual statements, instructions or function
calls of an imperative program are executed or evaluated. A control flow statement is a statement in
which execution results in a choice being made as to which of two or more paths to follow.
7. What is a function?
Functions are "self-contained" modules of code that accomplish a specific task. Functions usually
"take in" data, process it, and "return" a result. Once a function is written, it can be used over and
over and over again. Functions can be "called" from the inside of other functions.
8. Write the pseudo code to calculate the sum and product displaying the answer on the
monitor screen.
INITIALIZE variables sum, product, number1, number2 of type real
PRINT “Input two numbers”
READ number1, number2 sum = number1 + number2
PRINT “The sum is “, sum
COMPUTE product = number1 * number2
PRINT “The Product is “, product
END program
9. Give the rules for writing Pseudo codes.
∙ Write one statement per line.

∙ Capitalize initial keywords.

∙ Indent to show hierarchy.

∙ End multiline structure.

∙ Keep statements to be language independent.


10. Give the difference between flowchart and pseudo code.
Flowchart and Pseudo code are used to document and represent the algorithm. In other words, an
algorithm can be represented using a flowchart or a pseudo code. Flowchart is a graphical
representation of the algorithm. Pseudo code is a readable, formally styled English like language
representation of the algorithm.
11. Define a flowchart.
A flowchart is a diagrammatic representation of the logic for solving a task. A flowchart is drawn
using boxes of different shapes with lines connecting them to show the flow of control. The purpose
of drawing a flowchart is to make the logic of the program clearer in a visual form.
12. Give an example of iteration.
a=0
for i from 1 to 3 // loop three times
{
a=a+I // add the current value of i to a
}
print a // the number 6 is printed (0 + 1; 1 + 2; 3 + 3)
13. Write down the rules for preparing a flowchart.
While drawing a flowchart, some rules need to be followed—
(1) A flowchart should have a start and end,
(2) The direction of flow in a flowchart must be from top to bottom and left to right, and
(3) The relevant symbols must be used while drawing a flowchart.
14. List the categories of Programming languages.
Programming languages are divided into the following categories:
Interpreted, Functional, Compiled, Procedural, Scripting, Markup, Logic-Based, Concurrent and
Object-Oriented Programming Languages
15. Mention the characteristics of an algorithm.
∙Algorithm should be precise and unambiguous.

∙Instruction in an algorithm should not be repeated infinitely.

∙Ensure that the algorithm will ultimately terminate.


∙Algorithm should be written in sequence.

∙Algorithm should be written in normal English.

∙Desired result should be obtained only after the algorithm terminates.

16. Compare machine language, assembly language and high-level language.


Machine language is a collection of binary digits or bits that the computer reads and
interprets.
This language is not easily understandable by the human.
An assembly language directly controls the physical hardware. A program written in assembly
language consists of a series of instructions mnemonics that correspond to a stream of executable
instructions, when translated by an assembler can be loaded into memory and executed. The
programs written in this language are not portable and the debugging process is also not very easy.
A high level language is much more abstract, that must be translated or compiled in to machine
language. It is easily understandable and the programs are portable. Debugging the code is easy and
the program written is not machine dependent.
17. What is the difference between algorithm and pseudo code?
An algorithm is a systematic logical approach used to solve problems in a computer while pseudo
code is the statement in plain English that may be translated later to a programming language.
Pseudo code is the intermediary between algorithm and program.
18. List out the simple steps to develop an algorithm. Algorithm development process
consists of five major steps.
Step 1: Obtain a description of the problem.
Step 2: Analyze the problem.
Step 3: Develop a high-level algorithm.
Step 4: Refine the algorithm by adding more detail.
Step 5: Review the algorithm.
19. Give the differences between recursion and iteration.

20. What are advantages and disadvantages of recursion?

1. What are the building blocks of an algorithm? Explain in detail.


The building blocks of algorithm are -Statements
-State
-Control flow
-Functions
Statements:
There are 3 types of statements:
-Input/Output Statement
-Assignment Statement
-Control Statement
State:
There are 3 types of state:
-Initial state
-Current state
-Final state
Control flow:
-Sequence
The sequence structure is the construct where one statement is executed after another -Selection
The selection structure is the construct where statements can executed or skipped depending on
whether a condition evaluates to TRUE or FALSE. There are three selection structures in C:
1. IF
2. IF – ELSE
3. SWITCH
Repetition
The repetition structure is the construct where statements can be executed repeatedly until a
condition evaluates to TRUE or FALSE. There are two repetition structures in C:
1. WHILE
2. FOR
Functions:
A function is a block of organized reusable code that is used to perform a single action.

2. Briefly describe iteration and recursion. Illustrate with an example.


Example: Recursive algorithm for factorial of number

3. Explain in detail Algorithmic problem solving.


4
4. Write an algorithm and draw a flowchart to calculate 2 .

Algorithm:
Step 1: Start
Step 2: Initialize the value of result, r=1.
Step 3: Repeat step4 for 4 times
Step 4: calculate r=r*2
Step 5: Print the value of r
Step 6: Stop
Flowchart:

5. a) Describe pseudo code with its guidelines.


Pseudo code consists of short, readable and formally-styled English language used for explaining an
algorithm. Pseudo code does not include details like variable declarations, subroutines etc.
Preparing a Pseudo Code

∙Pseudo code is written using structured English.

∙In a pseudo code, some terms are commonly used to represent the various actions. For example,

for inputting data the terms may be (INPUT, GET, READ),


for outputting data (OUTPUT, PRINT, DISPLAY),
for calculations (COMPUTE, CALCULATE),
for incrementing (INCREMENT),
in addition to words like ADD, SUBTRACT, INITIALIZE used for addition, subtraction, and
initialization, respectively.

∙The control structures—sequence, selection, and iteration are also used while writing the pseudo

code.

∙The sequence structure is simply a sequence of steps to be executed in linear order.

∙The selection constructs—if statement and case statement. In the if-statement, if the condition is

true then the THEN part is executed otherwise the ELSE part is executed. There can be variations of
the if-statement also, like there may not be any ELSE part or there may be nested ifs. The case
statement is used where there are a number of conditions to be checked. In a case statement,
depending on the value of the expression, one of the conditions is true, for which the corresponding
statements are executed. If no match for the expression occurs, then the OTHERS option which is
also the default option, is executed.

∙WHILE and FOR are the two iterative statements.

b) Give an example for pseudo code.


Pseudocode for finding maximum in a list:
BEGIN
SET numlist=[ ]
GET n
FOR i=1 to n
GET numlist elements
ENDFOR
SET maximum = numlist[0]
FOR i in numlist
IF (n > maximum)
maximum = n
ENDIF
ENDFOR
PRINT maximum
END

6. a) What is flowchart?
Flowchart is a diagrammatic representation of the logic for solving a task. A flowchart is drawn
using boxes of different shapes with lines connecting them to show the flow of control. The purpose
of drawing a flowchart is to make the logic of the program clearer in a visual form.

b) List down symbols and rules for writing flowchart.

c) Draw a flowchart to count and print from1 to 10.

7. a) Write an algorithm and give the flowchart to find the net salary of an employee.

Algorithm:
Step 1: Start
Step 2 : Read the basic salary
Step 3 : IF the basic is greater than or equal to 4000 ELSE Goto Step 4
Step 3.1 : DA= 0.32 * basic (Dearness Allowance)
Step 3,2 : HRA = 0.15 * basic (House Rent Allowance)
Step 3.3 : CCA = 325 (City Compensatory Allowance)
Step 3.4 : Net Salary basic + DA HRA + CCA
Step 4 : Print the Net Salary
Step 5 : Stop

b) Write an algorithm and give the pseudo code to guess an integer number in a range.
Algorithm:
step 1: Start the program
step 2: Read an 'n' number
step 3: Read an Guess number
step 4: if Guess> n; print "Your Guess too high" Step 5: elif Guess <n ; print "Your Guess
too low" step 6: elif Guess = = n; print "Good job"
Step 7: else print"Nope "
Step :8 Stop the program
Pseudocode:
BEGIN
READ n
READ Guess = 20
IF Guess> n
print"Your Guess too High" elif Guess< n
print "Your Guess too low" elif Guess = = 20
print "Good Job"
ELSE
print"Nope"

8. a) Write an algorithm to insert a card in a list of sorted cards.


ALGORITHM:
Step 1: Start
Step 2: Declare the variables N, List[],I and X
Step 3: READ Number of element in sorted list as N
Step 4: SET i=0
Step 5: IF i<N THEN go to step 6 ELSE go to step 9
Step 6: READ Sorted list element as List[i]
Step 7: i=i+1
Step 8: go to step 5
Step 9: READ Element to be insert as X
Step 10: SET i=N-1
Step 11: IF i>0 AND X<List[i] THEN go to step 12 ELSE go to step 15
Step 13: i=i-1
Step 14: go to step 11
Step 15: List[i+1]=X
Step 16: Stop

b) Write an algorithm to find the minimum number in a list.


Algorithm:
Step 1 : Start
Step 2 : Initialize the value of minimum = 0
Step 3 : Enter the input number (n) of items in a list.
Step 4 : Get all the elements using for loop and store it in a list.
Step 5: Assign the first element in a list as minimum.
Step 6: Compare maximum with the first element in a list,n.
Step 7: Repeat step 8,9 until list becomes empty.
Step 8 : If n is less than the minimum
Step 9 : Assign minimum = n
Step 10 : Display mi nimum
Pseudocode:
BEGIN
SET numlist=[ ]
GET n
FOR i=1 to n
GET numlist elements
ENDFOR
SET minimum = numlist[0]
FOR i in numlist
IF (n < minimum)
minimum = n
ENDIF
ENDFOR
PRINT minimum
END

PART B:
1. Explain in detail about problem solving techniques?
2. Explain in detail about building blocks of algorithm?
3. Discuss the symbols and rules for drawing flowchart with the example?
4. Explain in detail about programming language?
5. Discuss briefly about algorithmic problem solving?
6. Write algorithm, pseudo code and flow chart for any example?
7. Explain in detail about simple strategies for developing algorithms?

You might also like