Standard algorithm

    Cards (51)

    • What are the four standard algorithms that you need to learn?
      Find Maximum, Find Minimum, Count Occurrences, Linear Search
    • What is the purpose of the Find Maximum algorithm?
      It identifies the largest number in an array of values.
    • What does the Find Minimum algorithm do?
      It identifies the smallest number in an array of values.
    • What is the function of the Count Occurrences algorithm?
      It identifies the number of times a target value appears in an array of values.
    • What does the Linear Search algorithm accomplish?
      It identifies the position of a target value in an array of values.
    • What value would Find Maximum return if used on the Ages array?
      16
    • What are the steps to implement the Find Maximum algorithm using arrays?
      1. SET max TO ages[0]
      2. FOR counter FROM 1 TO 4 DO
      3. IF ages[counter] > max THEN
      4. SET max TO ages[counter]
      5. END IF
      6. END FOR
      7. SEND "The highest age is " & max TO DISPLAY
    • What is the first step in the Find Minimum algorithm using arrays?
      SET min TO ages[0]
    • What are the steps to implement the Find Minimum algorithm using arrays?
      1. SET min TO ages[0]
      2. FOR counter FROM 1 TO 4 DO
      3. IF ages[counter] < min THEN
      4. SET min TO ages[counter]
      5. END IF
      6. END FOR
      7. SEND "The lowest age is " & min TO DISPLAY
    • What value would Find Minimum return if used on the Ages array?
      7
    • What are the steps to implement the Find Minimum algorithm using record structures?
      1. SET min TO UserDetails[0].ages
      2. FOR counter FROM 1 TO 4 DO
      3. IF UserDetails[counter].ages < min THEN
      4. SET min TO UserDetails[counter].ages
      5. END IF
      6. END FOR
      7. SEND "The lowest age is " & min TO DISPLAY
    • What is the purpose of the Count Occurrences algorithm?
      To identify how many times a particular value appears in an array.
    • What are the steps to implement the Count Occurrences algorithm using arrays?
      1. RECEIVE target FROM KEYBOARD
      2. SET numFound TO 0
      3. FOR counter FROM 0 TO 4 DO
      4. IF names[counter] = target THEN
      5. SET numFound TO numFound + 1
      6. END IF
      7. END FOR
      8. SEND "The number found is " & numFound TO DISPLAY
    • What would Count Occurrences return if used on the Names array for the name "Betty"?

      2
    • What are the steps to implement the Count Occurrences algorithm using record structures?
      1. RECEIVE target FROM KEYBOARD
      2. SET numFound TO 0
      3. FOR counter FROM 0 TO 4 DO
      4. IF UserDetails[counter].names = target THEN
      5. SET numFound TO numFound + 1
      6. END IF
      7. END FOR
      8. SEND "The number found is " & numFound TO DISPLAY
    • What is the purpose of the Linear Search algorithm?

      To identify whether or not an item is in a list and which position it occupies.
    • What are the steps to implement the Linear Search algorithm using arrays?
      1. RECEIVE target FROM KEYBOARD
      2. SET found TO FALSE
      3. SET position TO 0
      4. FOR counter FROM 0 TO 4 DO
      5. IF names[counter] = target THEN
      6. SET found TO TRUE
      7. SET position TO counter
      8. END IF
      9. END FOR
      10. IF found = TRUE THEN
      11. SEND "Found at position " & position TO DISPLAY
      12. ELSE
      13. SEND "Not found"
      14. END IF
    • What would Linear Search return if used on the Names array for the name "Betty"?

      3
    • What are the steps to implement the Linear Search algorithm using record structures?
      1. RECEIVE target FROM KEYBOARD
      2. SET found TO FALSE
      3. SET position TO 0
      4. FOR counter FROM 0 TO 4 DO
      5. IF UserDetails[counter].names = target THEN
      6. SET found TO TRUE
      7. SET position TO counter
      8. END IF
      9. END FOR
      10. IF found = TRUE THEN
      11. SEND "Found at position " & position TO DISPLAY
      12. ELSE
      13. SEND "Not found"
      14. END IF
    • What is the maximum number of entries in the examples provided for user input?
      10
    • What is the output message for the Find Maximum algorithm?
      "The largest number in the list is " & max
    • What is the output message for the Find Minimum algorithm?
      "The smallest number in the list is " & min
    • What is the output message for the Count Occurrences algorithm?
      "The name " & target & " appears " & counter & " times"
    • What is the output message for the Linear Search algorithm?
      "Item was found at position " & position
    • What is the output message if the item is not found in the Linear Search algorithm?
      "Item was not found"
    • What is the data structure used in the examples for user details?
      RECORD UserDetails IS {STRING Firstname, STRING Surname, INTEGER Age, STRING House}
    • What is the data type of the Age field in the UserDetails record structure?
      INTEGER
    • What is the data type of the Firstname field in the UserDetails record structure?
      STRING
    • What is the data type of the Surname field in the UserDetails record structure?
      STRING
    • What is the data type of the House field in the UserDetails record structure?
      STRING
    • What is the purpose of the InputBox function in the examples?
      It prompts the user to enter a value.
    • What is the purpose of the ListBox1.Items.Add function in the examples?
      It adds the entered value to a list box for display.
    • What is the purpose of the MsgBox function in the examples?
      It displays a message box with information to the user.
    • What is the significance of the counter variable in the algorithms?
      It is used to iterate through the elements of the array or record structure.
    • What does the term "initialise" mean in the context of the algorithms?
      It means to set a variable to a starting value.
    • What does the term "SET" indicate in the algorithms?
      It indicates assigning a value to a variable.
    • What does the term "SEND" indicate in the algorithms?
      It indicates displaying a message to the user.
    • What does the term "RECEIVE" indicate in the algorithms?
      It indicates getting input from the user.
    • What does the term "FOR" indicate in the algorithms?
      It indicates the start of a loop that iterates a specific number of times.
    • What does the term "END" indicate in the algorithms?
      It indicates the conclusion of a loop or conditional statement.
    See similar decks