Trusted by Students Everywhere
Why Choose Us?
0% AI Guarantee

Human-written only.

24/7 Support

Anytime, anywhere.

Plagiarism Free

100% Original.

Expert Tutors

Masters & PhDs.

100% Confidential

Your privacy matters.

On-Time Delivery

Never miss a deadline.

Assignment Lab 11 1) 20

Computer Science Jun 23, 2021

Assignment Lab 11

1) 20.10 (A)  (Generic linear search) Implement the following method for linear search:

Public static <E extends Comparable<E>>

Int linearSearch (E[] list, E key)

(B)  (Maximum element in an array) Implement the following method that returns the maximum in an array:

Public static <E extends Comparable<E>> E max (E[] list)

Assignment Lab 12

2).

20.10 (a)  (Perform set operations on priority queues)

{"George", "Jim", "John", "Blake", "Kevin", "Michael"} and             

{"George", "Katie", "Kevin", "Michelle", "Ryan"}, and find their union,

difference, and intersection.

 20.18 (b)   (Directory size) Listing 20.7, DirectorySize.java, gives a recursive     method for finding a directory size. Rewrite this method without using recursion. Your program should use a queue to store the subdirectories under a directory. The algorithm can be described as follows:

long getSize(File directory) {

long size = 0;

add directory to the queue;

 while (queue is not empty) {

Remove an item from the queue into t;

if (t is a file)

size += t.length();

else

add all the files and subdirectories under t into the queue;

}

 return size;

}

20.21 (C) ( (Use Comparator) Write the following generic method using selection sort and a comparator.

 public static void selectionSort(E[] list,

 Comparator comparator<? Super E> comparator)

Write a test program that creates an array of 10 GeometricObjects and invokes this method using the GeometricObjectComparator introduced in Listing 20.5 to  sort the elements. Display the sorted elements.   Use the following statement to create the array:

GeometricObject[] list1 = {new Circle(5), new Rectangle(4, 5),

new Circle(5.5), new Rectangle(2.4, 5), new Circle(0.5),

new Rectangle(4, 65), new Circle(4.5), new Rectangle(4.4, 1),

new Circle(6.5), new Rectangle(4, 5)};

Also in the same program, write the code that sorts six strings by their last

character. Use the following statement to create the array:

String[] list2 = {"red", "blue", "green", "yellow", "orange",

"pink"};

Assignment Lab 13

3) .

30.12 (a) (Parallel array initializer) Implement the following method using the Fork/ Join Framework to assign random values to the list.

 public static void parallelAssignValues(double[] list)

 Write a test program that creates a list with 9,000,000 elements and invokes parallelAssignValues to assign random values to the list. Also implement a sequential algorithm and compare the execution time of the two. Note that if you use  Math.random(),  your  parallel  code  execu- tion time will be worse than the sequential code execution time because Math.random() is synchronized and cannot be executed in parallel. To fix this problem, create a Random object for assigning random values to a small list.

 

3013 (b) (Generic parallel merge sort) Revise Listing 30.10, ParallelMergeSort.java, to define a generic parallelMergeSort method as follows:

public static <E extends Comparable<E>> void

parallelMergeSort(E[] list)

Expert Solution

Archived Solution
Unlocked Solution

You have full access to this solution. To save a copy with all formatting and attachments, use the button below.

Already a member? Sign In
Important Note: This solution is from our archive and has been purchased by others. Submitting it as-is may trigger plagiarism detection. Use it for reference only.

For ready-to-submit work, please order a fresh solution below.

Or get 100% fresh solution
Get Custom Quote
Secure Payment