0% found this document useful (0 votes)
14 views9 pages

Marking Guide for CSC 121 Exam

Question and Marking guide for problem solving will be useful to students and lecturers in Nigerian universities and beyond.

Uploaded by

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

Marking Guide for CSC 121 Exam

Question and Marking guide for problem solving will be useful to students and lecturers in Nigerian universities and beyond.

Uploaded by

ibrahim Paramole
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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)

Common questions

Powered by AI

Common challenges in debugging recursive programs include stack overflow errors, which can occur if the base case is missing or incorrect and results in infinite recursion . Another challenge is tracing the logic flow, as it becomes difficult to follow function calls without proper debugging tools due to multiple nested calls . These can be mitigated by ensuring a correct base case is defined and using debugging tools or inserting print statements to track the flow of recursion.

Approximation becomes necessary in real-world computational problem-solving when dealing with problems of high complexity or incomplete data, where exact solutions are infeasible due to time or resource constraints. For example, problems that require processing massive datasets may rely on approximation algorithms to deliver near-optimal solutions within practical limits. This necessity underscores the balance between accuracy and efficiency in resource-constrained environments .

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 continue running indefinitely. Alan Turing proved in 1936 that such an algorithm cannot exist, thus classifying the problem as unsolvable . This unsolvability highlights the limits of computation and mathematical logic, illustrating inherent constraints in algorithmic problem solving.

Pseudocode is more appropriate when quickly drafting or refining logic before coding, particularly for programmers familiar with language structures, as it provides a structured, plain-language representation of an algorithm without formal syntax . In contrast, flowcharts use graphical representations with standard symbols, useful for visualizing complex logic and communicating ideas to non-programmers . The key difference lies in their format and primary use: pseudocode is text-based and suitable for pre-coding stages, while flowcharts are visual and ideal for illustrating processes.

A good algorithm is characterized by being correct, meaning it produces the right result for all valid inputs, and being efficient, which involves using minimal time and resources while being easy to understand . These characteristics are important because they ensure the algorithm consistently solves the problem accurately and does so without unnecessary resource consumption, facilitating better performance and maintainability.

The Divide and Conquer strategy is significant in problem-solving, as it involves breaking down a complex problem into smaller, more manageable sub-problems, solving each independently, and then combining the results. This approach simplifies the process and can enhance efficiency, for example, in sorting algorithms like Merge Sort . It is applicable in various scenarios where the problem can be recursively divided, such as in optimizing large-scale computations and ensuring parallel processing.

In non-routine problem-solving, hypothesis testing is used by forming a hypothesis about the root cause of a problem, testing it through experiments or observations, and refining it based on results. For instance, if a user cannot log into an account, the hypothesis might be that the server authentication module is down. This can be tested by attempting logins from different accounts and checking server logs, helping refine or reject the hypothesis . This method encourages deep analysis and systematic exploration of potential issue causes.

Abstraction improves software design by hiding complexity, allowing developers to focus on high-level concepts and reducing cognitive load. This is exemplified by using a database ORM instead of raw SQL queries . Abstraction also enhances reusability and scalability, permitting systems to be easily maintained and extended, such as through an abstract payment interface that supports multiple payment providers .

Routine problems have known, repeatable methods of solution, often addressed by applying standard formulas or procedures, such as calculating the total bill in a supermarket using addition . Non-routine problems require creative thinking or novel approaches since there may be no standard method to solve them, such as designing a secure authentication system for an online banking platform . These differences affect problem-solving by determining whether familiar strategies can be applied or whether innovative solutions are necessary.

Solvable problems are those for which an algorithm can produce a correct solution in finite time, such as sorting a list of numbers . Unsolvable problems are those for which no algorithm can solve them for all inputs, exemplified by the Halting Problem, where it's impossible to create an algorithm that determines if any given program will halt or run indefinitely . These distinctions are fundamental in understanding the limits of computation and guiding research and development toward achievable goals.

You might also like