Docsity

Algorithms - Computer Science - Homework 2 | CS 332, Assignments of Computer Science

Toggle sidebar
bg1
CS 332: Algorithms
Homework #2
Assigned: Tuesday, September 19
Due: Tuesday, September 26
1. Rank the following functions by order of growth; that is, find an arrangement g1,
g2, โ€ฆ, g25 of the functions satisfying g1 =
๎šŸ
(g2), g2 =
๎šŸ
(g3), โ€ฆ g24 =
๎šŸ
(g25).
Partition your list into equivalence classes such that f(n) and g(n) are in the same
class iff f(n) =
๎˜‹
g(n)).
()
()
()
()
() ( )
1lg2!
lg!14lg2
2ln2lglg
2!lglg
!lglg223
lg2
lg
lg
lg
lglg
lg1223
2
lg
nnnn
nnn
nnnn
nnnn
nnn
n
n
n
n
nnn
n
n
n
n
+
โ‹…
โˆ—
2. Argue informally that the quicksort routine presented in the book will run in time
๎˜‹
n lg n) when all elements in the array are equal.
3. CLR 2.1.4
4. A sorting algorithm is described as stable if equal elements are in the same
relative order in the sorted sequence as in the unsorted sequence. Which of
insertion sort, quicksort, and mergesort are stable? Give a simple fix to make the
unstable sorts stable.
5. CLR 4-1 a-f
6. CLR 7-2 a-d

Partial preview of the text

Download Algorithms - Computer Science - Homework 2 | CS 332 and more Assignments Computer Science in PDF only on Docsity!

CS 332: Algorithms Homework #

Assigned: Tuesday, September 19

Due: Tuesday, September 26

  1. Rank the following functions by order of growth; that is, find an arrangement g 1 , g 2 , โ€ฆ, g 25 of the functions satisfying g 1 = ยŸ( g 2 ), g 2 = ยŸ( g 3 ), โ€ฆ g24 = ยŸ(g25). Partition your list into equivalence classes such that f(n) and g(n) are in the same class iff f(n) = g(n)).

! 2 lg 1

2 lg 4 1! lg

lglg 2 ln 2

lg lg! 2

3 2 2 lg lg!

2 lg

lg lg lg

lglg

3 2 2 1 lg

lg 2

n n n n

n n n

n n n n

n n n n

n n n

n

n n n

n n n

n

n n

n

โˆ—

  1. Argue informally that the quicksort routine presented in the book will run in time n lg n) when all elements in the array are equal.
  2. CLR 2.1.
  3. A sorting algorithm is described as stable if equal elements are in the same relative order in the sorted sequence as in the unsorted sequence. Which of insertion sort, quicksort, and mergesort are stable? Give a simple fix to make the unstable sorts stable.
  4. CLR 4-1 a-f
  5. CLR 7-2 a-d