Question: Solution needed in java Stream.java: import java.util.Random; class Stream { private Random generator; private int max; public Stream(int max, int seed) { // Don't pass
Solution needed in java


Stream.java:
import java.util.Random; class Stream { private Random generator; private int max; public Stream(int max, int seed) { // Don't pass anything to the Random number // generator if you want to create a different // sequence of numbers at each time. // // I want to generate the same sequence. It is // easier to test this *simple* program that way. // // But please do remember to always test your program // by generating difference sequences of // integers. generator = new Random(seed); this.max = max; } int getNext() { return generator.nextInt(max) + 1; } }
StreamProcessor.java:
class StreamProcessor{ private int index; private BTree storage; // YOU MIGHT HAVE TO MODIF THIS CLASS BY ADDING NEW METHODS AND MEMBERS public StreamProcessor() { this.index = 0; this.storage = new BTree(); } public void consume(int v) { storage.insert(v, index); index++; } public int[] search(int v) { // YOU NEED TO IMPLEMENT THIS METHOD return new int[1]; } public int at(int i) { // YOU NEED TO IMPLEMENT THIS METHOD return -1; } public void show() { storage.show(); } } Introduction This assignment focuses on constructing, balancing, and searching in binary trees. In terms of algorithms you are asked to implement AVL algorithm for balancing your binary trees Stream Processing You are provided a Stream class that generates random integers on demand. The Stream class is implemented in Stream.java file. You are also provided a StreamProcessor class that consumes (stores) the integers generated by the Stream class. The length of the stream is not known a priori, so the StreamProcessor class uses a sorted binary tree to stores the incoming integers. Classes BNode and BTree implement the sorted binary tree used here Searching At any time during the process the user can issue a search queries of the following form to the stream processor search(value); and at(index) The first query returns the index(s) at which the value appeared in the stream (assuming that the first integer from the stream is at index 0) or -1 if the value never appeared in the stream. While the second query returns the value that appeared at a particular index in the stream. Example Stream: 4534662 10 10 100 29.. search(5) returns 1 search(4) returns [0, 3] search(99) returns -1 at(4) returns 6 Efficient Data Structures A nave sorted binary tree implementation might work for implementing the search query, but it will perform miserably with the at query. So you need to implement the AVL algorithm to balance your binary tree in order to handle both queries efficiently
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
