Unit 4 (teachers notes) Flashcards
Sequential/ linear search:
Sequential/ linear search: Usual search, go through every value and compare to the target value.
Simple to implement, data doesn’t need to be in order. Inefficient with large number of elements,may have to go through every single one of them.
collections:
Collection: Group of objects. No assumptions are made about the order of the collection (if any) or whether it can contain duplicate elements. We add and retrieve data from them.
Suitability of an algorithm
Suitability of an algorithm
Efficiency: Amount of computer resources required to perform algorithm’s functions
Correctness: Extent to which algorithm satisfies specification
Reliability: Capability to maintain performance
Flexibility: Effort required to modify algorithm for other purposes
Big O notation: Measure of efficiency of an algorithm.
O(1) – efficiency and speed are always the same, time proportional to 1. e.g. addFront, algorithm
that adds up fixed no. of values etc.
O(n) – time and efficiency proportional to n. e.g. linear search method (proportional to length of array, longer array = longer time searching, loop to non-constant value etc.)
O(n2) – proportional to n2. Time required increases rapidly if n increases e.g. nested loops in bubble sort and select sort
Big O notation: Measure of efficiency of an algorithm.
Big O notation: Measure of efficiency of an algorithm.
O(1) – efficiency and speed are always the same, time proportional to 1. e.g. addFront, algorithm
that adds up fixed no. of values etc.
O(n) – time and efficiency proportional to n. e.g. linear search method (proportional to length of array, longer array = longer time searching, loop to non-constant value etc.)
O(n2) – proportional to n2. Time required increases rapidly if n increases e.g. nested loops in bubble sort and select sort
Pseudo cide, mod and div
Pseudo code
mod (returns remainder e.g. 15 mod 7 = 1),
div (how many times number fits e.g. 15 div 7 = 2)
Programming languages
Programming languages
Machine language: Low-level language directly understood by computer, made up of binary numbers.
Assembly language: Low-level language using symbols for instructions and memory addresses
High-level programming language: Uses elements of natural language. Easy to use for humans and more understandable. Abstracts some areas of computing systems, would otherwise take too long to write our systems in machine code.
Programming languages need to have…
Programming languages need to have…
Fixed vocabulary- Instructions for operations do not change. e.g. “print” will always print
Unambiguous meaning- Clear instructions
Consistent grammar and syntax- The way we declare and use language features must be the same.
Provide a way to define basic data types and operations on those types- ability to write functions/procedures
It has to run on/be able to be processed by a computer- it must have a compiler/interpreter
Higher level programming languages can differ by…
Higher level programming languages can differ by…
Method of translation- Whether by compiler or interpreter (or both)
Different programming paradigms- e.g. procedural or object-oriented
Purpose of the language- Specific for certain tasks (e.g. CSS for HTML websites or language for AI) or general purpose (can build any program with any logic e.g. Python)
Compatibility with different environments- e.g. Java with virtual machine can run on all OS while some languages can’t
Syntax differences- e.g. structure of statements
Source code:
Source code: Original code/program developed using high level language. Needs to be translated
Object/Target program:
Object/ target program: Program translated into machine language.
translation methods:
Translation methods:
Compiler: Executes translation process only once, translates the whole program. Object program is saved so it doesn’t need to be compiled again. All errors are displayed when the whole program is checked, compilation ends only once errors are fixed. Example: C++
Interpreter: Reads, translates and executes program line by line. Errors are displayed after each line is interpreted. Goes through the process every time the program is run, much slower than a compiler. Example: BASIC
Writing code
Variable
Constant
Object
Writing code
Variable: Used to store a data element that can be changed during program execution. Has an identifier and type.
Constant: Elements and quantities that don’t change. e.g. final double PI = 3.14
Object: Comprised of data and methods (operations that can be performed by the object)
Thinking procedurally
Sub-procedure:
This includes identifying the steps and putting them in the correct order e.g. recipes
Sub-procedure: A section of code in a program that does a specific job. Can be called by name when needed without naming the details as these are wrapped in the procedure. It is therefore an example of abstraction.
Thinking logically
Thinking ahead
Gantt Charts:
Thinking logically
Different actions are taken based on conditions, taking alternative procedures into account. Need to identify conditions associated with a given decision (like an IF statement
Thinking ahead
Need to identify inputs and outputs required in solution before carrying it out. e.g. cooking- need to identify the different ingredients.
Gantt Charts:
Outlining tasks, how long they will take to carry out, and when they are carried out. Can identify and show what tasks can be carried out concurrently.
Allows easy inspection and overlapping tasks, durations etc.
Pre-planning
Prefetching/ caching:
Pre-condition:
Post-condition:
Pre-planning
Prefetching/ caching: Building libraries of pre-formed elements for future use, e.g. using Java libraries to increase efficiency, making sure you have your most commonly used spices ready at the front of your cupboard for cooking etc.
Pre-condition: Starting state before algorithm is executed, conditions that need to be fulfilled. E.g. have to have the required ingredients, a place to cook
Post-condition: Final state after execution of algorithm, the state you are trying to achieve/ lead up to, the final result.
Will need to also consider exceptions when building pre-conditions, e.g. identifying conditions for calculating end of year bonus when not all employees have worked for the company for the whole year.