Analysis, Design and Comparison of Algorithms Flashcards

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

What are two things to check when Analysing an Algorithm

A
  • Time Complexity
  • Space Complexity
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the Time Complexity of an Algorithm

A

How much time an algorthim takes to solve a particular problem relative to the number of inputs it recieves

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

What is Time Complexity measured in

A
  • Big-O notation
  • Big-o notation shows the effectiveness of an algorithm
  • It shows an upper limit for the amount of time taken relative to the number of data elements given as an input
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How is Big-O notation written

A

In the form 0 (n), where n is the : the number of inputted entities, and 0 (n) is the time relationship

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

What are the examples of Big-O Notation

A
  • 0 (k) - Constant Time Complexity - the amount of time taken to complete an algorithm is independent from the number of elements inputted
  • 0 (n) - Linear Time Complexity - the amount of time taken to complete an algorithm is directly propoertional to the number of elements inputted
  • 0 (n2) - Polynomial Time Complexity (example) - the amount of time taken to complete an algorthim is directly propertional to the sqaure of the elements inputted
  • 0 (nn) - Polynomial Time Complexity - the amount of time taken to complete an algorithm is directly proportional to the elements inputted to the power of n
  • 0 (2n) - Exponential Time Complexity - the amount of time taken to complete an algorithm will double with every additional item
  • 0 (log n) - Logarithmic Time Complexity - the time taken to complete an algorithm will increase at a smaller rate as the number of elements inputted increases
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Give an Algorithm example of each Big-O Notation

A
  • Constant Time - print (“hello”)
  • Linear Time Complexity - for ([a,b,c … n] print(“hello”)
  • Polynomial Time Complexity - for ([a,b,c … n] for ([a,b,c … n]) print (“hello”)
  • Exponential Time Complexity - recursive algorithms with size n
  • Logarithmic Time Complexity - a divide and conquer algorithm
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Describe the Consant Time Complexity Graph

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

Describe the Linear Time Complexity Graph

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

Describe the Polynomial Time Complexity Graph

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

Describe the Exponential Time Complexity Graph

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

Describe the Logarithmic Time Complexity Graph

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

Which are the best and worst time complexities

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

What is the Space Complexity of an Algorithm

A

The amount of storage the algorithm takes

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

How is Space Complexity written

A
  • Big O notation
  • Algorithms store extra data whenever they make a copy, this isn’t ideal
  • When working with lots of data it is not a good idea to make copies as they takes up storage which is expensive
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is an Algorithm

A

A series of steps that complete a task

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

When does time complexity take priority and when does space complexity take priority

A
  • If you have a lot of processing power then focus on space complexity
  • If you have a lot of data that needs to be processed quickly you would focus on time complexity
17
Q

How do you reduce Space Complexity and Time Complexity

A
  • Reduce Space Complexity - perform all of the changes on the original piece of data
  • Reduce Time Complexity - reduce the number of embedded loops, reduce number of items you have to complete operations on (divide and conquer algorithm)
18
Q

What Big-O Notation does the Linear Search Algorithm have

A

0 (n)

19
Q

What is the Big-O Notation for the Binary Search Algorithm

A

0 (log(n))

20
Q

What is the Big-O Notation for a Bubble Sort Algorithm

A

O (n2)