algorithm Flashcards

(14 cards)

1
Q

what is an algorithm

A

an algorithm is a set of steps for solving an instance of a particular problem type

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

correctness

A

an algorithm should terminate for every input with the correct output.

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

efficiency

A
  • runtime: time for algorithm to execute is as fast as possible
  • storage: amount of physical storage required to run the algorithm is as little storage as possible
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

algorithmic analysis

A

how well an algorithm performs

linear search

binary search

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

linear search

A
  • initialize the index to the first element of the list
  • while index points to a list element
    o if the value at the current list index is equal to the required value, terminate and return the index
    o else increment the index
  • if the index has run off at the end of the list, return none
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

binary search

A
  • more efficient than linear search
  • initialize a sub-list to the full list, and the index to the midpoint of the list (keep going to the mid point and comparing it)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

algorithm families

A

exact methods

approximate methods

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

exact methods

A

calculate the solution with a guarantee of correctness, provides exact solution

  • brute force
  • divide and conquer
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

brute force

A

exact method

/ generate and test

  • assumption: set of candidate answers can be generated exhaustively
  • strategy: generate candidate answers and test them one by one until a solution is found
  • eg: linear search, testing whether a number is prime
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

divide and conquer

A

exact method

  • strategy: solve a smaller sub-problem akin to the original problem and extend the sub-solution to create the solution of the original problem
  • eg: binary search
  • eg: memoisation – technique to store the results of expensive function calls so that they can be reused later
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Approximate methods

A

estimate the solution with how close it is to the exact solution

simulation

heuristic search

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

simulation

A

type of approximate method

  • Strategy: play out a complex scenario with random inputs until we can verify stability of the answer
  • Eg: weather forecast, movement of planets
  • multiple runs
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

heuristic search

A

type of approximate method

  • strategy: search for a solution by exploring more promising avenues fist
  • sacrifice optimality for efficiency
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

memoisation

A

technique to store the results of expensive function calls so that they can be reused later

used to improve efficiency when a function is called several times with the same input to avoid duplicate computation

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