Survey

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts

Pattern recognition wikipedia, lookup

Knapsack problem wikipedia, lookup

Computational complexity theory wikipedia, lookup

Probabilistic context-free grammar wikipedia, lookup

Minimax wikipedia, lookup

Sieve of Eratosthenes wikipedia, lookup

Genetic algorithm wikipedia, lookup

Corecursion wikipedia, lookup

Operational transformation wikipedia, lookup

Fast Fourier transform wikipedia, lookup

K-nearest neighbors algorithm wikipedia, lookup

Fisher–Yates shuffle wikipedia, lookup

Simplex algorithm wikipedia, lookup

Smith–Waterman algorithm wikipedia, lookup

Algorithm characterizations wikipedia, lookup

Factorization of polynomials over finite fields wikipedia, lookup

Expectation–maximization algorithm wikipedia, lookup

Algorithm wikipedia, lookup

Quicksort wikipedia, lookup

Time complexity wikipedia, lookup

Transcript
```Advanced Higher
Computing Science
SDD Basic Revision
2. 2D Arrays
3. Sorting Algorithms
4. Binary Search
2D Arrays
1. Temperature readings are taken at 20 weather stations throughout the UK.
Readings are taken at each station 8 times in one day.
a) Describe how a 2-D array could be used to store the temperatures for
each station.
b) Declare this array
c) Write an algorithm that will count the number of occasions the
temperature was above 10oC
d) Write a single algorithm to find the highest and lowest temperature
recorded.
e) Write an algorithm that will create a data file containing all readings.
Stack
2.
a) Describe the operation of a stack
b) What is the purpose of the stack pointer? Describe how it works.
c) What value would be held in the stack pointer when the stack is
empty?
d) Name and describe two conditions that could cause a stack error.
e) Describe how a stack differs from a queue?
f) What are the advantages of using a linked list to implement a stack
rather than a 1D array?
Queues
3.
a) Describe the operation of a queue
b) What problem occurs in a queue when items continue to be added and
removed?
c) Describe how this problem is overcome?
d) State the values of the front and rear variables, below, after 2 items are
0
1
X
2
C
3
F
F
4
A
5
6
7
R
e) What are the advantages of using a linked list to implement a queue
rather than a 1D array?
4. The following data is held in a stack data structure.
Belmont
Ayr
Prestwick
Girvan
QMA
Kyle
a) Show how this stack would be represented using a linked list
Sorting Algorithms
5. A section of code from a sort algorithm is shown below.
1. FOR outer FROM 0 TO size
2.
3.
FOR inner FROM 0 TO size – 1
IF List[inner] > List[inner + 1] THEN
4.
SET temp TO List [inner]
5.
SET List[inner] TO List[inner + 1]
6.
SET List[inner + 1] TO temp
7.
END IF
8.
NEXT inner
9. NEXT outer
(a)
State the name of this sort algorithm
(b)
Describe how this algorithm works
(c)
Explain the purpose of each line from 3 to 6
(d)
Which order would this algorithm sort the list into?
(e)
Explain why this algorithm is not as efficient as it could be. Rewrite the
algorithm to show a more efficient implementation.
(f)
Under what circumstances will this new implementation be at its most
efficient?
6. A section of code from a sort algorithm is shown below.
1. FOR outer FROM 0 TO size
2.
SET min TO outer
3.
FOR inner FROM 1 TO size
4.
5.
IF List[inner] <= List[min] THEN
SET min TO inner
6.
END IF
7.
NEXT inner
8.
SET ListB[outer] TO List[min]
9.
SET List[min] TO 60
10. NEXT outer
(a)
State the name of this sort algorithm
(b)
Describe how this algorithm works
(c)
Explain the purpose of each line from 3 to 6 and 8 to 9.
(d)
Which order would this algorithm sort the list into?
(e)
A list of 10 numbers ranging from -3 to 28 is to be sorted. Suggest a
suitable value for the dummy value in this case and explain your
(f)
Give one reason why this algorithm is less efficient than the others.
7. A section of code from a sort algorithm is shown below.
1. FOR outer = 1 TO size
2.
SET temp TO List(outer)
3.
SET inner TO outer
4.
DO WHILE inner > 0 AND List(inner-1) > temp
5.
SET List(inner) TO List(inner - 1)
6.
SET inner TO inner – 1
7.
8.
REPEAT
SET List(inner) TO temp
9. END FOR
(a)
State the name of this sort algorithm
(b)
Describe how this algorithm works
(c)
Explain the purpose of each line from 4 to 8
(d)
Which order would this algorithm sort the list into?
Searching Algorithms
1. A section of code from a search algorithm is shown below.
Set lower to lowest index
Set higher to highest index
Loop
set middle to (lower+upper) /2
if search_value>list(middle) then
i
else
ii
end if
until list(middle) = search value or lower>upper
if search_value = list(middle) then
display “Search item was found at”,middle
Else
display “Search item is not in list”
End IF
(a)
What is the name of this algorithm?
(b)
Complete the missing lines i and ii.
(c)
State the essential requirement of the list for this algorithm to work
correctly?
0
5
1
9
2
12
3
15
4
18
5
21
6
45
7
62
8
75
(d)
When searching for the number 62, give the value of the middle, upper
and lower variables after the second pass.
(e)
How many comparisons would be required to find the value 9 in the
above list?
(f)
Compare this algorithm with one other in terms of efficiency when
(g)
Show how the above algorithm would have to change to find values in
the following list?
0
75
1
69
2
42
3
35
4
28
5
21
6
15
7
10
8
5
```