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

Homework3

The document outlines a homework assignment for CSC510 focusing on Divide and Conquer and Dynamic Programming techniques. It includes tasks such as sorting arrays using Merge Sort and Quick Sort, computing binomial coefficients, applying Floyd's Algorithm to directed graphs, and solving the 0-1 Knapsack Problem. Each task specifies points and requires the demonstration of work or reasoning behind the solutions.

Uploaded by

liza201357637
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)
5 views

Homework3

The document outlines a homework assignment for CSC510 focusing on Divide and Conquer and Dynamic Programming techniques. It includes tasks such as sorting arrays using Merge Sort and Quick Sort, computing binomial coefficients, applying Floyd's Algorithm to directed graphs, and solving the 0-1 Knapsack Problem. Each task specifies points and requires the demonstration of work or reasoning behind the solutions.

Uploaded by

liza201357637
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/ 2

CSC510 Homework #3 Divide and Conquer & Dynamic Programming (100 pts Total)

1. Starting with array S[] = {123, 34, 89, 56, 150, 12, 9} indexed from 1 to 7:
a) (15 pts) Sort S[] using Merge Sort. Show the recursive tree and indicate order of
execution, i.e., label steps in tree nodes.
b) (5 pts) For 𝑛 = 32, in the best case Merge Sort would be expected to perform
how many comparisons?

2. Starting with array S[] = {123, 34, 189, 56, 150, 12, 9, 240} indexed from 1 to 8:
a) (15 pts) Assuming that Quick Sort uses the first item in the list as the pivot item,
sort S[] using Quick Sort. Show the recursive tree. Show the recursive tree and
indicate order of execution, i.e., label steps in tree nodes.
b) (5pts) Give a list of 8 items that represent the worst case scenario. Describe the
reason why it represents a worst case as well as its time complexity with n inputs.

3. Consider the binomial expansion of (𝑎 + 𝑏)10 without resorting to computing factorials.


a) (10 pts) Find the value of the coefficient of the term 𝑎4 𝑏 6 in the above binomial
expansion without resorting to computing factorials. Show your work.
b) (5 pts) True or False: In the top-down Divide and Conquer algorithm for
computing binomial coefficients, the number of recursive calls required to
compute the coefficient of 𝑎4 𝑏 6 in the above expansion would be greater than
10
( ).
4
c) (5 pts) True or False: In the bottom-up Dynamic Programming algorithm for
computing binomial coefficients, the number of terms computed to determine
the coefficient of 𝑎4 𝑏 6 in the above expansion would be the same as the number
required to compute the coefficient of 𝑎6 𝑏 4

4. For a certain directed graph with 4 vertices, Floyd’s Algorithm has produced the
following arrays D(3) and P(3). Using these values, compute the missing values in the
arrays D(4) and P(4). Show how you computed.

D(3) 1 2 3 4 P(3) 1 2 3 4 D(4) 1 2 3 4 P(4) 1 2 3 4


1 0 8 1 3 1 0 0 0 3 1 0 1 3 1 0 4 0 3
2 16 0 7 9 2 3 0 0 3 2 15 0 9 2 4 0 3
3 9 17 0 2 3 0 1 0 0 3 8 5 0 2 3 4 0 0
4 6 3 7 0 4 0 0 1 0 4 6 3 7 0 4 0 0 1 0

a) (3 pts) D(4)[1][2] =
b) (3 pts) D(4)[2][3] =
c) (3 pts) P(4)[2][3] =
d) (3 pts) P(4)[3][2] =
© Kaz Okada
e) (5 pts) Using the array 𝑃(4) , find the path from v1 to v2 that is shortest. Show how
you apply the information in 𝑃 (4) to arrive at your answer.
f) (3 pts) True or False: In general for a directed graph with n vertices, the Floyd’s
Algorithm guarantees that for all vertices 𝑣𝑖 , 𝑣𝑗 , 𝑣𝑘 , 𝐷 (𝑛) [𝑖][𝑗] = 𝐷(𝑛) [𝑖][𝑘] +
𝐷(𝑛) [𝑘][𝑗]

5. For the 0-1 Knapsack Problem, the item #1 has weight of 4 and the value of $12; the
item #2 has weight of 1 and the value of $1; the item #3 has weight of 5 and the value of
$10; and the item #4 has weight of 2 and the value of $8. The capacity of the knapsack’s
weight is 10. The Dynamic Programming algorithm has produced the following array. Fill
the last two entries in the array and show how they are calculated.

0 1 2 3 4 5 6 7 8 9 10
0 0 0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 12 12 12 12 12 12 12
2 0 1 1 1 12 13 13 13 13 13 13
3 0 1 1 1 12 13 13 13 13 22 23
4 0 1 8 9 12 13 20 21 21

a) (6 pts) D[4][9] =
b) (6 pts) D[4][10] =
c) (8 pts) Which items should be put in the knapsack to achieve the maximum profit?
Show how you determined this result.

© Kaz Okada

You might also like