0% found this document useful (0 votes)
3 views7 pages

Problem Solving and Program Design Study Guide (Updated)

This study guide covers essential concepts in problem solving and program design, including algorithms, variables, constants, IPO charts, and pseudocode. It outlines algorithm representation methods, phases in problem solving, control structures, and types of loops. Additionally, it discusses data types, operators, and characteristics of good algorithms.

Uploaded by

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

Problem Solving and Program Design Study Guide (Updated)

This study guide covers essential concepts in problem solving and program design, including algorithms, variables, constants, IPO charts, and pseudocode. It outlines algorithm representation methods, phases in problem solving, control structures, and types of loops. Additionally, it discusses data types, operators, and characteristics of good algorithms.

Uploaded by

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

Problem Solving and Program Design Study Guide

Important Terms

Algorithm
A sequence of precise instructions which results in a solution to a problem
Must have finite number of steps, be precise, unambiguous, show flow of control, and terminate

Variables
An area of storage whose value can change during processing
Acts as a container for data
Examples: first_number, second_number, total

Constants
An area of storage whose value never changes during processing
Fixed values that remain the same throughout program execution

IPO Charts
Input-Processing-Output charts used to identify:

Inputs: The information needed to solve the problem

Processing: The steps needed to convert input data to desired outputs


Outputs: The goal of the problem solution

Pseudocode
Not an actual programming language
Uses short phrases and keywords close to programming language to write code before creating it in a
specific language

Algorithm Representation Methods


An algorithm can be represented in three ways:

1. Narrative
Uses normal English words to describe the algorithm steps
Written in plain language that anyone can understand
Example: "First, ask the user to enter three numbers. Then, add the three numbers together. Finally,
display the sum to the user."

2. Pseudocode
Uses keywords close to programming language
More structured than narrative but not actual code
Uses specific keywords for input, output, and processing

3. Flowcharts
Pictorial representation of an algorithm using symbols
Visual way to show the flow of data and decision points

Flowcharts
Pictorial representation of an algorithm using symbols to depict input, processing, and output of data

Phases in Problem Solving

Algorithm Phase
1. Define the problem

2. Propose and evaluate solutions


3. Determine the most efficient solution

4. Develop the algorithm

5. Test and validate the solution

Implementation Phase
1. Translate your algorithm using a programming language (BASIC, Pascal, C, Visual Basic)

2. Execute the program code


3. Maintain the program

How to Create IPO Charts

Structure
Input Processing Output

Identify all input data needed Identify processing steps to convert input to output Identify all outputs required
 

Examples
Example 1: Sum of Three Numbers

Input Processing Output

n1, n2, n3 sum := n1+n2+n3 sum


 

Example 2: Rectangle Area

Input Processing Output

l (length), w (width) area := l * w area


 

Example 3: Discount Calculation

Input Processing Output

discount_amt := regular_price * 0.20<br>discounted_price := discount_amt,


regular_price
regular_price - discount_amt discounted_price
 

Data Types of Variables


Data Type Possible Values Examples

Integer Positive or negative whole numbers without decimal places 0, -27, 540

Real Positive or negative numbers with decimal places 13.5, 3.1472, -8.0

Character Any single letter, number or symbol 'D', 'k', '#', '@'

String A group of characters 'Frank', 'Ruth', '925-0000'

Boolean Two possible values True/False, Yes/No


 

Keywords for Input and Output Statements

Input Statements
input

accept

read

Output Statements
output

print

display

write
Assignment Statements
set

store

:=

Characteristics of a Good Algorithm


1. Finite - Limited in size/number of steps

2. Precise - Clear and exact instructions

3. Unambiguous - Clear meaning, no confusion

4. Flow of control - Clear progression from one process to another

5. Terminate - Must come to an end

Control Structures
Control structures determine how the flow of control from one statement would take place. They are:

1. Sequence Control Structure


Sequential statements are executed one after the other from the first statement to the last

2. Selection/Conditional Branching
The selection control structure/conditional branching is used when a certain condition has to be met or if
you have a choice between two options. It uses two statements:

the if..then..endif statement

the if..then..else..endif statement

IF-THEN Statement

The IF-THEN statement suggests that one or more statements will only be considered based on a
condition or the answer to a question.

if (the condition is true)


then (carry out one or more statement)
endif (used to end the if-then statement)

IF-THEN-ELSE Statement
The IF-THEN-ELSE statement directs the algorithm to one or more statements if the outcome of the
condition is true. The algorithm is directed to another set of statements if the outcome of the condition is
false.

if (the condition is true)


then (carry out one or more statements)
else (carry out one or more statements)
endif

Nested Conditions

Nested conditions involves the use of IF-THEN or IF-THEN-ELSE statements, either separately or
combined.

3. Looping/Repetition/Iteration
Looping means that an algorithm will keep repeating itself until a certain condition is satisfied or met.

There are two types of loop statements:

Definite: when you know in advance how many times to repeat the loop (FOR-DO loop)

Indefinite: When you do not know in advance how many times to repeat the loop (WHILE or REPEAT
loops)

FOR-DO Loop (Definite)

The FOR-DO loop is used only when the start value and the end value are known.

for <variable> = <start value> to/downto <final value> do


statement(s)
endfor

WHILE-DO Loop (Indefinite)

Condition tested at the top of the loop

Loop is repeated as long as the condition is true

The loop will stop when the condition becomes false

So it is possible for the statement not be executed at all


while (condition is true) do
statement(s)
endwhile

REPEAT-UNTIL Loop (Indefinite)

Condition tested at the end of the loop

Loop is repeated as long as the condition is false

So the statement will always be executed at least once

repeat
statement(s)
until (condition is true)

Truth Tables

OR Operator
For OR table, only 1 value needs to be true for result to be true.

A B A OR B

TRUE TRUE TRUE

TRUE FALSE TRUE

FALSE TRUE TRUE

FALSE FALSE FALSE


 

AND Operator
For AND table, both values must be true for result to be true.

A B A AND B

TRUE TRUE TRUE

TRUE FALSE FALSE

FALSE TRUE FALSE

FALSE FALSE FALSE


 

NOT Operator
For NOT table, values are opposite.
A NOT A

TRUE FALSE

FALSE TRUE
 

Operators

Relational Operators
< (Less than)

> (Greater than)


= (Equal to)

<= (Less than or equal to)


>= (Greater than or equal to)
<> (Not equal to)

Logical Operators
AND
OR

NOT

Arithmetic Operators
+ (Addition)
- (Subtraction)

* (Multiplication)
/ (Division)

MOD (Integer remainder - gives fractional part)


DIV (Integer division - discards fractional part)

You might also like