0% found this document useful (0 votes)
3 views

Problem Solving

Uploaded by

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

Problem Solving

Uploaded by

atuwootindo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Computational Thinking, Problem-Solving, and Programming

Introduction: Computational thinking is an essential skill for solving problems effectively, not
just in programming but also in everyday life. It helps us break down complex tasks, analyze
patterns, and use logical steps to arrive at solutions.

The Big Ideas in Computational Thinking

1. Thinking Procedurally

Definition: Procedural thinking refers to breaking down a problem into a series of smaller,
manageable tasks. In programming, this is like dividing a program into functions, each
responsible for a specific part of the task.

Analogy: Consider making a sandwich. Instead of just trying to do it all at once, we break it into
steps.

Example: To make a peanut butter and jelly sandwich:

 Get two slices of bread.


 Open the peanut butter jar.
 Spread peanut butter on one slice.
 Open the jelly jar.
 Spread jelly on the other slice.
 Put the two slices together.
 Optionally, cut the sandwich diagonally for better taste!

Programming Perspective: In programming, procedural thinking means dividing a big problem


(e.g., sorting a list) into smaller tasks (e.g., compare two elements, swap them if necessary).

Python Example:

python
Copy code
def make_sandwich():
print("Get two slices of bread.")
print("Spread peanut butter on one slice.")
print("Spread jelly on the other slice.")
print("Put the slices together.")
print("Cut the sandwich.")

make_sandwich()

2. Decisions
Definition: Decision-making involves selecting actions based on certain conditions. In
programming, this is implemented using conditional statements like if and else.

Example: You want to check if a number is positive, negative, or zero:

python
Copy code
number = int(input("Enter a number: "))

if number > 0:
print("The number is positive.")
elif number < 0:
print("The number is negative.")
else:
print("The number is zero.")

Key Takeaway: Conditional statements help the program "decide" which path to follow based
on the input or environment.

3. Thinking Logically

Definition: Logical thinking helps in understanding cause and effect, applying rules, and
arriving at a correct solution systematically. It’s crucial for designing correct algorithms.

Example: Imagine creating a program that only accepts even numbers. You need to apply the
logic that an even number is divisible by 2.

Python Example:

python
Copy code
number = int(input("Enter a number: "))

if number % 2 == 0:
print(f"{number} is an even number.")
else:
print(f"{number} is an odd number.")

Programming Benefit: In debugging, logical thinking helps identify the root cause of errors by
tracing the flow of logic in the code.

4. Thinking Ahead

Definition: Thinking ahead is anticipating possible scenarios or problems before they happen.
This improves the robustness of programs, making them more user-friendly and reliable.
Example: When creating a user input system, think about:

 What if the user enters a wrong value?


 What if they press Enter without typing anything?

Python Example:

python
Copy code
def get_input():
user_input = input("Enter a number: ")

if not user_input.isdigit():
print("Invalid input. Please enter a valid number.")
return get_input()

return int(user_input)

number = get_input()
print(f"You entered: {number}")

5. Thinking Concurrently

Definition: Concurrent thinking involves handling multiple tasks at the same time. This is
particularly important in today's world of multi-core processors, where different processes can
run simultaneously.

Example in Python (using threads):

python
Copy code
import threading

def task1():
print("Task 1 is running.")

def task2():
print("Task 2 is running.")

thread1 = threading.Thread(target=task1)
thread2 = threading.Thread(target=task2)

thread1.start()
thread2.start()

Teaching Point: When teaching concurrency, emphasize how modern systems handle tasks like
downloading a file while allowing the user to type, browse, or even play music simultaneously.
6. Thinking Abstractly

Definition: Abstraction simplifies complex systems by focusing on the essential parts and
ignoring unnecessary details. It is key to managing complexity in both computational thinking
and programming.

Real-Life Analogy: When you drive a car, you only focus on the essential controls (steering
wheel, accelerator) without worrying about the engine mechanics.

Python Example: In Python, abstraction can be seen in the use of functions or classes:

python
Copy code
class Car:
def __init__(self, model):
self.model = model

def drive(self):
print(f"The {self.model} is moving.")

my_car = Car("Toyota")
my_car.drive()

Connecting Computational Thinking to Program Design

1. Arrays (Lists in Python)

Definition: Arrays allow storing multiple items of the same type. Lists in Python are flexible and
can hold different data types.

Example:

python
Copy code
fruits = ["apple", "banana", "cherry"]
print(fruits[0]) # Outputs: apple

2. Pseudocode

Definition: Pseudocode is a way to design your algorithm without worrying about syntax,
making it easier to plan.

Example (Finding the largest number in a list):

sql
Copy code
function findLargest(numbers):
set largest = first number
for each number in numbers:
if number > largest:
set largest = number
return largest

3. Algorithms

Definition: An algorithm is a step-by-step set of instructions to perform a task.

Tip: When designing algorithms, always aim for efficiency and correctness.

Python Example:

python
Copy code
def find_largest(numbers):
largest = numbers[0]
for number in numbers:
if number > largest:
largest = number
return largest

numbers = [1, 5, 3, 9, 2]
print(find_largest(numbers)) # Outputs: 9

4. Use of Programming Languages

Key concepts in programming languages that help apply computational thinking include:

 Variables and Constants: Variables can change, constants cannot.

python
Copy code
age = 25 # Variable
PI = 3.14159 # Constant

 Objects: Encapsulate data and behavior.

python
Copy code
class Dog:
def __init__(self, name):
self.name = name
def bark(self):
print(f"{self.name} says Woof!")

my_dog = Dog("Buddy")
my_dog.bark()

 Loops: Allow repeating a block of code.

python
Copy code
for i in range(5):
print(f"This is iteration {i}")

 Functions: Reusable code blocks that perform specific tasks.

python
Copy code
def greet(name):
return f"Hello, {name}!"

print(greet("Alice")) # Outputs: Hello, Alice!

You might also like