Assignment
Assignment
ASSIGNMENT QUESTIONS
YEAR: II
SEMESTER: IV
[CO1 – 8 marks, CO2 – 8 marks, CO3 – 8 marks, CO4 – 8 marks, CO5 – 8 marks]
Instructions to students:
S.No. Question CO
Puzzle 1: The 100 Doors Problem
There are 100 doors in a row, all initially closed.
You make 100 passes over them.
In the 1st pass, toggle every door.
In the 2nd pass, toggle every 2nd door.
1 In the 3rd pass, toggle every 3rd door, and so on… CO1
After 100 passes, which doors remain open?
1. Analyze the problem mathematically.
2. Derive a formula to find open doors.
3. Implement an efficient Python program.
4. Explain the time complexity.
Puzzle 2: The Two Egg Problem
Problem Statement:
You have two identical eggs and a 100-floor building. The eggs break at or above a
certain floor. Your goal is to find the highest safe floor using the minimum number
2 of drops. CO2
1. Analyze brute-force (linear search) vs. binary search methods.
2. Derive a formula to minimize worst-case drops.
3. Implement an optimized algorithm in Python.
Justify the time complexity.
Puzzle 3: The Bridge and Torch Problem
Problem Statement:
Four people need to cross a bridge at night.
They take 1, 2, 5, and 10 minutes to cross.
They have one flashlight, and at most two people can cross at a time.
3 CO3
Both must move at the slower person’s speed.
What is the minimum total time required?
1. Derive the step-by-step optimal crossing strategy.
2. Implement a Python program using a greedy algorithm.
Justify your approach with complexity analysis.
Puzzle 4: The 5L and 8L Jug Problem
Problem Statement:
You have a 5-liter and an 8-liter jug. There is an unlimited water supply, but no
markings on the jugs.
4 Measure exactly 4 liters of water. CO4
1. Explain why this problem is solvable using GCD properties.
2. Implement a Backtracking (or BFS-based) algorithm in Python.
3. Determine the minimum number of steps required.
4. Analyze the time complexity.
5 Puzzle 5: The Traveling Salesman Problem (TSP) CO5
Problem Statement:
A salesman must visit N cities exactly once and return to the starting city.
Find the shortest possible route that visits each city once.
1. Explain why TSP is NP-Hard.
2. Implement an Approximation Algorithm (e.g., Nearest Neighbor
Algorithm).
3. Compare Brute-force, Dynamic Programming, and Approximation
methods.
4. Analyze the time complexity.
Batch No. – (720323104011-720323104020)
S.No. Question CO
Puzzle 1: The Prisoners and the Light Bulb
Problem Statement:
A prison warden tells 100 prisoners that they will be placed in solitary cells but
allowed to visit a central room with a light bulb one at a time, in random order.
The bulb starts OFF.
Each prisoner can flip the switch or do nothing.
The prisoners must determine when all 100 have visited the room at least
1 CO1
once.
If they make a correct declaration, they go free.
If they guess incorrectly, they all stay imprisoned.
Devise a strategy to ensure freedom!
1. Derive a logical algorithm for tracking visits.
2. Implement a simulation using Python.
3. Explain the time complexity.
Puzzle 2: The Knight’s Tour Problem
Problem Statement:
A knight moves on an N × N chessboard following the standard L-shaped move.
The goal is to visit every square exactly once.
2 Find a possible tour using an efficient approach. CO2
1. Implement a Backtracking Algorithm for the tour.
2. Optimize using Warnsdorff’s Heuristic.
3. Compare brute force vs. heuristic methods.
Analyze the time complexity.
Puzzle 3: The Coin Change Problem
Problem Statement:
Given an unlimited supply of coins with values {1, 3, 4}, find the minimum
number of coins needed to sum to a given amount N.
3 CO3
1. Solve using Greedy Algorithm (where applicable).
2. Solve using Dynamic Programming (Optimal Substructure).
3. Compare both methods for different values of N.
Analyze the time complexity.
Puzzle 4: The Sudoku Solver
Problem Statement:
Given a 9×9 partially filled Sudoku board, fill in the missing numbers so that:
Each row, column, and 3×3 subgrid contains numbers 1-9 without
4 CO4
repetition.
1. Implement Backtracking Algorithm to solve the puzzle.
2. Optimize using Constraint Propagation.
Analyze the time complexity.
5 Puzzle 5: The Job Scheduling Problem CO5
Problem Statement:
You have N jobs, each with a deadline and profit.
If a job is finished before its deadline, you earn its profit.
Only one job can be scheduled at a time.
Find the maximum profit schedule.
1. Implement a Greedy Algorithm for optimal scheduling.
2. Compare with Brute Force and Dynamic Programming approaches.
3. Analyze the time complexity.
Batch No. – (720323104021-720323104030)
S.No. Question CO
Puzzle 1: The Infinite Monkey Theorem (Typing Monkeys Problem)
A monkey randomly types letters on a keyboard.
Given a target word (e.g., "HELLO"), find the expected number of keystrokes
before the monkey types the word correctly at least once.
1 Submission Guidelines: CO1
1. Derive the mathematical probability model.
2. Implement a Monte Carlo simulation in Python.
3. Compare the expected vs. actual time taken.
4. Analyze the time complexity.
Puzzle 2: The Bridges of Königsberg
S.No. Question CO
Puzzle 1: The Painter’s Partition Problem
You are given N boards and K painters. Each painter takes 1 unit of time per unit
of board length.
Find the minimum time required to paint all boards.
1 Each painter paints continuous boards only. CO1
Submission Guidelines:
1. Implement Binary Search + Greedy Algorithm for the solution.
2. Provide sample input and expected output.
3. Analyze the time complexity.
Puzzle 2: The Maze Solver
You are given an N×N maze where:
0 represents open paths, and 1 represents walls.
You must find the shortest path from (0,0) to (N-1, N-1).
2 Submission Guidelines: CO2
1. Implement BFS (Breadth-First Search) Algorithm for shortest path.
2. Compare with DFS (Depth-First Search).
3. Provide maze visualization.
Analyze the time complexity.
Puzzle 3: The Egg Drop Problem
You are given K eggs and a N-floor building.
Find the minimum number of attempts needed to determine the highest floor an
egg can be dropped from without breaking.
3 Submission Guidelines: CO3
1. Solve using Dynamic Programming.
2. Compare with Recursive Brute Force approach.
3. Provide test cases with expected output.
4. Analyze the time complexity.
Puzzle 4: The 5L and 8L Jug Problem
Problem Statement:
You have a 5-liter and an 8-liter jug. There is an unlimited water supply, but no
markings on the jugs.
4 Measure exactly 4 liters of water. CO4
1. Explain why this problem is solvable using GCD properties.
2. Implement a Backtracking (or BFS-based) algorithm in Python.
3. Determine the minimum number of steps required.
Analyze the time complexity.
5 Puzzle 5: The Bin Packing Problem CO5
Given N items with different sizes, pack them into the minimum number of bins
with a fixed capacity.
Submission Guidelines:
1. Implement First-Fit and Best-Fit Heuristic Algorithms.
2. Compare with Brute Force approach.
3. Analyze the time complexity.