Questions tagged [binary-heap]

225 questions
0
votes
0 answers

Implementation of Dijkstra's algorithm [I'm confused by a questions formatting]

I am currently working on a homework assignment that requires me to: Implement DIJKSTRA's algorithm for Single Source Shortest Path Problem with BINARY Heaps. The running time should be O(ElogV). Simple enough! However, the problem must be…
Ryan Tibbetts
  • 412
  • 1
  • 8
  • 22
0
votes
1 answer

Reducing Complexity of Agent-Based Models

I am developing an agent based model simulating the growth in-vitro of a cell culture. I am using the MASON library (Java), but I guess by question could be applicable to different implementations. Essentially, my agents are programmed to divide…
MrD
  • 4,986
  • 11
  • 48
  • 90
0
votes
0 answers

Complexity characteristics of a simple heap-based array function

I have a simple algorithm task for which I'd like to practice my complexity analysis, and I was hoping to get some confirmation that I'm correct. The task is; implement a function that takes an array of numbers of size n, and returns the k highest…
0
votes
2 answers

Binary heap insertion, don't understand for loop

In Weiss 'Data Structures and Algorithms In Java", he explains the insert algorithm for binary heaps thusly public void insert( AnyType x ) { if( currentSize == array.length -1) enlargeArray( array.length * 2 + 1); // Percolate…
Benjamin Lindqvist
  • 4,300
  • 3
  • 18
  • 19
0
votes
1 answer

insert same values into binomial heap

I have to insert some values into binomial heap. For example 25, 26, 24, 60, 65, 62. It will look like follows: But then I have to insert 25, 68, 65 to the same heap. Should I insert 25 again or just skip it as it is already present in the heap?
Bob
  • 10,427
  • 24
  • 63
  • 71
0
votes
1 answer

Construct a binary heap of size 2N from two binary heaps each of size N in linear time?

Constructing a binary heap of size N from scratch takes NlogN compares on an average and thus linearithmic time. Given that two binary heaps of size N are already in place, how to construct a single binary heap containing all 2N keys, in linear…
Novneet Nov
  • 592
  • 1
  • 7
  • 22
0
votes
1 answer

In-place "pop" operation for array-based binary heap?

I have an array-based binary heap used for graph searching (though the purpose is irrelevant). (The item at index 0 is the top of the heap.) Every once in a while, the item at the top of the heap satisfies the criterion that I'm seeking, and thus I…
user541686
  • 205,094
  • 128
  • 528
  • 886
0
votes
1 answer

get TreeNode by number

I am creating a heap from a binary tree in java. My implementation looks like this: public class Heap

,D> { // ATTRIBUTES private TreeNode root; private int size; // CONSTRUCTOR PriorityQueue() { …

MrLoh
  • 456
  • 1
  • 5
  • 12
0
votes
1 answer

How to store any type of comparable object in a Binary Heap

Java: I have implemented my own version of a Binary Heap. It should be able to store any type of Comparable object. The objects that are inserted into the heap come from input data, and all the input data will be of the same type. Is there a way to…
0
votes
1 answer

increaseKey() method for Binary Heap ADT

I have to implement increaseKey() method in a Binary Heap priority queue ADT, but I just can't see how to do it. The BinaryHeap just accept objects that extends Comparable which allows me to use a.compareTo(b), but there is no obvious way to…
0
votes
2 answers

Merging heap arrays with linear complexity

how can I merge two heap arrays into one balanced heap array and still maintain linear complexity? Much of the material I read about merging heaps takes O(nlogn).
0
votes
1 answer

Java implement priority queue using binary heap errors

I have a homework problem as follows: Created HeapPriorityQueue that will implement Priority queue import java.util.Arrays; public class HeapPriorityQueue> implements PriorityQueue { private static final int…
Krizia Simon
  • 13
  • 1
  • 2
  • 6
0
votes
1 answer

Java creating a HeapPriorityQueue using binary heap to implement PriorityQueue

I am trying to create a HeapPriorityQueue class that implements the PriorityQueue interface using binary heap. Without using the Java Collections' PriorityQueue. The HeapPriorityQueue class will be ran by this driver class: public class…
Krizia Simon
  • 13
  • 1
  • 2
  • 6
0
votes
2 answers

Should I use a Binary Heap?

Follow up Question from: https://codereview.stackexchange.com/questions/30243/how-can-i-improve-upon-my-a-pathfinding-code/ Summary: I asked for help improving my pathfinding code (A*). A user quickly spotted that I was sorting a particular list of…
Shivam Malhotra
  • 309
  • 1
  • 3
  • 10
0
votes
0 answers

Find the first null value in a breadth-wide search of a binary tree

I'm trying to write a binary heap implemented over a binary tree, but I'm having trouble finding a way to add a new node to the "bottom" of the heap, i.e. the first null space on the tree in a breadth-first traversal. I've already got a working…
user2309750
  • 1,403
  • 4
  • 14
  • 11