Computer Science Paper 2

Cards (55)

  • Decomposition is used to break a problem down into smaller tasks that are more manageable and easier to solve. Subroutines from decomposition can be used across programs to solve similar problems. Decomposition makes debugging and finding errors easier.
  • Connecting strings together with a + symbol is called concatenation.
  • On a flow chart, an oval shape represents start/stop.
    A parallelogram means input or output. This is where any text to be outputted on the screen will go.
    A diamond means a decision. This is where selection is used to see if the input is true.
    A rectangle is a process. This is where iteration, incrementation and calculations take place.
  • Write an SQL code to select Milly's name and her breed.
    SELECT Name, Breed
    FROM dogs
    WHERE Gender="F" AND Age>4
  • Write a code to write Coco's breed.
    SELECT *
    FROM dogs
    WHERE Breed="Labrador" AND Colour="Brown"
  • A variable is a location in the memory that can be changed or assigned a value during the execution of a program.
  • Local variables are variables that are declared in a function and are only accessible within that function. Global variables can be used at any point within the whole program.
  • What are advantages of local variables?
    Saves memory: Only uses memory when that variable is needed, global variables constantly use memory
    Easier to debug: Can only be changed within one subroutine
    Can be reused within other programs
  • What are advantages of global variables?
    Makes maintenance easier as they are only declared once
    Can be used anywhere throughout program
  • A constant is data that does not change. Its value in the program is always the same.
  • Real/float is a decimal number. An integer is a whole number,
  • Casting is changing the data type of a variable.
  • Write a program to search through an array named "XY" for the name "bz"
    for name in XY:
    if name == "bz":
    print(name)
  • Write a code to output the name Fred.
    print(ListName[4][0])
  • Write a code to output the name Dog.
    print(ListName[0][2])
  • What is a linear search?
    Each item in a list is checked from start to end until the correct item is found. A linear search can work on unordered lists but is very inefficient and time consuming for large lists.
  • What is a binary search?
    1. Find the middle item in an ordered list. If this is the correct item, stop searching.
    2. If not, compare the item to the middle item. If it comes before the middle item, get rid of the right half of the list. If it comes after the item, get rid of the left half of the list.
    3. Repeat the steps until there is a list that is half the size of the original size. Keep halving the list until the correct item is found.
    4. Binary searches only work on ordered lists
  • What is a bubble sort?
    1. Look at the first two items in the list. If they are in the correct order, leave it.
    2. If they are in the incorrect order, swap them.
    3. Move onto the next pair of items and check if they are in the correct order.
    4. Once you get to the end of the list, this is one pass. Each pass will have one less comparison than the one before it because the last item will be in the correct place.
    5. Repeat until there are no swaps in a pass.
  • What are advantages and disadvantages of a bubble sort?
    Advantages: Simple algorithm to be implemented on a computer. Efficient way to check if a list is already in order. Doesn't use much memory as all the sorting is done using the original list.
    Disadvantages: Inefficient way to sort a list and does not cope with a very long list of items
  • What is a merge sort?
    1. Split the list in half into sub-lists. The second sub-list should start with the middle item.
    2. Keep repeating until all the sub-lists only have one item.
    3. Place the final sub-lists in the correct order and then merge the sub-lists together until there is only one list in the correct order.
  • What are advantages and disadvantages of merge sorts?
    Advantages: Faster than bubble sort and more efficient. Consistent running time no matter of how long the list is
    Disadvantages: Slower than other algorithms for small lists. Uses more memory because it creates separate lists
  • What is insertion sort?
    1. Look at the second item in a list.
    2. Compare it to all the items before it and insert it in the right place.
    3. Repeat step 2 until the last item has been inserted into the correct place.
  • What are advantages and disadvantages of insertion sort?
    Advantages: Can be easily coded. Works well with small lists. Doesn't require additional memory. Works very quickly on sorted lists.
    Disadvantages: Doesn't work very well on large lists
  • What does x.upper do?
    Changes all the characters in a string to upper case
  • What does x.lower do?
    Change all the characters in a string to lowercase
  • What does x.left(i)
    Extracts the first i characters from string x
  • What does x.right(i)
    Extracts the last i characters from string x
  • Why is it important to have a maintainable program?

    Makes it easier for other programmers to understand what the code does. This makes understanding the code more straightforward.
  • How does indentation help make a code maintainable?
    Improves readability so you can see the flow of program more clearly and clearly shows each block of code.
  • How do comments help make a code maintainable?
    Comments are useful for explaining what the key features of a program do, helps other programmers understand the purpose of programs. Helps understand the purpose of each line of code.
  • How does using subprograms help make a program maintainable?
    Helps reuse code and makes programs easier to test. This is modularisation.
  • How do correct variable names help make a program maintainable?
    Makes it easier to keep track of variables and understand their purpose.
  • What are example of defensive design considerations?
    Anticipating misuse: Planning ahead so take steps against misuse or to prevent it from happening.
    Maintainable code: Making sure code is well maintained and can be easily read and fixed by programmers.
    Using authentication, verification and validation.
  • Input validation is checking data meets a certain criteria before entering it into a program.
  • Range check checks data is within a specified range
    Presence check checks data has been entered and is not left blank
    Format check checks if data has the correct format
    Look-up table checks the data against a table of acceptable values
    Length check checks the data has the correct length of characters
  • Authentication is used to confirm the identity of a user and to prevent unauthorized access to a system.
  • What are examples of authentication?
    Strong passwords, 2 step verification, limited password attempts
  • Syntax errors are errors in the grammar of the program and means the compiler cannot compile the code so the program will not run.
    Logic errors is when the program will run but there will be an incorrect or inaccurate result
  • Logic errors are more difficult to diagnose as compilers do not pick them up.
  • Normal data is data that is expected to be in the range of the data set.