Docsity

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

Toggle sidebar
bg1
CS 332: Algorithms
Homework #2
Assigned: Wednesday, January 30, 2002
Due: Wednesday, Feb 6, 2002
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. Is 2n+1 = O(2n)? Is 22n = O(2n)?
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 (also 4-1 in old book)
6. CLR 6-2 a-d (7-2 in old book)

Partial preview of the text

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

CS 332: Algorithms Homework #

Assigned: Wednesday, January 30, 2002

Due: Wednesday, Feb 6, 2002

  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 ), … g 24 = Ω ( g 25 ). 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. Is 2 n+1^ = O (2 n^ )? Is 2 2n^ = O (2 n^ )?
  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 (also 4-1 in old book)
  5. CLR 6-2 a-d (7-2 in old book)