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

Module 1 Solutions Model Questions

Uploaded by

amrthesha771
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

Module 1 Solutions Model Questions

Uploaded by

amrthesha771
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

MODULE 1 (MODEL QUESTIONS)

Q. How do you use a decomposition strategy to design a menu-driven calculator that


supports four basic arithmetic operators - addition, subtraction, multiplication,
and division? (3 marks)

 Understand the Problem:

The goal is to create a calculator that displays a menu of four operations (addition,
subtraction, multiplication, and division), performs the chosen operation on two
numbers, and displays the result.

Identify the Sub-Problems:

Sub-problem 1: Display the menu and get the user’s choice.

Sub-problem 2: Take two numbers as input from the user.

Sub-problem 3: Perform the calculation based on the chosen operation.

Sub-problem 4: Display the result.

Sub-problem 5: Allow the user to perform another calculation or exit.

Solve the Sub-Problems:

For each sub-problem, we can write a separate function:

Displays the list of operations (addition, subtraction, multiplication, division) and


an exit option.

Prompts the user to input two numbers.

Perform calculations:

add: Returns the sum of a and b.

subtract: Returns the difference between a and b.

multiply: Returns the product of a and b.

divide:Returns the quotient of a and b, with handling for


division by zero.

o Outputs the result to the user.

 Combine the Solution:


 Integrate these steps into the calculator’s flow:
 Display the menu, take input, get numbers, execute the operation, and show
results.
 Use a loop to keep the calculator running until the user chooses to stop.

 Test the Combined Solution:


o Check each arithmetic operation for correctness.
o Test error handling for cases like division by zero.
o Test the program’s overall functionality to ensure it meets user expectations

Q. A mad scientist wishes to make a chain out of plutonium and lead pieces. 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 marks)

STEP 1: UNDERSTAND SMALL CHAINS

1. For a chain of length 1:


o We have just one spot in the chain.
o We can put either "P" or "L" there.
o So, we have 2 options: "P" or "L".

Number of ways for length 1: 2

2. For a chain of length 2:


o We have two spots in the chain.
o Possible combinations without two "P"s together are:
 "PL" (Plutonium followed by Lead)
 "LP" (Lead followed by Plutonium)
 "LL" (Lead followed by Lead)

Number of ways for length 2: 3

STEP 2: RECOGNIZE A PATTERN

Now let’s see if we can find a pattern as the chain gets longer. To figure this out, let’s think
about how we can build a chain of length nnn using shorter chains.

1. If the chain starts with "L":


o We can make the rest of the chain any way we want, as long as it’s safe.
o So, the number of safe ways to complete the rest of the chain is the same as the number of
safe ways to make a chain of length n−1
2. If the chain starts with "P":
o The next piece must be "L" (otherwise there’d be an explosion).
o So, after "PL", we can complete the rest of the chain however we want, as long as it’s safe.
o The number of ways to complete the chain after "PL" is the same as the number of ways to
make a chain of length n−2

This gives us a rule, or formula, to find the number of ways for any length:

f(n)=f(n−1) + f(n−2)
Q. Walk through the six problem-solving steps to find the largest number out of three
numbers. (9 Marks)

To find the largest number out of three given numbers using the six problem-solving steps,
we can approach it as follows:

1. UNDERSTAND THE PROBLEM

The objective is to identify the largest number among three given numbers (say, A, B, and C).
We need to compare these numbers to determine which one is the greatest.

2. PLAN THE SOLUTION

We’ll use comparison operations to solve this problem. The plan is to:

 Compare A with B.
 Then compare the larger of A and B with C.
 The result will be the largest of the three.

3. DEVELOP AN ALGORITHM

Here’s a simple algorithm to find the largest number:

1. If A > B, then:
o If A > C, then A is the largest.
o Else, C is the largest.
2. Else, if B > C, then B is the largest.
3. Otherwise, C is the largest.

4. IMPLEMENT THE SOLUTION

Pseudocode

READ A, B, C
IF A > B THEN
IF A > C then
OUTPUT A as the largest
ELSE
Output C as the largest
ELSE
IF B > C THEN
OUTPUT B as the largest
ELSE
OUTPUT C as the largest

5. TEST THE SOLUTION

We can test this algorithm with different sets of values for A, B, and C:

 Example 1: A = 5, B = 8, C = 3 → The largest is B (8).


 Example 2: A = 10, B = 2, C = 7 → The largest is A (10).
 Example 3: A = 4, B = 4, C = 9 → The largest is C (9).

6. REVIEW

Evaluate if the algorithm works efficiently and correctly for all cases, including cases where two
or three numbers are equal. This approach is efficient and solves the problem using a minimal
number of comparisons.

Q. Your professor has given you an assignment on “Algorithmic thinking” to be


submitted by this Wednesday. How do you employ means-end analysis to devise a
strategy for completing your assignment before the deadline? (5 Marks)

1. DEFINE THE GOAL

The main goal is to complete the assignment by Wednesday. Break down this goal into
specific tasks, such as research, outlining, writing, and reviewing.

2. IDENTIFY CURRENT STATUS AND EVALUATE DIFFERENCES

Determine where you currently stand:

 Have you started the research?


 Have you outlined any sections?
 Do you have all necessary resources?

If you haven't started, the gap is larger; if you've already done some initial work, the
gap is smaller.

3. BREAK DOWN THE GOAL INTO SMALLER SUB-GOALS

Create a series of smaller objectives, for example:

 Day 1 (Today): Complete research and gather resources.


 Day 2 (Tomorrow): Outline the assignment structure, start drafting sections.
 Day 3 (Wednesday): Finalize the draft, proofread, and submit.

4. WORK ON SUB-GOALS STEP-BY-STEP

For each sub-goal:

 Allocate a specific time for each part of the task, ensuring you have time left for
review.
 Use tools or resources that could help speed up certain parts (like outlining software
or typing up notes).

5. EVALUATE PROGRESS REGULARLY

Check your progress each day:


 If you fall behind, adjust other steps accordingly.
 If ahead, use the extra time for additional review or improvement.

6. COMPLETE AND REVIEW

By breaking down and addressing each step day-by-day, you can ensure steady
progress and complete the assignment by the deadline without unnecessary last-
minute stress.

Q. Name two current problems in your life that might be solved through a heuristic approach.
Explain why each of these problems can be solved using heuristics.(4 Marks)

Heuristic problem-solving is a practical approach that relies on experience, intuition, and simple
rules to find a solution to complex problems. Heuristics offer "rules of thumb" or shortcuts that can
lead to a satisfactory answer quickly, even if it's not the optimal solution

1. Choosing What to Study First During Exam Prep


 Rule of Thumb: You know that certain subjects or topics are typically harder or have
more weight in exams, so prioritizing them makes sense.
 Current Conditions: You consider which topics you currently understand well and
which you’re struggling with, along with any hints the instructor may have given about
exam content.
 Alternative Routes: You could choose to focus on reviewing your notes, watching
videos, or doing practice problems depending on the subject and your learning style.
 Decision: Based on the time left before the exam, you prioritize studying topics that are
challenging and high-yield, rather than spending too much time on areas you already
understand.
2. Choosing a Movie to Watch with Friends
 Rule of Thumb: From past movie nights, you know certain genres are usually crowd-
pleasers for your group, like action or comedy, while others (like horror) may have
mixed appeal.
 Current Conditions: You consider which new movies are trending or have high ratings,
and ask friends if they have any preferences.
 Alternative Routes: You could look at recommendations on streaming platforms or
popular review sites, or go with a tried-and-true favourite if no one can decide.
 Decision: Based on the group’s vibe and preferences, you select a popular new release in
a genre you all enjoy, avoiding genres with mixed opinions to ensure everyone has a
good time.

You might also like