Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

Search and Sort Algorithms

Objectives - To test search and sort algorithms

As you add methods to the code given, add documentation similar to what is used on the other methods (comment boxes).

Turn in IntegerList and IntegerListTest, table filled in, and the answer to a question on sorting and searching - see step 8 below.

1. The selection sort is missing two methods (swap and minIndex) - add them or copy the code for a selection sort using one method from last week's lab. Use this selection sort code in the sortAscending method.

2. Write the insertion sort, changing the insertion logic to sort in descending order and use it for sortDecreasing method. (p. 523).

3. Make sure the selection sort is increasing order and the insertion sort is decreasing order by creating small arrays, sorting them, and then printing them.

4. Write a method that to implement the enhanced bubble sort that sorts in ascending order.

5. Sort an array filled with random numbers with the selection sort for the first timing and then sort it again with the selection sort for the second timing.

6. Sort an array filled with random numbers with the insertion sort for the third timing and then sort it again with the insertion sort for the fourth timing.

7. Sort an array filled with random numbers with the enhanced bubble sort for the fifth timing and then sort it again with the enhanced bubble sort for the sixth timing.

8. Remember that the data in an array must be in ascending sequence to search it with the binary search method. Fill the arrays with sorted data before calling the binary search method. Since it doesn't matter if you fill the arrays to be used with the sequential search with sorted or unsorted data, you might as well fill the search array with sorted data once, then sequentially search it and then binary search it.

9. Write a short paragraph on sorting and another on searching. Explain why the times changed (or didn't change) for the different methods and how the algorithms were affected by the larger array sizes.

Timing Searching and Sorting Algorithms

In this exercise you will use an IntegerList class (in the file IntegerList.java) and a driver (in the file IntegerListTest.java) to examine the runtimes of the searching and sorting algorithms. The IntegerListTest class has several options for creating a list of a given size, filling the list with random integers or with already sorted integers, and searching or sorting the list. (NOTE: You may have used a version of these classes in the last lab.) Save these files to your directory and run IntegerListTest a few times to explore the options.

The runtimes of the sorting and searching algorithms can be examined using the Java method System.currentTimeMillis(), which returns the current system time in milliseconds. (Note that it returns a long, not an int.) You will have to import java.util.* to have access to this method. In IntegerListTest, just get the system time immediately before and immediately after you perform any of the searches or sorts. Then subtract the first from the second, and you have the time required for the operation in milliseconds. WARNING: Be sure you are not including any input or output in your timed operations; these are very expensive and will skew your algorithm times!

Add appropriate calls to System.currentTimeMillis() to your program, run it and fill out the tables below. Note that you will use much larger arrays for the search algorithms than for the sort algorithms; do you see why? Also note that the first couple of times you run a method you might get longer runtimes as it loads the code for that method. Ignore these times and use the "steady-state" times you get on subsequent runs. On a separate sheet, explain the times you see in terms of the known complexities of the algorithms. Remember that the most interesting thing is not the absolute time required by the algorithms, but how the time changes as the size of the input increases (doubles here).

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M92064964
  • Price:- $40

Priced at Now at $40, Verified Solution

Have any Question?


Related Questions in Computer Engineering

Suppose you were working on a very large system that

Suppose you were working on a very large system that consisted of many .cpp files and the associated header files. Lots of libraries too, developed for the project. a. What ADT structure could you use to represent all th ...

Assignment from chapter 10 page 302 web-based case read and

Assignment: From Chapter 10, page 302, Web-Based Case. Read and answer the questions. KNOWLEDGE MANAGEMENT SYSTEMS AND CRM In answer to the challenges Nelnet faces in servicing a growing volume of student loans, the comp ...

Explain why some organizations may not place enough

Explain why some organizations may not place enough importance on disaster recovery. What might happen to these organizations in the event of an actual disaster?

Please respondexplain the properties and characteristics of

PLEASE RESPOND Explain the properties and characteristics of Transmission Control Protocol/Internet Protocol (TCP/IP).

A random sample of n data values is obtained from a process

A random sample of n data values is obtained from a process having an absolutely continuous cdf of unknown shape. The metallurgist wants to select the best fitting distribution among several candidate cdfs. She decides t ...

Suppose a punched card has 80 columns and 12 rowsa if any

Suppose a punched card has 80 columns and 12 rows. (a) If any number of holes can be punched in the card, how many different cards can there be. If more convenient, you may give your answer in the form of an expression. ...

What is the supply curve how do you apply the law of supply

What is the supply curve, how do you apply the law of supply in economics?

Given a list of numbers l a value x is said to be a

Given a list of numbers L, a value x is said to be a majority value if the value of over half the elements in L is x; in other words, if L has n elements and nx is the number of elements in L with value x, then x is a ma ...

Taskwrite an essay according to the following

Task Write an essay according to the following instructions. Your lecturer will provide few links for relevant articles and/or case studies. These will be available to you just after your second assignment submission dat ...

Question why most of the researchers in the field of arabic

Question : Why most of the researchers in the field of Arabic text classification collected their own corpus and what is In-house Arabic corpus. The response must be typed, single spaced, must be in times new roman font ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As