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

Algorithms Study Guide

This document serves as a study guide for COS 102, focusing on problem solving and algorithm design through algorithms and flowcharts. It defines an algorithm, outlines its essential properties, and provides examples of algorithms and corresponding flowcharts. Additionally, it includes practice problems to reinforce the concepts learned.

Uploaded by

adogwujoy2
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)
4 views7 pages

Algorithms Study Guide

This document serves as a study guide for COS 102, focusing on problem solving and algorithm design through algorithms and flowcharts. It defines an algorithm, outlines its essential properties, and provides examples of algorithms and corresponding flowcharts. Additionally, it includes practice problems to reinforce the concepts learned.

Uploaded by

adogwujoy2
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

COS 102 · PROBLEM SOLVING & ALGORITHM DESIGN

Algorithms &
Flowcharts
A complete visual study guide — from concept to worked
examples

0 1 C O R E CONCEPTS

What is an Algorithm? "


An algorithm is a finite, ordered set of well-defined instructions for solving
a problem or completing a task. Every algorithm must have a clear starting
point, produce a result, and eventually stop. Think of it as a recipe your
computer can follow.

0 2 T H R E E MUST-HAVE PROPERTIES

01

Clear
Each step must be unambiguous — only one way to interpret it, no guessing.

02
Finite
The algorithm must end after a limited number of steps — it cannot run forever.

03

E!ective
Every step must be simple enough to actually be carried out — no impossible operations.

0 3 E X A M P LE ALGORITHM — FIND THE LARGEST OF TWO NUMBERS

ALGORITHM

// Find the Larger of Two Numbers A and B

1. START

2. INPUT two numbers A and B from the user

3. IF A > B THEN

PRINT "A is the larger number"

ELSE

PRINT "B is the larger number"

END IF

4. STOP

0 4 F L O W C HART SYMBOLS REFERENCE

SHAPE NAME & TYPE

PURPOSE

Terminal
Terminal
OVAL / ROUNDED RECT

Process
RECTANGLE

Decision
DIAMOND

Input / Output
PARALLELOGRAM

Flow Line
ARROW

0 5 C O M P L ETE FLOWCHART EXAMPLE

Finding the Larger of Two Numbers


The same algorithm from Section 03 — now drawn as a flowchart
START

INPUT A and B

YES Is A > B? NO
(Decision)

PRINT "A is PRINT "B is


larger" larger"

merge

STOP

LEGEND
Terminal Decision Input/Output Flow

0 6 S E C O N D EXAMPLE — GRADE CLASSIFICATION

ALGORITHM

// Classify a student's score out of 100

1. START

2. INPUT score from user


3. IF score >= 70 THEN PRINT "Distinction"

ELSE IF score >= 60 THEN PRINT "Credit"

ELSE IF score >= 50 THEN PRINT "Pass"

ELSE PRINT "Fail"

END IF

4. STOP

0 7 K E Y R ULES TO REMEMBER

⬭ Always Start & End with an Oval


Every flowchart must open with START and close with STOP — no exceptions.

Diamonds Have Two Exits Only


Every decision shape must branch into exactly YES and NO — nothing else.

Arrows Show Direction


Flow lines must always point somewhere. Logic only flows in one direction at a
time.

Algorithm = Flowchart

They represent the same logic — one in words, one in pictures. Use both to verify
your thinking.

0 8 P R A C T ICE PROBLEMS

PRACTICE PROBLEM 01 — EVEN OR ODD BEGINNER


Task: Write an algorithm and draw a flowchart that takes a number as input and
determines whether it is Even or Odd.

Hint: A number is even if the remainder when divided by 2 equals zero (use the
MOD operator).

Step 1: START
Step 2: INPUT number N
Step 3: IF N MOD 2 = 0 THEN PRINT "Even"
ELSE PRINT "Odd"
END IF
Step 4: STOP

PRACTICE PROBLEM 02 — SUM OF 1 TO N INTERMEDIATE

Task: Write an algorithm that reads a positive integer N and calculates the sum of
all numbers from 1 to N.

Hint: You will need a loop (repetition). Use a counter variable that starts at 1 and
keeps adding until it reaches N.

Step 1: START
Step 2: INPUT N
Step 3: SET Sum = 0, Counter = 1
Step 4: WHILE Counter <= N DO
Sum = Sum + Counter
Counter = Counter + 1
END WHILE
Step 5: PRINT Sum
Step 6: STOP
QUICK REFERENCE

Cheat Sheet

Algorithm
A finite, ordered set of steps to solve a problem

Flowchart
A visual diagram representing an algorithm using shapes

Oval
Start / Stop — appears exactly twice

Rectangle
Process — calculations and assignments

Diamond
Decision — always has YES and NO branches

Parallelogram
Input / Output — reading or displaying data

Properties
Clear · Finite · Effective

Flow Lines
Arrows connecting shapes — must always point somewhere

COS 102 · Problem Solving & Algorithm Design · Study Guide

You might also like