HPC Practical 3 Vish-23-25
HPC Practical 3 Vish-23-25
PRACTICAL : 03
AIM: Using Divide and Conquer Strategies design a class for Concurrent
Quick Sort
INTRODUCTION:
Divide and Conquer is a powerful algorithmic technique used to solve complex problems by
breaking them down into simpler subproblems, solving each subproblem independently, and
then combining their solutions to form a solution to the original problem. Here's a step-by-step
introduction to the concept:
1. Divide: Split the problem into smaller, independent subproblems. The goal is to break
down the problem into subproblems of similar type, but of reduced complexity.
2. Conquer: Solve each subproblem independently. If the subproblems are still too large,
apply the divide and conquer strategy recursively to further break them down.
3. Combine: Combine the solutions of the subproblems to obtain the solution to the
original problem.
1) Merge Sort:
2) Quick Sort:
Divide: Select a pivot element and partition the array into two halves such that elements
less than the pivot are on one side and elements greater than the pivot are on the other.
Conquer: Recursively sort the partitions.
Combine: Since the array is sorted in place, no additional work is needed to combine.
3) Binary Search:
Divide: Compare the target value to the middle element of the array.
Conquer: If the target value is equal to the middle element, return the index. If the
target value is less, recursively search in the left half. If the target value is greater,
recursively search in the right half.
Combine: The combine step is trivial as the result is directly obtained from the
recursive call.
Efficiency: By breaking a problem into smaller subproblems, we can reduce the time
complexity in many cases.
Parallelism: Independent subproblems can often be solved in parallel, leading to
potential performance improvements on multi-core processors.
Simplicity: Complex problems can be simplified into more manageable subproblems,
making the overall problem easier to understand and solve.
Overhead: The process of dividing the problem and combining the results can
introduce additional overhead.
Not Always Optimal: For some problems, divide and conquer may not lead to the most
efficient solution compared to other algorithms.
PSEUDOCODE:
CODE:
OUTPUT: