Questions tagged [heap]

A heap (data structure) is a tree that is ordered with respect to depth. When the question concerns process memory set aside for dynamic allocation, tag with heap-memory instead.

In computer science, a heap is a specialized tree-based data structure that satisfies the heap property: If A is a parent node of B then key(A) is ordered with respect to key(B) with the same ordering applying across the heap. Either the keys of parent nodes are always greater than or equal to those of the children and the highest key is in the root node (this kind of heap is called max heap) or the keys of parent nodes are less than or equal to those of the children (min heap).

There are several variants of this data structure, and when this is relevant for the question, add the more specific tag as well: , , , , , ,

For questions on the heap-sort algorithm, add the tag.

Don't use this tag for the following:

1845 questions
0
votes
0 answers

NPE in array with generics

I create a Heap class which uses E general type generics extends from Comparable class. In the isEmpty method it checks whether the first element is empty or not. But when I implement it, a NullPointerException occurs at isEmpty and add methods.…
0
votes
1 answer

Can Fibonacci Heap have more than one nodes with equal rank(or value, or key)?

I am studying Fibonacci heap alone, and I came across a question. I know any nodes can be inserted into Fibonacci heap, but what if the rank(or value, or key) of that new node is equal to the sibling node? 1) For example, (1) <-minimum root / …
Joon. P
  • 2,238
  • 7
  • 26
  • 53
0
votes
1 answer

Path in a Heap takes too long time

This is a question from oj PAT Insert a sequence of given numbers into an initially empty min-heap H. Then for any given index i, you are supposed to print the path from H[i] to the root. However, my code always time out, i.e, it takes too long…
TIMFUNNY
  • 363
  • 4
  • 9
  • 26
0
votes
0 answers

Node Not Being Added Into Heap in Chronological Order

The function of my program is to allow a user to manage a list of Tasks using a Heap. The Current Task is based on the soonest due date. The task object contains 2 Strings a Name and a Due Date. I have no problem adding the Task Node to the Heap. My…
JCCS
  • 591
  • 8
  • 22
0
votes
1 answer

Using a Min-Heap to Sort Words

I am learning to use heaps and as an exercise I am trying to write a program using a heap class I have created to sort words. I have read in words from a file and added them to the heap successfully. I am having some trouble figuring out how I can…
JCCS
  • 591
  • 8
  • 22
0
votes
2 answers

Testing My Heap

1.) I'm having difficulty testing me heap class. When I try to print my heap, it's giving me code instead of the array. I tried using toString() and DeeptoString() and neither worked. 2.) In my updateValue method. I realize that it doesn't know what…
0
votes
1 answer

Priority Queue using a Max-Heap Data Structure

I am implementing a priority queue using a max-heap data structure in Python. I'm using several names that have numbers associated with them as their priority (9 being the highest and 1 being the lowest). The issue I am facing is that when I dequeue…
coleworld
  • 35
  • 1
  • 7
0
votes
1 answer

Making a priority queue using a Heap. Without using "queue" or "heapq"

I have made a heap class and I am trying to make a PriorityQueue class as well so both of them can work together. However, I need help on the Priority Queue part of my code. I have already made a working Heap. I tried looking up help on the internet…
Cooper
  • 123
  • 3
  • 17
0
votes
2 answers

Passing a function_pointer as a comparator in a stl make_heap c++

I'm developing this program to run Dijkstra's Algorithm with an heap implementation and I want it to be as versatile as it can be so I'm using function pointer in order to avoid code repetition. This is the error that it pops. I'm using the stl…
0
votes
3 answers

Get top-6 elements, subject to the condition that element >= 3

I'm trying to make a list of 11 elements I want to pop out the maximum element only from l[0] to l[5]. under one of the two conditions: l[5] >= 3 or l[5] is no longer exist or None. l = [2,8,6,2,8,7,9,8,6,7,4] max = 0 maxIndex = 0 while (l[5] >= 3…
Xi N
  • 1
  • 2
0
votes
1 answer

Heaps and Binary Search Trees

What is the run-time associated with (Max-heapify) that is implemented using k-ary heap. Is a k-ary heap more efficient than a binary heap asymptotically speaking? Is a k-ary heap more efficient than a binary heap in practice? can a search tree be…
Omar Kayali
  • 113
  • 1
  • 2
  • 7
0
votes
0 answers

Priority queue using heap (Whats wrong with my code?)

I am doing an assignment priority queue using heap these are instructions for every commands Add element create an element with the id an priority given add the element to the queue produce no output for this command Delete element deleted the…
0
votes
2 answers

NullPointerException when inserting into binary heap?

I'm trying to insert values into an initially empty binary heap. This is the relevant code: public class minHeap { int[] array; int n; public void minHeap() { array = new int [16]; n = 0; } public void…
itsmetheperson
  • 77
  • 1
  • 12
0
votes
1 answer

Merging two heaps: O(n*log(n)) vs. O(n + m)

I want to merge a binary heap implemented as an array with size m into another heap (of the same kind) with n elements. Using repeated inserts, this takes O(m * log(n)). It seems to be commonly agreed that the alternative method of concatenating the…
Oberon
  • 3,219
  • 15
  • 30
0
votes
1 answer

Amortized Analysis and Contest Questiosn, there is any problems?

I ran into a local contest question as follows. If on empty MIN-Heap we do n arbitrary insert and delete operations, (with given location of delete in min-heap). what is the amortized analysis for insert and delete? I) insert O(log n), delete…
user4737480
1 2 3
99
100