Java data Sturcture Searching and Sorting
Guidelines
Please follow the guidelines below:
Submit the homework and lab solutions in the drop box. For a programming question,
submit a .java file (for source code) and a .txt file for program output. If the problem
involves other questions, submit a separate .txt file to answer the question.
P1 (20 points)
Implement a binary search of an array iteratively using the methodpublic
static <T extends Comparable<? super T>> booleaninArrayIterativeSorted(T[]
anArray, T anEntry)
P2 (30 points)
Consider an array data of n numerical values in sorted order and a list of numerical target
values (target values are not necessarily sorted). Your goal is to compute the smallest range of
array indices that contains all of the target values. If a target value is smaller than data[0], the
range should start with -1. If a target value is larger than data[n - 1], the range should end with
n.
For example, given the array [ 5 8 10 13 15 20 22 26] and the target values (8, 2, 9, 17), the
range is -1 to 5.
1. Devise an efficient algorithm that solves this problem and implement it in
public static <T extends Comparable<? super T>>
Interval findInterval(T[] sortedData, List<T> targetValues)
where Interval is a class that provides two public methods getLower() and getUpper() to return
the lower and upper values of an Interval object. Implement the Interval class.
2. If you have n data values in the array and m target values in the list, what is the Big Oh
performance of your algorithm?
P3 (20 points)
Write the java code for the method
pubic static <T extends Comparable<? super T>> boolean isSorted(T[ ] a)
which returns true if the array a is in sorted in ascending order. The code must run in O(n) time.
P4 (30 points)
Consider a revised selection sort algorithm so that on each pass it finds both the largest and
smallest values in the unsorted portion of the array. The sort then moves each of these values
into its correct location by swapping array entries.
1. Implement the modified selection sort using the method
public static <T extends Comparable<? super T>> void modifiedSelectionSort(T[] a, int n)
2. How many comparisons are necessary to sort n values?
7 years ago
25
- ONE PAGE
- Final EXAM.docx Write a scene between any two main characters from any of the plays we have studied that takes place 5 years after the action of the play ends. Place them in a specific setting, in a specific context. The meeting cannot be accidental-one
- I just need a few questions answered asap
- History of Art class,, who can write for me two pages about (christo jeanne claude surrounded island ) ,, i want this work in Next 12 hours
- BSHS 435 Week 2 Individual Assignment Sampling and Data Collection in Research Paper
- Answer the next questions (Parts A and B) on the basis of the following cost data for a firm
- journal
- QNT561 Week 6 Chapter 7(Ex.50)
- for assignment wizard only
- 2nd Leadership