Exam 2 Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What is a precondition for a binary search?

A

The data must be in order

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How does linear search work?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the difference between passing a parameter by value and by reference?

A

By reference receives a memory location yet by value receives a copy of the variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is one benefit and one drawback of using global variables instead of local?

A

Can be accessed by any function
More memory used

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Describe a feature of IDE’s that can be helped to write and test programs

A

Write:
Auto complete- can help fill in the rest
Testing:
Breakpoints- can stop the code at times to check values of variables

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Why is an integer value used in an array instead of seperate variables

A

Numbers can be passed in as a single parameter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How can caching be used in a plane simulation?

A

Store frequently use data in the cache ( quicker memory) such as the weather

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a difference between a data tree and a graph data structure?

A

Graphs don’t have a root node

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Why is performance modelling used to test a system?

A

It is more expensive to test a system

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How would you create a 2D array for cards?

A

cards = [][]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Table question:

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

OOP code add in?

A

0
-1
-1
pointerValue
returnValue

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Pseudocode for program stack?

A

True
push
false
print

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How can an array be used to implement a queue data structure?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Breadth first vs depth first AO1?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Breadth vs depth AO2?

A

Do the breadth vs depth searches

17
Q

Breadth vs depth AO3?

A

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

18
Q

Why are integers value passed as an array?

A

Can be passed as a single variable

19
Q

Bubble sort code?

A

50
-2
temp value
y
temp value

20
Q

Bubble vs merge vs insertion AO1?

A

Merge sort splits data into individual lists
Bubble sort compares one to next
Insertion sort makes new list and adds in

21
Q

Bubble vs merge vs insertion AO2?

A

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)

22
Q

Bubble vs insertion vs merge AO3?

A

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

23
Q

Difference between A* and Dijkstras?

A

A* uses heuristics

24
Q

How can an array be used to implement a queue data structure?

A

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

25
Q

OOP vs procedural AO1?

A

OOP defines an object as an entity
Oop defines attributes of the object and then the methods they can be used in
Attributes can be private to stop accidental changes
Procedural statements are executed as they are written

26
Q

OOP vs procedural AO2?

A

OOP allowed an object to be created for the queue
This can be repeated very easily by being declared in the main program
Procedural every queue needs to be declared individually

27
Q

OOP vs procedural AO3?

A

OOP can create multiple instances of the queue without having to repeat the code every time
OOP less code required so fewer errors as only written once
Procedural would require global variables for ease which is more storage