A heap is a tree-based data structure that satisfies the heap property. For questions about memory allocated from the system heap, use the [memory-management] tag.
1
vote
2answers
36 views
1
vote
0answers
41 views
Generic implementation of mutable binary heap
std::priority_queue does not support dynamically updating element priorities. This class template extends it by allowing updating priorities of elements in the ...
1
vote
1answer
43 views
Generic implementation of SiftUp/Down operations on binary heap
Binary heap construction and maintenance boil down to the two basic operations: sift up and sift down. Following are generic template implementations of the two operations. Any comments are welcome. ...
1
vote
2answers
88 views
Fibonacci heap in C - follow-up
(See the previous iteration.)
I have incorporated some points made by ChrisWue and refactored my Fibonacci heap implementation:
fibonacci_heap.h
...
5
votes
3answers
133 views
3
votes
1answer
90 views
Minimalist Tree
While working on a small project, I tried to implement a super simple tree class in C++. It supports an arbitrary number of branches from each node.
In addition to general comments, my main concerns ...
4
votes
0answers
36 views
Heap update generic algorithms
In the standard library, there are no algorithms for element updates. This makes it unsuitable as a queue for a Dijkstra's algorithm, for example. Thus I implemented generic heap update functions with ...
10
votes
1answer
147 views
Binary heap performance optimization
I have implemented a binary heap as a exercise in data structures. I realize that I'm missing some useful functions (increase/decrease key for example) but I don't consider them interesting for the ...
3
votes
0answers
24 views
Min-Heap based priority queue class written in ES6
I would appreciate any feedback on syntax, naming convention, possible shortcuts, clarity of code and any other constructive feedback. This code was based off of the Priority Queue chapter in The ...
1
vote
2answers
60 views
Read characters from stdin into an resizeable array
As first steps in C, I'm trying to write a program that reads from stdin into an array allocated on the free store, until an exclamation mark ! is entered. The ...
1
vote
0answers
51 views
Min Heap Sort using Generics
Here is my working code for a min-heap sort using an Array-List. I would like any input as to areas that need additional refining and any areas that are against proper formatting/usage. Although not ...
14
votes
1answer
220 views
C# Treap implementation
I recently developed a simple treap data structure in C#. In the future, I may have the class extend IDictionary. For now, I only expose a public accessor and a ...
3
votes
1answer
116 views
N-ary heap implementation
NaryHeap as a generalization of binary heap. Each node has up to N children. A template specialization for N = 2 (BinaryHeap) ...
3
votes
1answer
51 views
d-ary heap in C
Now I have this d-ary heap data structure. Note that for d = 2 this is a binary heap. The client programmer specifies the value ...
5
votes
2answers
427 views
Merge k Sorted Arrays
Please review my answer for this interview question:
Merge k sorted arrays, using min heap.
...
2
votes
2answers
69 views
Heapsort for arbitrary ranges in Java
I plan to work on Introsort, which requires a working implementation of heap sort. Also, the heap sort implementation must be able to sort arbitrary ranges within an array, which, in turn, requires ...
1
vote
1answer
59 views
Heap selection sort - follow-up
See the previous and initial iteration.
I got rid of Run objects and just maintain two integer arrays in the RunHeap: one for ...
4
votes
1answer
116 views
Heap selection sort in Java
See the next iteration.
I designed and implemented this adaptive heap sort in Java. It works as follows:
Copy the range to be sorted into auxiliary array \$A\$
Create an empty run heap \$H\$
Scan ...
6
votes
1answer
129 views
D-ary max heap implementation
I implemented a D-ary max heap backed by a vector for resizing. I would like to know any possible improvements in performance, design, and in the code in general.
...
2
votes
1answer
220 views
Sorting an integer array using heap sort
I have written this program to sort an array using heap sort. Please review it for further improvements.
...
-2
votes
1answer
231 views
kth smallest element in min heap [closed]
I am working on to find the kth smallest element in min heap. I have code for this whose complexity is \$O(k \log k)\$. I tried to improve it to \$O(k)\$.
...
8
votes
3answers
217 views
Dijkstra's algorithm without relaxation
I'm trying to implement Dijkstra's algorithm in Python, but the issue is that Python doesn't have support for key-based heaps out of the box, so applying relaxation step of the classical algorithm ...
4
votes
2answers
316 views
Heap implementation of the “median maintenance” algorithm
I have implemented a heap data structure for Coursera's algorithms course. The problem I have to solve is:
The goal of this problem is to implement the "Median Maintenance"
algorithm. The text ...
4
votes
4answers
351 views
Find Kth largest element in an array
I am preparing for interviews where my code would be judged based on optimizations, OOP concepts, code readability as well as my knowledge of JAVA and design patterns.
What comments will you give in ...
1
vote
0answers
27 views
Building a correct d-max heap bottom up
I want to implement a d-max heap using a bottom-up approach. This way I will start from the last parent in the tree and build myself up to the root of the heap. We will compare children and parents in ...
1
vote
1answer
148 views
Max-heap implementation with List
I am trying to create max-heap for practice.
Are there any bugs?
Are there ways that I can improve the code quality?
...
6
votes
2answers
947 views
Simple binary heap in C#
I've written a simple binary heap in C# and I want to know if it has any problems or if I can make it better.
...
7
votes
2answers
253 views
Implementation of a binary heap
I've read a little about binary heaps/priority queues and decided to try my hand at making my own implementation of one. I'm not the most experienced programmer and I would be really grateful if you ...
6
votes
2answers
386 views
Function to get top k words in a given String
This is a two-part job:
to identify a word
to find the top k words
I've tried to use regex to split but it's taking 10x more time when string is really long. ...
2
votes
1answer
2k views
Max heap implementation
I have implemented a max-Heap data structure backed by an array. I wanted to know whether this is an acceptable implementation or not.
Any improvements or suggestions are welcome.
...
1
vote
0answers
244 views
Binary heap implementation in Golang
I have implemented a binary heap in Go to get familiar with the language.
GitHub
...
4
votes
2answers
557 views
Inefficient hash map operation provokes OutOfMemory: Java heap space error
I know I can increase the size of the heap but that seems like a poor solution.
This program runs correctly on small files but when run on large data sets it crashes with the OutOfMemory: Java heap ...
2
votes
1answer
709 views
Binomial heap in Java
I have this implementation of a binomial heap providing insert, decrease-key and extract in logarithmic time.
MinPriorityQueue.java:
...
4
votes
1answer
232 views
Binary heap with O(1) lookup and O(log n) change key
I needed a priority queue that allowed efficient searching and changing of keys. I tried std::priority_queue, but the interface was extremely limiting. Not being ...
2
votes
1answer
121 views
A different implementation of Heap Sort
The following implementation is a bit different form the standard implementations I have read. Is it correct?
...
3
votes
4answers
3k views
MinHeap implementation in Java
I have made my own MinHeap in Java. I would like to get review comments on the same.
...
14
votes
2answers
993 views
TopCoder problem “Lottery” - SRM 144 (Division I Level Two)
The problem statement
Summary:
The rules of a lottery are defined by two integers (choices and blanks) and two boolean variables (sorted and unique). choices represents the highest valid number ...
5
votes
2answers
3k views
0
votes
2answers
4k views
Optimizing Dijkstra implementation using PriorityQueue in Java
I am trying to make Dijkstra implementation more efficient. Below is the code for class Node which implements Comparable so it ...
2
votes
1answer
597 views
Binary HeapSort and Ternary HeapSort implementation
This is my take on binary and ternary heapsort implementation for a university assignment. The code works but I wonder if there are any mistakes or things to improve.
...
1
vote
1answer
76 views
HeapSort Efficiency
For heap (array based) sort, we need to start at index 1, ignoring the 0th index. If I want to make a static function like
...
3
votes
0answers
180 views
Binomial Heap in Haskell
Here's a partial binomial heap implementation in Haskell (just merge and insert):
...
12
votes
3answers
2k views
Implementation of binary min-heap data structure
What do you think is wrong with this code, and how can it be improved? What corner case have I overlooked, if any?
Note: I do not want to use any STL features here, but I'm okay with anything else ...
2
votes
2answers
1k views
Merge N sorted list
Given n sorted lists, merge them.
This is a fairly common question, attributed to plenty of interview question websites.
I'm looking for code-review, optimizations and best practices. I'm also ...
4
votes
1answer
206 views
A functional binary heap implementation
I've implemented a binary heap in F#. It's pure and uses zippers for tree modification.
To test it out I have implemented heap sort using it but it takes 10 seconds to sort a list of 100 000. Regular ...
6
votes
1answer
539 views
Scala heap implementation
I'm a Scala beginner, so it'd be great if anyone would be so kind to give some feedback.
...
5
votes
2answers
2k views
Constraint Programming: Map color problem
I've written some python code to solve the map coloring problem. In my code, I represent the problem using Territory and ...
12
votes
2answers
12k views
Implementation of binary heap in C++
Things I can think of include integer overflow, if the input type is int, etc. But other than that, what do you think is wrong with this code, design-wise, style-wise, and also in terms of other ...
4
votes
3answers
143 views
Time limit exceeded in Heap
I wrote a Heap, but the judge system reports "time limit exceeded" in some tests. I use a sift_down to build, so I don't know why.
Maybe I can improve the build? ...
4
votes
2answers
2k views
Heap implementation using pointer
I know heaps are commonly implemented by an array. But, I wanted to share my pointer implementation and have your feedback(s) :)
General idea:
I convert the index to its binary value and then trace ...