Implement and test a generic binary search

Assignment Help Data Structure & Algorithms
Reference no: EM131266145

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.

Reference no: EM131266145

Questions Cloud

Implement an application that will hold the customer list : You will need to implement an application that will hold the customer list for Acme Anvil Supply. This list will be read from a file and stored in a binary tree.
How is fashion industry being corporatized today : How does economic development in society influence how and what artistic work is being created in fashion industry? How is fashion industry being corporatized today? Can you think of methods or strategies of corporativism that were employed in your..
Privately and publicly owned forests : In 150 words how is the supply of forest goods influenced by privately and publicly owned forests?
Discuss impact of multinational firms on the world economy : Discuss the impact of multinational firms on the world economy. - What could foreign governments do to make them more beneficial?
Implement and test a generic binary search : 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.
What are the major barriers to international trade : What are the major barriers to international trade? Explain how government policies may be used to either restrict or stimulate global marketing.
Accompanying consolidated balance sheets : Rowe Price Group, IncWe have audited the accompanying consolidated balance sheets of T. Rowe Price Group, Inc and subsidiaries (the Company) as of December 31, 2010 and 2009, and the related consolidated statements of income, stockholders' equity,..
Draw a domain concept diagram for the abt : Select one of the predictive analytics models that you proposed in your answer to the previous question about the oil exploration company for exploration of the design of its analytics base table.
Create a class called dateprofile that has instance members : Create a class called DateProfile that has the following private instance members: gender - a char, the gender of the applicant ('M' or 'F').

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Implement an open hash table

In this programming assignment you will implement an open hash table and compare the performance of four hash functions using various prime table sizes.

  Use a search tree to find the solution

Explain how will use a search tree to find the solution.

  How to access virtualised applications through unicore

How to access virtualised applications through UNICORE

  Recursive tree algorithms

Write a recursive function to determine if a binary tree is a binary search tree.

  Determine the mean salary as well as the number of salaries

Determine the mean salary as well as the number of salaries.

  Currency conversion development

Currency Conversion Development

  Cloud computing assignment

WSDL service that receives a request for a stock market quote and returns the quote

  Design a gui and implement tic tac toe game in java

Design a GUI and implement Tic Tac Toe game in java

  Recursive implementation of euclids algorithm

Write a recursive implementation of Euclid's algorithm for finding the greatest common divisor (GCD) of two integers

  Data structures for a single algorithm

Data structures for a single algorithm

  Write the selection sort algorithm

Write the selection sort algorithm

  Design of sample and hold amplifiers for 100 msps by using n

The report is divided into four main parts. The introduction about sample, hold amplifier and design, bootstrap switch design followed by simulation results.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd