Zum Inhalt springen

English:Introduction to Algorithms

Aus MOOCsWiki Staging

Introduction to Algorithms



Introduction

An algorithm is a clear, finite set of steps for solving a problem or completing a task. You use algorithm-like plans every day: getting ready for school, following directions, making a sandwich, or sorting books on a shelf. In computer science, algorithms tell a computer what should happen and in what order.

You do not need to be an expert programmer to learn algorithms. The main skill is thinking carefully about steps. By the end of this aiMOOC, you should be able to describe simple algorithms, spot mistakes, use decisions and repetition, and compare different ways to solve a problem.

The image shows a simple flowchart with actions in sequence: one step follows another. This is one way to make an algorithm visible.

This beginner-friendly video from Khan Academy introduces the idea of an algorithm and why algorithms matter.


What Makes a Good Algorithm?

A useful algorithm has several important features. Its instructions are clear, so the person or computer following them knows what to do. The steps are in a sensible order. The algorithm also stops after a limited number of steps, and it should produce the result it was designed to produce.

Imagine the instruction "Draw a square." A clearer algorithm would say: draw a line, turn right, and repeat until four equal sides are drawn. If a step is missing or unclear, different people may get different results.


Inputs, Steps, and Outputs

Many algorithms can be understood using three ideas. An input is information the algorithm starts with. The steps tell what to do with that information. An output is the result.

For example, a "find the largest number" algorithm might start with the input 4, 9, 2, 7. It compares the values by following a plan and gives 9 as the output. A navigation app starts with places and map information, follows route-finding rules, and gives a route as an output.


Precision Matters

Computers follow instructions very literally. "Move a little" is unclear because "a little" can mean different things. "Move forward three squares" is more precise. Good algorithm writers ask: Could someone else follow my steps without guessing?

Try giving a classmate directions for drawing a simple shape without showing the finished picture. If the drawing is not what you expected, improve the instructions so that the steps become clearer.


Three Building Blocks

Many beginner algorithms use three basic control ideas: sequence, selection, and repetition. These ideas appear in recipes, games, robots, and computer programs.


Sequence: Do Steps in Order

A sequence is a set of steps performed in order. To wash your hands, you might turn on the water, wet your hands, add soap, scrub, rinse, and dry. Changing the order can change the result.

A simple movement algorithm could be: move forward, turn right, move forward, stop. The same commands in a different order may lead to a different place.

Code.org's Graph Paper Programming activity shows how a sequence of simple commands can act like an algorithm even without writing traditional code.


Selection: Make a Decision

Selection means choosing between different actions based on a condition. You use selection when you think, "If it is raining, take an umbrella; otherwise, leave it at home."

In a game, an algorithm might say: if the player touches a star, add one point; otherwise, keep moving. A decision lets the next step depend on what is happening.

In a flowchart, a diamond is often used for a decision. The algorithm can follow one path when a condition is true and another path when it is false.


Repetition: Repeat Useful Steps

Repetition, often called a loop, means doing a step or group of steps more than once. Instead of writing "move forward" ten times, an algorithm can say "repeat move forward ten times."

Loops are useful when the same action is needed again and again. A loop should have a clear rule for how many times to repeat or when to stop. Without a stopping rule, a program could keep repeating.


From Algorithms to Programs

An algorithm is the plan; a program is an implementation of that plan in a form a computer can run. The same algorithm can sometimes be written in different programming languages or shown with pictures and blocks.

Block-based programming tools such as Scratch let you connect commands like puzzle pieces. A group of blocks can represent the steps, decisions, and loops in an algorithm.

You can also write an algorithm in plain language or in pseudocode. Pseudocode is a structured way to describe steps without worrying about the exact rules of a programming language.

For example:

START
move forward
IF path is blocked
    turn right
ELSE
    move forward
STOP

This is not code for a specific programming language. It is a readable plan that helps you think about what should happen.


Flowcharts: Drawing an Algorithm

A flowchart uses shapes and arrows to show how steps connect. Flowcharts can help you see where a process starts, what action happens next, where a decision is made, and when the process ends.

When you create a flowchart, follow the arrows from the start. Check that every decision has a clear path and that the process can reach an end.


Testing and Debugging

Even a sensible-looking algorithm can have a mistake. Testing means trying the algorithm with examples to see whether it works. Debugging means finding and fixing problems.

