Algorithms 1 Flashcards
Describe how the linear search algorithm works.
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.
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.
integer
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
Boolean
State the final value of the variable ‘valid’ in the algorithm for the following different starting values of instr.
False
True
True
State what an assembly language program must be translated into before it can be executed by a computer.
Machine code
State two reasons why a programmer, would usually choose to develop in a high level language rather than a low level language.
- (High-level languages) are easier to understand/read
2. High level languages are easier to debug.
The algorithms in Figure 4 and 5 have the same purpose
State this purpose
To multiply the value in number by 3
Explain why the algorithm shown in Figure 4 can be considered to be more efficient algorithm than the algorithm shown in Figure 5
Algorithm in figure 4 uses less variables
Show the steps involved to bubble sort the array shown.
8,4,1,5
8,4,1,5 4,8,1,5 4,1,8,5 4,1,5,8 1,4,5,8 1,4,5,8
Complete the table showing all the outputs from the subroutine call main (3)
10 5 16 8 4 2 1
Describe how the developer has used the structured approach to programming in Figure 7
The developer has used local variables
The developer has used parameters
Shade one lozenge to show what value would be returned from the subroutine call CODE_TO_CHAR(100)
B - ‘d’
State the value that will be returned from the subroutine call
CODE_TO_CHAR(CHAR_TO_CODE(‘E’)+2)
G;
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.
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