Big O Notation Flashcards

1
Q

What is Big O notation?

A

A way to describe how fast or slow an algorithm is as the size of the input grows.

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

What does O(1) mean?

A

Constant time -the algorthim takes the same time as the input grows

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

What is an example of an O(1) operation?

A

Accessing an array element by index (e.g., arr[0]).

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

What does O(n) mean?

A

Linear time – time grows directly in proportion to input size (n).

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

Give an example of an O(n) algorithm.

A

Linear Search or a simple loop (e.g., for i in range(n)).

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

What does O(log n) mean?

A

Logarthmic time- takes less time as input grows

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

Give an example of an O(log n) algorithm.

A

Binary Search.

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

What does O(n²) mean?

A

Quadratic or polynomial time – time grows proportionally to n squared.

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

Give an example of an O(n²) algorithm.

A

Bubble Sort or nested loops (for i in range(n): for j in range(n):).

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

What does O(2ⁿ) mean?

A

Exponential time – time doubles as input size grows (n).

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

Give an example of an O(2ⁿ) algorithm.

A

Recursive Fibonacci or brute-force combinatorics.

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

What is meant by “worst-case scenario” in Big O?

A

The algorithm takes the longest possible time for a given input size.

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

What is algorithm efficiency?

A

A measure of how well an algorithm performs based on time and space as input size grows.

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

What is Dijkstra’s algorithm used for?

A

An algorithm for finding the shortest paths between nodes in a graph

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

What is A* (A-star) algorithm?

A

An algorithm that finds the shortest path by using both actual cost and a heuristic to find the most efficient path to the target node.

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

What is a heuristic in A*?

A

An estimated cost from the current node to the goal (e.g., Euclidean or Manhattan distance).

17
Q

What does “admissible heuristic” mean?

A

A heuristic that never overestimates the minimum cost to reach the goal.

18
Q

How does A* compare to Dijkstra in terms of performance?

A

A star is faster ,because the heuristic guides the search more efficiently.

19
Q

What is meant by “comparing algorithm complexity”?

A

Evaluating which algorithm is more efficient based on Big O, considering how they scale with larger inputs.