Time Complexity Flashcards

1
Q

What is time complexity?

A

Time complexity is a way to measure how fast or slow an algorithm runs based on the size of the input (n).

It helps us understand how the time required for execution grows when the input size increases.

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

O(1) - Constant Time

A

The algorithm always takes the same amount of time, no matter the input size

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

O(log n) - Logarithmic Time

A

The number of steps reduces by half each time (same as in a Binary Search)

In the worst case it takes O(log2 n) steps.

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

O(n) - Linear Time

A

The time increases directly with the input size (for example searching for an element in an unsorted list)

If there are 1000 elements, it may take up to 1000 steps

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

0(n2)- Quadratic Time

A

Time grows exponentially as the input increases

For example in a bubble sort, where we compare every element to every other element

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

Smaller complexity = Faster algorithms T/F

A

True

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

Which is better Linear Search O(n) or Binary SearchO(log n)?

A

Binary Search O(log n)

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