Computer science paper 1

Cards (137)

  • Algorithm
    A set of rules, instructions
  • A variable is a location in memory which you can temporarily store text or numbers
  • Linear Search
    • 1) Check the first value
    • 2) If it is desired value, stop
    • 3) Otherwise check the second value
    • 4) Keep Going until all elements have been checked or the value is found
  • Binary Search
    • 1) Put the list in order
    • 2) Take the middle value
    • 3) Compare it to the desired value
    • a) If it is the desired value, stop
    • b) If it is larger than the desired value, take the list to the left of the middle value
    • c) If it is smaller than the desired value, take the list to the right of the middle value
    • 4) Repeat step 3 with the new list
  • Selection
    • Allows the program to make decisions
    • Uses conditions to change the flow of the program
    • Selections may be nested one inside another
    • IF statements perform comparisons sequentially and so the order is important
    • SELECT CASE has less typing but is less flexible
  • Abstraction
    Using symbols and variables to represent a real-world problem using a computer program and removing unnecessary elements
  • Abstraction
    • Allows the creation of a general idea of how to solve the problem
    • Provides focus on what actually needs to be done
    • Uses short symbols and variables to describe a problem
    • Generally looks a little more structured than normal English
    • Flexible
    • Less precise than a programming language
  • Variables
    A box in which data may be stored
  • Arrays
    A list of data, each element has an index, all elements must be the same data type
  • Operators
    Allow us to work with data, to change it and compare it
  • Arithmetic Operators
    • Addition
    • Subtraction
    • Multiplication
    • Division
    • MOD (remainder from division)
    • DIV (integer division)
    • Exponentiation
  • Comparison Operators
    • == (equal to)
    • != (not equal to)
    • < (less than)
    • <= (less than or equal to)
    • > (greater than)
    • >= (greater than or equal to)
  • Boolean Operators
    • AND (two conditions must be met)
    • OR (at least one condition must be met)
    • NOT (inverts the result)
  • Syntax Errors
    • When the code does not follow the syntax rules of the programming language used, stops the program from running
    • Examples: misspellings, using a variable before it's declared, missing/incorrect brackets
  • Logic Errors
    • The program runs but does not do what it should
    • Examples: incorrectly using logical/Boolean operators, creating infinite loops, incorrectly using brackets in calculations, using the same variable name for different purposes
  • Runtime Errors
    • Takes place during the running of a program causing it to crash
    • Examples: trying to divide by zero, trying to access an item outside the bounds of an array
  • Trace Tables
    A method of recording the values used within an algorithm at each stage of processing to help in troubleshooting
  • Trace Tables
    • Tests algorithms for logic errors which occur when the algorithm is executed
    • Simulates the steps of the algorithm
    • Each stage is executed individually allowing inputs, outputs, variables, and processes to be checked for the correct value at each stage
    • A great way to spot errors
  • Decomposition
    Breaking down large problems into a set of smaller parts
  • Decomposition
    • There are several different approaches, and not one single right way to do this
    • Advantages: smaller problems are easier to solve, each part can be solved and tested independently, the parts are combined to produce the full problem, allows each smaller problem to be examined in more detail
  • Constants
    A fixed value used by the program
  • Constants
    • Allows easy use of fixed values without having to store them in the program
    • Smaller and easier to type than writing out the value each time
    • Easier for someone else to understand the program
    • Can be saved separately and used across other programs
    • Saves time as code that hasn't been tested can be reused
  • if elif else
    Branch depending on condition
  • input()
    Get user input
  • Greater than
  • output()
    Output to the user
  • for
    Repeat a set number of times
  • while
    Repeat while a condition is true
  • for
    Do a loop until a condition is true
  • str()
    Convert an integer to a string
  • int()
    Convert a string to an integer
  • = assignment
  • == Equal to
  • Data types
    • Integer
    • Floating point
    • Boolean
    • Character
    • String
  • Integer
    A whole number
  • Integer
    • 1475, 0, -5
  • Floating point

    A number with a decimal point
  • Floating point
    • 56.75, 6.0, -2.456, 0.0
  • Boolean

    Can only be True or False
  • Boolean
    • True, False