0% found this document useful (0 votes)
51 views4 pages

21BCA1946 Worksheet1.5

The document summarizes a student's experiment on implementing the quick sort algorithm. The student wrote a C++ program that takes an array as input, applies the quick sort algorithm to sort the array using a pivot element, and outputs the sorted array. Key steps included dividing the array around a pivot element, recursively calling quicksort on the subarrays, and using functions and recursion to implement the divide and conquer approach. The program demonstrated the student's understanding of concepts like arrays, recursion, and quicksort.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views4 pages

21BCA1946 Worksheet1.5

The document summarizes a student's experiment on implementing the quick sort algorithm. The student wrote a C++ program that takes an array as input, applies the quick sort algorithm to sort the array using a pivot element, and outputs the sorted array. Key steps included dividing the array around a pivot element, recursively calling quicksort on the subarrays, and using functions and recursion to implement the divide and conquer approach. The program demonstrated the student's understanding of concepts like arrays, recursion, and quicksort.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Experiment 2.

Student Name: Divya Prakash Singh UID: 21BCA1946


Branch: BCA Section/Group: 21PH-BCA 5B
Semester: 3rd semester Date of Performance: 13/10/2022
Subject Name: DS lab Subject Code: 21CAP-214

1. Aim/Overview of the practical: Write a program to implement sorting algorithm which


uses pivot element.

2. Task to be done: Creating a quick sort algorithm that can sort an array by the divide and
conquer principle.

3. Concept used: Arrays, Recursion, Quick Sort, functions.

4. Steps/Commands involved to perform practical:


#include <bits/stdc++.h>
using namespace std;

int divide(int arr[], int start, int end)


{
int pivot = arr[end];
int smaller_no = start-1;
for (int i = start; i <= end; i++)
{
if (arr[i] < pivot)
{
smaller_no++;
swap(arr[smaller_no], arr[i]);
}
}
swap(arr[smaller_no+1], arr[end]);
return smaller_no+1;
}
void quickSort(int arr[], int start, int end)
{
if (end > start)
{
int mid = divide(arr, start, end);
quickSort(arr, start, mid-1);
quickSort(arr, mid+1, end);
}
}

int main(int argc, char const *argv[])


{
int n;
cout << "Enter size of array: ";
cin >> n;
int arr[n];

cout << "Enter elements of array: ";


for (int i = 0; i < n; i++)
{
cin >> arr[i];
}

cout << "unsorted array: " << endl;


for (int i = 0; i < n; i++)
{
cout << arr[i] << " ";
}

quickSort(arr, 0, n-1);

cout << "Sorted array: " << endl;


for (int i = 0; i < n; i++)
{
cout << arr[i] << " ";
}
return 0;
}

5. Result/Output/Writing Summary:
Learning outcomes (What I have learnt):

1. I learned to create an algorithm to perform Quick sort.

2. I learned to sort an array using quick sort.

3. And I learned to implement divide-and-conquer method.

Evaluation Grid:

Sr. No. Parameters Marks Obtained Maximum Marks


1. Worksheet 20
2. Demonstration/Performance / 10
Quiz/Viva
Worksheet Rubrics:
Understanding of Experiment 10% of total grade that is 2 marks

Command Description for all concepts covered in experiment 30% of total grade that is 6marks

Steps Involved in question 40% of total grade that is 8 marks

Writing Output/Screenshot 20% of total grade that is 4 marks

You might also like