Questions tagged [binary-heap]

225 questions
0
votes
1 answer

Adding an element to the first non-occupied leaf in a binary tree

Right now I'm trying to write a binary heap in Java implemented over a binary tree structure, and while I do have a very good grasp on how to "heapify" the tree after adding an element, the logic for finding the first unoccupied leaf at the bottom…
user2309750
  • 1,403
  • 4
  • 14
  • 11
0
votes
1 answer

Complexity of binary heaps using linked lists

I am trying to compare the implementing a binary heap using an array and linked lists. I think arrays are better in every way because all operations can be done faster than or equal to the operations using a linked list. It also needs less memory.…
omega
  • 40,311
  • 81
  • 251
  • 474
0
votes
1 answer

unresolved external symbol PriorityQueue

can anyone help me with this please. I am trying to build a priority queue but keep getting a unresolved external symbol error. Any help would be well appreciated. Error 2 error LNK2019: unresolved external symbol "public: __thiscall…
JonDog
  • 517
  • 7
  • 23
-1
votes
1 answer

Binary Heap get_parent() function in Python not working as expected

I am to define a function called get_parent(a_list, index) which takes a binary min-heap represented by a Python list and an integer as parameters. The function should return the value of the parent of the element specified by the parameter index.…
-1
votes
1 answer

Trying to print out the elements in the last level of a min heap

I'm trying to print the last level in a min heap. I thought I had code that works, but one of the test cases fail. In terms of the test cases, I only have access to how the output does not match. Here is my code: #include "MinHeap.h" #include…
HughJass24
  • 39
  • 1
  • 4
-1
votes
1 answer

Java's PriorityQueue showing unexpected behavior for duplicate keys added with higher priority

I was trying to implement a slightly modified version of the Djikstra's algorithm using the PriorityQueue class for the priority queue. I came across a weird behavior which I couldn't find an explanation for anywhere. I have my suspicions for this…
8u88y
  • 33
  • 1
  • 6
-1
votes
1 answer

find median of a unsorted array using heap

Is there a way to find median of a unsorted array using heap ? If it is possible, is it more efficient than using sorting and then finding median ?
Dinithi
  • 518
  • 5
  • 17
-1
votes
1 answer

C++ - Popping the first element of a vector

I apologize if this is a duplicate. I promise I tried to find an answer first. I want to make a binary heap using a vector. To do so, I have to implement a pop function, that removes the "top." In this case, it simply removed the first element. I…
user11344930
  • 49
  • 2
  • 6
-1
votes
1 answer

Having problems inserting "double" variables inside of a binary heap

Here's how I created my binary heap: int *heapArray; // pointer to array of elements in heap int capacity = 0; // maximum possible size of min heap int heap_size; // Current number of elements in min heap int d = 2; int parent(int i) { return…
Bob K
  • 69
  • 1
  • 9
-1
votes
1 answer

Implementing Dijkstra's algorithm using Binary Heaps

How would you go about implementing Dijkstra's algorithm using binary heaps? My goal is to have a runtime of O(M log N). Say there are N cities in a kingdom, M train routes in this kingdom, and S is the capital city. Th input is N M S followed by a…
-1
votes
1 answer

Ternary Heap Null Pointer Exception

package queue; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; public class TernaryHeap > extends AbstractPriorityQueue { private List keys; private int…
J. Choi
  • 45
  • 7
-1
votes
2 answers

Java Heap Vs Balanced Tree

Which data structure can be used for storing a set of integers such that each of the following operations can be done in O(log N) time, where N is the number of elements? deletion of the smallest element insertion of a element if it is not already…
-1
votes
1 answer

binary heap/Give the class a max value

Below is what I have done but it Does not handle the max requirement on insert. how do I Give the class a max value and check it in the insert and then remove the least significant element. Then figure out what is the least significant element in…
mike 4332
  • 9
  • 3
-1
votes
1 answer

Python: Using my heap in a priority queue implementation

I am having real trouble using my custom-made heap class functions to be used in my Priority Queue class. I am having trouble on what functions from my heap class to use for my "enqueue", "dequeue", "front" and "size" functions for my PriorityQueue.…
Cooper
  • 123
  • 3
  • 17
-1
votes
3 answers

Binary Heap: Height of subtree rooted at position i

Given n values I created a Binary Max-Heap. I want to know the formula to calculate height of subtree rooted at any position i.
Ashish Paliwal
  • 76
  • 1
  • 1
  • 9
1 2 3
14
15