Arun Exp-5
Arun Exp-5
Experiment - 5
Student Name: Arun UID: 22BET10320
Branch: BE-IT Section/Group: 22BET_IOT_703/B
Semester: 5th Date of Performance: 13/08/2024
Subject Name: DAA Subject Code: 22ITH-311
1. Aim: Sort a given set of elements using the Quick sort method and determine the time
required to sort the elements. Repeat the experiment for different values of n, the
number of elements in the list to be sorted. The elements can be read from a file or can
be generated using the random number generator.
2. Objective: Implement Quick sort algorithm to sort elements, measure time complexity,
and analyze performance with varying input sizes (n) using file input or random
number generation. Repeat experiment to understand algorithm's efficiency, scalability,
and identify potential areas for optimization, providing insights into its practical
applications and limitations.
3. Implementation/Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
int n;
printf("Enter the number of elements: ");
scanf("%d", &n);
printf("Sorted array:\n");
printArray(arr, n);
printf("Time taken to sort: %f seconds\n", (double)(end_time - start_time) /
CLOCKS_PER_SEC);
free(arr);
return 0;
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
4. Output:
5. Time Complexity:
quickSort: O(n log n), partition: O(n), swap: O(1), printArray: O(n), main: O(n)
Overall time complexity: O(n log n)
6. Learning Outcomes:
• Understanding of Quicksort Algorithm: The code demonstrates a clear understanding
of the quicksort algorithm, including the partition scheme, recursive function calls,
and the swapping of elements to sort the array.
• Implementation of Dynamic Memory Allocation: The code showcases the use of
dynamic memory allocation using malloc to allocate memory for the array, and free to
deallocate the memory when it's no longer needed.
• User Input and Output Handling: The code demonstrates how to handle user input and
output, including reading input from the user, storing it in an array, and printing the
sorted array to the console.