2.3 - Algorithms Flashcards

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

Define an Algorithm

A

A set of steps must be followed, one after each other to solve a problem.

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

What are the 3 main components of an algorithm?

A
  1. Input
  2. Process
  3. Output
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the qualitites of a good algorithm?

A
  • has clear + precisly stated steps that produce the correct output for any set of valid inputs.
  • allows for invalid inputs.
  • must always terminate at soome point.
  • should execute efficiently in as few steps as possible.
  • designed so other people can understand + modify if necessary.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Define a statement

A

A single line of instruction in code.

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

Define efficiency

A

No. of assignment statements. Less lines = more efficient + less memory storage is used. Instructions proceed quicker.

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

What can cause execution time to be longer?

A

If the promblem size is bigger or there is a larger amount of data.

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

What is the equation for a linear function?

A

f(n) = an +b
a + b are constants
e.g. f(n) = 3n, f(n) = n + 5, f(n) = 6n + 1

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

What is the equation for a constant function?

A

f(1)
e.g f(2), f(100)

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

Define a constant function.

A

No matter how large n gets, f(1) stays the same.

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

What is the order of magnitde for a linear function?

A

O(n)

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

Define a linear function.

A

Everything increases in a straight line

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

What is the equation for a quadratic function?

A

f(n) = an∧(2) + bn + c

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

Define a quadratic function.

A

As n increases, the n∧(2) term increases much faster than either of the other terms.

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

What is a stack?

A

A stack is an abstract data type that serves as a collection of elements. An example of FILO. (Try to imagine FILO with books.)

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

What is the order of magnitude for a quadratic function?

A

O(n∧2)

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

What is a queue

A

A queue is an abstract data type (ADT) is a logical description of how we view the data and possible operations, that holds an ordered. It is an example of FIFO. Often represented as an array.

17
Q

What is the dominent term?

A

The term that grows the fastest.
e.g n² grows faster than n, so if we have g(n) = n² + 5n + 6, it will be big O(n²).

18
Q

What is the equation for a logarithmic function?

A

f(n) = alog∨(2)n
e.g. log∨(2)16 = log∨(2)2∧(4)

19
Q

Define a logarithmic function.

A

the logarithm of a number of a number is the power to which the base must be rasied to make it equal to the number. f(n) increases very slowly in relation to n.

20
Q

What is the order of magnitude for a logarithmic function?

A

O(log n)

21
Q

What is Big-O notation?

A

A measure of time complexity of an algorithm. An aproximation of the time taken to execute an algroithm for a given number of items in a data set.

22
Q

What are trees

A

A tree is a connected, undirected graph with no cycles, a common abstract data type (ADT)

23
Q

What is a rooted tree?

A

A rooted tree is a tree with one node that is defined as the root. Every node except the root has one unique parent (different from binary tree)

24
Q

How do divide + conquer algorithms (logarithmic functions) work?

A

They halve the size of the problem at each pass. So the time complexity increases very slowly as the problem size increases.
e.g. in binary search algorithm, for balenced tree of 1024 (i.e. 2∧(10)) only 10 items need to be explained. Or 2948 (i.e. 2∧(11)) only 11 items need to be explaned.

25
Q

What is a permutation?

A

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

26
Q

What is a repition permutation?

A
27
Q

What is a no repition permutation?

A
28
Q

What is the time complexity of a no repition permutation?

A

O(n!)

29
Q

What is the time complexity of a repition permutation?

A