8. algorithms Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

recursive subroutine

A

defined in terms of itself and calls within itself.

the process of executing this subroutine is called recursion

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

3 characteristics of recursive routine

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 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

in-order transversal

A

transverse the left subtree
visit the root node (middle)
visit the right subtree

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

post-order family

A

transverse the left subtree
transverse the right subtree
visit the root (right)

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

pre-order traversal

A

visit the root (left)
transverse the left subtree
transverse the right subtree

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

big O notation in order of efficiency

A

constant
logarithmic
linear
polynomial
exponential
factorial

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

constant

A

o(1)
no loops or recursion - what to look out for
e.g. accessing an element in array
linear straight line graph - what the graph looks like

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

logarithmic

A

o(log n)
1/2 data sets
e.g. binary search
similar to linear graph but with a bump at the start

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

linear

A

o(n)
a single loop
e.g. linear search
‘directly proportional’

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

polynomial

A

o(n^2)
nested loops
e.g. bubble sort
half a u

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

exponential

A

o(2^n)
recursion
e.g. recursion
half a u closer to y axis

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

o n log n

A

e.g. merge sort

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

permutations

A

the permutation of a set of objects is the number of ways of arranging the objects.

e.g. if you have 3 objects A B C, you can choose any of A B C to be the first object, you then have two choices for the second object.

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

formula for calculating the number of permutations of 4 objects is…

A

4 x 3 x 2 x 1, written as 4!, spoke as “four factorial”

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

constant time

A

same amount of time to execute regardless of the size of the input data set

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

linear time

A

describes an algorithm whose performance will grow in linear time, in direct proportion to the size of the data set

17
Q

polynomial time

A

describes an algorithm whose performance is directly proportional to the square of the size of the data set

18
Q

exponential time

A

describes an algorithm where the time taken to execute will double with every additional item added to the data set.

the execution time grows in exponential time and quickly become very large.

19
Q

logarithmic time

A

the time taken to execute an algorithm of order o(log n) (logarithmic time) will grow very slowly as the size of the data set increases.

20
Q

factorial time

A

the time taken to execute an algorithm of order o(n!) will grow very quickly, faster than o(2^n).

21
Q

time complexity of linear search

A

o(n)

22
Q

time complexity of binary search

A

o(log n)

23
Q

time complexity of merge sort

A

o(n log n)

24
Q

depth-first (using a stack)

A

is implemented automatically during execution of a recursive routine to hold local variables, parameters and return addresses each time a subroutine is called. alternatively, a non-recursive routine could be written and the stack maintained as part of the routine.

start at root, follow one branch as far as it will go, then backtrack.

25
Q

breadth-first (using a queue)

A

start root, scan every node connected and then continue scanning from left to right.

26
Q

applications of depth-first search

A
  • in scheduling jobs where a series of tasks is to be performed, and certain tasks must be completed before the next one begins
  • in solving problems such as mazes, which can be represented as a graph
27
Q

applications of breadth-first search

A
  • a major application of a breadth-first search is to find the shortest path between two points A and B. finding the shortest path is important in e.g. GPS navigation systems and computer networks
  • facebook, each user profile is regarded as a node or vertex in the graph, and two nodes are connected if they are each others friends
  • web crawlers. a web crawler can analyse all the sites you can reach by following links randomly on a particular website
28
Q

we increasingly rely on computers to find the optimum solution to a range of different problems. for example…

A
  • scheduling aeroplanes and staff so that air crews always have the correct minimum rest time between flights
  • finding the nest move in a chess problem
  • timetabling classes in schools and colleges
  • finding the shortest path between two points - for building circuit boards, route planning, communication networks and many other application
29
Q

dijkstra’s algorithm

A

is designed to find the shortest path between one particular start node and very other node in a weighted graph.

uses priority queue rather than FIFO queue

30
Q

dijkstra (pronounced dike-stra)

A

lived from1930 to 2002
dutch computer scientist
received the turing award in 1972 for fundamental contributions to developing programming languages

31
Q

weights

A

e.g. could represent distances or time taken to travel between towns or the cost of travel between airports

32
Q

brute-force method

A

testing out very combination of routes

33
Q

traceable problem

A

has a polynomial time solution 0(n^k)

e.g. problems which have solutions with time complexities of o(n), o(n log n) and o(n^10) are all traceable

34
Q

untraceable problem

A

is one that does have a polynomial-time solution
e.g. problems of time complexity o(2^n) and o(n!) are examples of intractable problems.

35
Q

heuristic approach

A

an approach to problem solving which employs an algorithm or methodology not guaranteed to be optimal or perfect, but is sufficient for the purpose.

an adequate solution may be achieved by trading optimality, completeness, accuracy or precision for speed.

36
Q

the halting problem

A

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

what the halting problem shows is that there are some problems that cannot be solved by computer.

37
Q

david hilbert

A

1920s mathematician proposed any problem defined properly could be solved by writing an appropriate algorithm - i.e. that every problem was computable.

38
Q

turing 1936

A

was able to prove david wrong. some problems are simply non-computable. the fact that some problems have no solution is significance to computer scientists.

one definition of computer science is “the study of problems that are and that are not computable”, or the study of the existence and the non existence of algorithms.