Find Jobs
Hire Freelancers

need some code in java

₹100-400 INR / hour

Zavřený
Zveřejněno před více než 7 roky

₹100-400 INR / hour

Concerning the size field in each Node 1.1 Get a listing by index Our goal is to implement a get(int i) method which takes an integer zero-based index i and return the i-th smallest (with respect to the price) listing in the BST. There are many ways to accomplish this, in fact, it can be done in at least two ways by using methods you implemented in Homework 8. For example, we can call getMin to get the listing at index 0, then keep calling getNext until we find the i-th listing. This will take O(ilog n) time on a balanced BST with n nodes which is OK for small i but is not efficient when i approaches n. Alternatively we can use the toArray method to dump the tree into a sorted array then simply return the listing at index i. This approach will take O(n) time and O(n) extra space. In order to do it more efficiently (namely, in O(log n) time), we add a size field to each node which keeps record of the number of nodes in the subtree rooted at this node. Given this field, we can easily determine (why?) whether the target node is to the left, to the right, or is just at the current node. We recommend that you do this using a recursive helper method doGet(Node r, int i) but this is not an absolute requirement. 1.2 Reimplement the add method Notice that in order to keep the size field of each node correct, our add method has to be modified to update it. Recall the add method needs to first find the correct position to add a new element, all the nodes on this search path need to have their size fields updated unless we did not add the new element (which will happen if there is some other listing with the same price). This can be done by first add the node, if succeeded, then go through this search path again to update size. However this is not efficient in the sense it does twice as many comparisons as necessary. Keeping track of all the nodes encountered on the search path using a stack will work but in order to give you more practice on recursion, we will NOT do it. Instead, we will re-implement the add method using a recursive helper method Node doAdd(Node r, listing l) which tries to add the new listing into a subtree rooted at r and returns the (possibly modified) root of this subtree. 1.3 New invariant In addition to the above changes, we need to check if the size field in each node is correct as an invariant. This can be done by augmenting the _checkInRange method you implemented in
IČ projektu: 12082489

O projektu

12 nabídky
Vzdálený projekt
Aktivní před 7 roky

Chcete si vydělat nějaké peníze?

Výhody podávání nabídek na Freelancer

Stanovte si rozpočet a časový rámec
Získejte za svou práci zaplaceno
Načrtněte svůj návrh
Registrace a podávání nabídek je zdarma
12 freelanceři nabízejí v průměru ₹316 INR/hodinu za tuto práci
Avatar uživatele
WTF? What an understandable and unreadable project(................................................................... .............................
₹277 INR v 10 dnech
5,0 (2 recenze)
2,6
2,6
Avatar uživatele
Hi I'm ready to help you
₹200 INR v 1 dni
4,7 (4 recenze)
1,8
1,8
Avatar uživatele
We are a team of new Freelancers. We have good experience in Java Coding. We can finish your project in less than a week. We are willing to give you the least price because all we are looking forward to is customer's trust and reviews.
₹111 INR v 40 dnech
0,0 (0 recenze)
0,0
0,0
Avatar uživatele
I currently live in calgary where I lead the development of a huge, critical java application where performance is critical.
₹277 INR v 10 dnech
0,0 (0 recenze)
0,0
0,0
Avatar uživatele
We are a team of more than 10+ years of experience in different domains, as part of this project we will deliver within stipulated period.
₹533 INR v 50 dnech
0,0 (0 recenze)
0,0
0,0
Avatar uživatele
A proposal has not yet been provided
₹333 INR v 3 dnech
0,0 (0 recenze)
0,0
0,0

O klientovi

Pochází z INDIA
Bangalore, India
4,8
231
Členem od led 29, 2011

Ověření klienta

Díky! Poslali jsme vám e-mailem odkaz pro získání kreditu zdarma.
Při odesílání e-mailu se něco pokazilo. Zkuste to prosím znovu.
Registrovaných uživatelů Zveřejněných projektů
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Načítání náhledu
Bylo uděleno povolení ke geolokaci.
Vaše doba přihlášení vypršela a byli jste odhlášeni. Přihlaste se znovu.