SlideShare a Scribd company logo
1. Please hand in your homework in classroom.
2. Please hand in your homework within first 10 minutes of class. No late
homework is allowed
3. Please hand in your hand-writing homework. No computer print-out is
accepted.
Homework #2 (Due on 03/24/2017)
1. Do Exercise 6.3-3 in CLRS second or third edition.
2. Do Exercise 6.4-1 in CLRS second or third edition.
3. Do Exercise 7.2-1 in CLRS second or third edition.
4. Do Exercise 7.2-2 in CLRS second or third edition.
5. Do Exercise 8.1-4 in CLRS second or third edition.
6. (Median-of-3 Partition) One way to improve the RANDOMIZED-QUICKSORT
is to choose the pivot for partitioning more carefully than by picking a random
element from the array. One common approach is to choose the pivot as the
median of a set of 3 elements randomly selected from the array. Assume that all
elements in the array are distinct. Please answer following questions.
(a) What is the probability of getting an OK split if the pivot is chosen at random?
Explain. (A split is “OK” if the smaller piece has at least n/4 elements.)
(b) Roughly, what is the probability of getting an OK split with the new
median-of-3 method? Explain.
(c) Let I be the indicator random variable for getting an OK split using the
median-of-3 partition:
1 if the split is OK
I =
0 otherwise
What is the expectation of I?
7. You are given an array of n integers ranging from 1 to 999. Design an O(n)
algorithm to rearrange elements of the array in place so that all 1-digit numbers
precede all 2-digit numbers, and all 2-digit numbers precede all 3-digit numbers.
Analyze the worst-case running time of your algorithm.

More Related Content

PPT
Laws of exponents
PPTX
Lesson 8
PDF
Working of Merge Sort Code
PPTX
Selection sort algorithm presentation, selection sort example using power point
PDF
Do not use arrays or any library sorting method. Declare 3String variables: s...
PPTX
Exponents Rules
PPT
Calc02 3 n
Laws of exponents
Lesson 8
Working of Merge Sort Code
Selection sort algorithm presentation, selection sort example using power point
Do not use arrays or any library sorting method. Declare 3String variables: s...
Exponents Rules
Calc02 3 n

What's hot (20)

DOCX
Quick sort
PDF
Sorting arrays
PDF
7th Math (C2) - L58--March13
PPTX
Bubble sort | Data structure |
PPT
Needleman wunsch computional ppt
PDF
Linked list implementation of Queue
PPTX
Merge sort js
PPTX
Approximation and error
PPTX
3.6 (1)
PPTX
Bubble Sort Algorithm Presentation
PPT
Numerical Method
PPTX
Error Finding in Numerical method
PDF
Lecture 6
PPTX
How bubble sort works
PDF
Lecture 7
PPTX
(7) Inquiry Lab - Add Integers
PPTX
Dot matrix seminar
PPTX
5 4 Notes
PPTX
Dynamic programming
PDF
Measurements and error in experiments
Quick sort
Sorting arrays
7th Math (C2) - L58--March13
Bubble sort | Data structure |
Needleman wunsch computional ppt
Linked list implementation of Queue
Merge sort js
Approximation and error
3.6 (1)
Bubble Sort Algorithm Presentation
Numerical Method
Error Finding in Numerical method
Lecture 6
How bubble sort works
Lecture 7
(7) Inquiry Lab - Add Integers
Dot matrix seminar
5 4 Notes
Dynamic programming
Measurements and error in experiments
Ad

Similar to Algorithm Homework2 (20)

PDF
Skiena algorithm 2007 lecture09 linear sorting
PDF
Quicksort in practice___________________
PPT
lecture 10
PDF
Book.pdf01_Intro.ppt algorithm for preperation stu used
PDF
Sienna 4 divideandconquer
PDF
Skiena algorithm 2007 lecture08 quicksort
PPTX
Unit III Version I.pptx
PDF
Linear sorting
PPTX
Sortings .pptx
PPTX
Data Structure and algorithms for software
PPT
Lec 6 Divide and conquer of Data Structures & Algortihms
PPT
Introduction to basic algorithm knowledge.ppt
PPT
Quick Sort
PDF
Ee693 sept2014midsem
PPT
Randomizing quicksort algorith with example
PPT
lecture 11
PPT
lecture7.ppt
PPT
Quick sort Algorithm Discussion And Analysis
Skiena algorithm 2007 lecture09 linear sorting
Quicksort in practice___________________
lecture 10
Book.pdf01_Intro.ppt algorithm for preperation stu used
Sienna 4 divideandconquer
Skiena algorithm 2007 lecture08 quicksort
Unit III Version I.pptx
Linear sorting
Sortings .pptx
Data Structure and algorithms for software
Lec 6 Divide and conquer of Data Structures & Algortihms
Introduction to basic algorithm knowledge.ppt
Quick Sort
Ee693 sept2014midsem
Randomizing quicksort algorith with example
lecture 11
lecture7.ppt
Quick sort Algorithm Discussion And Analysis
Ad

