Click here to Skip to main content
15,916,189 members
Home / Discussions / Algorithms
   

Algorithms

 
QuestionTree algo Pin
dfreeser2-Apr-09 5:58
dfreeser2-Apr-09 5:58 
AnswerRe: Tree algo Pin
Alan Balkany3-Apr-09 3:43
Alan Balkany3-Apr-09 3:43 
GeneralRe: Tree algo Pin
dfreeser3-Apr-09 5:15
dfreeser3-Apr-09 5:15 
GeneralRe: Tree algo Pin
Alan Balkany3-Apr-09 5:42
Alan Balkany3-Apr-09 5:42 
GeneralRe: Tree algo Pin
dfreeser3-Apr-09 6:02
dfreeser3-Apr-09 6:02 
GeneralRe: Tree algo Pin
Alan Balkany3-Apr-09 6:16
Alan Balkany3-Apr-09 6:16 
GeneralRe: Tree algo Pin
dfreeser3-Apr-09 6:33
dfreeser3-Apr-09 6:33 
Questioncalculate polygon area and its centre in 3d Pin
beko31-Mar-09 22:57
beko31-Mar-09 22:57 
AnswerRe: calculate polygon area and its centre in 3d Pin
Alan Balkany1-Apr-09 3:46
Alan Balkany1-Apr-09 3:46 
GeneralRe: calculate polygon area and its centre in 3d Pin
beko1-Apr-09 19:26
beko1-Apr-09 19:26 
AnswerRe: calculate polygon area and its centre in 3d Pin
cp98761-Apr-09 20:10
cp98761-Apr-09 20:10 
QuestionStable Quicksort algorithm Pin
Member 419459331-Mar-09 6:04
Member 419459331-Mar-09 6:04 
AnswerRe: Stable Quicksort algorithm Pin
Lutosław31-Mar-09 12:39
Lutosław31-Mar-09 12:39 
GeneralRe: Stable Quicksort algorithm Pin
Member 419459331-Mar-09 16:06
Member 419459331-Mar-09 16:06 
AnswerRe: Stable Quicksort algorithm Pin
Stephen Hewitt31-Mar-09 17:11
Stephen Hewitt31-Mar-09 17:11 
GeneralRe: Stable Quicksort algorithm Pin
Member 41945931-Apr-09 17:16
Member 41945931-Apr-09 17:16 
GeneralRe: Stable Quicksort algorithm Pin
supercat93-Apr-09 6:22
supercat93-Apr-09 6:22 
GeneralRe: Stable Quicksort algorithm Pin
Member 41945934-Apr-09 5:58
Member 41945934-Apr-09 5:58 
AnswerRe: Stable Quicksort algorithm [modified] Pin
bulg3-Apr-09 14:15
bulg3-Apr-09 14:15 
GeneralP.s. Pin
bulg3-Apr-09 14:28
bulg3-Apr-09 14:28 
GeneralRe: Stable Quicksort algorithm Pin
Member 41945934-Apr-09 6:36
Member 41945934-Apr-09 6:36 
GeneralRe: Stable Quicksort algorithm Pin
bulg9-Apr-09 11:42
bulg9-Apr-09 11:42 
Hey Dave,

I'm gonna answer the copyright question first: You are protected & free to write or say anything you want *about* Knuth's books, including the contents, as long as you don't do it for profit. If you use it authoritatively, you should also say, "as Knuth wrote in ...", aka, cite it. Otherwise, a million kids across the country turning in book reports with "at least 4 quotes from the book" would be copyright villains.


Here's my lazy quick sort again, this time with better annotation. Still pseudo-code, though:
struct pivot { 
  int l,r;
}; /* the "pivot" struct represents a range in an array */

function partition( array, left, right ) {
  pivot.l = pivot.r = left  /* pivot starts as a range of 1 variable,
                               array[left] */
  for i = left to right 
  {
    if (array[i] >= pivot.l)
      pivot.r += 1          /* increase the range of the pivot */
    else 
      swap_r(pivot,i)       /* swap the entire range with the 
                               next element, to stay stable */
  }
  return pivot.l            /* return the start of the pivot range */
}

swap_r (range, index) {     
/* swaps an index with a range, by going through 
   the entire range one at a time. Probably naive */

  int t=range.r
  while(range.l<=t)
    swap_i(t--,index)
}

swap_i (index1, index2) { 
  /// straight swap, requires a single 
  /// temporary element (or possibly just a pointer)
}

function quicksort(array) { 
  int p = partition(array,0,length-1)
  quicksort(array,0,p)
  quicksort(array,p+1,length-1)
}


This works on paper. I used the values
0 1 4 4 5 4 2 4 2 3 5 3 7 6 7 4
when I did it by hand.

If you wanted to make it like I envisioned lazy quick sort, then you could employ another range for swapping, instead of swapping at the first index that is < pivot.l. I am not convinced this would be faster... but I don't really have time to try it. If you do, please let me know!!

-Ryan
GeneralRe: Stable Quicksort algorithm Pin
Member 41945939-Apr-09 16:51
Member 41945939-Apr-09 16:51 
QuestionVector orientation Question. Pin
Maximilien31-Mar-09 4:59
Maximilien31-Mar-09 4:59 
AnswerRe: Vector orientation Question. Pin
Luc Pattyn31-Mar-09 5:06
sitebuilderLuc Pattyn31-Mar-09 5:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.