Finding min-max Recursive

# Objective

To implement a program to find out the largest and smallest number from a list using the recursive divide and conquer algorithm.

# Theory

The objective is to identify the maximum and minimum elements in a provided list within a specified range. Employing the divide-and-conquer approach, a prevalent algorithmic technique involves breaking down the problem into smaller subproblems. Each subproblem is addressed independently, and the solutions are then combined to derive the solution for the original problem. The time complexity of this algorithm is O(n), where n is the size of the input list, because each element is visited only once.

Way to finding the maximum and minimum values in a list:

• Divide:
• Split the input list into two halves.
• Identify a base case that defines when the problem is small enough to be solved directly (e.g., when the list has only one element).
• Conquer:
• Recursively find the maximum and minimum values in each of the subproblems created during the division step.
• The recursive calls continue until the base case is reached.
• Combine:
• The results obtained from the subproblems are combined to determine the maximum and minimum values for the larger subarrays.
• The combination step involves comparing and selecting the maximum and minimum values from the results of the left and right subproblems.

In case of finding the maximum and minimum values in a list, the divide-and-conquer approach allows for a reduction in the number of comparisons needed to determine the extreme values, resulting in a more efficient algorithm compared to a naive linear search.

# Learning Outcomes

By learning the Divide and Conquer algorithm to find the maximum value of an array, you can achieve several learning outcomes, including:

• Implementing Recursive Functions: You'll learn how to design and implement recursive functions to solve complex problems. The program uses recursion to split the list into sub lists and recursively calls the 'maxmin' function on these sub lists.
• Analyzing and Solving Sub problems: The program requires analyzing sub problems and combining their solutions to solve the larger problem. You'll enhance your ability to break down complex problems into smaller, manageable parts and develop strategies to combine the solutions effectively.
• Working with List Indexing and Slicing: The program utilizes list indexing and slicing to divide the input list into sub lists. You'll become familiar with these concepts and learn how to manipulate lists based on specific indices.
• Comparing and Updating Values: The program involves comparing and updating values to determine the maximum and minimum elements within a range. You'll gain experience in comparing values and utilizing conditional statements to update variables accordingly.
• Handling Base Cases: Understanding how to handle base cases is crucial in recursive programming. The program checks for the base case where the sub list has only one element, and returns the maximum and minimum values directly without further recursion.
• Implementing Helper Functions: The program suggests the presence of helper functions such as 'maxmin' to encapsulate the recursive logic. You'll learn the benefits of using helper functions to modularize code and improve readability.
• Familiarity with Global Variables: The program assumes the existence of global variables 't' and 'res'. You'll gain an understanding of how global variables can be used to store and update values across multiple function calls.
• Analyzing Time Complexity: By studying the program, you can analyze its time complexity. The divide-and-conquer approach typically has a time complexity of O(n log n) for problems like finding the maximum and minimum elements.
• Debugging and Problem-Solving Skills: As you explore and potentially execute the program, you may encounter errors or unexpected behavior. This presents an opportunity to practice debugging techniques and enhance your problem-solving skills.