MARANATHA UNIVERSITY, LAGOS
COURSE CODE: CSC 121
COURSE TITLE: Problem Solving
INSTRUCTION: Attempt QUESTION 1 and any other two questions.
MARKING GUIDE
QUESTION 1 (Compulsory - 30 MARKS)
1a. Define the following terms as used in computing:
i. Computing
Answer: Computing refers to the process of using computers or other devices to perform tasks such as
processing data, solving problems, and executing instructions using hardware and software resources. It
involves both theoretical and practical aspects, including algorithms, data structures, and system operations.
(2 marks)
ii. Problem
Answer: In computing, a problem is a task, question, or situation that requires a solution through logical
reasoning, computation, or programming. Problems can range from simple arithmetic operations to complex
system designs.
(2 marks)
iii. Algorithm
Answer: An algorithm is a well-defined, finite sequence of steps or instructions designed to perform a
specific task or solve a particular problem. It must be precise, unambiguous, and terminate after a finite
number of steps.
(2 marks)
1b. Explain the difference between routine and non-routine problems. Provide one example of each
from real life.
Answer:
Routine Problem: A routine problem has a known, repeatable method of solution, often solved by
applying standard formulas or procedures.
Example: Calculating the total bill in a supermarket using addition. (2 marks)
Non-Routine Problem: A non-routine problem requires creative thinking, analysis, or novel
approaches as there may be no standard method to solve it.
Example: Designing a secure authentication system for an online banking platform. (2 marks)
1c. List and describe the four major steps in the problem-solving process. (4 marks)
Answer:
1. Problem Identification: Clearly defining and understanding the problem. (1 mark)
2. Problem Analysis: Breaking down the problem into smaller, manageable parts and identifying
requirements. (1 mark)
3. Solution Design: Developing algorithms or strategies to solve the problem. (1 mark)
4. Solution Implementation and Testing: Writing the program or carrying out the steps, then verifying
correctness. (1 mark)
1d. Consider the scenario: A vending machine that returns an item and correct change.
i. Identify the problem involved:
The machine must determine if the user has inserted enough money, then dispense the correct item and
return the right amount of change. (1 mark)
ii. Outline an algorithm:
1. Accept the item selection from the user. (0.5 mark)
2. Display the item price. (0.5 mark)
3. Accept money input. (0.5 mark)
4. Compare money inserted to the price. (0.5 mark)
5. If enough, dispense the item and calculate change. (0.5 mark)
6. Return change. (0.5 mark)
7. If not enough, prompt for more money. (0.5 mark)
1e. Write an algorithm in pseudocode to determine the maximum of three numbers.
Pseudocode:
START
READ num1, num2, num3
IF num1 >= num2 AND num1 >= num3 THEN
max ← num1
ELSE IF num2 >= num1 AND num2 >= num3 THEN
max ← num2
ELSE
max ← num3
ENDIF
PRINT "Maximum is", max
STOP
(4 marks)
1f. Convert your pseudocode in (e) into a flowchart. (4 marks)
Answer:
(4 marks)
1g. Explain what makes an algorithm “good”. (2 marks)
Answer:
A good algorithm is:
Correct: Produces the right result for all valid inputs (1 mark)
Efficient: Uses minimal time and resources while being easy to understand (1 mark)
1h. Identify and explain any two characteristics of effective problem solvers. (2 marks)
Answer:
Analytical Thinking: Ability to break down problems into logical steps.
Creativity: Ability to think of innovative solutions when standard methods fail.
(1 mark each)
QUESTION 2 (Optional - 20 MARKS)
2a. Define the following problem-solving techniques:
i. Abstraction
ii. Analogy
iii. Divide and Conquer (6 marks)
Answers:
i. Abstraction
Abstraction in computing is the process of removing unnecessary details to focus on the essential
characteristics of a problem or system (Denning, 2019). In problem solving, it allows the designer to
generalize the problem so that the solution applies to a wide range of cases.
Example: In designing an online payment system, focusing on the general process of “authorizing
payment” without considering the internal API calls of each payment gateway. (2 marks)
ii. Analogy
Analogy involves solving a new problem by recognizing its similarity to a previously solved problem
and adapting the previous solution.
Example: Designing a food delivery tracking system by adapting the GPS tracking concepts from
ride-hailing apps. (2 marks)
iii. Divide and Conquer
Divide and Conquer is a strategy where a complex problem is broken into smaller, more manageable
sub-problems. Each sub-problem is solved independently, and the results are combined to form the
overall solution.
Example: Sorting an array using the Merge Sort algorithm. (2 marks)
2b. Write a pseudocode and draw a flowchart for checking if a given number is even or odd. (6 marks)
Answers:
Pseudocode (3 marks)
START
INPUT number
IF number MOD 2 = 0 THEN
PRINT "Number is even"
ELSE
PRINT "Number is odd"
ENDIF
END
Flowchart (3 marks)
Flowchart Elements:
Oval for Start/End
Parallelogram for Input number
Diamond for Condition: number MOD 2 = 0?
Parallelogram for output ("Even"/"Odd")
Proper connectors showing flow.
2c. Differentiate between flowcharts and pseudocode. When is each more appropriate? (4 marks)
Answers:
Flowcharts – Graphical representation of an algorithm using standard symbols to depict the sequence
of steps and decisions. Useful for visualizing complex logic and communicating ideas to non-
programmers. (2 marks)
Pseudocode – A structured, plain-language representation of an algorithm without formal syntax.
Best for quickly drafting or refining logic before coding, and for programmers familiar with language
structures. (2 marks)
2d. Describe two ways abstraction can improve software design. (4 marks)
Marking Guide & Solutions:
Hiding complexity – By abstracting implementation details, developers can work with high-level
concepts, reducing cognitive load. Example: Using a database ORM instead of raw SQL queries. (2
marks)
Reusability and scalability – Abstract designs can be reused in multiple contexts, making systems
easier to maintain and extend. Example: An abstract payment interface for multiple payment
providers. (2 marks)
QUESTION 3 (Optional - 20 MARKS)
3a. Define the following terms as used in problem solving:
i. Trial and Error
ii. Hypothesis Testing (4 marks)
Marking Guide & Solutions:
i. Trial and Error – A problem-solving method involving testing multiple solutions until the correct
one is found, without a systematic approach. Example: Guessing a forgotten password by trying
different options. (2 marks)
ii. Hypothesis Testing – A method where a proposed explanation (hypothesis) is tested through
experiments or observations, refining the hypothesis based on results. Example: Testing whether a
network issue is due to DNS misconfiguration. (2 marks)
3b. A user cannot log in to an account.
i. Describe a routine problem-solving approach.
ii. Describe a non-routine approach using hypothesis testing. (6 marks)
Answer:
i. Routine approach – Follow standard troubleshooting steps: check username/password, verify
Caps Lock, try password reset. (3 marks)
ii. Non-routine with hypothesis testing – Form a hypothesis (e.g., “The server authentication
module is down”), test by attempting logins from different accounts and checking server logs, then
refine or reject the hypothesis. (3 marks)
3c. Write a Python program that prompts the user for a number and prints whether it is positive,
negative, or zero. (6 marks)
Answer:
number = float(input("Enter a number: "))
if number > 0:
print("Positive")
elif number < 0:
print("Negative")
else:
print("Zero")
Correct syntax (2 marks)
Correct logic (2 marks)
Correct conditional structure (2 marks)
3d. Discuss two ways to test and debug the program in question 3c. (4 marks)
Answer:
Unit testing – Provide a set of inputs (positive, negative, zero) and check if outputs match expected
results. (2 marks)
Print statements/logging – Insert print/log messages to verify that the correct conditional branch
executes. (2 marks)
QUESTION 4 (Optional - 20 MARKS)
4a. Write an algorithm (in pseudocode) to calculate the factorial of a number using recursion. (4
marks)
Solution:
FUNCTION Factorial(n)
IF n == 0 THEN
RETURN 1
ELSE
RETURN n * Factorial(n - 1)
ENDIF
END FUNCTION
Base case (1 mark)
Recursive case (2 marks)
Function structure (1 mark)
4b. Implement the algorithm in:
i. C++ Programming
ii. Python (8 marks)
C++ Solution:
#include <iostream>
using namespace std;
int factorial(int n) {
if (n == 0)
return 1;
else
return n * factorial(n - 1);
}
int main() {
int num;
cout << "Enter a number: ";
cin >> num;
cout << "Factorial: " << factorial(num);
return 0;
}
(4 marks)
Python Solution:
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n - 1)
num = int(input("Enter a number: "))
print("Factorial:", factorial(num))
(4 marks)
4c. Explain two challenges commonly faced when debugging recursive programs. (4 marks)
Stack overflow errors – Can occur if base case is missing or incorrect, leading to infinite recursion.
(2 marks)
Tracing logic flow – Difficult to follow function calls without proper debugging tools due to
multiple nested calls. (2 marks)
4d. What are variables and data types? Provide two examples each from C or Python. (4 marks)
Variables – Named memory locations used to store data values. (1 mark)
Example: x = 10 (Python), int x = 10; (C). (1 mark)
Data types (1 mark) – Define the kind of data a variable can hold. (1 mark)
Examples: int, float in C; str, bool in Python. (1 mark)
QUESTION 5 (Optional - 20 MARKS)
5a. Define the following terms with examples:
i. Solvable Problem
ii. Unsolvable Problem (4 marks)
Answers:
Solvable Problem – A problem for which an algorithm can produce a correct solution in finite time.
Example: Sorting a list of numbers. (2 marks)
Unsolvable Problem – No algorithm can solve it for all inputs. Example: The Halting Problem. (2
marks)
5b. Using the example of checking if a number is prime, explain:
i. How it is a solvable problem
ii. How to write a simple algorithm for it (6 marks)
Solution:
i. Solvable – We can design an algorithm that checks divisibility from 2 to √n to determine primality.
(2 marks)
ii. Algorithm
START
INPUT number
IF number <= 1 THEN
PRINT "Not prime"
ELSE
FOR i = 2 TO sqrt(number)
IF number MOD i == 0 THEN
PRINT "Not prime"
STOP
ENDIF
NEXT i
PRINT "Prime"
END
(4 marks)
5c. Explain the Halting Problem and why it is classified as unsolvable. (4 marks)
The Halting Problem asks whether there exists an algorithm that can determine, for any given
program and input, whether the program will eventually stop or run forever (2 marks). Alan Turing
proved in 1936 that such an algorithm cannot exist, making it unsolvable (2 marks).
5d. List and explain any three limitations of computation in real-world problem solving. (6 marks)
Undecidability – Some problems, like the Halting Problem, cannot be solved by any algorithm. (2
marks)
Resource limits – Limited CPU speed, memory, and energy constrain computation. (2 marks)
Approximation needs – Some problems can only be solved approximately due to complexity or
incomplete data. (2 marks)