- 1

need help in improving performance of a method in binomial heap

public void decreaseKey(T key, T value) { if (value.compareTo(key)>=0){ return; } //BinoNode<T> temp= new BinoNode<T>(key); List<BinoNode<T>> zz=this.roots.stream().filter(x->x.toList(Order.PRE).contains(key)).collect(Collectors.toList()); if (zz.size()==0){ return; } if (zz.get(0).toList(Order.PRE).contains(key)) { zz.get(0).decreaseKey(key,value,zz.get(0)); } return; } public void decreaseKey(T key, T value, BinoNode<T> parent) { if (parent.getValue().compareTo(key)==0){ parent.setValue(value); return; } else if (parent.getValue().compareTo(value)>0){ T val= parent.getValue(); parent.setValue(value); value=val; } BinoNode<T> zz = (BinoNode<T>) Arrays.stream(parent.getChildren()).filter(x -> x.toList(Order.PRE).contains(key)).collect(Collectors.toList()).get(0); decreaseKey(key, value, zz); return; } This is my code, in which I have to decrease the value of the given node. my method is taking more time than usual, I need any help or suggestion to improve the performance the method toList(Order.PRE) gives the list of the children including children's children

16th Jan 2022, 10:58 AM
sam
0 Answer