paper 1 Flashcards
What is in structured programming?
- decomposing into manageable sub tasks, which can be written individually as sub routines
- modularising (using subroutines)
*using parameters
*using return variables
*using local variables
Why use structured programming?
- easier to test structured programs as each module can be tested individually
- individual subroutines can be fixed and updated, without affecting the rest of the program
- the subroutines can be re-used for future programs
- programmers can work on one program, as each module can be written individually
*coding may be easier
What is authentication?
the process of check a user is who they say
What is INPUT validation?
checks that the data meets a certain criteria before passing into the program
What are the types of input validation?
*range: checks that the data is within a specific range
*presence: checks that data has actually been entered
*format: checks that the data has the correct format
*look-up: checks the data against a table of acceptance values
*length: checks the data correct length
why should programs be easy to maintain?
- change parts of the source code, without the risk of causing problems elsewhere in the code
How can you improve the maintainability of the code?
*comments explaining key features
*indentation to clearly see the flow of the program
*only using global variables where necessary, as they affect the rest of the code, variables with local scope will not affect the rest program, when other programmers change this variable it won’t affect the other part so he program
*variable names are enough for the reader to understand
What are the different types of errors?
*syntax error
*logical error
What is a syntax error?
When the compiler or interpreter doesn’t understand something you have typed because it doesn’t follow the rules or grammar of the programming language
How would you use the python in range function for pseudocode?
Why are meaningful identifiers names used?
Describes the purpose of the variable
makes the code easier to understand and maintain
What are the different types of test data ?
🟢normal data
🟢boundary valid data
🟢boundary invalid data
🟢erroneous data
What are trace tables ?
Helps to find logical errors
What is time efficiency in algorithms?
Measures things like the number of time memory was accessed and the number of CPU cycles taken to execute commands
Define ‘algorithm’
The sequence of steps that can be followed to complete a task
Define decomposition
The breaking of a problem into a number of sub problems, so that each sub problems accomplishes an identifiable task, which might itself be further subdivided
“Abstraction “
The process of removing unnecessary detail from a problem
Why are data types used?
Each data type is allocated a different amount of memory, using the correct data types makes the code more memory efficient, robust and predictable
Define constants
Define variables
What is an algorithm?
An algorithm is a sequence of steps that can be followed to complete a task.
What is decomposition?
Breaking a complex problem into sub problems until each task is manageable, then solving each one individually
What is abstraction?
Removing unnecessary detail from a problem so you are left with important bits, simplifying the task
What is algorithmic thinking?
A logical way of getting from the problem to the solution. Acknowledging if certain bits of code can be reused
What must you always do in pseudocode?
Declare variables
What is efficiency in programming?
How much time is needed to a run a particular algorithm and how much space is needed
Which one is more efficient a bubble sort or a merge sort?
A merge sort
Splits and then merges instead of swapping each pair
Which is more efficient binary search or a linear search?
Binary search
Only when list is ordered
Keeps on cutting of half rather than checking each number
How would you address questions about abstraction?
1-definition
2-important detail
3-unnecessary detail
How do you address questions about decomposition?
1- definition
2- two questions you can think of to sub section
What is considered ‘time’ in programming?
How may number of times memory was accessed
The number of CPU cycles taken to execute the command
is a computer program an algorithm ?
Why use the correct data types?
As each data type is allocated a different amount of memory , using the correct data types makes the code more memory efficient , robust and predictable
What is program flow ?
The order in which statements are executed in a program
- can be controlled used selection and iteration
Write a pseudocode that creates a 6 digit username.
With the first 3 letters being from town first three letters
Then the second 2 digits being their current age
The last digit is the last letter of their surname
Why use meaningful identifiers ?
What are arrays ?
A data structure where data values of the same type are stored and defined under one variable name.
Why are subroutines good ?
🔵can be tested individually making it easier to debug .
🔵can be recalled many times within the program , rather than repeating sections of code (more efficient)
🔵can be stored as separate modules and reused in other programs
What is a local variable
A variable that can only be used within the structure that they have been declared .
✅cannot and are not affected by anything outside a subroutine (same variable name can be used elsewhere )
✅✅
What is a data type?
Specification is what type of value a variable has.
What are the five data types?
Integer
Real/float
Character
String
Boolean
What is an integer?
A numerical data type for whole numbers
2/4 bytes
What is a real/float ?
A numerical data type for decimal numbers
4/8 bytes
What is a character?
A single alphanumerical symbol
1 byte
What is a string?
A data type for one or more alphanumerical characters.
* can be a number or string
1 byte for each character
What is a Boolean?
A data type that can only take one of two values - TRUE or FALSE
1 bit-1 byte
What is the difference between constants and variables?
Variables can be changed throughout out the program.
What is iteration?
Loops controlled by conditions
What are types of indefinite iteration?
Only rely on a condition(can be infinite):
Repeat until- condition at end, run at least once
While- condition at the start of loop
Do while
What is selection?
Causes the program to make a choice and flow in a given direction
What is a variable?
A named piece of memory that holds a value , can change as the program is running
What is a constant?
A named piece of memory where the value cannot be changed while a program runs
What is a type of selection?
An if else statement
What is definite iteration?
A loop that repeats a set number of times - usually a for loop
What is a nested statement ?
An iteration or selection made up of multiple statements inside each other
What is the need for meaningful identifiers?
Suitable names for variables, makes it easier for the next person to work on the code to understand
How do you find the length of a string?
LEN(string)
*starts from 1
🐍len(string)
How do you find the position of a string?
POSITION(string,character)
*includes the 0
🐍 string.index(‘x’)
How do you take a certain part of the string?
SUBSTRING(x ,y ,string)
*includes the 0
*does include last number
🐍string[x : y]
*does not include last number
How do you concatenate strings?
+
Does not include spaces
Normally done with variables
🐍everything has to be a string
How do you change one data type to another?
STRING_TO_INT (“your mom”)
STRING_TO_REAL (“your mom “)
INT_TO_STRING (69)
REAL_TO_STRING (9.58)
🐍
str()
int()
float()
How do you get the quotient (whole number)?
DIV
🐍//
How do you get the remainder?
MOD
🐍%
What is not equal to
!=
What is equal to , comparatively?
==
What are subroutines?
A set of code within a program , that can be called any time from the man program
What are the advantages of subroutines?
✅can be tested individually, making it easier to debug
✅can be used throughout the program repeatedly, however code only has to be written once = shorter programs
✅can be saved separately as modules , and reused in other programs = saving time
How are subroutines done in Python and pseudocode ?
What are global and local variables?
Global = can be used throughout the program , at any time
Local = can only be used within the structure they are declared in
*less memory
What are parameters ?
A special variable , that passes data into the subroutine
*local scope
1-D |rrays in python and pseudocode
Used to store multiple data values.
A a variable with a single identifier
*index begins at zero for both python and pseudocode
How do you calculate the length of an array in pseudo code and python ?
2D arrays
How do you calculate length in arrays?
How do you access all values within a 2D array?
How do you write a for loop in python and pseudocode ?
What are records?
Basically a dara structure (array), that can store items with different data types
Each record is an individual list in the list of lists 9rows’0
Columns are known as fields, each field is declared with a variable
How do you make a record in python (dictionary) and pseudocode?
What is a data structure ?
A format, for storing multiple data values under one variable name
What is validation?
Checking that data meets certain criterias before passing the program.
It reduces the data entry errors , and prevents the ro gram from crashing if inalienable data is input
What are the types of validation?
Presence check
Format check
Range check
Look up table
Length check
What is authentication?
Checking the identity of a user
What is a syntax error?
When the compiler/interpreter doesn’t understand something , because it doesn’t follow the rules or grammar of the programming language
What is a logic error
When the compiler/ interpreters are able to run the code, but the code does something unexpected
What are the types of testing data ?
Normal
Erroneous
Boundary/ extreme:
Boundary valid & boundary invalid
What are some benefits of the structured approach ?
what are some benefits of arrays
Arrays help maintain large sets of data under a single variable name to avoid confusion that can occur when using several variables
What are the two search algorithms?
🟢Binary search
🟢Linear search
What are the two sort algorithms?
🔵bubble sort
🔵merge sort
describe binary search
Binary search pseudocode code and python
What is the pseudo code for binary search
Describe merge sort
Describe bubble sort
What is the pseudo code for a bubble sort
Merge sort advantages and disadvantages
FOR loop (definite iteration )
Python V pseudocode
Subroutines (procedures and functions)
Python V pseudocode
Arrays (1D & 2D)
Pseudocode vs Python
How do you convert a character into an ASCII value ?
ord()
print (ord(65))
= 65
How do you convert an ACII value into a character?
chr()
print(chr(97))
=a
Describe a linear search
Starts at the beginning of the array
Compares each element until the value being searched for is found, or until the end of the array is reached
What makes an algorithm “more efficient “?
🟢fewer variables
🟢fewer instructions, will take up less memory
🟢will execute in less time
What should be avoided when writing your own programs?
Not using compounded if statements
Instead of an if inside an if use AND
Instead of an elif inside an if use OR
Trying to avoid flag variables : have the whole condition presented within the while statement
How do you declare FOR loops in pseudocode?
Length in array for pseudocode
How do you declare records in pseudocode?
Random number generation for pseudocode
How do you declare records in python ?
How do you find the position of a character in python?
What is the string to character conversion in python?
Random number generation in python
How do you substring an array in python?
what are some things to remember within the exam?
- to use <= instead of the pseudocode syntax
- using a colon after the brackets
- trying to use boolean operators as much as posible