Implement and test a generic binary search

Assignment Help Data Structure & Algorithms
Reference no: EM13811065

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);

Reference no: EM13811065

Questions Cloud

Analyze the rationale and purpose of the exclusionary rule : analyze the rationale and purpose of the exclusionary rule, and identify exceptions. In your analysis, state the ramifications of the exclusionary rule
What is the exclusionary rule and what is an example : What is the Exclusionary Rule and what is an example. What are the exceptions of the rule. How does the Exclusionary Rule apply to criminal procedure
Calculate the hall voltage for an experiment : Calculate the Hall voltage for an experiment on a conductor where n = 3.7x 1022 cm3, q = 1.602 x 10-19C. The current I = 100 mA, the conductor thickness t = 0:1 mm, and the magnetic field B = 0.5 Tesla.
Which announces whether or not the player has won the game : 2D graphics, instead of text, to display the Xs and Os in the grids of the square- shaped buttons decision logic or recursion in order to determine whether or not a player wins the games. Display a message which announces whether or not the player ha..
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
Discuss how government intervention promotes efficiency : Discuss how government intervention promotes efficiency and equity in the economy. Be sure that you include restraint of trade, indirect costs, deregulation, and overregulation within your analysis.
Conflicts as competition intensifies for water : How will we counter the rapid rise of resource conflicts as competition intensifies for water and arable land. How should governments respond to this impending crisis of a diminished food supply
Intrusions in asia-opera and society : Intrusions in Asia-Opera and Society
Strategic planning for organizations : Strategic Planning for Organizations

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Algorithm for a bank account

Write algorithm to settle following question: A bank account starts out with $10,000. Interest is compounded monthly at 6 percent per year (0.5 percent per month).

  Creating visual studio asp .net web site

Make a Visual Studio 2008 ASP .NET Web Site with 2-Web Forms. Add a DropDownList server control and a Label server control to 1st Web Form.

  Program for stack by using dynamically allocated array

Write a C++ class which implements stack by using a dynamically allocated array. Initial size of particular stack must be determined when it is created.

  Write an algorithm called find-g

Write an algorithm called "Find-G" to nd a maximally-general consistent hypothesis. You can assume the data will be noise-free and that the target concept is in the hypothesis space.

  Creating sql statements

Create three SQL statements: the 1st statement should add pending amounts to appropriate accounts, the second statement should subtract the pending amounts from appropriate accounts,

  Question about multi dimensional arrays

Multi-dimensional arrays could cost a lot of memory. Determine how much memory does it take to create an integer array of 3 dimensions,

  Show state of memory after processes by best fit algorithm

Using the best fit algorithm, show the state of memory after processes of 212K, 417K, 112K and 350K (in request order) arrive.

  Analyzing the use of databases

Create a paper analyzing the use of databases in your company. Include what database applications are used. Conclude through proposing improvements.

  What is meant by application service provider

What is meant by Application Service Provider? What factors drive their emergence? How does Jamcracker fit in ASP space? Describe the Jamcracker business model.

  Question 1you are required to provide suitable examples of

question 1you are required to provide suitable examples of your own for each part of the question where appropriateai

  Describe the requirement for complex data structures

Describe the requirement for complex data structures and how they are utilized. Describe the design and application of arrays and how the array simplifies program development.

  Calculate the wait time between two iterations

Question on Retry factor and Retry and Retry Interval, practical question is asked on this to calculate the wait time between two iterations?

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