sequence is the natural order of going down one line at a time
iteration is repeating something, especially with a small change each time.
Recursion is iteration, which uses a conditional. It will repest code untill the conditional is the expected value
Another form of selection is switch case systems
Switch case systems use a certain variable and act depending on if that variable is one out of a few possible values. Each value should have a process dependent on it
What is the psuedocode for switch case where if the value is 1 it prints error else prints nice?
SWITCH input:
CASE 1:
SEND 'error' TO DISPLAY
DEFAULT:
SEND 'nice' TO DISPLAY
ENDSWITCH
In python switch case can be used with 'match' for switch and 'case_' for default
Operation follow the rules of BIDMAS
Structured programming is the top-down approach which uses modularization. Each module uses structured code
Range creates a list in the specified range with the specified steps (default +1)
for loops are used for iteration and are very useful if we only want a process to repeat a set number of times
While loops occur if a condition is met and are checked before running the code
Repeat until loops break when the condition is no longer met but only checks if the condition is no longer met after running the code, and therefore it will always be ran at least once
a range misses the last number so range (5) would create the following, 0,1,2,3,4
3 benefits of structured programming:
Easier to debug
Easier to maintain
Easier to write
Main negative of structured programming:
It takes longer implement as it must be converted into machine code
Hierarchy charts are just breaking down a problem with each problem being as broken down as possible. It is often used for planning top-down programming
Structured programming is using lots of modern practices such as modularisation and conditionals
How would you explicitly iterate over all separate elements of a multi-dimensional array:
Assume array is called array_name
numpy has been imported as np
for i in np.nditer(array_name):
Lists have to move to an entirely new memory address whenever data is appended
Linked lists, chain many nodes (a pointer, and an item on the list), to store data without having to move the entire list each time an item is appended.
What is this an image of?
linked list
A priority queue is a linked list that also does an equation that sets a priority value to each item
Declaring a variable or function means you specify it's type