Loading Interactive Experience...
Swipe to navigate
1/20

🚀 Computational Thinking

Algorithms & Programming Logic

Master algorithms, flowcharts, data structures, and Python programming

Press → or swipe to continue

What is an Algorithm?

An algorithm is a step-by-step set of instructions designed to solve a problem or complete a task.

Types of Algorithms:

1
Sorting Algorithms: Arrange elements in order (e.g., alphabetical)
2
Mathematical Algorithms: Perform calculations (average, sum, area)
3
Encryption Algorithms: Encode data for security
4
Search Algorithms: Find specific elements in data
Key Requirements: Clear, Ordered, Finite, and Effective!

Variables: Storage Containers

Variables are named storage locations that hold values which can be changed.

529
+
256
=
?

Algorithm Example: Addition

Pseudocode:

1
Assign x the value 529
2
Assign y the value 256
3
Assign z the sum of x and y
4
Output the value of z

Python Code:

x = 529
y = 256
z = x + y
print(z)
Output: 785

Flowchart Symbols

Flowcharts use standard shapes to represent different operations:

Start/End
Terminal (Oval) Marks the Start/End of a program
Process
Rectangle Represents a Process/Action step
Input/Output
Parallelogram Used for Input/Output operations
Decision
Diamond Decision point / Conditional statement
Remember: Arrows connect shapes and show the program's flow direction

Interactive Flowchart

Addition Algorithm with User Input - Click to Animate

START Input x Input y z = x + y Output z END
Symbols:
🟩 Terminal
🟦 Process
🟪 Input/Output

Swap Algorithm

The swap algorithm exchanges values of two variables without losing data.

Real-World Analogy:

Imagine swapping contents of two cups - you need a temporary cup to hold one drink while you pour!

Swap Steps:

1
Temp = A - Store first value in temporary variable
2
A = B - Copy second value to first variable
3
B = Temp - Copy temporary value to second variable
Important: Without a temporary variable, we'd lose the original value of A!

Interactive Swap Demo

🍊 Orange
🥭 Mango

Python Code:

# 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}")

Swap: User Input Version

# 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}")

Data Structures: Arrays

Arrays organize data in a linear sequence, like items in a market list.

What is an Array?

A collection of elements stored at contiguous memory locations. Each element can be accessed by its index (position).

Example Array:

Akple
[0]
Fufu
[1]
Kenkey
[2]
Banku
[3]
# Creating an array in Python
foods = ["Akple", "Fufu", "Kenkey", "Banku"]
print(foods[0])  # Output: Akple
print(foods[2])  # Output: Kenkey

Array Operations

1
Reverse: Reverse the order of elements
2
Sort: Arrange elements in order
3
Search: Find specific elements
4
Count: Count occurrences of an element
5
Copy: Duplicate the array
Tablet
Desktop
Smartphone
Supercomputer

Reversing an Array

# 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)
The .reverse() method modifies the array in place!

Counting Occurrences

# 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)}")
Result: "tablet" appears 3 times, "mainframe" appears 0 times

Three Algorithm Representations

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

All Three = Same Solution!

Pseudocode → Flowchart → Code

Data Structure Classifications

Linear vs Non-Linear:

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
Arrays are linear data structures - elements arranged in sequence!

Practice Activity

🎯 Challenge: Rectangle Area Calculator

Create an algorithm to calculate rectangle area

10
×
5
=
?

Complete Python Example

# 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}")
This code demonstrates: Functions, Input/Output, Variables, and Calculations

Key Takeaways

Variables

  • ✓ Storage containers
  • ✓ Have names & values
  • ✓ Can change
  • ✓ Use = for assignment

Algorithms

  • ✓ Step-by-step instructions
  • ✓ Clear and ordered
  • ✓ Finite and effective
  • ✓ Three representations

Data Structures

  • ✓ Organize data
  • ✓ Arrays are linear
  • ✓ Enable efficient operations
  • ✓ Essential for programming

What You've Learned

Algorithms: Step-by-step problem solving
Flowcharts: Visual algorithm representation
Variables: Data storage and manipulation
Swap Algorithm: Exchanging values safely
Arrays: Linear data structures and operations
Python Programming: Implementing algorithms in code

🚀 Keep Practicing!

The more you practice, the better you become at computational thinking!

🎉 Congratulations!

You've Completed the Course!

You now have the foundation for
Computational Thinking & Programming!

Press ESC for overview
to navigate slides
Swipe on mobile devices