Algorithms Flashcards

1
Q

What is recursion?

A

Recursion is breaking down a problem into subsets of the same problem.

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

What is a recursive function?

A

A recursive function is a function that calls itself.

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

What is a base case in recursion?

A

A base case is a condition that stops the recursive function from calling itself.

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

What happens when the base case is reached in recursion?

A

Once the base case is reached, the function returns a value.

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

What is recursion depth?

A

Recursion depth is how many times the recursive function has been called.

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

What is the maximum recursion depth in Python?

A

Python has a maximum recursion depth of 1000.

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

What is an advantage of using recursion?

A

Recursion can lead to less code and more elegant, efficient solutions.

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

What is a disadvantage of using recursion?

A

Recursion can be difficult to understand.

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

What is the Fibonacci sequence?

A

The Fibonacci sequence is a series where each number is the sum of the two preceding ones, starting with 0 and 1.

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

What is linear search?

A

Linear search checks each element in the list one by one until the target is found.

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

What is the time complexity of linear search?

A

The time complexity of linear search is O(n).

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

What is binary search?

A

Binary search divides the list into halves repeatedly until the target element is found.

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

What is the time complexity of binary search?

A

The time complexity of binary search is O(log n).

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

What is selection sort?

A

Selection sort finds the smallest item in a list and places it at the correct position.

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

What is the time complexity of selection sort?

A

The time complexity of selection sort is O(n²) in the worst, average, and best cases.

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

What is insertion sort?

A

Insertion sort inserts each item one at a time into its correct position.

17
Q

What is the time complexity of insertion sort?

A

The time complexity of insertion sort is O(n²) in the worst, average, and best cases.

18
Q

What is bubble sort?

A

Bubble sort iterates through a list comparing pairs of items and swaps them if they are in the wrong order.

19
Q

What is the time complexity of bubble sort?

A

The time complexity of bubble sort is O(n²).

20
Q

What is quicksort?

A

Quicksort selects a pivot and partitions the list into two sub-lists based on whether elements are less than or greater than the pivot.

21
Q

What is the average case time complexity of quicksort?

A

The average case time complexity of quicksort is O(n log n).

22
Q

What is the worst-case time complexity of quicksort?

A

The worst-case time complexity of quicksort is O(n²).

23
Q

What is time complexity?

A

Time complexity refers to the computational time taken by an algorithm relative to the input size.

24
Q

What are the types of time complexity?

A

Best case, worst case, and average case time complexity.

25
Q

What is a characteristic of Quick Sort regarding stability?

A

Quick Sort is not a stable sorting algorithm, meaning it may change the relative order of equal elements.

26
Q

How does Quick Sort compare to Bubble Sort, Selection Sort, and Insertion Sort?

A

Quick Sort typically offers better average-case performance with O(n log n) time complexity.

27
Q

When might Quick Sort not be suitable?

A

Quick Sort may not be suitable for small lists or nearly sorted lists due to its potential for worst-case performance.

28
Q

What are Comparison-based sorting algorithms?

A

Comparison-based sorting algorithms include Selection Sort, Insertion Sort, and Bubble Sort. They rely on comparing elements of the list and swapping them based on their values.

29
Q

What is a characteristic of Comparison-based sorting algorithms?

A

They typically have quadratic time complexity and do not employ any divide-and-conquer strategies.

30
Q

What are Divide-and-conquer sorting algorithms?

A

Divide-and-conquer sorting algorithms include Quick Sort.

31
Q

How does Quick Sort work?

A

Quick Sort works by selecting a ‘pivot’ element from the list and dividing the other elements into two sub-lists according to whether they are less than or greater than the pivot.

32
Q

What is the average-case time complexity of Quick Sort?

A

Quick Sort typically has a better average-case time complexity compared to comparison-based algorithms.