Recently uploaded (20)

PDF
VARICELLA VACCINATION: A POTENTIAL STRATEGY FOR PREVENTING MULTIPLE SCLEROSIS
PDF
The scientific heritage No 166 (166) (2025)
PPTX
ECG_Course_Presentation د.محمد صقران ppt
PDF
HPLC-PPT.docx high performance liquid chromatography
PDF
AlphaEarth Foundations and the Satellite Embedding dataset
PPTX
BIOMOLECULES PPT........................
PPTX
Introduction to Cardiovascular system_structure and functions-1
PPTX
ANEMIA WITH LEUKOPENIA MDS 07_25.pptx htggtftgt fredrctvg
PPTX
2. Earth - The Living Planet Module 2ELS
PPTX
Taita Taveta Laboratory Technician Workshop Presentation.pptx
DOCX
Q1_LE_Mathematics 8_Lesson 5_Week 5.docx
PDF
Unveiling a 36 billion solar mass black hole at the centre of the Cosmic Hors...
PPTX
G5Q1W8 PPT SCIENCE.pptx 2025-2026 GRADE 5
PPTX
The KM-GBF monitoring framework – status & key messages.pptx
PPTX
Cell Membrane: Structure, Composition & Functions
PDF
Mastering Bioreactors and Media Sterilization: A Complete Guide to Sterile Fe...
PPTX
Comparative Structure of Integument in Vertebrates.pptx
PDF
Cosmic Outliers: Low-spin Halos Explain the Abundance, Compactness, and Redsh...
PPT
POSITIONING IN OPERATION THEATRE ROOM.ppt
PPTX
DRUG THERAPY FOR SHOCK gjjjgfhhhhh.pptx.
VARICELLA VACCINATION: A POTENTIAL STRATEGY FOR PREVENTING MULTIPLE SCLEROSIS
The scientific heritage No 166 (166) (2025)
ECG_Course_Presentation د.محمد صقران ppt
HPLC-PPT.docx high performance liquid chromatography
AlphaEarth Foundations and the Satellite Embedding dataset
BIOMOLECULES PPT........................
Introduction to Cardiovascular system_structure and functions-1
ANEMIA WITH LEUKOPENIA MDS 07_25.pptx htggtftgt fredrctvg
2. Earth - The Living Planet Module 2ELS
Taita Taveta Laboratory Technician Workshop Presentation.pptx
Q1_LE_Mathematics 8_Lesson 5_Week 5.docx
Unveiling a 36 billion solar mass black hole at the centre of the Cosmic Hors...
G5Q1W8 PPT SCIENCE.pptx 2025-2026 GRADE 5
The KM-GBF monitoring framework – status & key messages.pptx
Cell Membrane: Structure, Composition & Functions
Mastering Bioreactors and Media Sterilization: A Complete Guide to Sterile Fe...
Comparative Structure of Integument in Vertebrates.pptx
Cosmic Outliers: Low-spin Halos Explain the Abundance, Compactness, and Redsh...
POSITIONING IN OPERATION THEATRE ROOM.ppt
DRUG THERAPY FOR SHOCK gjjjgfhhhhh.pptx.

Algorithm Homework2

  • 1. 1. Please hand in your homework in classroom. 2. Please hand in your homework within first 10 minutes of class. No late homework is allowed 3. Please hand in your hand-writing homework. No computer print-out is accepted. Homework #2 (Due on 03/24/2017) 1. Do Exercise 6.3-3 in CLRS second or third edition. 2. Do Exercise 6.4-1 in CLRS second or third edition. 3. Do Exercise 7.2-1 in CLRS second or third edition. 4. Do Exercise 7.2-2 in CLRS second or third edition. 5. Do Exercise 8.1-4 in CLRS second or third edition. 6. (Median-of-3 Partition) One way to improve the RANDOMIZED-QUICKSORT is to choose the pivot for partitioning more carefully than by picking a random element from the array. One common approach is to choose the pivot as the median of a set of 3 elements randomly selected from the array. Assume that all elements in the array are distinct. Please answer following questions. (a) What is the probability of getting an OK split if the pivot is chosen at random? Explain. (A split is “OK” if the smaller piece has at least n/4 elements.) (b) Roughly, what is the probability of getting an OK split with the new median-of-3 method? Explain. (c) Let I be the indicator random variable for getting an OK split using the median-of-3 partition: 1 if the split is OK I = 0 otherwise What is the expectation of I? 7. You are given an array of n integers ranging from 1 to 999. Design an O(n) algorithm to rearrange elements of the array in place so that all 1-digit numbers precede all 2-digit numbers, and all 2-digit numbers precede all 3-digit numbers. Analyze the worst-case running time of your algorithm.