Algorithms 1 Flashcards

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

Describe how the linear search algorithm works.

A

Start at the beginning of the array, then compare each element until the value being searched is found or until the end of the array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
code ← '' 
i←0
WHILE instr[i] ≠ ':' AND i < 4 
code ← code + instr[i]
 ENDWHILE
 valid ← False
 IF code = 'ADD' OR code = 'SUB' OR code = 'HALT' THEN
 valid ← True
ENDIF

Shade one lozenge to show the most appropriate data type of the variable i in the algorithm.

A

integer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
code ← '' 
i←0
WHILE instr[i] ≠ ':' AND i < 4 
code ← code + instr[i]
 ENDWHILE
 valid ← False
 IF code = 'ADD' OR code = 'SUB' OR code = 'HALT' THEN
 valid ← True
ENDIF

state the data type of the variable ‘valid’ in the algorithm

A

Boolean

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

State the final value of the variable ‘valid’ in the algorithm for the following different starting values of instr.

A

False
True
True

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

State what an assembly language program must be translated into before it can be executed by a computer.

A

Machine code

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

State two reasons why a programmer, would usually choose to develop in a high level language rather than a low level language.

A
  1. (High-level languages) are easier to understand/read

2. High level languages are easier to debug.

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

The algorithms in Figure 4 and 5 have the same purpose

State this purpose

A

To multiply the value in number by 3

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

Explain why the algorithm shown in Figure 4 can be considered to be more efficient algorithm than the algorithm shown in Figure 5

A

Algorithm in figure 4 uses less variables

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

Show the steps involved to bubble sort the array shown.

8,4,1,5

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

Complete the table showing all the outputs from the subroutine call main (3)

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

Describe how the developer has used the structured approach to programming in Figure 7

A

The developer has used local variables

The developer has used parameters

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

Shade one lozenge to show what value would be returned from the subroutine call CODE_TO_CHAR(100)

A

B - ‘d’

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

State the value that will be returned from the subroutine call
CODE_TO_CHAR(CHAR_TO_CODE(‘E’)+2)

A

G;

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

A developer needs to store data about thousands of songs in a program. She needs to be able to hold information on every song’s title, singer, and year of release.
Explain how the developer could use a combination of an array and records to store this information.

A

An array could be used to store all the songs
A record could be used to store data for one song.

The singer could be a string
the year of release could be a integer
the song title is a string

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