










Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!











◉ What are the three cases analyzed in time complexity? Answer: Best Case, Average Case, and Worst Case. ◉ What does Big O notation describe? Answer: It classifies algorithms based on how their runtime requirements grow as the input size increases. ◉ What is the worst-case scenario for a linear search? Answer: The target element is at the very end of the list or not in the list at all. ◉ What is the best-case scenario for a linear search? Answer: The target element is the very first element in the list. ◉ What is the time complexity of the best-case scenario for a linear search? Answer: O(1), indicating constant time.
◉ What is the time complexity of a linear search in the worst case? Answer: O(n), where n is the number of elements in the list. ◉ What is time complexity analysis? Answer: A method to quantify the amount of time an algorithm takes to run as a function of the length of the input. ◉ What is space complexity? Answer: The memory usage of an algorithm. ◉ What are the baseline metrics for evaluating algorithms? Answer: Readability and passing all test cases. ◉ What is the function of the 'max_profit_linear' algorithm? Answer: To calculate the maximum profit from stock prices in a linear time complexity. ◉ What is the function of the 'max_profit_quadratic' algorithm? Answer: To calculate the maximum profit from stock prices using a quadratic time complexity. ◉ What is the time complexity of a quadratic algorithm?
Answer: It evaluates the efficiency of an algorithm based on readability and tests. ◉ What is the significance of analyzing time complexity? Answer: To identify inefficient algorithms that may lead to increased resource consumption and slower processing times. ◉ What is the meaning of 'asymptotic analysis'? Answer: It refers to the behavior of an algorithm as the input size approaches infinity. ◉ What is the average case in time complexity? Answer: An estimate of the typical number of operations performed by the algorithm. ◉ What is the impact of inefficient algorithms? Answer: They can lead to increased resource consumption and slower processing times. ◉ What does Big Omega (Ω) notation represent? Answer: It provides the lower bound, indicating the minimum time an algorithm will take.
◉ Why is Big Omega important in algorithm analysis? Answer: It helps in understanding the best-case efficiency of algorithms. ◉ What does Big Theta (Θ) notation indicate? Answer: It provides a tight bound on an algorithm's growth rate, representing both upper and lower bounds. ◉ What is the significance of Big Theta in algorithm performance? Answer: It describes the exact asymptotic behavior of an algorithm's execution time. ◉ Can every algorithm be described by Big Theta? Answer: No, not every algorithm has a tight bound described by Big Theta. ◉ What does the average-case complexity of linear search indicate? Answer: The average-case complexity is O(n), assuming a uniform distribution of the target in the list. ◉ What is the worst-case time complexity of linear search? Answer: O(n), where n is the number of elements in the list.
◉ What happens in unbalanced nested loops? Answer: The number of iterations in the inner loop depends on the current iteration of the outer loop. ◉ How do you calculate the total iterations in an unbalanced loop? Answer: The total iterations can be evaluated as n(n-1)/2, leading to a complexity of O(n²). ◉ What is the time complexity of a recursive function in the worst case? Answer: O(n), where n is the total number of elements in the list. ◉ What is the average-case complexity of linear search? Answer: O(n), assuming the target is found around the midpoint of the list. ◉ What does the notation O(n log n) signify? Answer: It indicates a slightly super-linear growth rate. ◉ What is the impact of constants in asymptotic analysis? Answer: Constants are ignored in asymptotic analysis.
◉ What is the relationship between linear growth and quadratic growth in asymptotic notation? Answer: Linear growth (n) is in O(n log n) and O(n²), indicating it grows slower than quadratic growth. ◉ What is the complexity of a loop that increments by a fixed amount? Answer: It still has a linear complexity, O(n), because it runs approximately n/constant. ◉ What is the definition of average-case complexity? Answer: It is the expected time complexity of an algorithm based on a uniform distribution of inputs. ◉ What does the term 'dominant term' refer to in complexity analysis? Answer: It refers to the term that grows the fastest as n increases, dictating the overall complexity. ◉ What is the significance of analyzing loops in algorithm complexity? Answer: It helps determine the time complexity based on the number of iterations relative to input size.
◉ What is the time complexity of the function halve_list_until_one in the worst case? Answer: O(log n), as it reduces the problem size by half each time. ◉ What is the average-case time complexity for halve_list_until_one? Answer: O(log n), similar to the worst case. ◉ What is the significance of exponential reduction in halve_list_until_one? Answer: Each division by two cuts the remaining amount in half, leading to log_2(n) steps. ◉ What is the time complexity of the Fibonacci function in the worst case? Answer: O(2^n), as each call generates two additional calls. ◉ What is the average-case time complexity for the Fibonacci function? Answer: O(2^n), as every increase in n roughly doubles the number of calls. ◉ What does Big O notation provide in terms of algorithm performance?
Answer: It guarantees that performance will not exceed a specified bound. ◉ Why do we use Big O notation for analyzing algorithms? Answer: It simplifies discussions by avoiding multiple notations for different cases. ◉ What is the execution time measurement method using the time module in Python? Answer: Use time.time() to capture start and end times, then calculate elapsed time. ◉ How do you estimate time performance for an algorithm with linear complexity O(n)? Answer: If it processes 1000 elements per second, it would take approximately 10 seconds for 10,000 elements. ◉ What is the time complexity of an algorithm with quadratic complexity O(n²)? Answer: If it processes 100 elements in 1 second, it would take around 100 seconds for 1,000 elements. ◉ What is the relationship between processing time and the number of elements in quadratic complexity?
Answer: It manages local variables and return addresses for each recursive call. ◉ What is the recursive step in a recursive function? Answer: The core logic that reduces the problem size and moves the state toward the base case. ◉ How is the factorial of a number calculated recursively? Answer: By multiplying the number by the factorial of the number minus one until reaching the base case of 1. ◉ What is the purpose of type hints in Python functions? Answer: To enforce type integrity and improve code readability. ◉ What is the significance of the 'strictly pure functional programming paradigm' in this course? Answer: All solutions must be developed without side effects and should only use recursion. ◉ What does the function 'find_min_index' do in the selection sort algorithm? Answer: It finds the index of the minimum element in the unsorted portion of the list.
◉ What is the purpose of the 'swap' function in selection sort? Answer: To exchange the positions of two elements in the list. ◉ What is a recursive call chain? Answer: A sequence of function calls where each call waits for the next to complete before proceeding. ◉ What does the term 'self-reference' mean in recursion? Answer: A method where the solution to a problem depends on solutions to smaller instances of the same problem. ◉ How does the recursive implementation of insertion sort differ from the iterative version? Answer: It uses a recursive function to insert elements rather than using a loop. ◉ What is the role of the 'insert' function in the recursive insertion sort? Answer: To place the current element in its correct position within the sorted portion of the list. ◉ What happens when the base case of a recursive function is reached?
Answer: They should be modified to move closer to the base case. ◉ What is the purpose of conditional logic in a recursive function? Answer: To ensure that each recursive step is moving towards the base case. ◉ What does each recursive call result in on the call stack? Answer: A new entry that keeps track of the recursive function awaiting completion. ◉ What happens when a recursive call reaches its end? Answer: The corresponding stack frame is de-allocated or 'popped' off the stack. ◉ What is a recursive helper function? Answer: A utility that simplifies the recursive interface by managing state variables. ◉ What is the base case for the Fibonacci function? Answer: Fib(0) = 0 and Fib(1) = 1. ◉ What does the function 'find_max_recursive' return? Answer: The maximum value in a list using recursion.
◉ What is the main difference between insertion sort and selection sort in terms of recursion? Answer: Insertion sort builds a sorted array one element at a time, while selection sort repeatedly selects the minimum element. ◉ What is the purpose of the 'insert' function in insertion sort? Answer: To place the key element in its correct position in the sorted part of the list. ◉ In the context of recursion, what does 'state preservation' mean? Answer: Passing auxiliary parameters like indices or accumulators across calls. ◉ What is the role of the 'swap' function in selection sort? Answer: To exchange the positions of two elements in the list. ◉ How does the 'reverse_string_recursive' function work? Answer: It reverses a string by recursively appending the first character to the reversed substring of the remaining string. ◉ What is the initial assumption in the 'find_max_iterative' function? Answer: The first item in the list is assumed to be the largest.