Use induction to prove.
2. Problem 2 Parts a, b, c, d, e and f
Although merge sort runs in (nlgn) worst-case time and insertion sort runs in (n2) worst-case time, the constant factors in insertion sort can make it faster in practice for small problem sizes on many machines. Thus, it makes sense to coarsen the leaves of the recursion by using insertion sort within merge sort when subproblems become sufficiently small. Consider a modification to merge sort in which n/k sublists of length k are sorted using insertion sort and then merged using the standard merging mechanism, where k is a value to be determined.
- Use insertion sort to sort the unsorted array < 40,17,45,82,62,32,30,44,93,10 >. Make sure to show the array after every pass.
- Use merge sort to sort the unsorted array < 75,56,85,90,49,26,12,48,40,47 >. Make sure to show the steps of splitting the array then merging the array.
- Show that insertion sort can sort the n/k sublists, each of length k, in (nk) worst-case time. (d) Show how to merge the sublists in (nlg(n/k)) worst-case time.
- Given that the modified algorithm runs in (nk + nlg(n/k)) worst-case time, what is the largest value of k as a function of n for which the modified algorithm has the same running time
1
as standard merge sort, in terms of -notation?
- How should we choose k in practice?
3. Problem 3
Write a (m + n) algorithm that prints the in-degree and the out-degree of every vertex in an m-edge, n-vertex directed graph where the directed graph is represented using adjacency lists.
4. Problem 4 Chapter 12 Binary Search Trees
Exercise 12.2-1. Suppose that we have numbers between 1 and 1000 in a binary search tree and we want to search for the number 363. Which of the following sequences could not be the sequence of nodes examined?
- 2, 252, 401, 398, 330, 397, 363.
- 924, 220, 911, 244, 898, 258, 362, 363. 925, 202, 911, 240, 912, 245, 363.
- 2, 399, 387, 219, 266, 382, 381, 278, 363.
- 935, 278, 347, 621, 299, 392, 358, 363.
- Problem 5 Sorting Iris Plants Note this is a Collaborative Problem
The Iris Plants Database contains 3 classes of 50 instances each, where each class refers to a type of Iris plant. Five attributes/features were collected for each plant instance. The dataset can be downloaded from iris.arff on the Sample Weka Data Sets webpage (https://storm.cis.fordham.edu/ gweiss/datamining/datasets.html). Develop an algorithm to sort the five features in the dataset to determine if any of the five sorted features can separate the three plant types. Show the efficiency of your sorting algorithm based on its ability to sort the five sets of features.
Reviews
There are no reviews yet.