Exam 2 Flashcards
What is a precondition for a binary search?
The data must be in order
How does linear search work?
compare the first item with the search value
then compare next item with the search value
repeat process until end of array
to repeat process until the search item has been found and stopped
return the array position
What is the difference between passing a parameter by value and by reference?
By reference receives a memory location yet by value receives a copy of the variable
What is one benefit and one drawback of using global variables instead of local?
Can be accessed by any function
More memory used
Describe a feature of IDE’s that can be helped to write and test programs
Write:
Auto complete- can help fill in the rest
Testing:
Breakpoints- can stop the code at times to check values of variables
Why is an integer value used in an array instead of seperate variables
Numbers can be passed in as a single parameter
How can caching be used in a plane simulation?
Store frequently use data in the cache ( quicker memory) such as the weather
What is a difference between a data tree and a graph data structure?
Graphs don’t have a root node
Why is performance modelling used to test a system?
It is more expensive to test a system
How would you create a 2D array for cards?
cards = [][]
Table question:
5-4-3-2-1
5-4-3-2-1
start from bottom then add up all of the numbers 1+2+3+4+5
OOP code add in?
0
-1
-1
pointerValue
returnValue
Pseudocode for program stack?
True
push
false
print
How can an array be used to implement a queue data structure?
Queue has head pointer and tail pointer
When an item is enqueued the tail pointer increments
When an item is dequeued the head pointer increments
Breadth first vs depth first AO1?
Breadth: check top node then visits all nodes connecting to it, then all the nodes connecting to them
Depth: Visits far bottom left node- returns in then checks the one to its right, does all lf them then goes up and across
Breadth vs depth AO2?
Do the breadth vs depth searches
Breadth vs depth AO3?
Breadth more efficient when it’s closer to the root
Depth more efficient when data is further down
In large trees depth may not even return a value
Why are integers value passed as an array?
Can be passed as a single variable
Bubble sort code?
50
-2
temp value
y
temp value
Bubble vs merge vs insertion AO1?
Merge sort splits data into individual lists
Bubble sort compares one to next
Insertion sort makes new list and adds in
Bubble vs merge vs insertion AO2?
Insertion and bubble average O(n^2)
Insertion and bubble best O(n)
Merge average same as merge best
Merge always O(n log n)
Bubble vs insertion vs merge AO3?
Small number of elements so bubble and insertion best storage wise
Small number of elements so not very many merge sub lists storage wise
Bubble and insertion both best time complexity wise as small number of elements
Difference between A* and Dijkstras?
A* uses heuristics
How can an array be used to implement a queue data structure?
Queue has a pointer and tail pointer
when an item is added to queue the tail pointer increments
when an item is removed from the queue the pointer increments