Algorithms Flashcards
(32 cards)
What is recursion?
Recursion is breaking down a problem into subsets of the same problem.
What is a recursive function?
A recursive function is a function that calls itself.
What is a base case in recursion?
A base case is a condition that stops the recursive function from calling itself.
What happens when the base case is reached in recursion?
Once the base case is reached, the function returns a value.
What is recursion depth?
Recursion depth is how many times the recursive function has been called.
What is the maximum recursion depth in Python?
Python has a maximum recursion depth of 1000.
What is an advantage of using recursion?
Recursion can lead to less code and more elegant, efficient solutions.
What is a disadvantage of using recursion?
Recursion can be difficult to understand.
What is the Fibonacci sequence?
The Fibonacci sequence is a series where each number is the sum of the two preceding ones, starting with 0 and 1.
What is linear search?
Linear search checks each element in the list one by one until the target is found.
What is the time complexity of linear search?
The time complexity of linear search is O(n).
What is binary search?
Binary search divides the list into halves repeatedly until the target element is found.
What is the time complexity of binary search?
The time complexity of binary search is O(log n).
What is selection sort?
Selection sort finds the smallest item in a list and places it at the correct position.
What is the time complexity of selection sort?
The time complexity of selection sort is O(n²) in the worst, average, and best cases.
What is insertion sort?
Insertion sort inserts each item one at a time into its correct position.
What is the time complexity of insertion sort?
The time complexity of insertion sort is O(n²) in the worst, average, and best cases.
What is bubble sort?
Bubble sort iterates through a list comparing pairs of items and swaps them if they are in the wrong order.
What is the time complexity of bubble sort?
The time complexity of bubble sort is O(n²).
What is quicksort?
Quicksort selects a pivot and partitions the list into two sub-lists based on whether elements are less than or greater than the pivot.
What is the average case time complexity of quicksort?
The average case time complexity of quicksort is O(n log n).
What is the worst-case time complexity of quicksort?
The worst-case time complexity of quicksort is O(n²).
What is time complexity?
Time complexity refers to the computational time taken by an algorithm relative to the input size.
What are the types of time complexity?
Best case, worst case, and average case time complexity.