mistakes 2 Flashcards
(65 cards)
linear s
Compare the search item with the first value
* ….then compare the search item with the next value
* ….repeat the above process until either
* ….the end of the array has been reached or
* ….the search item is found and then stop
* ….then return the array position // return -1 / False if not found
by value vs by reference
By reference the function receives the memory location of the data
* By value the function receives a copy of the variable
- By reference will make changes to the original variable
- By value will make changes to the copy of the variable
- By reference will overwrite data in the original variable
- By value will not overwrite the data in the original variable
- By reference will keep the changes after the function ends
- By value will not keep the changes after the function ends
define local and global
Local variables:
* Scope within the module defined
within
* Cannot access externally unless
passed as parameter, or returned
from function
* When module is exited, memory of
variable is freed
Global variables:
* Scope within the entire program
* Can access from anywhere
* Retained in memory permanently
ByRef Points to location of variable
ByVal Sends the value
Local adv + dis
need to be passed as parameters
byreference
Can send ByVal – but not always
possible with arrays in some
languages
Modules are self contained and then
can be reused in other programs he
wants to create without needing to
take the global variables with them
+ve Local = memory efficient
-ve Local = more difficult to
trace/debug/follow where the values
are passed
Global adv + dis
can be accessed from all modules by direct reference
might not be memory intensive,
unlikely anyone else is going to
access/amend e.g. use as a library –
therefore global would not waste
significant resources
Benefits:
* Variable doesn’t need passing as a parameter (byref)
* You don’t need to return a value
* Can be accessed from any function / anywhere in the program
easier programming,
simpler to follow, easier to debug
Drawback:
* Increases memory usage (as it is used until full program execution is over)
* Alterations within the function may have unwanted side effects elsewhere in
the program.
memory inefficient, not
good programming technique
IDE writing
- Auto-complete
- Start typing an identifier/command and it fills in the rest
- Auto-indent
- Indents code automatically within structures to avoid errors
- syntax highlighting
- Shows which commands are correct // help identify key elements
autocorrect - Tell you when you make a syntax error
IDE testing
- Breakpoints
- Stop the program running at a set point to check variables
- Variable watch window
- Display the values of the variables while the program is run
- Stepping
- Run one line at a time and check variables
Unit Testing
* Automated tests to be run to check changes ensure changes haven’t introduced errors.
IDE debugging
Underlines syntax errors dynamically
Can be corrected before running // saves times
Watch window
View how variables change during running of the program
Break points
Stop the program at set points to check the values of variables
Error message list
Tells you where errors are and suggests corrections
Step-mode
Executes program one statement at a time to watch variable values and program pathways
Traces
Print-outs of variable values for each statement execution within a program
Crash-dump/post-mortem routine
Shows the state of variables where an error occurs
Stack contents
Shows sequencing through procedures/modules
Cross-referencers
Identifies where variables/constants are used in a
program to avoid duplications
Reusable components
Saves time from having to write the same algorithm repeatedly
* Reduced testing requirements
* Can be taken and used in different programs as well as the program they are
written in // can be used in a program library
Breadth?
takes first value then visits all
nodes connected to it. It then takes all
nodes connected to those nodes.
more efficient when the data
searched for is closer to the root
Depth?
note same as post order
left node, this
becomes a new tree. It continues going to
the left until a leaf. It then returns this, then
goes right and repeats from the start. Follow
left, follow right, take root.
breath vs depth
Breadth is more efficient when the data
searched for is closer to the root.
* Depth is more efficient when data to be
search for is further down.
* Depth memory requirement is linear
* Depth can be written recursively to aid
understanding.
* Breadth in general is better time complexity
* In large trees depth may never return a
value
why use array instead of separate v?
all values can be indexed in one
array
* The numbers can be passed as a single parameter
* Does not need 50 variables to be declared/passed
Merge vs bubble vs insertion vs quick
Merge sort splits data into individual lists and merges
* Insertion makes first value sorted list, then inserts each item into the sorted list
* Bubble sort looks through each item in turn, number of items times
Merge uses more memory as new lists are needed. Insertion and Bubble need constant memory.
Quick increases not as much as merge
Best time:
* Bubble and Insertion have the best times, both O(n) because they run through data once. (increase at same rate as # elements)
Quick and merge increase at greater rate merge sort requires a minimum number of stages so best case is longer (O(n log(n))
* Merge average is the same as best.
Insertion and Bubble has average o(n^2).
Worst time: insertion and quick increase significantly by n for each additional item. O(n^2) for bubble + insertion
Merge sort increases less per
element - same number of stages
are needed.
When use bubble, merge, insertion, quick?
small number - bubble or insertion as no further space needed and tc small
merge may not need lots of memory too but timewise theyre all similar ish as small number - space not imp tho
large
Log more appropriate for large number
of elements
but memory imp although logarithmic more appropriate
Differences bet reality and simulation
Removal of visual elements such as buildings on the ground
* Simplification of controls
* Focus on important elements such as weather, height, speed
Why abstract?
Reduce memory requirements
* Reduce processing requirements
* Simplify the problem being solved
Reduces complexity of design
Reduces complexity of programming
Could involve a large number of images that would take
excessive memory
Reality contains things that aren’t relevant to a computer program
How use caching?
Store data that has been used in cache/RAM in case needed again
Directed vs undirected
ARCS/EDGES in 1 direction for directed
Graph vs tree
Graphs:
multiple paths
no (clear) root node
weighted (can be)
loops/cycles
bi-directional
tree has hierarchy
Both:
nodes, connected by edges, non-linear DS, dynamic
Visualisation
benefit humans rather than computers
present the information in a simpler form to understand
best explain complex situations
symbols
edges for physical connections bet addresses not actual physical routes
D vs A*
both pathfinding algos to find shortest route
A* is (usually) more efficient // dijkstra’s is (usually) slower
* A* uses heuristics to find a solution faster // Dijkstra’s does not use heuristics
Performance modelling?
Simulate/model behaviour of the system (before it is) used under load
* Because it would be too expensive/unsafe/time critical to test the real system
Test with large and small values
* Model how well the system scales with increasing use
recursive func
A function that calls itself // a function that is defined in terms of itself
* …has a base case (that terminates the recursion)