3.3 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

3.3 Video 2

Vocabulary

  • algorithm- finite set of instructions that accomplish a specific task, composed of sequencing, selection, and iteration.
  • selection- a section of code is run only if a condition is met.
  • iteration- repeating steps or instructions over and over again
  • sequencing- outline or set of steps that we do and follow in order that they are given
  • variable- you can store an actual value, the value of a variable in another variable, the result of an operation, or result of a procedural call

Practice: calculate and display average of 25, 43, and 18

num 1 ⟵ 25

num 2 ⟵ 43

num 3 ⟵ 18

average ⟵ (num 1 + num 2 + num 3)/3

display average

Click for the answer! 28.667

Practice: consider the following code segment, which uses the variables a, b, c:

a ⟵ 1

b ⟵ 2

c ⟵ 3

a ⟵ b

b ⟵ c

display(a)

display(c)

  • which is displayed as a result of running the code segment
    1. 1 1
    2. 1 2
    3. 2 3
    4. 3 2
Click for the answer! 3. 2 3

Practice: consider the following code segment

s ⟵ 10

l ⟵ 20

a ⟵ 30

y ⟵ 40

s ⟵ l

l ⟵ a

y ⟵ l

a ⟵ s

what is the value of a as a result of executing the code segment?

  1. 10
  2. 20
  3. 30
  4. 40
Click for the answer! 2. 20

3.3 Video 3

Mathematical Expressions

Arithmetic Operators

A plus sign indicates addition: a + b

A subtraction sign indicates subtraction: a - b

An asterisk/star indicates multiplication: a * b

A slash indicates division: a / b

MOD represent the Modulus operator. Returns the value after division: a MOD b

ex: 
   
9 MOD 2 = 1
Practice Problem

Click for the answer! answer: 29

3.4 Video 1

Big Idea: Strings

Goal: To evaluate expressions that manipulate strings

Vocab and Examples:

String: a sequence of characters

  1. Len: finds the number of characters in a string

    len(“school”)

    Result: “5” ————————————————————

  2. String concatenation: combines two or more strings into one

    concat(“computers”, “arecool” )

    Result: “computersarecool” ————————————————————

  3. Substring: a part of a existing string

    substring(“APCSPrinciples”, 3, 6)

    Result: “CSPrin”

    Starts at the 3rd character (“C”) and takes 6 characters after that (“SPrin), then in all (“CSPrin”)