P2 theory Flashcards
computational thinking
decomposition - breaking down a complex problem into lots of smaller ones
abstraction - simplifying a problem by picking out important bits of information
Algorithmic thinking - coming up with a series of logical steps to get from a problem to a solution
search algorithms
Binary search:
Pros:
- efficient at searching large lists
Cons:
- list must be ordered first
Linear Search:
Pros:
- simple
- works on unordered lists
Cons:
- inefficient at searching large lists
sorting algorithms
Bubble and Insertion sorting:
Pros:
- simple and easy to implement
- quick to check if a list is already sorted
- doesn’t need much memory, sorting only uses original list
Cons:
- inefficient on large lists
Merge sort:
Pros:
- efficient on large lists
- running time affected by order of items in original list
Cons:
- slower on small lists
- goes through whole process even if list is already sorted
- uses more memory in order to create sub-lists
subprograms
subprogram - a set of instructions stored under one name that are executed when called. They help to improve code structure, improve reliability and avoid repeating code.
Procedures - a subprogram that doesn’t return a value
Functions - a subprogram that does return a value
maintainability
Ways to improve maintainability:
1) comments - write comments to explain what the code does
2) indentation - use indentation to make program flow easier to see
3) descriptive names - use descriptive names for variables, subprograms and parameters so its easier to keep track of them
4) subprograms - use subprograms to separate parts of the program
defensive design
Input Validation:
input validation - checking if data meets certain criteria before passing it into the program
programs normally use a variety of validation checks including:
1) range check - checks the datas in a specified range
2) presence check - checks the datas actually been entered
3) format check - checks the data has the correct format
Authentication:
authentication - confirming the identity of a user before allowing access. Passwords or biometrics are usually associated with a username.
Four ways to make passwords more secure:
1) force strong passwords
2) limit the number of failed authentication attemps
3) require passwords that are change regularly
errors
Syntax errors - when the rules of grammar of the programming language have been broken
Logic errors - when a program is able to run, but does something unexpected
testing
Iterative testing - testing a program whilst its being developed:
- individual modules can be tested and errors fixed
- process is repeated until modules work correctly
- fixing small errors early prevents large errors later on
Final testing - testing a program at the end of development:
- the whole program is tested at the same time
- check for errors where modules interact with eachother
Languages
High level languages:
- the majority of code is written in high level languages e.g. python
- one instruction represents many instructions of machine code
- code is easy to read and write
- must be translated or interpreted before executed
- slower and less memory efficient
Low Level Languages:
- machine code and assembly languages
- one instruction of assembly code can represent one of machine code
- code is hard to read and write
- code usually only works for one machine or processor
- need to know the internal structure of CPU and how it managaes memory
- machine code can be executed directly, without being translated
- faster and more memory efficient
Translators
Compiler:
- translates all code at once into machine code, creating an executable file
- only needed for initial translation
- returns a list of errors for whole program when compiling is complete
- compiling can take a long time, but program runs quickly once compiled
Interpreter:
- translates and runs one instruction at a time using its own machine code subroutines
- used everytime code is run
- stops and returns first error found
- programs run more slowly
IDEs
Integrated Development Environment - software to help develop programs
1) code editor - where code is written. can often automatically colour, indent, correct and complete code
2) run time environment - allows code to be run and tested within the IDE
3) error diagnostics - debugging toool to show information about detected errors
4) break points - pasues the program at certain lines. values can be checked to help diagnose logic errors
5) translator - a compiler or interpreter to allow source code to be executed