Algorithms

Cards (58)

  • Algorithms that have affected your life today
    • Algorithms used to control automatic-pilot systems in aeroplanes
    • Closely guarded algorithms help me have quicker results for more relevant searches on browsers such as google
    • A recipe for pancakes
  • Algorithm
    A step-by-step process used to solve problems, it is usually a set of instructions
  • Algorithms are used by both humans and computers
  • Algorithm for making a cup of tea
    1. Get a kettle
    2. Plug the kettle into a socket
    3. Fill the kettle up with water and turn on
    4. While waiting for the water to boil get a cup/mug and grab a tea bag
    5. When the water has boiled add it to the tea bag in the cup/mug
    6. Fill to ¾ of the cup
    7. Add milk
    8. Add sugar if needed
    9. Take tea bag out of mug/cup
  • Differences between algorithms for making a cup of tea may include basic steps such as plugging the kettle in and adding the tea bag after the water
  • Algorithm for journey to the concert
    1. Find the location of the concert
    2. Add the address to the Sat-Nav of the car/taxi
    3. Make sure you have everything needed before locking your house up and setting an alarm
    4. Get into the car
    5. If manual put the car into first gear and push the clutch until you feel a bite and add a bit of gas (acceleration) to get the car moving at a steady speed
    6. Follow the Sat-Navs instructions until you reach your destination and park your car
  • Examples of iteration or selection
    • Combing your hair (iteration)
    • Deciding whether to turn left or right at a junction (selection)
    • A heating system turning off at a given time (iteration/selection)
  • Algorithm for preparing a bath with the correct water temperature
    1. Put plug in the bath
    2. Turn on hot tap
    3. Is the water the correct temperature?
    4. Turn cold tap until water is at the correct temperature
    5. Turn off both taps when the temperature is correct and 9/10ths full
  • Criteria for a successful algorithm
    • Clear - Each of its steps should be clear in all aspects and must lead to only one meaning
    • Straight forward - It should be easy to understand in case it is the first time a human is doing the task and also receiving the best results by making it more simple
  • Computer scientists must consider health and safety when designing real-life solutions because if the instruction is not clear or not safe it could injure another person
  • Variables used in the guessing game algorithm
    • Year
    • FIRST
    • LAST
    • USERNAME
    • X
  • Usernames generated for students
    • 05CJ1
    • 06FG1
  • Facts about a student with the username 03SSmith13
  • Tips for choosing variable identifiers
    • Shorter identifiers are easier to type and spell
    • Longer identifiers may be used if they are more descriptive of the data they represent
    • Some identifiers may be reserved words used by the programming language and cannot be used
    • In many programming languages, identifiers cannot begin with a number
  • Sensible identifier for a variable that stores someone's age

    • Age
  • Python reserved word
    • print
  • Valid identifier

    • first
  • Examples of camel case

    • ComputerScience
    • computerScience
  • Example of snake case
    • computer_science
  • Constant in Python
    • numberOfHoursInDay ← 24
    • vatRate ← 20
  • Why programmers add comments to their code

    • To explain to others, and often to remind yourself, what the code is intending to do
  • Pseudocode to ask a user for their name and age and print a message

    1. OUTPUT "Please enter your name"
    2. UserName ←USERINPUT
    3. OUTPUT "Please enter your age"
    4. UserAge ← USERINPUT
    5. OUTPUT "Hello UserName. You are UserAge years of age."
  • Why keywords can't be used as variable or constant identifiers
  • Operators and operands

    Operands are the variables and the Operator is the action being done to it
  • DIV operator

    Like division, but it only returns the whole number or the integer
  • MOD operator
    This will return the remainder of a division
  • Pseudocode algorithm to calculate the area of a wheel given the diameter
    1. OUTPUT "Please enter the diameter of the wheel"
    2. diameter ← USERINPUT
    3. radius ← diameter / 2
    4. area3.142 *radius *2
    5. OUTPUT "The area is" * + area
  • Relational operator

    Comparison operator
  • Remembering > and < on the number line
  • ELSE IF
    It is simple, efficient, and easier to read when there are fewer conditions
  • Role of indentation in programming
    • Indentation refers to the spaces at the beginning of a code line
  • Pseudocode algorithm to ask user for a number between 1 and 10 and output if it is low or high
    1. OUTPUT "enter a number"
    2. nom = USERINPUT
    3. IF nom <= 5
    4. OUTPUT (nom) "is a low number"
    5. ELSE
    6. OUTPUT (nom) "is a high number"
  • Boolean operators

    Named after George Boole, a 19th century English mathematician who formulated an algebraic system of logic
  • Boolean operators
    • AND - Logical AND operator, if all operands are true then condition is true
    • OR - Logical OR operator, if any operands are true then condition is true
    • NOT - Logical NOT operator
  • Indentation
    The spaces at the beginning of a code line
  • Algorithm to ask user to enter a number between 1 and 10
    1. OUTPUT "enter a number"
    2. nom = USERINPUT
    3. IF nom <= 5
    4. OUTPUT (nom) "is a low number"
    5. ELSE
    6. OUTPUT (nom) "is a high number"
  • Boolean operators

    • AND
    • OR
    • NOT
  • AND operator

    Logical AND operator, if all operands are true then the condition becomes true
  • OR operator
    Logical OR operator, if any of the operands are true then the condition becomes true
  • NOT operator
    Logical NOT operator, used to reverse the logical state of the operand