Big O Notation Flashcards

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

What is Big O Notation?

A

Big O notation is used in Computer Science to describe the performance or complexity of an algorithm. Big O specifically describes the worst-case scenario, and can be used to describe the execution time required or the space used (e.g. in memory or on disk) by an algorithm.

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

What is O(1)?

A

O(1), or constant time, describes an algorithm that will always execute in the same time (or space) regardless of the size of the input data set.

Examples: determining if a binary number is even or odd; calculating (-1)^n; using a constant-size lookup table

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

What is O(log n)?

A

O(log n), or log time, describes an algorithm that will halve the number of items for each iteration of execution.

Examples: binary search, binomial heap

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

What is O(n)?

A

O(n), or linear time, describes an algorithm whose performance will grow linearly and in direct proportion to the size of the input data set.

Examples: finding a number in an unsorted array (worst case, the number will be at the end)

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

What is O(n*log n)?

A

O(n*log n), or linearithmic or loglinear time, describes an algorithm that will pass through the input once and deliver results in an log n fashion.

Examples: heapsort, quicksort (best and average case), and mergesort

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

What is O(n^2)?

A

O(n^2), or quadratic time, describes an algorithm whose performance is directly proportional to the square of the size of the input data set. This is common with algorithms that involve nested iterations over the data set. Deeper nested iterations will result in O(N3), O(N4) etc.

Examples: quicksort(worst case), insertion sort, selection sort

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

What is O(c^n)?

A

O(c^n), or exponential time, describes an algorithm whose growth will be multiplied by c with each additional element in the input data set.

Examples: finding the (exact) solution to the traveling salesman problem using dynamic programming; determining if two logical statements are equivalent using brute-force search

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

What is O(n!)?

A

O(n!), for factorial time, describes an algorithm whose growth by multiplying every member of the input set with every other member.

Examples: solving the traveling salesman problem via brute-force search

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

What is O(n^1/2)?

A

Fractional time.

Examples: searching a kd-tree

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