0% found this document useful (0 votes)
3 views

Python Unit 1 (2marks )

Uploaded by

itsanthosh024
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Python Unit 1 (2marks )

Uploaded by

itsanthosh024
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

72

Problem Solving and Python Programming


ANNA UNIVERSITY 2 MARK QUESTIONS WITH
ANSWERS

1. Write an algorithm to find the sum of first N' natural numbers.


(AU Nov/ Dec 2022, R20211
1. Start.
2. Read N.
3. Assign sum =0 and i= 1.
4. If i<N then calculate sum = sum +1.
5. Increment i=j-1.
6. Repea step 4.
7. Print sum.
8. Stop.
2. Distinguish between top down and bottom approaches to design
algorithms.
(AUNov/ Dec 2022, R2021)
In the top-down approach, a bigger module problem is divided into smaller
modules. In contrast, in the bottom-up approach, the smaller
and then they are integrated to find the solution of a bigger problems solved
are
problem.
3. Write an algorithm to find smallest among three
numbers.
(AUApr/ May 2022, R2021)
Step 1: Start.
Step 2: Read the three numbers A, B,C,
Sten 3:Compare A and B. If A is the smallest perform step 4 else
perform
step 5.
Sten 4:Compare A and C. If A is the smallest, output "A is the
smallest"
else output "C isthe smallest".
Step 5:Compare B and C. If Bis the smallest,output "B is the smallest" clse
output "C is the smallest".
Step 6: Stop.
4. Which is better iteration or recursion? Justify your answer.
(AUApr/ May 2022, R2021)
Iteration is faster and moreefficient than recursion. lt's easier to optimize iterative
codes, and they generally have polynomial time complexity.
(omputationalThinking and Problen Solving 73

Write an algorithu to acvept two numbers, compute the sum and print the resuit.
(AU Jan 2022, R2021, AUJan 2018)

: Kead wonnberN a and b.


Caleulate sunt atb

5. Stop

0. Detine an interative statement. (AU Jan 2022, R202 1)


upon a
The iteration is a lcchniquc that repeats a set of statements based
block) 1s
condition. l acondition evaluates to truc, the set of statements (true
the repetition
CNCUIed again and again. Assoon as the condition becomes false,
slops. This is also knownas looping statement or iteration statement.

7. How ill youanalyze the efficiency of an algorithm?


(AUNov/ Dec 2019,R2017)

The complexity
T'he eticicncy of an algorithm is measured by its Complexity.
is how fast it is" and how
That
of an algorithm is measured in Time and Space.
either case (timne or space) the
much space it uses lo process agiven input. In techniques.
cficieney is evaluated by experimentaltechniques or by analytical
Pseudocode in the perspective
8. What is the use of algorithm, Flowchart and (AUNov/ Dec 2019, R2017)
of problem solving?
computer how to solve a
Algorithm is a step-by-step instruction that tells the
representation that illustrates the
particular problem. Flowchart is a diagrammatic
steps that must be performed to solve a problem. Pseudocode is a
scquence of
algorithm that uses the
compact and informal high-level description of an
structural conventions of aprogramming language.
and program. (AUDec/Jan 2019, R2017)
9. Distinguish between algorithm

Algorithm Program
Algorithm step-by-step Program is a formal definition for an
set of instructions
procedure for solving a task or a algorithm. It is a
for the computer to follow.
problem.
74
Problenm Solving and Python Programming
10. Write an algorithm to find the minimum number in a given list of
numbers.
(AUDec/Jan 2019, R2017)
1. Start.
2. Read n.
3. Read all n elements and store in list A.
4. Assumemin first element in the list.
5. Read all elenments in a list one by one
if A[i]<min then assign
min=A[)
6. Repeat step 5 till allelements are compared
7. Print min as minimum element.
8. Stop.
11. What is an algorithm? (AUJan 2018, R2017)
(AUNov/Dec 2015, Nov/Dec 2014, May/June 2013, Jan 2013, Jan 2012.
May/June 2012, Jan 2010)
Algorithm is an ordered sequence of finite, well defined, unambiguous
instructions for completing a task.
12. What is a pseudocode? (AUNov/Dec 2015, Jan 2013, May/June 2009)
Pseudocode is a of short, readable and formally styled English language
instructions used for explaining an algorithm.
13. What are flowcharts and list down their advantages?
(AUNov/Dec 2014, May/June 2013, May/June 2012)
Aflowchart is a diagrammatic representation of the logic for solving a task.
Advantages of flowcharts:

The symbols used in a flowchart are self-explanatory. This makes a


flowchart easier to understand.
communicate the
Being a graphical representation, flowcharts better
problem-solving logic to the users.
effective way.
With the help of a flowchart., a problem can be analysed in an
also helps in monitoring, data collection and identifies areas for
It
improvement or increase in efficiency.
Dutational Thinking and Problem Solving 75
14. Enlist the advantages of
algorithm. (AUJan 2012)
1. It is a simple to
understand step by step solution of theproblem.
2. It is easy to
debug.
3. An algorithm is independent of programming
languages.
15. What is the
difference between
program and algorithm?
(AU April/May 2011)
Program: A program is a set of instruction given to a computer to
problem. solve a

Algorithm: An algorithm is a procedure or finite sequence of steps that


provides the solution to a problem.
16. What are the benefits of pseudocode? (AUApr/May 2011)

A Pseudocode is closer to the programming code. Thus, it can be easily


converted into the actual program.
Writing Pseudocode is much easier in comparison with drawing a flowchart.

17. Write down steps involved in writing a program to solve a problem.


(AUMay/June 2010)
To design aprogram, a programmer must determine three basic steps.

1. The instructions to be performed.


to be performed.
2. The sequence in which those instructions are
instructions.
3. The data required to perform those
algorithms.
18. List the different building blocks of
constructed from basic building blocks. These building
The algorithms can be
blocks are,
Instructions/statements

State
Control flow
Functions
76
Problem Solving and Python Programming
19. Draw a flowchart to find the
maximum among the three numbers.
(AU Jan 2009)
Start

Read x.y,z Yes


is z>big
big =z
big =x No

Print big
is y> big Yes

No big = y Stop

20. List the different building


blocks of algorithms.
The algorithms can be constructed from basic building blocks. These
building
blocks are,
Instructions/statements
State
Control flow
Functions
21. What is coding?

Translating an algorithm into a programming language is called coding the


algorithm.
22. Define recursion.

Afunction or procedure is called by itself again and


again until a given
condition is satisfied, is called recursion.

You might also like