Algorithms Flashcards
State the eight steps of the counting occurrences algorithm.
- Set counter to 0
- Recieve searchvalue from keyboard
- For position FROM 0 to number of items in list -1
- If item (position) = searchvalue THEN
- Set counter to counter + 1
- End if
- End for
- Send [counter] to display
What is a dry run?
This involves working through each line of code manually with a sheet of paper and pen. The values of the variables calculate dare written down as they change in a trace table.
What kind of error can be found by using a dry run?
Logic error
What is a breakpoint?
It is a marker set at a line of code, whereupon the program reaches the breakpoint execution is suspended and you can examine the values of the variables.
State the seven steps of the finding the min/max algorithm.
(Below steps are for max algorithm. replace max with min and > with < when doing min algorithm).
- Set max to item(0)
- For position FROM 1 to number of items in list -1
- If item (position) > max THEN
- Set max to item(position)
- End if
- End for
- Send [max] to display
What is a watchpoint?
This is a type of breakpoint that stops the program execution when a condition is met, such as a variable being less than specified.
What are the three kinds of errors?
Syntax, execution and logic.
What is a syntax error?
These are mistakes in the rules and spelling of the programming language and are generally found when the program is being translated.
State the 14 steps of the linear search algorithm.
- Set found to false
- Set position to 0
- Recieve searchvalue from keyboard
- REPEAT
- IF item(position) = searchvalue THEN
- Set found to true
- Send searchvalue to dsplay
- ELSE
- Set position to position + 1
- END IF
- Until found = true OR position > number of items in list
- If found = false
- Send [“Not found!”] to display
- End if
What is an execution error?
This is when the program is being run but fails to carry out an instruction.
What is a logic error?
These are mistakes in the programs steps and can be discovered by comparing expected output to actual output.