COS 102

concept of problem solving; lecture 1 week 2

Learn about concept of problem solving; lecture 1 week 2 in COS 102. Comprehensive study materials and practice questions.

Study notes included Document available CBT practice ready

Study Document

Open full

Study Notes

COS 102

Course Information

  • Course Codes: COS 102 / CSC 120
  • Course Title: Computer as a Problem-Solving Tool
  • Topic: Concept of Problem Solving
  • Lecture: Lecture 1, Week 2
  • Lecturer: Dr. Ufuoma C. Ogude
  • Department: Computer Sciences, University of Lagos

Outlines of the Course (Weeks 2-7)

  • Concept of Problem solving
  • Introduction to programming
  • Concept & properties of Algorithm
  • Fundamentals of programming (1): variable/variable naming convention/data types in Python
  • Fundamentals of programming (2): operators and expressions
  • Fundamentals of programming (3): control structures

Topic 1: Concept of Problem Solving

Sub-topics:

  • Classes of problem
  • Problem Solving Tools
  • Debugging Strategies

Understanding the Problem: Ask Questions

To fully understand a problem, consider asking the following questions:

  • What do I know about the problem?
  • What is the information that I have to process in order to find the solution?
  • What does the solution look like?
  • What sort of special cases exist?
  • How will I recognize that I have found the solution?

Definition of Problem Solving

Problem solving is the act of finding a solution to a perplexing, distressing, vexing, or unsettled question.

  • Computers can solve problems by performing billions of operations per second.
  • A programmer's job is to find solutions by breaking down problems into easy-to-follow steps for a computer.

Concept of Problem Solving (Detailed)

Problem solving is the act of:

  • defining a problem;
  • determining the cause of the problem;
  • identifying, prioritizing (ranking, ordering), and selecting alternatives for a solution;
  • and implementing a solution.

Problem Solving Tools

  • Problem-solving is the process of transforming the description of a problem into a solution by using our knowledge of the problem domain and by relying on our ability to select and use appropriate problem-solving strategies, techniques and tools.
  • Programming is a problem solving activity. When we write a program, we are actually writing an instruction for the computer to solve something for us.
  • Using a computer as a problem solving tool following steps are involved.

Problems, Solutions, and Tools (Computer Context)

The basic process for problem-solving with computers involves:

  • A computer is a tool that can be used to implement a plan for solving a problem.
  • A computer program is a set of instructions for a computer. These instructions describe the steps that the computer must follow to implement a plan.
  • An algorithm is a plan for solving a problem.
  • A person must design an algorithm.
  • A person must translate an algorithm into a computer program.

Problem Solving Process (General)

The problem-solving process typically involves these steps:

  1. Identify the Problem
  2. Analyze the Problem
  3. Develop the Solutions
  4. Implement a Solution
  5. Evaluate The Results
  6. Standardize The Solution (and Capitalize on New Opportunities)

Design of Algorithms

  • A person must translate an algorithm into a computer program.
  • An Algorithm: A sequence of instructions describing how to do a task (or process).

Debugging

Debugging in problem solving is the process of fixing a bug in the software.

  • It refers to identifying, analyzing and removing errors.
  • This activity begins after the software fails to execute properly and concludes by solving the problem and successfully testing the software.
  • Debugging is the process of finding and resolving bugs (defects or problems that prevent correct operation) within computer programs, software, or systems.

Debugging and Testing

Testing and debugging go together:

  • Testing finds errors; debugging localizes and repairs them.
  • Together these form the "testing/debugging cycle": we test, then debug, then repeat.
  • Any debugging should be followed by a reapplication of all relevant tests, particularly regression tests. This avoids (reduces) the introduction of new bugs when debugging.
  • Testing and debugging need not be done by the same people (and often should not be).

Debugging Process

Steps involved in the debugging process:

  1. Reproduce the problem.
  2. Describe the bug. Try to get as much input from the user to get the exact reason.
  3. Capture the program snapshot when the bug appears.
  4. Analyze the snapshot based on the state and action.
  5. Fix the existing bug, but also check that any new bug does not occur.

Errors in Debugging

Common types of errors in programs:

  • Syntax Errors: Identified by the compiler at the program compilation time (e.g., grammatical mistakes in the code).
  • Logical Errors: Not identified by the compiler at compile time and identified at the execution time (e.g., misuse of operators, incorrect calculations).

Testing is the process of checking the program for its correct functionality by executing the program with some input data set and observing the output of the program.

Why Debugging is Hard

Debugging can be challenging due to several reasons:

  • There may be no obvious relationship between the external manifestation(s) of an error and its internal cause(s).
  • Symptom and cause may be in remote parts of the program.
  • Changes (new features, bug fixes) in a program may mask (or modify) bugs.
  • Symptom may be due to human mistake or misunderstanding that is difficult to trace.
  • Bug may be triggered by rare or difficult-to-reproduce input sequence, program timing (threads) or other external causes.
  • Bug may depend on other software/system state, things others did to your systems weeks/months ago.

Assignment

Explain with a detailed example the Classes of problem.

Computer Problem-Solving Process (6 Steps)

  1. Understand the Problem
  2. Formulate a Model
  3. Develop an Algorithm
  4. Write the Program
  5. Test the Program
  6. Evaluate the Solution

Computer Problem-Solving: Example (Calculate Average Grade)

Problem: Calculate the average grade for all students in a class.

  1. Input: Get all the grades (e.g., by typing them in, reading from a USB flash drive or hard disk).
  2. Process: Add all the grades up and compute the average grade.
  3. Output: Output the answer (e.g., to the monitor, printer, USB flash drive, or hard disk, or a combination).

PS Step 1: Understand Problem (Detailed Questions for Example)

  • What input data/information is available?
  • What does it represent?
  • What format is it in?
  • Is anything missing?
  • Do I have everything that I need?
  • What output information am I trying to produce?
  • What do I want the result to look like ... text, a picture, a graph ...?
  • What am I going to have to compute?

PS Step 2: Formulate a Model (for Average Grade)

Assuming input data are integers or real numbers (X1, X2, ..., Xn) representing grade percentages, the computational model is:

Average = (X1 + X2 + X3 + ... + Xn) / n

Where the result will be a number from 0 to 100.

PS Step 3: Develop an Algorithm

It's time to come up with a precise plan of what the computer should do.

  • An algorithm is a precise sequence of instructions for solving a problem.

PS Step 4: Write the Program (Pseudocode & Example Code)

Pseudocode:

  1. set the sum of the grade values to 0.
  2. load all grades X1 ... Xn from file.
  3. repeat n times {
  4.   get grade Xi
  5.   add Xi to the sum
  6. }
  7. compute the average to be sum / n.
  8. print the average.

Processing Code (i.e., program - example in Java-like syntax):

int sum = 0;
byte[] x = loadBytes("numbers");
for (int i=0; i<x.length; i++) {
    sum = sum + x[i];
}
int avg = sum / x.length;
print(avg);

PS Step 5: Test the Program

  • Running a program is the process of telling the computer to evaluate the compiled instructions.
  • If the program works, you should see the correct output.
  • If output is incorrect, it could be due to:
    • Improper conversion of algorithm to program.
    • An improper algorithm that doesn't handle all situations.
    • Instructions out of sequence.
  • Such problems are known as bugs.
  • Bugs are problems/errors with a program that cause it to stop working or produce incorrect or undesirable results.
  • To find bugs effectively, test with many test cases (a test suite).
  • Having others test the program can reveal situations you didn't consider.
  • The process of finding and fixing errors in code is called debugging.
  • Carefully following problem-solving steps 1-3 can greatly reduce bugs and make debugging easier.

PS Step 6: Evaluate Solution & Practice Exercises

Once your program produces a seemingly correct result, reconsider the original problem to ensure the answer is formatted as a proper solution. You might realize the solution doesn't fully meet the initial requirements or that more steps are needed.

Practice Exercises:

Formulate a model and then develop an algorithm for each of the following problems. Start with a simple algorithm and then consider potential issues and make adjustments. There is no single "right" answer; solutions will be unique.

  1. Making a peanut butter and jam sandwich
  2. Putting together a jigsaw puzzle
  3. Playing the game of musical chairs
  4. Replacing a flat tire on your car
  5. Getting home from school today
  6. Emptying a case of drinks into your refrigerator
  7. Shopping for groceries (from entering store to leaving store)

Test Your Knowledge

Challenge yourself with targeted practice questions and accelerate your mastery of concept of problem solving; lecture 1 week 2.

Practice CBT Study Flashcards