UCEST105 Algorithmic Thinking With Python MODEL QP SEMESTER 1
UCEST105 Algorithmic Thinking With Python MODEL QP SEMESTER 1
PART A
Answer all questions. Each question carries 3 marks CO Marks
1 How do you use a decomposition strategy to design a menu-driven calculator 1 (3)
that supports four basic arithmetic operators - addition, subtraction,
multiplication, and division?
2 A mad scientist wishes to make a chain out of plutonium and lead pieces. 4 (3)
There is a problem, however. If the scientist places two pieces of plutonium
next to each other, BOOM! The question is, in how many ways can the
scientist safely construct a chain of length n?
3 Write a case statement that will examine the value of flag and print one of the 3 (3)
following messages, based on its value.
1 Hot
2 Luke warm
3 Cold
4 Draw a flowchart to print the numbers that are divisible by 4 but not by 3 in a 3 (3)
list of n positive numbers.
5 Identify and rectify the problem with the following recursive definition to find 4 (3)
the greatest common divisor of two positive integers.
ABC ( n , m )
if n == 2 return m
else return ABC(m , n mod m)
6 Write a recursive procedure to search for a key in a list of n integers. 4 (3)
7 Compare and contrast greedy and dynamic programming strategies. 3 (3)
Page 1 of 4
8 Give the pseudocode for brute force technique to find the mode of elements 3 (3)
in an array. Mode is the value that appears most frequently in the array.
PART B
Answer any one full question from each module. Each question carries 9 marks
Module 1
9 Walk through the six problem-solving steps to find the largest number out of 1 (9)
three numbers.
10 a) Your professor has given you an assignment on “Algorithmic thinking” to be 2 (5)
submitted by this Wednesday. How do you employ means-end analysis to
devise a strategy for completing your assignment before the deadline?
b) Name two current problems in your life that might be solved through a 1 (4)
heuristic approach. Explain why each of these problems can be solved using
heuristics.
Module 2
11 a) Mr. Shyam, a history professor, would like to know the percentage increase 3 (6)
in the population of our country per decade given the first decade and the last
decade. Other given data include the population at the beginning of each
decade. Draw a flowchart for determining the percentage increase in the
population.
b) Draw a flowchart to find the average mileage of a car in kilometers per litre 3 (3)
after six fill-ups at petrol pumps. Input data include the number of litres of
diesel, the starting odometer reading, and the odometer reading at each fillup.
12 a) A standard science experiment is to drop a ball and see how high it bounces. 3 (6)
Once the “bounciness” of the ball has been determined, the ratio gives a
bounciness index. For example, if a ball dropped from a height of 10 feet
bounces 6 feet high, the index is 0.6, and the total distance traveled by the ball
is 16 feet after one bounce. If the ball were to continue bouncing, the distance
after two bounces would be 10 ft + 6 ft + 6 ft + 3.6 ft = 25.6 ft. Note that the
distance traveled for each successive bounce is the distance to the floor plus
0.6 of that distance as the ball comes back up. Write an algorithm that lets the
user enter the initial height of the ball, bounciness index and the number of
times the ball is allowed to continue bouncing. Output should be the total
distance traveled by the ball.
Page 2 of 4
b) Light travels at 3 × 108 meters per second. A light-year is the distance a light 3 (3)
beam travels in one year. Write an algorithm that inputs a large distance value
(in meters) and displays it in light-years.
Module 3
13 a) Write a recursive function to find an array's minimum and maximum 4 (5)
elements. Your method should return a tuple (a, b), where a is the minimum
element and b is the maximum.
b) Write a program to input a matrix and determine its type: lower triangular, 4 (4)
upper triangular, or diagonal.
14 a) Write a program to read N words and display them in the increasing order of 4 (6)
their lengths. The length of each word is also to be displayed.
b) There are 500 light bulbs (numbered 1 to 500) arranged in a row. Initially, 4 (3)
they are all OFF. Starting with bulb 2, all even numbered bulbs are turned
ON. Next, starting with bulb 3, and visiting every third bulb, it is turned ON
if it is OFF, and it is turned OFF if it is ON. This procedure is repeated for
every fourth bulb, then every fifth bulb, and so on up to the 500th bulb. Devise
an algorithm to determine which bulbs glow at the end of the above exercise.
Module 4
15 a) Studies show that the capacity of an empty human stomach is 1.5 litres on 3 (6)
average. Give a greedy algorithm to output an efficient lunch menu
maximizing the total nutritional value. The available items along with their
nutritional values are tabulated below:
Available Nutritional
Recipe
quantity value
Page 3 of 4
Fish fry 0.5 cup 200 calories
Page 4 of 4