Video 1

Learning Objective

Express an algorithm that uses sequencing without using a programming language

Essential Knowledge

  • Algorithms can be expressed in a variety of ways and can be executed by programs which are implemented using programming languages.
  • Every algorithm can be constructed using combinations of sequencing, selection, and iteration

An algorithm is a finite set of instructions that accomplish a specific task, us as humans, do algorithms on a daily basis.

Sequencing is doing steps in order, for example, doing the first step then the second then the third, etc.

Selection is when the programmer decides between two different outcomes.

Iteration is when you have to repeat a step until that condition is fulfilled.

Examples

Most algorithms use a flow chart to demonstrate how the algorithm proceeds.

  1. Set largestNumber to 0
  2. Get next number in list
  3. If number is larger than largestNumber then set largestNumber to number
  4. If there are more numbers in list, go back to Step 2
  5. Display largestNumber

Sequencing: Steps 1-5 in order

Selection: Step 3

Iteration: Step 4

numbers = [0,1,2,3,4,5,6,7,8,9,10]
evens = []

# This is selection where they go through the numbers and decide whether if it is even or not. 
for i in numbers:
    # This is iteration because they repeat the steps until they go through all the numbers in the list. 
    if (numbers[i] % 2 == 0):
        evens.append(numbers[i])

print(evens)
[0, 2, 4, 6, 8, 10]

show two examples and label which one is sequence, selection, iteration

# This is the sequence
i = 1
starString = "*"
# This is iteration because they repeat until i reaches 5
while i <= 5:
  j = 1
  # This is the selection where they decide what j is
  while j <= i:
    print ("*", end= "")
    j += 1
  print ()
  i += 1