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

  Rewrite pseudocode of warshalls algorithm assuming that the

rewrite pseudocode of warshalls algorithm assuming that the matrix rows are represented by bit strings on which the

  Write the function definition as a recursive search

Write the function definition as a recursive search, assuming a linked list implementation. After you have corrected the function, trace the execution of NumPaths with n = 4 by hand. Why is this algorithm inefficient?

  What is the data type

What is the data type and What is the type of the parameter

  Compare symmetric encryption to asymmetric encryption

Evaluate the advantages and disadvantages of using digital certificates. Evaluate the challenges related to public and private key management when using PKI.

  Describe open source and proprietary databases

Describe open source and proprietary databases. What are some drawbacks and benefits of each type of database?

  Write algorithm find intersection of two singly-linked list

Write an algorithm (pseudocode) to find the intersection of two singly-linked lists. Assume that the data in each list are in nondecreasing order.

  Process a weighted undirected graph

Set up and print the adjacency matrix representation of the Graph.

  Write a method that takes a sorted integer array a

Write a method that takes a sorted integer array A and a key k and returns the index of the first occurrence of k in A. Return -1 if k does not appear in A

  In this programming assignment you will implement an open

in this programming assignment you will implement an open hash table and compare the performance of four hash functions

  Creating algorithm to implement function

Create an Algorithm to implement the given function and explain how the required task can be achieved in a step by step process.

  Algorithm for checking whether a list of integers is sorted

Consider the obvious algorithm for checking whether a list of integers is sorted: start at the beginning of the list, and scan along until we first find a successive pair of elements that is out of order.

  What are some of the critical differences

When you start a new project, what are the essential tasks you take care or start with?

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