ATP Module 1 Examples
ATP Module 1 Examples
ATP Module 1 Examples
For steps in problem solving using trial and error method, algorithm
thinking, heuristics, mean end analysis and decomposition – Refer
Chapter 1 (World of Problem solving) in KTU Textbook on
“Algorithm thinking with Python”.
How do you use a decomposition strategy to design a menu-driven calculator that supports
four basic arithmetic operators - addition, subtraction, multiplication, and division?
Solution,
Decompose the calculator design into smaller sub-problems or components that can be
developed independently. These components may include:
1. Input Handling:
o Get the user’s choice of operation.
o Collect the two numbers on which the operation will be performed.
2. Performing the Calculation:
o Create separate functions for each arithmetic operation (addition,
subtraction, multiplication, division).
3. Menu Display:
o Create a menu that displays the available operations (addition, subtraction,
multiplication, and division).
4. Error Handling:
o Handle errors such as invalid inputs, division by zero, etc.
5. Loop for Multiple Calculations:
o Allow the user to perform multiple calculations without restarting the
program.
1. Input Handling
Display Menu: Show a list of available options (1. Addition, 2. Subtraction, etc.).
Get User Input: Prompt the user to select an operation (e.g., choose 1 for addition).
Get Numbers: Ask the user for two numbers.
3. Menu Display
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Exit
Allow the user to choose an option by entering a number (e.g., 1 for addition).
4. Error Handling
Invalid Input Handling: If the user enters a non-numeric input or an invalid menu
option, prompt them to enter a valid option.
Division by Zero: Check for division by zero before performing division, and display
an error message if the user attempts to divide by zero.
Repeat: After performing an operation, ask the user if they want to perform another
calculation or exit.
With the components decomposed, we can structure the program flow logically:
Explain the code using flow chart or pseudo code and implement the code in the required
programming language.
Once the components are implemented, test the calculator by performing various
operations:
Addition: 5 + 3 = 8
Subtraction: 10 - 4 = 6
Multiplication: 6 * 7 = 42
Division: 8 / 2 = 4 (test division by zero as well)
Rearrange the letters in the words new door to create a one word
Solution,
“A student wants to achieve a high score on an upcoming exam”. Explain how means-end
analysis can be employed for this.
Solution,
Means-end analysis is a problem-solving strategy that involves breaking down a goal into
smaller, more manageable subgoals and determining the steps or "means" needed to
achieve each subgoal. This process is typically used in decision-making and problem-solving
to navigate the gap between the current state and the desired outcome.
For a student wanting to achieve a high score on an upcoming exam, means-end analysis
could be employed as follows:
Six glasses are in a row. The first three are full of water and next three are empty. By moving
only one glass, can you arrange them so that empty and full glasses are alternate?
Solution,
To solve this puzzle, we need to rearrange six glasses, where the first three are full of water
and the next three are empty. The goal is to move only one glass so that the glasses
alternate between full and empty. The initial arrangement is:
Full (F), Full (F), Full (F), Empty (E), Empty (E), Empty (E)
We are given six glasses in a row, three full and three empty. Our task is to rearrange them
so that the glasses alternate between full and empty by moving only one glass.
We need to create an alternating pattern of full and empty glasses. The goal is to end up
with this pattern:
Full (F), Empty (E), Full (F), Empty (E), Full (F), Empty (E)
To get this alternating pattern with only one move, let's think about the positions:
We have six glasses. The first three are full (F), and the last three are empty (E):
o FFFEEE
We can move one glass, but the trick is figuring out which glass to move and where.
The simplest and most effective way to achieve the alternating pattern with one move is to
move content of one of the full glasses (F) into one of the empty spots (E) where it will
create the correct alternating pattern.
The Move:
Move the third full glass (F) to the fifth position, which is currently empty (E).
F, E, F, E, F, E
By moving only the contents of second full glass (F) into the fifth position, we achieve the
desired alternating pattern with only one move.
After making the move, the glasses are now arranged as:
F, E, F, E, F, E
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?.
Solution,
To solve this problem, we need to figure out how many different ways the scientist can
construct a chain of length n using two types of pieces: plutonium (denoted by P) and lead
(denoted by L), with the condition that two pieces of plutonium cannot be adjacent to each
other. In other words, no two P pieces can be placed next to each other.
We need to determine how many valid arrangements of P (plutonium) and L (lead) pieces
can be made in a chain of length n, where no two P pieces are adjacent. This can be thought
of as a problem of counting valid binary strings of length n, where:
We can define a recursive relation for the number of valid chains of length n. Let f(n)
represent the number of valid chains of length n.
If the last piece in the chain is L, then the remaining part of the chain is a valid chain
of length n−1. So, there are f(n−1) ways to extend the chain.
If the last piece in the chain is P, then the second-to-last piece must be L (because
two P pieces cannot be adjacent). This means that the rest of the chain (up to length
n−2) must also be a valid chain of length n−2. So, there are f(n−2) ways to extend the
chain.
f(n)=f(n−1)+f(n−2)
This relation is similar to the Fibonacci sequence, but with different base cases.
f(0)=1: There's exactly one way to arrange a chain of length 0 — the empty chain.
f(1)=2: There are two valid chains of length 1: either L or P.
Using the recursive relation and base cases, we can compute f(n) for any n.
f(3)=f(2)+f(1)
So:
f(3)=3+2=5
The valid chains of length 3 are: LLL, LLP, LPL, PLP, PLL.
f(n)=f(n−1)+f(n−2)
f(0)=1
f(1)=2
Final Answer:
The number of ways the scientist can safely construct a chain of length n is given by
f(n)f(n)f(n), where f(n)f(n)f(n) follows the recurrence relation f(n)=f(n−1)+f(n−2) with initial
conditions f(0)=1 and f(1)=2. This sequence grows similarly to the Fibonacci sequence, but
with different starting values.
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.
Solution,
Problem:
You have a long to-do list with various tasks, deadlines, and responsibilities. It feels
overwhelming, and you're unsure where to start.
Another heuristic is the Eisenhower Matrix, where tasks are categorized into:
By using these simple rules of thumb, you can quickly prioritize tasks without needing to
spend excessive time analyzing each one in-depth.
Problem:
You’re searching for a new place to live, and you have a list of criteria (location, price,
amenities, etc.). There are too many options, and you don’t have time to visit them all or
carefully consider every detail.
"Rule of Thumb for Rent-to-Income Ratio": Only consider places where the rent is
no more than 30% of your monthly income. This helps you filter out unaffordable
options quickly.
Another heuristic could involve eliminating options based on obvious dealbreakers (e.g., no
pets allowed, noisy neighborhood, etc.), leaving you with a manageable number of potential
places to evaluate in more detail.
Solve the Missionaries and Cannibals problem using the 6 steps of problem solving.
Solution,
Problem Statement: You have three missionaries (M) and three cannibals (C) on one
side of a river. They need to cross to the other side using a boat that can carry only
two people at a time.
Constraint: At no point on either side of the river can the number of cannibals
outnumber the missionaries. If they do, the cannibals will eat the missionaries.
Goal: Move all three missionaries and three cannibals safely to the other side of the
river.
Current State: All 3 missionaries and 3 cannibals are on the left side of the river, and
the boat is on the left side.
Goal State: All 3 missionaries and 3 cannibals must be on the right side of the river,
and the boat must be on the right side.
Constraints:
o The boat can only carry 2 people at a time.
o Cannibals cannot outnumber missionaries on either side of the river at any
time.
Since we must ensure the safety of the missionaries, we’ll avoid any move where cannibals
would outnumber missionaries on either side of the river.
After analyzing the problem and possible moves, we will start solving the problem step by
step by using safe moves. The approach we’ll take is to make moves that maximize the
number of missionaries and cannibals safely transferred without violating the constraints.
Initial state: (3, 3, left) — 3 missionaries, 3 cannibals, boat on the left side.
Step 1: Move 2 cannibals to the right side.
o New state: (3, 1, right)
Step 2: One cannibal returns to the left side.
o New state: (3, 2, left)
Step 3: Move 2 cannibals to the right side again.
o New state: (3, 0, right)
Step 4: One cannibal returns to the left side.
o New state: (3, 1, left)
Step 5: Move 2 missionaries to the right side.
o New state: (1, 1, right)
Step 6: One cannibal and one missionary return to the left side.
o New state: (2, 2, left)
Step 7: Move 2 missionaries to the right side again.
o New state: (0, 2, right)
Step 8: One cannibal returns to the left side.
o New state: (1, 1, left)
Step 9: Move 2 cannibals to the right side.
o Final state: (0, 0, right) — All missionaries and cannibals are safely on the
right side!
Final State: The goal state has been reached: (0, 0, right) — All 3 missionaries and 3
cannibals are safely on the right side of the river.
Solution Verification: At no point were cannibals outnumbering the missionaries on
either side of the river. Every move was checked to ensure safety.
Walk through the six problem-solving steps to find the largest number out of three
numbers.
Solution,
2. Gather Information
Let's say the three numbers are: 12, 5, and 20. We need to analyze these numbers to find
the largest one.
3. Generate Alternatives
4. Evaluate Alternatives
5. Choose a Solution
Solution,
For each component, outline specific actions to bridge the gap between your current state
and the goal:
5. Create a Timeline
6. Monitor Progress
Adjust your timeline if you find certain sections take longer than expected.
Stay focused and avoid distractions to maximize productivity.
By systematically breaking down the assignment using means-end analysis, you can
effectively strategize and ensure that you complete the task before the deadline.
Name two current problems in your life that might be solved through a trial and error
approach.
Solution,
Problem: My internet connection is slow, and I'm not sure why it's happening.
1. Initial Attempt:
Solution 1: Restart the router.
o Action: Turn off the router for 30 seconds, then turn it back on.
o Result: Internet speed is still slow.
o Learning: This solution didn’t work.
2. Second Attempt:
Solution 2: Move the router to a different location in the room (closer to the area
where I use the internet the most).
o Action: Position the router in a more central location and away from
obstructions.
o Result: The connection improves slightly but is still slower than expected.
o Learning: Proximity to the router does help, but there’s still a problem.
3. Third Attempt:
Solution 3: Disconnect other devices from the network to reduce congestion.
o Action: Unplug other devices using the Wi-Fi, like phones or smart TVs.
o Result: The speed improves, but it’s still not as fast as it should be.
o Learning: Reducing devices on the network makes a difference, but the root
cause is likely elsewhere.
4. Fourth Attempt:
Solution 4: Change the Wi-Fi channel or frequency band (from 2.4 GHz to 5 GHz).
o Action: Access the router settings and switch the channel/frequency.
o Result: The internet speed drastically improves, and I experience better
performance.
o Learning: Changing the channel to avoid interference solved the issue.
If your mobile phone isn't turning on, the trial and error method can be an effective way to
diagnose and solve the issue.
Solution 1: Plug the phone into the charger and wait for a few minutes (at least 10–
15 minutes) to see if the battery was completely drained.
o Action: Connect the phone to a known working charger and leave it plugged
in for a while.
o Result: The screen shows a charging symbol after a few minutes, and the
phone powers on.
o Learning: If the phone turns on, the problem was simply a dead battery. Keep
in mind that if the battery was completely drained, it may take a few minutes
before any signs of life appear.
If the phone doesn't show any signs of charging or powering up after waiting for a
while, proceed to the next step.
If the power button seems fine and the phone still won’t turn on, move to the next
step.
Solution 5: Determine if the phone is actually on but the screen isn’t working.
o Action: Listen for any sounds (e.g., notification alerts, vibrations) that would
indicate the phone is on but the screen is not displaying anything. Try
adjusting the screen brightness or tapping on the screen to see if the display
is just dim or frozen.
o Result: You may notice the phone is on but the display is blank or frozen,
indicating an issue with the screen or display components.
If you don’t hear any sounds and the screen is still black, proceed to the next step.
Solution 6: Attempt a factory reset via recovery mode (for Android) or DFU (Device
Firmware Update) mode (for iPhones).
o Action:
For Android: Boot into recovery mode (usually by holding Power +
Volume Up/Down together when the phone is off) and choose Wipe
Cache Partition or Factory Reset (this will erase all data, so only do
this if necessary).
For iPhones: Connect the iPhone to a computer with iTunes (or Finder
on macOS) and attempt to restore or update the device through
recovery or DFU mode.
o Result: If successful, the phone will start up after the reset.
o Learning: A software corruption issue could be preventing the phone from
booting. A factory reset may clear this, but it will erase all data on the device.
Use this as a last resort.
If the phone still doesn’t turn on, it might indicate a hardware failure that requires
professional repair.
Outcome:
Through trial and error, you’ll likely identify whether the issue is related to:
Battery charge
Frozen system requiring a reset
A faulty power button or charger
Screen/display issues
Software corruption needing a factory reset
If none of the steps resolve the issue, the problem may be deeper, such as a hardware
failure (e.g., motherboard or internal component damage), which may require professional
repair or replacement.