Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

this is java problem. --------------------------------------------------------------------------------- public class Blob { private int coolnessFactor; public Blob(int coolnessFactor) { this.coolnessFactor = coolnessFactor; } public int getCoolnessFactor() { return

this is java problem.

image text in transcribedimage text in transcribed

---------------------------------------------------------------------------------

public class Blob {

private int coolnessFactor;

public Blob(int coolnessFactor) {

this.coolnessFactor = coolnessFactor;

}

public int getCoolnessFactor() {

return coolnessFactor;

}

@Override

public String toString(){

return "B(" + coolnessFactor + ")";

}

}

---------------------------------------------------------------

import java.util.ArrayList;

public class BinarySearchTester {

public static int binarySearch( ArrayList blobs, Blob bKey1, Blob bKey2 ) {

// ---> WRITE THIS METHOD

// Write code here to implement as described in problem description.

// ***Need to write a recursive helper method also.

return 1;

}

public static void main( String[] args ) {

// Sample code to create a sorted Blob list with 5 twins (10 elements).

// You should make sure your code works with other numbers of twins.

ArrayList blobs = buildBlobList(5);

printBlobList(blobs);

// ---> WRITE CODE HERE TO TEST

}

// You may use this method to build and return a sorted Blob

// list based on sum of coolness factor for each of the twins.

// Creates "numTwins" twins (i.e. 2*numTwins elements)

private static ArrayList buildBlobList(int numTwins) {

ArrayList blobs = new ArrayList();

int cNess = 2;

for(int i=1; i

Blob b1 = new Blob(cNess);

cNess+=2;

Blob b2 = new Blob(cNess--);

blobs.add(b1);

blobs.add(b2);

}

return blobs;

}

// You may use this method to print a blob list in a way that

// emphasizes the twins and the sum of their coolness factors.

private static void printBlobList(ArrayList blobs) {

StringBuilder sb = new StringBuilder("Sorted Blob list: ");

for(int i=0; i

int cNess1 = blobs.get(i).getCoolnessFactor();

int cNess2 = blobs.get(i+1).getCoolnessFactor();

int twinPower = cNess1 + cNess2;

sb.append(String.format("B(%d)+B(%d)=%d, ", cNess1, cNess2, twinPower));

}

sb.delete(sb.length()-2, sb.length());

System.out.println(sb.toString());

}

}

ou will write a version of recursive binary search that works on "blob twins". Blob objects have an integer coolness factor. Blob objects are stored in an ArrayList. In the example below, we use the notation B(x) to denote a blob with coolness factor x.w Index 0 40 64 For the purposes of this problem, every two blobs are considered twins. For example:+ Twins Twins Twins Twins Index 0 40 64 You will write a recursive binary search that works in the following way:+ Assume the ArrayList of Blobs is sorted on the sum of the coolness factors for twins. For example, the first two Blobs have a sum of 5, the second two have a sum of 7, etc. Thus, we can see that they are sorted as described. a. Twins-5 Twins-7+ Twins-10 Twins-15 Index 0 40 64 b. The "key" (item being search for) is a two Blobs. For example, B(6) & B(4) c. A key is considered found if sum of the coolness factors in the two keys matches the sum of the coolness factors for a set of twins in the array. Note, the coolness factors do not have to be the same, just their sum has to match the sum for the keys. For example, the key: 16) & B(4) is found in the list above for the Blobs at indices 4 and 5 because B(8) & B(2) sum to 10

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke

1st Edition

0130086509, 978-0130086501

More Books

Students also viewed these Databases questions