DAA Report
DAA Report
Submitted By
Name: Atharva Litake
Roll no: 41143 Class: BE-1
2. PROBLEM DEFINITION
3. LEARNING OBJECTIVES
4. LEARNING OUTCOMES
5. ABSTRACT
8. CONCLUSION
1. TITLE:
Implement merge sort and multithreaded merge sort. Compare
time required by both the algorithms. Also analyze the performance
of each algorithm for the best case and the worst case.
2. PROBLEM DEFINITION:
4. LEARNING OUTCOMES:
5. ABSTRACT:
The project explores and compares the efficiency of the traditional merge
sort algorithm with its multithreaded counterpart. Merge sort is a well-
known divide-and-conquer sorting algorithm, which we extend by
parallelizing the sorting tasks using threads. The comparison focuses on
time complexity, execution speed, and resource utilization under
different input cases (best and worst). Through this project, we aim to
demonstrate how multithreading can potentially reduce the execution
time for large datasets by parallelizing computational tasks.
6. TECHNICAL DETAILS ABOUT THE PROJECT
Performance Analysis
Best Case: The array is already sorted, leading to minimal reordering during
the merge step.
Worst Case: The array is sorted in reverse order, requiring the most
comparisons and swaps during merging.
Time Measurement
In C++, the time can be measured using the <chrono> library to compare the
execution times of both the traditional and multithreaded merge sort algorithms.
We run the algorithms on arrays of varying sizes to get an accurate performance
comparison.
Hardware Considerations
Multithreaded performance depends heavily on the number of CPU cores
available. If the number of threads exceeds the available cores, performance
gains can diminish due to the overhead of thread context switching.
7. GLIMPSE OF THE PROJECT & DEPLOYMENT:
return;
}
void mergeSort(int left, int right, vector<int> &arr)
{
// Base Case : Only single element is there, it is already sorted
if (left >= right)
{
return;
}
// Calculate mid index for dividing array equally in two parts left and right
int mid = left + (right - left) / 2;
// Invoke Merge Sort function for left part and rigth part of array
mergeSort(left, mid, arr);
mergeSort(mid + 1, right, arr);
return;
}
int main()
{
// Take array size as input
int n;
cin >> n;
// Display array
for (int i = 0; i < n; i++)
{
cout << arr[i] << endl;
}
return 0;
}
Multithreaded Merge Sort Code:
#include <iostream>
#include <vector>
#include <thread>
using namespace std;
return;
}
// Calculate mid index for dividing array equally in two parts left and right
int mid = left + (right - left) / 2;
return;
}
int main()
{
// Take array size as input
int n;
cout<<"Enter no. of elements in array: ";
cin >> n;
return 0;
}
8. CONCLUSION