Ge3151 Unit1 2marks
Ge3151 Unit1 2marks
2marks
1.What is an algorithm? (University question)
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.
6. Write the pseudo code to calculate the sum and product displaying the answer on the
monitor screen.
BEGIN
INITIALIZE variables sum, product, number1, number2 of type real
Recursion Iteration
Function calls itself until the base condition is Repetition of process until the condition fails.
reached.
Only base condition (terminating condition) is It involves four steps: initialization, condition,
specified. execution and updation.
It keeps our code short and simple. Iterative approach makes our code longer.
It is slower than iteration due to overhead of Iteration is faster.
maintaining stack.
It takes more memory than iteration due to Iteration takes less memory.
overhead of maintaining stack.
Advantages Disadvantages
Recursive functions make the code look clean Sometimes the logic behind recursion is hard to
and elegant. follow through.
A complex task can be broken down into Recursive calls are expensive (inefficient) as
simpler sub-problems using recursion. they take up a lot of memory and time.
Sequence generation is easier with recursion Recursive functions are hard to debug.
than using some nested iteration.
Step 1: Start
Step 2: READ the value of two numbers
Step 3:Compute sum of two numbers
Step 4 :Print the sum
Step 5:Stop
21.Write an algorithm to find the minimum number in a given list of numbers.
(Universityquestion)
• Step 1: Start
• Step 2:Read the total number of element in the list as N
• Step3:Read first element as E
• Step 4:MIN=E
• Step 5:Set i=2
• Step6:IF i>n goto Step 11 ELSE goto Step 7
• Step 7:Read i th element as E
• Step 8:IF E<MIN then set MIN=e
• Step 9:i=i+1
• Step 10:goto step 6
• Step 11:print MIN
• Step12:Stop
22. Outline the logic to swap the contents of two identifiers without using the third variable
(University question)
• Step1: Start
• Step 2:Read A,B
• Step 3 :A=A+B
• Step 4:B=A-B
• Step5:A=A-B
• Step 6:Print A ,B
• Step 7:Stop
Unit-2
TWO MARKS
1. What is a value? What are the different types of values? (University question)
A value is one of the fundamental things – like a letter or a number – that a program manipulates.
Its types are: integer, float, , strings , lists and Dicitionary.
2. Define a variable and write down the rules for naming a variable.
A name that refers to a value is a variable. Variable names can be arbitrarily long. They can contain
both letters and numbers, but they have to begin with a letter. It is legal to use uppercase letters, but it is good
to begin variable names with a lowercase letter.
3. Define keyword and enumerate some of the keywords in Python. (University question)
A keyword is a reserved word that is used by the compiler to parse a program. Keywords cannot be
used as variable names. Some of the keywords used in python are: and, del, from, not, while, is, continue.
Eg 1: Message = “hello”
Eg 2: n = 17
9. What is the order in which operations are evaluated? Give the order of precedence.
The set of rules that govern the order in which expressions involving multiple operators and
operands are evaluated is known as rule of precedence. Parentheses have the highest precedence
followed by exponentiation. Multiplication and division have the next highest precedence followed by
addition and subtraction.
0.70710678118
22.What is meant by traceback?
A list of the functions that tells us what program file the error occurred in, and what line, and what
functions were executing at the time. It also shows the line of code that caused the error.
23.Write a program to accept two numbers multiply them and print them. (University
question)
A
=1
0
B
=2
multiplication=A*B
print (“Multiplication of two numbers :” ,multiplication)