[Show all top banners]

computerScience
Replies to this thread:

More by computerScience
What people are reading
Subscribers
:: Subscribe
Back to: Kurakani General Refresh page to view new replies
 Any Math CompScience guru ?? Need help..
[VIEWED 5945 TIMES]
SAVE! for ease of future access.
Posted on 09-19-10 12:25 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Malai kasari insertion or heap sort lai stable banaune kehe idea chahiyo. Algorithm bhanam. Koi chan hola yeha math computer guru haru...
 
Posted on 09-19-10 2:27 PM     [Snapshot: 44]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Insertion sort
http://www.roseindia.net/java/beginners/arrayexamples/InsertionSort.shtml

Heap sort
http://www.java-tips.org/java-se-tips/java.lang/heap-sort-implementation-in-java.html

 
Posted on 09-19-10 6:48 PM     [Snapshot: 111]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

I am actually looking for how to change hear sort into a stable algorithm. Not its implementation and hint would be great.
 
Posted on 09-19-10 11:30 PM     [Snapshot: 189]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

did you get a chance to look here?


http://en.wikipedia.org/wiki/Sorting_algorithm#Stability


Prolly this is helpful


Stability


Stable sorting algorithms maintain the relative order of records with equal keys. If all keys are different then this distinction is not necessary. But if there are equal keys, then a sorting algorithm is stable if whenever there are two records (let's say R and S) with the same key, and R appears before S in the original list, then R will always appear before S in the sorted list. When equal elements are indistinguishable, such as with integers, or more generally, any data where the entire element is the key, stability is not an issue. However, assume that the following pairs of numbers are to be sorted by their first component:

(4, 2) (3, 7) (3, 1) (5, 6)

In this case, two different results are possible, one which maintains the relative order of records with equal keys, and one which does not:

(3, 7) (3, 1) (4, 2) (5, 6) (order maintained)
(3, 1) (3, 7) (4, 2) (5, 6) (order changed)

Unstable sorting algorithms may change the relative order of records with equal keys, but stable sorting algorithms never do so. Unstable sorting algorithms can be specially implemented to be stable. One way of doing this is to artificially extend the key comparison, so that comparisons between two objects with otherwise equal keys are decided using the order of the entries in the original data order as a tie-breaker. Remembering this order, however, often involves an additional computational cost.


Sorting based on a primary, secondary, tertiary, etc. sort key can be done by any sorting method, taking all sort keys into account in comparisons (in other words, using a single composite sort key). If a sorting method is stable, it is also possible to sort multiple times, each time with one sort key. In that case the keys need to be applied in order of increasing priority.


Example: sorting pairs of numbers as above by first, then second component:

(4, 2) (3, 7) (3, 1) (5, 6) (original)
(3, 1) (4, 2) (5, 6) (3, 7) (after sorting by second component)
(3, 1) (3, 7) (4, 2) (5, 6) (after sorting by first component)

On the other hand:

(3, 7) (3, 1) (4, 2) (5, 6) (after sorting by first component)
(3, 1) (4, 2) (5, 6) (3, 7) (after sorting by second component,
order by first component is disrupted).


 
Posted on 09-20-10 4:02 PM     [Snapshot: 262]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

 SAS guru, what is the best book for the SAS beginner. I want to learn it as self-study.

 
Posted on 09-20-10 4:02 PM     [Snapshot: 262]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

 SAS guru, what is the best book for the SAS beginner. I want to learn it as self-study.

 
Posted on 09-20-10 5:50 PM     [Snapshot: 291]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Insertion Sort is stable.

Heap Sort is unstable. You cannot maintain the order of keys once sorted. If you really want to "pretend" you made heap sort stable, do one thing BUT strongly not recommended unless you want to be a smart-ass.

- Heap sort is a special case of selection sort, with building Heap every time it does the basic selection sorting. Now - skip building Heap :)
- So you are left with selection sort Only, which is not stable either. But there is a way you can make selection sort stable.

Follow this link to the way you could make a selection sort stable by "wildfrog"
http://www.codeguru.com/forum/showthread.php?t=362340





 


Please Log in! to be able to reply! If you don't have a login, please register here.

YOU CAN ALSO



IN ORDER TO POST!




Within last 90 days
Recommended Popular Threads Controvertial Threads
शीर्षक जे पनि हुन सक्छ।
NRN card pros and cons?
What are your first memories of when Nepal Television Began?
TPS Re-registration case still pending ..
Basnet or Basnyat ??
nrn citizenship
Sajha has turned into MAGATs nest
Nas and The Bokas: Coming to a Night Club near you
डीभी परेन भने खुसि हुनु होस् ! अमेरिकामाधेरै का श्रीमती अर्कैसँग पोइला गएका छन् !
3 most corrupt politicians in the world
अमेरिकामा बस्ने प्राय जस्तो नेपालीहरु सबै मध्यम बर्गीय अथवा माथि (higher than middle class)
if you are in USA illegally and ask for asylum it is legal
Travelling to Nepal - TPS AP- PASSPORT
emergency donation needed
Top 10 Anti-vaxxers Who Got Owned by COVID
निगुरो थाहा छ ??
ढ्याउ गर्दा दसैँको खसी गनाउच
Poonam pandey - death or suicide?
Doctors dying suddenly or unexpectedly since the rollout of COVID-19 vaccines
काेराेना सङ्क्रमणबाट बच्न Immunity बढाउन के के खाने ?How to increase immunity against COVID - 19?
Nas and The Bokas: Coming to a Night Club near you
NOTE: The opinions here represent the opinions of the individual posters, and not of Sajha.com. It is not possible for sajha.com to monitor all the postings, since sajha.com merely seeks to provide a cyber location for discussing ideas and concerns related to Nepal and the Nepalis. Please send an email to admin@sajha.com using a valid email address if you want any posting to be considered for deletion. Your request will be handled on a one to one basis. Sajha.com is a service please don't abuse it. - Thanks.

Sajha.com Privacy Policy

Like us in Facebook!

↑ Back to Top
free counters