Download 124370-hw2-1-

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Lateral computing wikipedia , lookup

Sieve of Eratosthenes wikipedia , lookup

Recursion (computer science) wikipedia , lookup

Computational electromagnetics wikipedia , lookup

Genetic algorithm wikipedia , lookup

Computational phylogenetics wikipedia , lookup

Knapsack problem wikipedia , lookup

Selection algorithm wikipedia , lookup

Algorithm characterizations wikipedia , lookup

Fisher–Yates shuffle wikipedia , lookup

Factorization of polynomials over finite fields wikipedia , lookup

Simplex algorithm wikipedia , lookup

Page replacement algorithm wikipedia , lookup

Computational complexity theory wikipedia , lookup

Algorithm wikipedia , lookup

Travelling salesman problem wikipedia , lookup

Corecursion wikipedia , lookup

Expectation–maximization algorithm wikipedia , lookup

Quicksort wikipedia , lookup

Halting problem wikipedia , lookup

Time complexity wikipedia , lookup

Recurrence relation wikipedia , lookup

Transcript
CS 4120/5120 Spring 2017
Homework 2
_______ / 50 points
DUE MONDAY FEBRUARY 13, 2017 7:30PM
Turn in both an electronic copy on Canvas and a printed copy in lecture.
Name ______________________________________
ID
______________________________________
1. [5 pts] Draw the recursion tree (see Fig 2.5, page 38 in the book for an example) for the recurrence:
T(n) = θ(1) if n = 1
= 2T(n/2) + n2 if n > 1
1
CS 4120/5120 Spring 2017
Homework 2
2. [2 pts] Use the tree from Problem 1 to guess a solution to the recurrence.
3. [5 pts] Use the substitution method to solve the recurrence based on your guess in Problem 2.
4. [5 pts] Use the Master Method to solve the recurrence in Problem 1.
2
CS 4120/5120 Spring 2017
Homework 2
5. [5 pts] Use MERGE-SORT algorithm (available on Page 34 in textbook) to sort the following list:
5 8 2 1 6 6 4 2 3
Show the steps (One example is illustrated in Fig 2.4 on Page 35 in the textbook).
3
CS 4120/5120 Spring 2017
Homework 2
6. [7 pts] Design a 3-way merge sort algorithm, which divides the given array into three equal parts,
recursively sorts each part, then merges the results. In the main MergeSort3(A,p,r) algorithm,
you may assume the existence of an appropriate Merge3(A,p,q1,q2,r) linear-time ((n))
algorithm. Provide the pseudocode for the main algorithm (but not for the Merge3 helper). Don't forget
to properly handle the base case!
MergeSort3(A,p,r)
7. [3 pts] Give a recurrence relation T(n) for your solution to Problem 6.
8. [3 pts] Use the Master Method to solve the recurrence you gave in Problem 7.
4
CS 4120/5120 Spring 2017
Homework 2
9. [3 pts] Given the following input array [40, 10, 30, 80, 5, 60] show as a “heap” (in binary tree form). Note
that this initial “heap” may not satisfy the max-heap property.
10. [5 pts] Convert the heap in Problem 9 into a maximum-heap. Show each step of BUILD-MAX-HEAP
(including marking the node i in each step, similar to Figure 6.3, page 158).
5
CS 4120/5120 Spring 2017
Homework 2
11. [7 pts] Show HEAPSORT on the final maximum-heap from Problem 9 (i.e., skip line 1 of the algorithm that
calls BUILD-MAX-HEAP). Show each step (including marking the node i in each step, similar to Figure 6.4,
page 161).
6