Docsity

Homework 2: Sorting Algorithms, Assignments of Engineering

Toggle sidebar
bg1
Homework 2: Sorting Algorithms, Dynamic Programming,
AVL tree, and Recurrences
Dewan T. Ahmed
September 18, 2026
Note: All work turned in must be handwritten and represent the individual, original work of the student.
Question 1 [2 + 3 = 5 points]
1. Describe the contexts in which Quicksort and Merge Sort are expected to perform better or worse.
Discuss the characteristics of the input and the factors that can affect the performance of each
algorithm.
2. Analyze the expected runtime of the Quicksort algorithm in detail. (Hint: Refer to the lecture
slides.)
Question 2 [5 + 2 = 7 points]
Given a chain of five matrices A1,A2, A3, A4, A5. The dimensions of the matrices are:
A1: 4 ×5
A2: 5 ×8
A3: 8 ×10
A4: 10 ×3
A5: 3 ×4
Solve the matrix-chain problem above using dynamic programming. Compute the minimum cost and
present the required parenthesization. (Hint: Refer to the lecture slides and in-class practice problem.)
Question 3 [6 points]
Let S={a, b, c, d, e, f, g}be a collection of objects with benefit-weight values as follows:
a b c d e f g
Benefit 10 9 7 11 13 7 8
Weight 4 6 5 6 3 1 6
Solve the 0-1 Knapsack problem for the item collection Swith a knapsack capacity of 18. You must show
your complete work (such as the dynamic programming state matrix) and list the final optimal selection
of objects along with their combined benefit.
1
pf3

Partial preview of the text

Download Homework 2: Sorting Algorithms and more Assignments Engineering in PDF only on Docsity!

Homework 2: Sorting Algorithms, Dynamic Programming,

AVL tree, and Recurrences

Dewan T. Ahmed

September 18, 2026

Note: All work turned in must be handwritten and represent the individual, original work of the student.

Question 1 [2 + 3 = 5 points]

  1. Describe the contexts in which Quicksort and Merge Sort are expected to perform better or worse. Discuss the characteristics of the input and the factors that can affect the performance of each algorithm.
  2. Analyze the expected runtime of the Quicksort algorithm in detail. (Hint: Refer to the lecture slides.)

Question 2 [5 + 2 = 7 points]

Given a chain of five matrices A 1 , A 2 , A 3 , A 4 , A 5. The dimensions of the matrices are:

A 1 : 4 × 5 A 2 : 5 × 8 A 3 : 8 × 10 A 4 : 10 × 3 A 5 : 3 × 4

Solve the matrix-chain problem above using dynamic programming. Compute the minimum cost and present the required parenthesization. (Hint: Refer to the lecture slides and in-class practice problem.)

Question 3 [6 points]

Let S = {a, b, c, d, e, f, g} be a collection of objects with benefit-weight values as follows:

a b c d e f g Benefit 10 9 7 11 13 7 8 Weight 4 6 5 6 3 1 6

Solve the 0-1 Knapsack problem for the item collection S with a knapsack capacity of 18. You must show your complete work (such as the dynamic programming state matrix) and list the final optimal selection of objects along with their combined benefit.

Question 4 [3 points]

Write down the recurrence relation for the well-known minimum Coin Change Problem used in dynamic programming. In other words, give the change for amount n using the minimum number of coins of denominations d 1 < d 2 < · · · < dm. Next, demonstrate how the solution is built step by step using a concrete example. (Hint: Refer to the in-class practice problem.)

Question 5 [3 points]

Explain, in your own words, one linear-time sorting algorithm and illustrate how it works with an example. Also explain why the algorithm has a linear running time. (Hint: Refer to the lecture slides.)

Question 6 [3 points]

Prove that the height of an AVL tree is O(log n). (Hint: Refer to the lecture slides.)

Question 7 [5 points]

Show the AVL tree that results after each of the integer keys 9, 7, 5, 10, 28, 21, 41, 3, 19, 22, 35, 13, 40, 14, 11, 26 and 20 are inserted, in that order, into an initially empty AVL tree. Clearly show the tree after each insertion, and clearly indicate any rotations that need to be performed.

Question 8 [3 points]

Starting with the AVL tree shown below, perform a delete ‘10’ operation. Show the tree after each operation, as well as after any intermediate restructuring steps performed.

Figure 1: Initial AVL Tree Structure