Suppose a robot must reach a desk. Your algorithm says: move forward three steps, turn left, move forward two steps. During testing, the robot bumps into a chair. You could change the route, change the number of steps, or add a decision such as "if something blocks the way, stop and choose another direction."

A good test includes more than one example. If you design an algorithm to sort names, test it with names already in order, names in reverse order, and names that begin with the same letter.


Searching: How Can We Find Something?

A searching algorithm helps find an item in a collection. Imagine trying to find the number 17 on a row of cards.

With a linear search, you start at one end and check each card until you find 17 or reach the end. This works even if the cards are in a mixed-up order.

With a binary search, the cards must already be sorted. You check the middle item and decide whether to search the lower half or the higher half. Each decision removes a large part of the remaining search area.

This diagram shows binary search narrowing down a sorted list. You do not need to memorize the numbers; focus on the idea of repeatedly choosing the half that could still contain the target.


Sorting: Putting Things in Order

A sorting algorithm puts items into an order, such as numbers from smallest to largest or words from A to Z. Different sorting algorithms use different strategies.

One simple method is bubble sort. It compares neighboring items and swaps them when they are in the wrong order. The process repeats until the whole list is sorted.

Watch the bars in the animation. Neighboring values are compared again and again, and larger values gradually move toward the correct end.

For a small classroom activity, write six different numbers on cards. Work with a partner to sort them by comparing only neighboring cards. Count how many comparisons and swaps you make.


Algorithms Can Find Routes Too

Some algorithms search for paths through maps, games, or robot spaces. An advanced example is the A* search algorithm, which tries to find a low-cost route while avoiding obstacles.

You do not need to understand every detail of A*. Notice the main idea: the search follows rules, explores possible choices, avoids blocked areas, and works toward a goal. This is a more complex version of the same step-by-step thinking you use in a classroom maze.


Comparing Algorithms

Two algorithms can solve the same problem in different ways. To compare them, ask questions such as: Do both give the correct result? Which one usually takes fewer steps? Which one is easier to understand? Does one need special conditions, such as a list already being sorted?

For example, linear search works on an unsorted list, while binary search needs a sorted list. Binary search can remove about half of the remaining search area after each comparison, which can make it much faster for large sorted lists.

At your level, you do not need complicated formulas for speed. You can compare algorithms by counting steps, comparisons, or moves on small examples.

This Code.org Code Break lesson explores algorithms through unplugged activities and programming. Use it as an optional class extension or project starter.


Interactive Tasks


Quiz: Test Your Knowledge

What is an algorithm? (A clear set of steps for solving a problem) (!A picture that always contains numbers) (!A computer that can only play games) (!A random guess with no plan)




Why is the order of steps important in many algorithms? (Changing the order can change the result) (!All steps always happen at the same time) (!The first step is never used) (!Order matters only when drawing pictures)




Which word describes doing steps one after another in order? (Sequence) (!Selection) (!Output) (!Debugging)




What does selection allow an algorithm to do? (Choose an action based on a condition) (!Repeat every step forever) (!Remove all inputs) (!Turn every number into a picture)




What is a loop used for? (Repeating steps) (!Hiding a mistake) (!Sorting only one item) (!Stopping before the algorithm begins)




What does debugging mean? (Finding and fixing problems) (!Making instructions less clear) (!Deleting every test) (!Changing correct answers into guesses)




How does a linear search usually look for a target? (It checks items one by one) (!It always checks only the last item) (!It mixes the list before searching) (!It skips every item)




What must be true before using binary search correctly? (The list must be sorted) (!The list must contain pictures) (!Every item must be the same) (!The target must be first)




What does bubble sort compare? (Neighboring items) (!Only the first and last item) (!Items from two different lists only) (!Nothing in the list)




Which is a good question when comparing two algorithms? (Which one solves the problem correctly with fewer steps) (!Which one has the longest name) (!Which one uses the most paper) (!Which one was written in the biggest letters)





Memory Game

Algorithm A clear finite set of steps for solving a problem
Sequence Steps carried out in order
Selection A choice based on a condition
Loop Instructions that repeat
Debugging Finding and fixing problems
Flowchart A diagram that shows steps and decisions





Drag and Drop

