I need help writing java code for the Binary Heap Priority Queue assignment. Task:
// Deletes all instances of the parameter obj from the PQ if found, and returns true. Returns false if no match to the parameter obj is found.
public boolean delete(E obj); // provided ADT
How can I write this in O(logn)? assuming you are using Sink/Swim (insert/remove) operations
Additional info:
Each method must be as efficient as possible. That is, an O(n) is unacceptable if the method could be written with O(log n) complexity. Both insert and remove must be O(log n).
Your BinaryHeap must be stable--able to determine the oldest entry among those with identical priority.
Your iterator must be fail-fast.
You may not make any modifications to the PriorityQueue interface provided. I will grade your project with my copy of this file.
All relevant requirements from earlier assignments apply here.
import .java .util.*;
class priority{
public static int[] insert(int a[])
{
int a[]=new int[];
PriorityQueue<String> pQueue =
new PriorityQueue<String>();
Iterator itr = pQueue.iterator();
Scanner input=new scanner(System.in);
System.out.print("Enter an value: ");
while (itr.hasNext())
{
int a[]= input.nextInt();
a[]=pQueue.add(itr.next());
a++;
}
return a[ ];
}
public boolean delete(obj[])
{
if(comparator.obj[]=comparator.obj[])
{
iterator<String> itr2 = pQueue.iterator();
while (itr2.hasNext())
pQueue.remove(obj[]);
return true;
}
else
return false;
}
public class main()
{
public static void main()
{
int[] obj=insert(s[]);
boolean j=delete(obj[]);
}
}
I need help writing java code for the Binary Heap Priority Queue assignment. Task: // Deletes all...
In class, we discussed the priority queue (PQ) ADT implemented using min-heap. In a min-heap, the element of the heap with the smallest key is the root of the binary tree. On the other hand, a max-heap has as root the element with the biggest key, and the relationship between the keys of a node and its parent is reversed of that of a min-heap. We also discussed an array-based implementation of heaps. In this assignment, your task is to...
PROGRAM DESCRIPTION Using the given class definitions for either C++, create a minimum heap that stores integers and and implements a minimum priority queue. (Your program can be "hard coded" for integers - it does not need to use templates, generics, or polymorphism.) Your data structure must always store its internal data as a heap. Your toString function should return a string with the heap values as a comma separated list, also including the size of the heap as well....
Since we do not want to have to rewrite this code when the element type changes, this classes uses a Comparator to assist in ordering the elements. You will need to complete the siftUpComparator() and siftDownComparator() methods in the LinkedHeap Class. siftUp §Added element may violate heap-order property §siftUp() restores order starting at added node §Processing will continue working up the tree until: úFinds properly ordered node & parent úReaches the root (reaches node without parent) siftDown §Restores heap’s order...
Need help with fixing "TreeMap cannot be resolved to a type" error in code. This was posted in another chegg question but has errors. Was wondering if someone can please fix this. Link to the question asked: https://www.chegg.com/homework-help/questions-and-answers/using-java-import-javautiliterator-import-javautilnosuchelementexception-public-class-pric-q44594716?trackid=undefined I have written the updated code (changes highlighted with green color). The idea is to add a new treemap to priceQueue class to be able to satisfy the asked requirements. Now, if we look at the changes we will need to update...
I need help with this assignment, can someone HELP ? This is the assignment: Online shopping cart (continued) (C++) This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program). (1) Extend the ItemToPurchase class per the following specifications: Parameterized constructor to assign item name, item description, item price, and item quantity (default values of 0). (1 pt) Public member functions SetDescription() mutator & GetDescription() accessor (2 pts) PrintItemCost() - Outputs the item name followed by...
I need Help PLZ ( Java Code ).
Today 14.06.2019 I have to hand in my homework.
reachability
Actually, you find flying very good, but you do not trust the
whole new-fangled flying stuff and the infrastructure it has built
up. As a diehard medieval metal fan you prefer to travel from A to
B but rather the good old catapult. Since one can not easily take
the favorite cat on vacation with it (cats do not get drafts, which...
All those points need to be in the code
Project 3 Iterative Linear Search, Recursive Binary Search, and Recursive Selection Sort Class River describes river's name and its length in miles. It provides accessor methods (getters) for both variables, toString() method that returns String representation of the river, and method isLong() that returns true if river is above 30 miles long and returns false otherwise. Class CTRivers describes collection of CT rivers. It has no data, and it provides the...
Hi, can you help me with Part E? Please use Java language. So
for this Part, you will be given 3 files of starter code that is
already done for you. All you have to do is to add on to it in
order to produce the exact output shown in the pictures below.
Please only add on to the code, but not change any of them. Out of
the 3 given files, 1 of them is already completed. The...
C++ Binary Search Tree question. I heed help with the level 2
question please, as level 1 is already completed. I will rate the
answer a 100% thumbs up. I really appreciate the help!. Thank
you!
searching.cpp
#include <getopt.h>
#include <iostream>
#include <sstream>
#include <stdlib.h>
#include <unistd.h>
using namespace std;
// global variable for tree operations
// use to control tree maintenance operations
enum Mode { simple, randomised, avl } mode; // tree type
// returns size of tree
//...
C++ Binary Search Tree question. I heed help with the level 2
question please, as level 1 is already completed. I will rate the
answer a 100% thumbs up. I really appreciate the help!. Thank
you!
searching.cpp
#include <getopt.h>
#include <iostream>
#include <sstream>
#include <stdlib.h>
#include <unistd.h>
using namespace std;
// global variable for tree operations
// use to control tree maintenance operations
enum Mode { simple, randomised, avl } mode; // tree type
// returns size of tree
//...