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

  Question 1a i what is a pointer illustrate with an

question 1a i what is a pointer? illustrate with an exampleii give two advantages of the use of pointers over arraysb i

  Determine the values for m and l for the b+ tree

A B+-tree is to be stored on disk whose block size is 2048 bytes. The data records to be stored are 50 bytes, and their key is 4 bytes. Determine the values for M and L for the B+-tree. Assume pointers are 4 bytes each.

  Different levels of a dbms

Recognize the level within a database system user and designer of the DBMS software at which each of the following concerns or activities happen,

  Write recursive version of array-based linear search

Write an algorithm but not code. Write a recursive version of the array-based linear search algorithm. Write a recursive version of the linked-list-based linear search algorithm."""

  Database design

As with the previous exams(SQL,E-R diagram and Normalization, you may complete this assignment at any time up to its due date of December 8, 2013.

  Create tree correspond to expression pre-order traversal

Let the algebraic expression E=(2x+y)(5a-b)^3. Create tree T which correspond to expression E and determine pre-order traversal of T.

  Project documentation

Follow the docx template. Show all the work with comments. Please have a flow chart, description, analysis, and psuedocode.  I posted this earlier...and I got played. I can't sit down and do homework right now...I'm way too busy. I KNOW this stuff...

  Show the postfix expressions

An infix expression is one in which operators are located between their operands - Pop the stack elements and add them to the queue (PostQueue) one by one until the top of the stack has an element of lower precedence

  Sequential logic structures-flowchart or pseudocode

Document the steps for the logic structure to capture the payment information. This can be done as either a flowchart or pseudocode. Be sure to include inputs, variable declarations and assignments, and outputs.

  Babylonian algorithm

Babylonian Algorithm. The Babylonian algorithm to compute the square root of a positive number n is as given:

  1decryption speeda certain cryptography vendor was

1.decryption speeda certain cryptography vendor was providing an encryption technology that was breakable within 10

  The development of complex algorithms that can mine mounds

the development of complex algorithms that can mine mounds of data that have been collected from people and digital

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