Match the correct terms. Topic
Sequence Do steps in order
Selection Choose between actions
Repetition Repeat useful steps
Testing Try examples to see whether the plan works
Debugging Find and fix a problem




...


Crossword Puzzle

Algorithm What do we call a clear set of steps for solving a problem?
Sequence What means carrying out steps in order?
Decision What kind of point lets an algorithm choose between paths?
Loop What repeats one or more instructions?
Debugging What is the process of finding and fixing problems?
Flowchart What diagram uses shapes and arrows to show a process?





LearningApps


Cloze Text

Complete the text.

An

is a clear set of steps for solving a problem. When steps must happen in order, they form a

. A choice based on a condition is called

. Repeating useful instructions is called a

. Trying an algorithm with examples is called

. Finding and fixing a problem is called

. A

can show steps and decisions with shapes and arrows. Binary search needs the list to be

before it begins.




Open-Ended Tasks


Easy

  1. Everyday algorithm: Write an algorithm with six to ten clear steps for a familiar task such as packing your school bag, feeding a pet, or making a paper airplane.
  2. Human robot: Work with a partner. One person is the robot and follows only exact movement instructions while the other person improves the algorithm after each test.
  3. Flowchart: Draw a simple flowchart for deciding what to wear when the weather is sunny, rainy, or cold.
  4. Sequence: Create four picture cards showing a small task, mix them up, and ask another learner to place them in the correct algorithmic order.


Standard

  1. Pseudocode: Write pseudocode for moving a character through a small grid maze using sequence, selection, and at least one loop.
  2. Linear search: Make a set of word cards, hide one target word in the set, run a linear search, and record how many checks were needed in three different trials.
  3. Sorting algorithm: Demonstrate bubble sort with number cards, make a short video or photo sequence of the swaps, and explain what happens after each comparison.
  4. Debugging: Design an algorithm with three deliberate mistakes, exchange it with a partner, and ask your partner to test, identify, and repair the bugs.


Advanced

  1. Binary search algorithm: Create a sorted set of at least twenty number cards and compare the number of checks needed by linear search and binary search for several targets.
  2. Algorithm efficiency: Invent two different routes through the same grid maze, count the moves in each algorithm, and explain which route you would choose and why.
  3. Programming: Build a small Scratch or block-based program that uses a sequence, a decision, and a loop, then explain the algorithm before showing the code.
  4. Computational thinking: Interview someone about a repeated task at home, school, or work, turn the task into an algorithm, test it with another person, and improve any unclear steps.



Learning Assessment

  1. Algorithm design: Design an algorithm for organizing a mixed set of classroom objects, explain the input and desired output, and justify why each step is needed.
  2. Algorithm comparison: Use the same sorted list to compare linear search and binary search, record the number of checks for at least three targets, and explain the pattern you notice.
  3. Debugging strategy: Analyze a flawed route algorithm for a grid maze, identify where it fails, repair it, and explain how your test proved the repair worked.
  4. Flowchart reasoning: Turn a plain-language algorithm containing one decision and one loop into a flowchart, then explain how a reader can follow every possible path.
  5. Transfer task: Choose a real activity outside computing and show how sequence, selection, and repetition can be used to describe or improve it.
  6. Program planning: Before using a programming tool, write pseudocode for a simple interactive project and explain how the plan would guide the code.




Evidence of Learning

  1. Knowledge: You can explain algorithm, input, output, sequence, selection, repetition, testing, debugging, searching, and sorting in your own words.
  2. Skills: You can write clear steps, draw a basic flowchart, trace an algorithm, test examples, find mistakes, and improve unclear instructions.
  3. Products: You can produce an everyday algorithm, a flowchart, pseudocode, a search or sorting demonstration, and a small block-based program or model.
  4. Reasoning: You can compare two possible algorithms by correctness, clarity, and the number of steps or comparisons they use.
  5. Transfer: You can recognize algorithmic thinking in school subjects, games, routes, routines, and real-life problem solving.




OERs on the Topic

The English Wikipedia article below provides a broader reference about algorithms. Some sections are more advanced, so use your teacher or another trusted adult to help choose parts that fit your level.



Linked Learning Areas

Algorithms connect computer science with mathematics, language, design, robotics, games, and everyday problem solving. Learning to describe clear steps also helps you explain your reasoning in other school subjects.


aiMOOC Projects