Unit 8 - Algorithms Flashcards

(19 cards)

1
Q

What are factorials?

A

5! (spoken 5 factorial) is a shorthand way of expressing the product of numbers 1 to 5:
- 5! = 5 x 4 x 3 x 2 x 1
- 0! = 1

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

What is a recursive subroutine?

A

A subroutine that contains itself.
A recursive subroutine has three essential characteristics:
- A stopping condition or base case must be included which when met means that the routine will not call itself and will start to “unwind”,
- For input values other than the stopping condition, the routine must call itself,
- The stopping condition must be reached after a finite number of calls.

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

How do recursive subroutines work with the call stack?

A
  • Every time a subroutine is called, the return address (the line after CALL statement) is put on the call stack,
  • Even with a stopping condition, the recursive routine can only be called a limited number of times or the stack will overflow the maximum memory capacity.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is an example of a recursive algorithm?

A

Tree traversal algorithms.

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

What are two ways to measure how efficient a program is?

A
  • Length of code,
  • Execution time .
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is Big-O notation?

A

Big-O notation is a measure of the time complexity of an algorithm, it is a useful approximation of the time taken to execute an algorithm for a given number of items in a data set.
- There is no such thing as, for example, O(2n + 1),
- Only the dominant term counts, so it is O(n).

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

What is a permutation?

A

A permutation of n items is the number of ways the n items can be arranged.

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

What are the types of permutations?

A
  • Repetition allowed; for example, a combination lock with 4 digits 0 to 9,
  • No repetition allowed; for example, you have 4 differently coloured balls in a bag, and you draw them out one at a time.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the two ways of traversing a graph?

A
  • Depth-first,
  • Breadth-first.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is depth-first traversal?

A

You go as far as you can down a path before backtracking and going down the next path.

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

What is breadth-first traversal?

A

You explore all the neighbours of the current vertex, then the neighbours of each of those vertices and so on.

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

What is Dijkstra’s shortest path algorithm?

A

The algorithm is designed to find the shortest path between a start node and every other node in a weighted graph.

  • It works like a breadth-first search,
  • It uses a priority queue as the supporting data structure to keep a record of which vertex to visit next,
  • It starts by assigning a temporary distance value to each node,
  • The temporary distance is 0 at the start node, and ∞ at every other node.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are computable problems?

A

A problem is defined as being computable if there is an algorithm that can solve every instance of it in a finite number of steps.

Some problems may be theoretically soluble by computer but if they take millions of years to solve, they are, in a practical sense, insoluble.

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

What imposes limits on computations?

A
  • Algorithmic complexity,
  • Hardware.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is The travelling salesman problem (TSP)?

A

“Given a list of towns and the distances between each pair of towns, what is the shortest possible route that the salesman can use to visit each town exactly once and return to the starting point?”

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

What are tractable problems?

A

A problem that has a polynomial-time solution or better is called a tractable problem.

17
Q

What are intractable problems?

A

An intractable problem is one that does not have a polynomial time solution.
Although the problem may have a theoretical solution, it is impossible to solve it within a reasonable time for values of n greater than something very small.

18
Q

What is a heuristic approach?

A

A heuristic approach is one which tries to find a solution which may not be perfect but which is adequate for its purpose.

19
Q

What is the Halting problem?

A

This is the problem of determining for a given input, whether a program will finish running or continue for ever.