ADSA Exp2
ADSA Exp2
WORKSHEET :2
Student Name: Piyush Patel UID: 23BCS12673
Branch: BE-CSE Section/Group: 717/B
Date of Performance: 27/08/2024 Semester: III
Subject Name: Advanced DSA Subject Code: 23CSH-204
1.Aim
1.1 In a sports tournament you need to rank competitors based on their scores the dataset is
large and you are required to determine most efficient based on time complexity for different
types of input data.
Note: You can take any two sorting techniques for comparison.
2.Source Code:
Solution 1.1
#include<iostream>
using namespace std;
void swap(int &a, int &b){
int temp=a;
a=b;
b=temp;
}
int partition(int *arr, int start, int end){
int pivot=arr[start];
int count=0;
for(int i=start;i<=end;i++){
if(arr[i]<pivot){
count++;
}
}
int pivotIndex=count+start;
swap(arr[start],arr[pivotIndex]);
int i=start, j=end;
while(i<pivotIndex && j>pivotIndex){
while(arr[i]<=pivot){
i++;
}
while(arr[j]>pivot){
j--;
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
else{
arr[k] = rightArray[j];
j++;
}
k++;
}
while(i < size1){
arr[k] = leftArray[i];
i++;
k++;
}
while(j < size2){
arr[k] = rightArray[j];
j++;
k++;
}
delete []firstArray;
delete []secondArray;
}
void mergeSort(int *arr, int left, int right){
if(left < right){
int mid = left + (right - left) / 2;
mergeSort(arr, left, mid);
mergeSort(arr, mid + 1, right);
merge(arr, left, mid, right);
}
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
int main() {
int arr[20]={11,24,45,23,1,4};
int n=6;
cout << "Original array: ";
for (int i = 0; i < n; i++) {
cout << arr[i] << " ";
}
cout << endl;
quickSort(arr, 0,n-1 );
cout << "Sorted array by (quick Sort): ";
for (int i = 0; i < n; i++) {
cout << arr[i] << " ";
}
cout << endl;
mergeSort(arr,0,n-1);
cout << "Sorted array by (MergeSort): ";
for (int i = 0; i < n; i++) {
cout << arr[i] << " ";
}
cout << endl;
return 0;
}
Solution 1.2
#include<iostream>
#include<vector>
Using namespace std;
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
return 0;
}
3. Screenshots of Outputs:
1.1
1.2
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
4. Learning Outcomes:
a) Learnt about using optimized sorting techniques for different types of data.
b) Learnt about vectors implementation.
c) Learnt solving problem statements using arrays and vectors.