0% found this document useful (0 votes)
36 views

Problem Statement:: #Include

The document provides instructions for an assignment to implement and analyze the performance of iterative and recursive Quicksort algorithms. Students are asked to: 1. Implement an iterative Quicksort algorithm using a stack to track sublists. 2. Measure execution times for input sizes from 10 to 107 and estimate time complexity. 3. Compare execution times and space usage of recursive and iterative implementations. The deliverables are an iterative Quicksort function, main code to print a time and space analysis table, and use of libraries to measure execution time.

Uploaded by

Ishan Chawla
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

Problem Statement:: #Include

The document provides instructions for an assignment to implement and analyze the performance of iterative and recursive Quicksort algorithms. Students are asked to: 1. Implement an iterative Quicksort algorithm using a stack to track sublists. 2. Measure execution times for input sizes from 10 to 107 and estimate time complexity. 3. Compare execution times and space usage of recursive and iterative implementations. The deliverables are an iterative Quicksort function, main code to print a time and space analysis table, and use of libraries to measure execution time.

Uploaded by

Ishan Chawla
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Tuesday 18.08.

09

Birla Institute of Technology and Science, Pilani


Data Structures and Algorithms
Lab: 3 (Tuesday, 25th Aug)
QUICKSORT
Max Marks: 16

Problem Statement:
1. Implement iterative version of the Quicksort algorithm. Use Stack ADT to maintain the
sub-list information. Input should be generated randomly for a given size of array.
2. Measure the execution time in microseconds for the above function for varying input
sizes from 10 to 107. Use time.h library functions for measuring execution time. Use of
time functions is demonstrated below. Compute NlogN for the different input sizes (N)
and estimate the constant of proportionality c so that all the measured values are upperbounded by cNlogN.
3. Measure the execution time of the recursive algorithm for same sets of input data and
find the ratio of improvement in execution time for each input size.
4. Measure the maximum space utilized by both recursive and iterative Quicksort
algorithms. For recursive algorithm maintain a counter for depth of recursion to simulate
maximum growth of machine stack. For iterative algorithm, measure the maximum
growth of the explicit stack.

Measuring Execution Time:


#include <sys/time.h>
int main(int argc,char **argv)
{

......
// Declaration of timeval variables which will capture the system time
long time_start, time_end;
struct timeval tv;
// Write all the initialization code here
// Time measurement begins here
gettimeofday(&tv,NULL); /*gets the current system time into variable tv */
time_start

= (tv.tv_sec *1e+6) + tv.tv_usec;

// calculating start time in seconds

// Write the code to be analyzed here


gettimeofday (&tv, NULL);
time_end = (tv.tv_sec *1e+6) + tv.tv_usec;
// calculating end time in seconds
// (time_end-time_start) gives the total execution time
return (0);
}

Given:
1. Implementation of recursive Quicksort algorithm.
2. ADT Stack

Deliverables:
1. Iterative Quicksort function in quicksortfunctions.c
2. Print comparative time analysis in following format in main.c
Time and Space analysis of recursive Vs. iterative quicksort
Input
size

n*logn

Time
(recursive)

Const
(CR)

Time
(Iterative)

Const(CI)

Ratio of
improvement

10

33.219

2.00

16.610

58.00

0.573

..

5010

61575.879

1182.00

52.095

123593.00

0.498

(Sample output)
Input
size

Space measured (recursive)

Space measured (iterative)

You might also like