CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2001
    Posts
    6

    In-place Sorting

    Hi,

    I am not sure what exactly "sorting in-place" means, although I am aware of the definition that an in-place algorithm uses constant amount of space for variables while doing the sorting... or could it be O(n)???
    If we use recursive algorithms to sort (like mergesort/quicksort), the number of activation records placed on the stack depends on n, the number of elements being sorted. Would this make such an algorithm classify as non-in-place? Some resources classify quicksort as an in-pace algorithm and mergesort as non-in-place. I do not understand this.

    It would be great if someone could please make the basis of calling an algo. "in-place" clear, by providing an example of an algorithm that sorts in-place, and one that does not.

    Are the following in-place sorting algorithms?

    -Bubblesort - I think yes (at least if implemented in imperative languages)

    -Heapsort - I think yes

    -Quicksort - I don't know

    -Mergesort -I don't know

    -Selection sort - I think yes

    -Insertion sort - I think yes

    Your responses will be highly appreciated!

    Thanks very much!

    Sincerely,
    Sumithra

  2. #2
    Join Date
    Feb 2001
    Location
    teh INTARWEB
    Posts
    542
    in-place sorting == a constant number of elements (may be 0 even) are ever stored outside the original array.

    All those sorting algorithms can be implemented to work in-place, but that would raise the expected order O() of many; due to extra computations to manipulate available space.

    This url, comparing various in-place algorithms, may help: http://www.cs.ubc.ca/spider/harrison...ting-demo.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured