Problem Solving in Computer Science
Prologue
Solving problems is the core of computer science. Programmers must first understand how a
human solves a problem, then translate this 'algorithm' into something a computer can do, and
finally write the specific syntax required to get the job done. Machines may solve problems
differently from humans.
Problem solving uses generic or ad hoc methods in an orderly manner. Techniques from
philosophy, AI, computer science, engineering, and more relate to mental techniques studied in
psychology and cognitive sciences.
Problem Solving in Computer Science
Includes algorithms, heuristics, and root cause analysis.
Resources like time, memory, and energy are considered (computational complexity theory).
Tools include linear/non-linear programming, queuing systems, and simulation.
Debugging is a major part of the programming process.
Steps in Solving a Problem Using a Computer
1. Problem Analysis
2. Program Design – Algorithm, Flowchart, and Pseudocode
3. Coding
4. Compilation and Execution
5. Debugging and Testing
6. Program Documentation
1. Problem Analysis
Investigates a situation to understand and propose solutions.
Steps:
- Understand the problem
- Break it into parts
- Define problem goals
- Measure progress towards goals
2. Program Design
**Algorithm**: A finite, unambiguous sequence of steps for solving a problem. Optimal
algorithms can outperform non-optimal ones even on older hardware.
**Flowchart**: Diagrammatic representation of an algorithm using boxes and arrows.
**Pseudocode**: Human-readable steps resembling programming logic. Example (FizzBuzz):
for (i = 1; i <= 100; i++) {
set print_number to true;
if i is divisible by 3 {
print "Fizz";
set print_number to false;
}
if i is divisible by 5 {
print "Buzz";
set print_number to false;
}
if print_number, print i;
print a newline;
}
3. Coding
The process of writing code to perform tasks.
Involves analysis, algorithm generation, implementation, and resource management.
4. Compilation and Execution
**Compilation**: Converts high-level code into machine code using a compiler.
**Execution**: The computer runs instructions to solve the problem.
5. Debugging and Testing
**Debugging**: Finding and resolving errors in programs.
Techniques: interactive debugging, unit testing, log analysis, etc.
**Testing**: Ensures the software works as expected.
Tests: requirement validation, input handling, performance, usability, installability.
6. Program Documentation
Explains how software operates and how to use it.
Types:
- Requirements
- Architecture/Design
- Technical (code, API)
- End-user manuals
- Marketing materials