Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

Assignment

Implement and test a generic binary search. Note that your test program must use at least 2 types of data to prove that bsearch is generic.

Templating means that instead of passing a parameter such as Integer you pass a parameter T. (T is a type variable and can be named anything). This means that you can call bsearch with different types of objects.

Pseudo Code Example:

Bsearch(String) Bsearch(Integer)

This means you do not have to write 2 separate bsearch methods, one for String and one for Integer.

The heart of how this is accomplished is the Comparable interface. If a class implements Comparable, it defines less than, greater than and equals. Also, by making the type variable you can call with any object that implements Comparable.

Example Code:

public class Searches

{

public static int bsearch(T[] a, int first, int last, T key)

{

called in main as:

result = Searches.bsearch(IntegerArray,0, 10, key);

result = Searchesbsearch(StringArray,0,10,key);

Example Output:

--------------------Configuration: --------------------

Integer test array contains:

0 2 4 6 8 10 12 14 16 18

-3 is not in the array.

-2 is not in the array.

-1 is not in the array.

0 is at index 0

1 is not in the array.

2 is at index 1

3 is not in the array.

4 is at index 2

String test array contains:

apples oranges peaches strawberries watermelons

apples is at index 0

plums is not in the array.

Process completed.

Computer Engineering, Engineering

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

Priced at Now at $40, Verified Solution

Have any Question?


Related Questions in Computer Engineering

Can someone help me identify how intrustion detection

Can someone help me identify how Intrustion detection system and intrusion prevent system can help protect confidentiality, integrity and availability

Task create an array that holds 100000 random integers

Task : Create an array that holds 100000 random integers between 1-100000. Allow the user to enter an integer to search. Create and implement modified bubble sort algorithm which will sort the array before the Binary Sea ...

A marketing research firm was hired to estimate the mean

A Marketing Research firm was hired to estimate the mean prime-lending rate for banks located in the western region of the United States. A random sample of n = 50 banks was selected from within the region, and the prime ...

Question the states of california arizona new mexico utah

Question : The States of California, Arizona, New Mexico, Utah, and Nevada each send a team of 6 delegates to the Sounth Western States annual conference. A sub commitee of 9 is to be formed to discuss water rights. How ...

A survey of 200 students is selected randomly on a large

A survey of 200 students is selected randomly on a large university campus. They are asked if they use a laptop in class to take notes. The results of the survey is that 70 of the 200 students responded yes. Calculate th ...

Arectangular box without a top has surface area 2500 cm2

A rectangular box without a top has surface area 2500 cm 2 . The length x of its base is 18 cm longer that its width. • (a) Use MATLAB's polynomial functions to express the volume V of the box in terms of x. • (b) Plot V ...

Question task a based on the case above as well as your own

Question: Task A: Based on the Case Above as well as your Own Research on IT Service Delivery, answer the following questions: 1) What were the key reasons for the IT implementation failure? 2) In your view, who is respo ...

How does consumers influence the market price of goods it

How does consumers influence the market price of goods it sells, and what does the term, "market power" means?

Question set up geometric data tables for a unit cube using

Question ; Set up geometric data tables for a unit cube using only vertex and polygon tables and a single polygon table. Compare the two methods for representing the unit cube with a representation using three data table ...

Search the web for two or more sites that discuss the

Search the web for two or more sites that discuss the ongoing responsibilities of security manager. What other components of security management, as outlined by this model, can be adapted for use in the security manageme ...

  • 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