Algorithms Flashcards

1
Q

State the eight steps of the counting occurrences algorithm.

A
  1. Set counter to 0
  2. Recieve searchvalue from keyboard
  3. For position FROM 0 to number of items in list -1
  4. If item (position) = searchvalue THEN
  5. Set counter to counter + 1
  6. End if
  7. End for
  8. Send [counter] to display
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a dry run?

A

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.

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

What kind of error can be found by using a dry run?

A

Logic error

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

What is a breakpoint?

A

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.

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

State the seven steps of the finding the min/max algorithm.

A

(Below steps are for max algorithm. replace max with min and > with < when doing min algorithm).

  1. Set max to item(0)
  2. For position FROM 1 to number of items in list -1
  3. If item (position) > max THEN
  4. Set max to item(position)
  5. End if
  6. End for
  7. Send [max] to display
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a watchpoint?

A

This is a type of breakpoint that stops the program execution when a condition is met, such as a variable being less than specified.

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

What are the three kinds of errors?

A

Syntax, execution and logic.

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

What is a syntax error?

A

These are mistakes in the rules and spelling of the programming language and are generally found when the program is being translated.

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

State the 14 steps of the linear search algorithm.

A
  1. Set found to false
  2. Set position to 0
  3. Recieve searchvalue from keyboard
  4. REPEAT
  5. IF item(position) = searchvalue THEN
  6. Set found to true
  7. Send searchvalue to dsplay
  8. ELSE
  9. Set position to position + 1
  10. END IF
  11. Until found = true OR position > number of items in list
  12. If found = false
  13. Send [“Not found!”] to display
  14. End if
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is an execution error?

A

This is when the program is being run but fails to carry out an instruction.

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

What is a logic error?

A

These are mistakes in the programs steps and can be discovered by comparing expected output to actual output.

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