1. Algorithm
An algorithm is a clear, concise, and effective procedure for achieving a certain outcome or solving a specific problem. Think of it like a recipe for cooking a dish. It provides a step-by-step guide to get from your raw ingredients (the input) to your finished meal (the output).
In the world of programming, an algorithm might be a series of instructions to calculate the average of a set of numbers. Here’s an example in Python:
def calculate_average(numbers):
total = sum(numbers)
count = len(numbers)
return total / count
numbers = [4, 2, 9, 6, 5]
print(calculate_average(numbers)) # Output: 5.2
public boolean isFull(){
boolean full = false;
// case 1 --> front = 0 && rear = size - 1
if (front == 0 && rear == size - 1)
full = true;
else if (front == rear + 1)
full = true;
return full;
}
Decomposition involves breaking down a large or complex problem into smaller, more manageable parts. It’s like solving a big jigsaw puzzle by focusing on smaller sections one at a time.
In programming, we might decompose the task of creating a digital clock into smaller tasks like getting the current time, formatting the time into hours, minutes, and seconds, and displaying the time. Here’s an example in Python of a program decomposed into smaller functions: