Master algorithms, flowcharts, data structures, and Python programming
Press → or swipe to continue
An algorithm is a step-by-step set of instructions designed to solve a problem or complete a task.
Variables are named storage locations that hold values which can be changed.
x = 529
y = 256
z = x + y
print(z)
Flowcharts use standard shapes to represent different operations:
Addition Algorithm with User Input - Click to Animate
The swap algorithm exchanges values of two variables without losing data.
Imagine swapping contents of two cups - you need a temporary cup to hold one drink while you pour!
# Swap Algorithm
a = 49
b = 61
print(f"Original: a={a}, b={b}")
# Swap using temporary variable
temp = a
a = b
b = temp
print(f"After swap: a={a}, b={b}")
# Version 2: User Input
a = input("Enter a value for a: ")
b = input("Enter a value for b: ")
print(f"Original: a={a}, b={b}")
temp = a
a = b
b = temp
print(f"After swap: a={a}, b={b}")
Arrays organize data in a linear sequence, like items in a market list.
A collection of elements stored at contiguous memory locations. Each element can be accessed by its index (position).
# Creating an array in Python
foods = ["Akple", "Fufu", "Kenkey", "Banku"]
print(foods[0]) # Output: Akple
print(foods[2]) # Output: Kenkey
# Reverse array example
activities = ["Morning jog", "Breakfast", "Study"]
print("Original:", activities)
# Using built-in reverse method
activities.reverse()
# Output each element
for activity in activities:
print(activity)
.reverse() method modifies the array in place!
# Count occurrences in array
computerList = ["tablet", "desktop", "tablet",
"smartphone", "supercomputer", "tablet"]
# Count specific items
toCheck1 = "tablet"
toCheck2 = "mainframe"
print(f"Number of {toCheck1}: {computerList.count(toCheck1)}")
print(f"Number of {toCheck2}: {computerList.count(toCheck2)}")
| Format | Best For | Advantage |
|---|---|---|
| Pseudocode | Planning & Communication | Language independent, easy to understand |
| Flowchart | Visualizing Logic | Shows flow clearly, visual representation |
| Program Code | Computer Execution | Can be run by computer, produces actual results |
Pseudocode → Flowchart → Code
| Criteria | Linear | Non-Linear |
|---|---|---|
| Data Arrangement | Sequential (one after another) | Hierarchical or interconnected |
| Traversing | Single run (one path) | Multiple paths possible |
| Examples | Arrays, Lists, Stacks, Queues | Trees, Graphs, Tables |
Create an algorithm to calculate rectangle area
# Complete algorithm implementation
def calculate_rectangle_area(length, width):
"""Calculate and return rectangle area"""
area = length * width
return area
# Get user input
length = float(input("Enter length: "))
width = float(input("Enter width: "))
# Calculate area
result = calculate_rectangle_area(length, width)
# Display result
print(f"The area of the rectangle is: {result}")
The more you practice, the better you become at computational thinking!
You now have the foundation for
Computational Thinking & Programming!
Press ESC for overview
to navigate slides
Swipe on mobile devices