0% found this document useful (0 votes)
72 views1 page

Problem 1: Nalyze The Time Complexity of The Following Functions in Terms of N

This document outlines an assignment on algorithms with 3 problems. Problem 1 asks about quicksort's best case time complexity, stable sorting algorithms, and illustrating Radix-Sort. Problem 2 analyzes the time complexity of 6 functions. Problem 3 involves writing code for Partition and Quicksort, analyzing their time complexities, and discussing average and worst case performances.

Uploaded by

ansari ssav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views1 page

Problem 1: Nalyze The Time Complexity of The Following Functions in Terms of N

This document outlines an assignment on algorithms with 3 problems. Problem 1 asks about quicksort's best case time complexity, stable sorting algorithms, and illustrating Radix-Sort. Problem 2 analyzes the time complexity of 6 functions. Problem 3 involves writing code for Partition and Quicksort, analyzing their time complexities, and discussing average and worst case performances.

Uploaded by

ansari ssav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Assignment 2 Algorithm Deadline: 26-April-2019

Problem 1

1. Show that quicksort’s best-case running time is Ω(n lg n).


2. Which of the following sorting algorithms are stable: Insertion sort, merge sort, quicksort and
counting sort? Give a simple scheme that makes any sorting algorithm stable. How much time
and space does your scheme entail?
3. Using Figure 8.3 as a model, illustrate the operation of Radix-Sort on the following list of English
words: COW, DOG, SEA, RUG, ROW, MOB, BOX, TAB, BAR, EAR, TAR, DIG, BIG, TEA, NOW, FOX

Problem 2 Analyze the time complexity of the following Functions in terms of N.

Int f1(int N) int f2(int N) int f3(int N)


{ { {
int Count = 0; int Count=0; int Count=0;
for(int i = 1; i<=N ; i*= 2) int C = f1(N); int C = sqrt(f1(N));
for(int j=1; j<= i ; j++) for(int i=0; i<C; i++) for(int i=0; i<C; i*=2)
Count++; Count++; Count++;
return Count; return Count; return Count;
} } }

int f4(int N) int f5(int N) int f6(int N)


{ { {
int Count=0; int Count=0; if(N==1)
for(int i=0; i<f1(N) * f1(N); i++) for(int i=0; i<sqrt(f1(N) * f1(N)); i++) return 1;
Count++; Count++; f1(N);
return Count; return Count; f2(N);
} } f3(N);
f4(N);
f5(N);
return F6(N-1) + F6(N-1);
}

Problem 3
1. Write the code for Partition which should randomly choose a pivot and partition the array
into less then the pivot values to the left half and all the greater values to the right half
and all the values equal to pivot values in the middle.
2. Write the code for Quick Sort.
3. Analyze its time complexity. What will be its average/expected time complexit. What will
be its worst time complexity?

You might also like