Please enable JavaScript.
Coggle requires JavaScript to display documents.
1.3 Algorithms and Programs (Definitions (Algorithm - A set of…
1.3 Algorithms and Programs
Definitions
Algorithm - A set of instructions that takes an input and turns it into an output of some kind.
Variable - A value that can be stored in RAM temporarily and be called upon whenever needed.
Constant - A value which doesn't get changed, but is set to a variable, so that it is easy to use multiple times. Eg. Pi
Local Variable - When defined, local variables will be confined to just that subroutine, which means its value will be cleared when the subroutine ends.
Global Variable - Can be used throughout the program, its value isn't deleted until the program ends.
Verification - Checks done by a human to ensure that data/code is correct.
Validation - Checks done by a computer for spelling or syntax errors.
Sequence - A set of instructions that are carried out once each.
Selection - Where the program makes a decision. Eg. If statement
Repetition - Where a statement is repeated more than once. Eg. While/For loop
Scope - Where in a program a variable can be accessed
Flowchart symbols
Terminator - Shows the start/end of the chart
Decision - Describes statements such as IF and ELSE
Input - For collecting the user's input
Output - Will output something to the user
Process - Handles things like variable assignment
Big O
O(1) - Constant time
O(log n) - Logarithmic time
O(n) - Linear time
O(n²) - Polynomial time
O(2ⁿ) - Exponential time
Searching/Sorting Algorithms
Linear Search - Compares each value in a list, one at a time until it finds the correct value.
Binary Search - Compares the middle item in a list, decides if it's too big or too small, then finds the middle of the correct half and repeats. Only works on sorted lists.
Insertion Sort - Takes each value one at a time, and puts it into the right order, until all values have been sorted
Compression
Lossless - Compression that doesn't change the file in any way, but makes use of repeating phrases and words. Eg. Run Length Encoding (RLE) would turn 0000 0110 into 5(0) ; 2(1) ; 0
Lossy - Compression that removes data that might be deemed unneeded. Eg. Lowering a picture's quality
Pseudocode
FOR i = 1 to 10 // OUTPUT i // NEXT i
MOD - Outputs the remainder of a division
Arrays - Names ← ["Adam", "Ryan", etc]
Parameter Passing
Function - A subroutine that will return a value. In this, parameters are used to "copy" the data that they hold, into the subroutine.
Procedure - A subroutine that doesn't return a value
Parameters by value - Any variable that goes into the function/procedure is unchanged (although the new variable may be changed)
Parameters by reference - Where the variable outside the function/procedure is changed by it.
Modules
Code that's split into different sections, and could run by itself. Together it makes a bigger program. Eg. Login Screen/Different sections in a game.
Can be created by different programmers who specialise in that specific section.
Tested separately, and is easier to spot the bugs (because smaller program).