Questions tagged [heap-sort]

Heapsort is an efficient comparison-based sorting algorithm that divides an input into a sorted and an unsorted part and iteratively shrinks the unsorted part by extracting the largest element and moving that to the sorted part. Run time is O(n log n).

Filter by
Sorted by
Tagged with
14 votes
4 answers
3k views

Max-heap implementation in C

I have tried to implement my Heap in C. The following are the 13 operations defined: build_maxheap insert exctract_max (delete heap max root) max_delete (delete an element or key) max_heapify clear ...
V_head's user avatar
  • 525
8 votes
2 answers
518 views

Planned Economy Bakery - Trying to scale a nested loop with a heap

Let's say you are living in a controlled economy where there is a baker in town, and every day he bakes a random number of loaves of bread (sometimes the oven breaks, or he has less ingredients). The ...
Tennis Tubbies's user avatar
3 votes
0 answers
130 views

C# code for minimizing the sum of an array by dividing it's elements (repetition allowed) by 2 for k times

The assumption is that k is quite large as compared to no. of elements in the array and division by 2 returns ceiling of the result. Request for your review and suggestions for further improvements ...
Deepak Mishra's user avatar
1 vote
1 answer
48 views

Heap selection sort in Javascript

I have (designed and) implemented this fancy sorting algorithm that combines natural runs in the input array with a heap data structure: ...
coderodde's user avatar
  • 27k
3 votes
2 answers
324 views

Heap Sort in Python

NOTE: I am beginner in Python I learnt the Heap sort today and tried my own implementation using Python. Can i get feedback for my code and areas of improvement. I have tried to add comments inline, ...
prabh's user avatar
  • 141
-2 votes
3 answers
329 views

Heap sort implementation in Python 3

This code relies on Python3.7.4 I'm learning Heapsort in python 3. Please show me the errors in my code. Runs on my computer but tell me if Python rules or not. ...
Brijesh Kalkani's user avatar
6 votes
1 answer
1k views

Python 3 simple external sort with heapq

I've implemented a minimal external sort of text file using heapq python module. On the few tests I did it seems to works well, but I would like to have some advice to have a cleaner and faster code. ...
RomainL.'s user avatar
  • 239
5 votes
1 answer
203 views

Maximum Heap Container

I implemented this max-heap to satisfy the C++ Container requirements. I am fairly confident I implemented bubble_up, bubble_down...
Brady Dean's user avatar
2 votes
2 answers
2k views

Heap Sort Implementation in Python

Objective: Create a heap sort that returns a unsorted list to sorted from greatest to least. Does this implementation look correct? Do you have any tips for optimizing this? ...
Johnathan's user avatar
  • 131
3 votes
2 answers
842 views

Min-Heap in JavaScript

As part of my study on fundamentals, I have implemented the following code in JavaScript for a MinHeap data structure. Please have a look and I look forward to ...
Still Questioning's user avatar
3 votes
2 answers
4k views

Min&Max Heap implementation in .NET

Overview I was doing some performance optimization patterns when I stumbled upon PriorityQueue and I implemented for that reason ...
kuskmen's user avatar
  • 413
1 vote
1 answer
652 views

Implemented heapsort algorithm in Java

I am learning algorithms by using Java. Here is an implementation of heapsort. Let me know if anything is wrong and and suggestion to improve the algorithm. ...
Bahodir  Boydedayev's user avatar
3 votes
1 answer
896 views

Implementation of the Heap Sort algorithm in C++

I'm writing a little collection of sorting algorithms and some benchmarks (using Google benchmark). I wrote the following heap sort but I'm struggling in ...
Davide Spataro's user avatar
5 votes
3 answers
324 views

Local heapsort in C++

Suppose we need to sort a sequence and we know that every sequence component is within \$d\$ steps from its correct position. In such a case we can use a local heapsort: we take \$d\$ as an argument ...
coderodde's user avatar
  • 27k
4 votes
1 answer
716 views

Heap Sort in Scala

Trying to implement Heap Sort in Scala ...
Martin York's user avatar
  • 94.3k
2 votes
2 answers
334 views

C++ Heap Sort In C++14

Realized I have never implemented heap sort. So here is my first attempt: ...
Martin York's user avatar
  • 94.3k
1 vote
1 answer
260 views

Heapsort With Full-Scale Genericity

I've written a heapsort implementation. It's generic: generic comparators and sequences with elements of a generic type. The implementation (follows closely chapter 6 from Introduction to Algorithms ...
cadaniluk's user avatar
  • 187
6 votes
1 answer
3k views

C++ Heap implementation

I'm on my way of understanding basic data structures and sorting algorithms through implementing them in c++. Post is followed of my implementation of Vector. I decided to weld the heap behaviour ...
vatevr's user avatar
  • 81
4 votes
0 answers
250 views

Heap sort in Rust

The tests are taken from this answer on an insertion sort in rust question. The algorithm is taken from Algorithms in a Nutshell (2nd Edition). I'm not looking at crazy performance, the goal being ...
little-dude's user avatar
4 votes
2 answers
939 views

In-place sorting of a binary file using heapsort

I have been working on sorting a file in-place with heapsort. I'm very glad it is working. But the time it takes is just too much. So I was wondering on how I could improve it. Here are my ...
BrainStone's user avatar
1 vote
1 answer
255 views

heapifyDown in heapsort

This is for heapsort and am wondering about the heapifyDown method. Here it is for review. I included relevant helper methods. The heap is stored in array starting ...
redbeans's user avatar
7 votes
1 answer
263 views

Heapsort implementation in C++14

Please review the following implementation of heapsort and pay attention to the following: Have I correctly chosen the names InputIt and ...
alisianoi's user avatar
  • 315
7 votes
2 answers
884 views

C++ Heap Sort Implementation

Just checking if I could still do it: ...
Martin York's user avatar
  • 94.3k