heapsort Questions

28

So I was going through different sorting algorithms. But almost all the sorting algorithms require 2 loops to sort the array. The time complexity of Bubble sort & Insertion sort is O(n) for Bes...
Barrett asked 12/8, 2015 at 14:52

13

Solved

Both quicksort and heapsort do in-place sorting. Which is better? What are the applications and cases in which either is preferred?
Slover asked 18/3, 2010 at 5:45

4

Solved

I'm wondering if a max or min heap tree is allowed to have duplicate values? I've been unsuccessful in trying to find information regarding this with online resources alone.
Tradescantia asked 21/3, 2014 at 21:47

3

Solved

I tried watching http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-006-introduction-to-algorithms-fall-2011/lecture-videos/lecture-4-heaps-and-heap-sort/ to understand heaps ...
Cloudless asked 28/1, 2016 at 0:59

6

Solved

Heap Sort has a worst case complexity of O(nlogn) while Quicksort has O(n^2). But emperical evidences say quicksort is superior. Why is that?
Inappreciative asked 5/12, 2009 at 19:38

7

Solved

I'm trying to implement Heap Sort in Python, but I can't seem to get it right. I've tried to implement this pseudo code, but my code does not sort! It just sifts to ridiculous effect. I'm inclined ...
Symbol asked 20/12, 2012 at 20:11

6

Solved

I'm trying to understand why heapsort isn't stable. I've googled this, but haven't found a good, intuitive explanation. I understand the importance of stable sorting - it allows us to sort based ...
Phrenology asked 12/10, 2013 at 17:5

2

Solved

Which algorithm is faster when iterating through a large array: heap sort or merge sort? Why is one of these algorithms faster than the other?
Sid asked 12/11, 2018 at 19:40

1

Solved

I am having trouble understanding why solutions for finding the kth smallest element uses a Max heap approach. And for the kth largest element a min heap approach. Wouldn't it make more sense to us...
Paschall asked 7/11, 2018 at 16:26

2

Solved

A heap can be constructed from a list in O(n logn) time, because inserting an element into a heap takes O(logn) time and there are n elements. Similarly, a binary search tree can be constructed fr...
Dave asked 25/12, 2017 at 20:26

7

Solved

At school we are currently learning sorting algorithms in Java and I got for my homework the Heap Sort. I did my reading, I tried to find out as much as I could, but it seems I just can't grasp the...
Neglectful asked 20/1, 2012 at 8:6

3

Solved

I was wondering if anyone has ever used linked lists to do heap sort and if they have could they provide the code. I have been able to do heapsort using arrays, but trying to do it in linked lists ...
Marijane asked 4/6, 2012 at 17:27

2

I'm attempting to write a heapsort method in java but it's not working exactly as I want it to: public class HeapSort { private static int n; private static void swap(int[] A, int a, int b) {...
Gourde asked 30/10, 2015 at 15:4

1

Solved

I'm working on a program which sorts an array by dividing it into smaller max-heaps and extracting the max-integer out of each one, then deleting it from the heap and running again until every heap...
Humblebee asked 20/5, 2015 at 22:1

3

Solved

When I implement heapsort using a min-heap it sorts the array from largest to smallest. Is this the desired output for a heapsort using min-heap? It seems redundant to sort again to output smallest...
Volkan asked 20/9, 2013 at 17:27

1

I created this program for an assignment in which we were required to create an implementation of Quichesort. This is a hybrid sorting algorithm that uses Quicksort until it reaches a certain recur...
Anthropomorphic asked 21/12, 2014 at 18:34

4

Solved

I have implemented two algorithms for sorting elements from highest to lowest. The first one, takes quadratic time on the real RAM model and the second an O(n log(n)) time. The second one uses p...
Pilfer asked 1/9, 2014 at 22:22

3

Solved

In reading in Chapter 14 of Jon Bentley's "Programming Pearls", 2nd Edition, I understand that heaps use a one-based array and the easiest approach in C is to declare x[n+1] and waste element x[0] ...
Halda asked 22/10, 2012 at 13:15

2

Solved

How many number of elements can be sorted in Θ(log n) time using heap sort? When we do a heapsort, to build the heap we need Θ(n) complexity and then to do the heapsort O(nlog n). I understa...
Copyright asked 16/1, 2014 at 7:43

9

Solved

As an exercise in Haskell, I'm trying to implement heapsort. The heap is usually implemented as an array in imperative languages, but this would be hugely inefficient in purely functional languages...

1

Functions called: (regardless of class) def partition( pivot, lst ): less, same, more = list(), list(), list() for val in lst: if val < pivot: less.append(val) elif val > pivot: more.a...
Prohibitionist asked 29/11, 2013 at 21:15

2

Solved

From the Soft Heap wikipedia page, it seems that the min extraction only takes constant time, thus using a soft heap to perform heapsort should lead to an amortized O(n). Even if the constant is la...
Hydrometeor asked 10/6, 2013 at 5:4

1

Solved

Quicksort outperforms Heapsort in practice. Mergesort is the only stable one of the 3 (in plain vanilla implementations). So it's either quicksort or mergesort that'd get used depending on th...
Macedo asked 30/12, 2012 at 1:12

4

Solved

In a max heap (assuming it's represented by an array), the top of the heap (ie. the largest value in the heap) swaps with the last element in the array (ie. one of the smallest values in the heap),...
Stefa asked 14/7, 2012 at 23:38

2

Solved

In heapsort, the data is stored in something called a "heap". Almost all the implementations I've seen use a flat list for the data structure. Can someone explain to me why this is? Why not use ...
Warden asked 30/3, 2012 at 6:58

© 2022 - 2024 — McMap. All rights reserved.