Comprehensive Study Guide for Problem Solving and Program Development
Fundamentals of Problem Solving in Computer Science
- The Core of Computer Science: Solving problems is considered the heart of the discipline. To effectively solve a problem using a computer, a programmer must follow a specific progression:
- Understand how a human solves the specific problem.
- Translate that human logic into an "algorithm" that a computer can conceptually follow.
- Write the specific syntax required by a computer to execute the task.
- Human vs. Machine Logic: It is important to note that a machine may solve a problem in a way that is completely different from a human approach.
- Requirements for Problem Solving:
- Identify how to represent the information or data describing the problem.
- Determine the necessary steps to transform information from one representation into another.
- Plan and document the solution as an algorithm.
- Primary Tools: Programmers utilize two main tools for problem-solving: the flowchart and pseudocode.
Algorithms and Statement Constructs
- Definition: An algorithm is defined as a procedure, formula, recipe, or a set of specific, ordered instructions used to solve a problem.
- Execution Control: A robust algorithm must have the ability to alter the order in which instructions are executed.
- The Three Statement Constructs:
- Sequential: Instructions executed one after another in a linear path.
- Conditional: Decision-making points that branch the logic based on specific criteria.
- Iteration: Repetitive execution of steps (loops).
The Software Development Cycle (SDLC)
- Overview: Developing a program involves a sequence of phases known as the program development life cycle (PDLC) or software development cycle. Although generally cited as having 6 phases, the framework encompasses the following 7 stages:
- Problem Definition
- Program Design
- Coding
- Debugging
- Testing
- Documentation
- Maintenance
Phases of Program Development
- Problem Definition:
- This is the initial step involving thorough identification and formal definition of the problem.
- Factors to consider: Input/Output (I/O), processing requirements, memory requirements, error handling, and interfacing with other programs.
- Program Design:
- Developers create the design or blueprint of the program logic.
- Primary tools used are algorithms and flowcharts.
- Coding:
- The design is translated into instructions using a specific computer programming language.
- Coding is often a small and less time-consuming part of the overall process.
- Goal: Eliminate syntax errors (spelling, missing commas, undefined labels).
- Coding Guidelines:
- Use meaningful names and labels for variables.
- Write simple and clear expressions.
- Emphasize modularity (generalized modules).
- Utilize comments and proper indentation.
- Avoid jumps to transfer control within the program.
- Debugging (Program Validation):
- This is the process of detecting and correcting errors in the program.
- Common Errors:
- Uninitialized variables.
- Reversing the order of operands.
- Confusion between numbers and characters.
- Inverting conditions (e.g., jumping on zero instead of not zero).
- Testing:
- The program is executed against various test cases.
- A test plan should be established during the Program Design stage.
- Identify and test trivial cases, special cases, and boundary values (maximum and minimum values for all variables).
- Documentation:
- Essential for users and maintenance personnel.
- Ensures that future modifications, redesigning, or maintenance can be performed easily.
- Maintenance:
- Accounts for updating and correcting the program based on changed conditions or field experience.
- Required when: Specifications change, equipment changes, or errors are found during actual program execution.
Flowcharts: Graphical Representation
- Definition: A flowchart is a graphical or visual representation of an algorithm charting the logical flow of activities.
- Flowchart Symbols:
- Start/End (Terminator): An oval or rounded shape representing the start points, end points, and potential outcomes of a path.
- Process (Action Symbol): A rectangle representing a process, action, or function; the most commonly used symbol.
- Input/Output (Data Symbol): A parallelogram representing data available for input or output, as well as resources used or generated.
- Decision Symbol: A diamond shape indicating a question (usually Yes/No or True/False) that splits the flowchart into different branches.
- Connector Symbol: A circle used in complex charts to connect separate elements across a single page.
- Flow Line: Arrows showing the direction of the process, connecting two blocks.
- Flowchart Example (Sum of Two Numbers):
- START (Terminator)
- INPUT A, B (I/O Symbol)
- C=A+B (Process Symbol)
- DISPLAY C (I/O Symbol)
- STOP (Terminator)
Flowchart Best Practices and Evaluation
- Design Rules:
- Concentrate on logic first; draw the main path.
- Maintain a consistent level of detail; exclude minute details in favor of essential steps.
- Use common, easy-to-understand words.
- Ensure variable names are used consistently (A,B,C).
- Flow should move from left-to-right and top-to-bottom.
- There must be exactly one START point and one STOP point.
- Symbols must be appropriately sized and named.
- Advantages:
- Easy to understand and analyze the problem.
- Effective for joining different logic parts.
- Facilitates systematic coding, debugging, and testing.
- Disadvantages:
- Can be time-consuming to document.
- Difficult to modify once drawn.
- Lack of universal standards.
Pseudocode: The Logical Method
- Definition: "Pseudo" implies false; pseudocode is not actual code. It is an algorithm writing method using a standard set of words to resemble code without being executable.
- Structure and Keywords:
- Must start with BEGIN or START and end with END or STOP.
- Phrases are written in English and indented for readability.
- Keywords:
- INPUT or READ: Accept a value from a user.
- DISPLAY, WRITE, or PRINT: Output a value.
- Constructs: A collective set of instructions in pseudocode is called a construct. The three types are sequence, selection, and iteration.
- Pseudocode Example (Sum of Two Numbers):
- BEGIN
- INPUT A, B
- C=A+B
- DISPLAY C
- END
Pseudocode Best Practices and Evaluation
- Writing Rules:
- The pseudocode should be understandable by non-programmers.
- Variables must be self-descriptive; avoid abbreviations.
- Only logical steps should be shown, not actual programming syntax.
- Each statement goes on its own line.
- Keywords, procedure names, and module names should be capitalized (e.g., DISPLAY, END).
- Use indentation to show the logical hierarchy.
- Advantages:
- Quick and easy to create since there are no symbols or strict syntax.
- Easy to translate into actual programming code.
- Disadvantages:
- Lack of industry standards.
- Does not focus on the "big picture" or overall visual flow as well as flowcharts.