Paper 2

Cards (79)

  • Compiler: Translates high-level language into machine code. Translates all code at once and creates an executable file
  • Interpreter: Translates high-level code into machine code line-by-line
  • Abstraction
    Ignoring unnecessary information and focusing only on the important facts
  • Abstraction
    • Simplifies a problem to make it less complex
    • Makes the problem more straightforward to understand and create a solution
  • Decomposition
    Breaking a problem down into smaller tasks so that it is easier to solve
  • Decomposition
    • Each individual problem can be separately tested and solved
    • Enables different people to work on the different parts of a larger problem that can later be recombined to produce a full solution
  • Algorithmic thinking
    Following logical steps to solve the problem
  • Computational thinking
    1. Abstraction
    2. Decomposition
    3. Algorithmic thinking
  • Algorithm
    A set of instructions, presented in a logical sequence
  • Algorithm
    • In an exam you may be asked to read and understand an algorithm that has been written
    • To prove your understanding you may be asked to respond by actions such as listing the outputs of the algorithm, correcting errors or identifying an error within it
  • Programmers
    Create algorithm designs as a method of planning a program before writing any code
  • Methods of defining algorithms
    • Pseudocode
    • Flowcharts
  • OCR exams require specific questions to be written either in OCR Exam Reference Language or a high-level programming language such as Python
  • OCR Exam Reference Language
    The language used in OCR exams to represent algorithms
  • Basic commands in OCR Exam Reference Language
    • Annotation
    • Assignment
    • Constants and Global Variables
    • Input / Output
    • Casting
    • Random Number
  • Selection (if - then - else)

    1. If firstname == "Steven" then print("Hello" + firstname)
    2. Elif firstname == "Steve" then print("Please use full name")
    3. Else print("Who are you?")
  • Selection (case select)
    1. Switch day: case "Sat": print("It is Saturday")
    2. Case "Sun": print("It is Sunday")
    3. Default: print("It is a Weekday")
  • Iteration (for loop)
    For i = 1 to 10 step 1 input item next i
  • Iteration (while loop)
    While firstname != "Steven" firstname = input("Try again:") endwhile
  • Iteration (do while loop)
    Do firstname = input("Guess name:") until firstname == "Steven"
  • String Handling
    • Length of a String
    • Substrings
    • Concatenation
    • String Cases
    • ASCII Conversion
  • File Handling - Reading Lines
    1. file1 = open("Customers.txt")
    2. While NOT file1.endOfFile() print(file1.readLine())
    3. file1.close()
  • File Handling - Writing to a (New) File
    1. newFile("paint.txt")
    2. file2 = open("paint.txt")
    3. paint = input("Enter a paint colour:")
    4. file.writeLine(paint)
    5. file2.close()
  • Arrays
    • Declare Array
    • Declare 2D Array
    • Assign Values
  • Flowcharts
    • A flowchart can be used to visually represent an algorithm
    • It is more likely you will need to be able to interpret a flowchart rather than draw one
  • Flowchart symbols
    • Algorithm
  • Below are two different methods for representing the same algorithm - a program to encourage people to buy items cheaply at a supermarket
  • Pseudocode
    1. total = 0
    2. itemsentered = 0
    3. While total < 100 itemprice = input("enter the price of the next item") total = total + itemprice itemsentered = itemsentered + 1 endwhile
    4. If itemsentered >= 20 then print ("You are on your way to saving money.") elif itemsentered => 30 then print ("You're a real money saver.") else print ("Look for better deals next time.") endif
  • In an exam you may be asked to read an algorithm and prove your understanding, most commonly by listing the outputs
  • Start from the first line and follow the program line by line, recording the value of variables as you go
  • When you encounter a for loop, repeat the indented code as many times as stated in the range
  • Example Algorithm
    1. procedure NewProgram()
    2. maxvalue = input()
    3. for i = 1 to maxvalue output (i * i) ????????? print("program finished") endprocedure
  • Trace tables
    • Used to track the value of variables as a program is run
    • Can be used to manually track the values in order to investigate why the program isn't working as intended
  • Each row in the trace table represents another iteration. Each column stores the value of a variable as it changes
  • For most algorithms, not every variable will be updated in each iteration. Values may not be entered in the order of the trace table either
  • Linear search
    The most simple search algorithm, where each data item is searched in order from the first value to the last as if they were all laid out in a line. The list does not have to be in any order before it is searched. Also known as a sequential search.
  • For large lists, linear search is not very efficient
  • Binary search
    A much more efficient searching algorithm that generally searches through fewer data and is often much quicker, especially for large data sets. The list of data must already be sorted in order before a binary search can take place.
  • Merge sort
    A sorting algorithm based on the idea of 'divide and conquer'. A merge sort divides a list into half, again and again until each data item is separate. Then the items are combined in the same way as they were divided, but now in the correct order. When the individual lists are all merged together as one list again, then the data is in order and the algorithm will end.
  • Bubble sort
    An algorithm based on the comparison of adjacent data elements. Data elements are swapped if they are not in the correct order. A bubble sort is not suitable for large sets of data.