2.3 Algorithms extra Flashcards

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

Process of pushing to a stack()

A

Check if the stack is full (pointer =
array.length/array.length+1)
If it is not ¡V insert the item
If it is ¡V return/error that the stack is
full

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

Process of pushing to a stack()

A

line 02
Include an OR with variations (e.g.
userAnswer = “PUSH” OR
userAnswer = “Push” etc.)/Convert
input to uppercase/lowercase and just
compare to equivalent

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

Describe how a 1D array can be set up and used to push and pop items as a stack.

A

Array size defined
A stack pointer is used to point to the
top of the stack
When an item is pushed the stack
pointer is incremented
When an item is popped the stack
pointer is decremented

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

Explain how a linear search would check if the departure station exists in the array.

A

Start at the first item (Cavalry)
Compare with departure station ‘Bridge
Heights’
If matched, report found
Otherwise continue to the next item in
list (Bridge)
Continue until item found, or end of list
reached…
and then False returned

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

Describe the stages of a binary search on an array of size n.

A

Repeat
Calculating an array midpoint…
…by adding the array lower bound to
the array upper bound, dividing by 2
and rounding
Compare array midpoint with value to
search for…
…if equal set found flag to true
…if array midpoint < value to search
for, change lowerbound to equal
midpoint + 1
…if array midpoint > value to search
for, change upperbound to equal
midpoint - 1
Until lowerbound is greater than or
equal to upperbound
Return/output found flag

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

Pre condition for tree to be searched

A

Binary tree and ordered/sorted

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

Describe the disadvantages of using a bubble sort.

A

Bubble sort is an inefficient algorithm…
Meaning it will take more
time/processing cycles to sort the list.
Generally outperformed by Insertion
sort/quick sort/ merge sort (accept any
other sensible sorting algorithm)
The item to be sorted is at the end of
the list (and so can only move back
one place per pass) which is the worst
case scenario for bubble sort

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

dentify the characteristic of this problem that minimises the disadvantages of a bubble sort.

A

There are only a small number of data
items

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

Describe how an insertion sort is performed.

A

One item at a time / serially …
…moved into correct position…
…until all items in list checked

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