Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.programming > #1316

Re: What algorithm is this? (Variant of Selection sort?)

From "R. Rajesh Jeba Anbiah" <ng4rrjanbiah@rediffmail.com>
Newsgroups comp.programming
Subject Re: What algorithm is this? (Variant of Selection sort?)
Date 2012-02-13 02:34 -0800
Organization http://groups.google.com
Message-ID <fa99b06e-bb8d-4335-a3ce-334e59ddb35e@m3g2000pbi.googlegroups.com> (permalink)
References <fac5f87d-b59c-4892-a810-2132e9dd73ba@n8g2000pbc.googlegroups.com> <8inhj7lj5gbgfilndrd4ek5nkhuc5afr8f@4ax.com>

Show all headers | View raw


On Feb 13, 2:59 pm, Robert Wessel <robertwess...@yahoo.com> wrote:
> On Sun, 12 Feb 2012 23:36:26 -0800 (PST), "R. Rajesh Jeba Anbiah"
> <ng4rrjanb...@rediffmail.com> wrote:
> ><?php
> >$arr = array(10,9,8,7,6,5,4,3,2,1);
> >for($i=0, $len=count($arr); $i<$len-1; ++$i){
> >  for($j=$i+1, $len=count($arr); $j<$len; ++$j){
> >     if ($arr[$i] > $arr[$j]) {
> >        $temp = $arr[$i];
> >        $arr[$i] = $arr[$j];
> >        $arr[$j] = $temp;
> >     }
> >  }
> >}
> >?>
>
> >   As I understand, selection sort is about finding index first and
> >doing the swap. What about the above? Is it a variant or sort with
> >some name? TIA
>
> It's a bad variation of a selection sort.  Instead of keeping an index
> at the end, it swaps candidate values to the destination positions. It
> is selecting the next value for each iteration through the outer loop,
> it just does it poorly.

   Yes, thanks for your explanation.

> I don't know if it has a name.

   If anyone knows it, or at least can ascertain that it's official
variant of selection sort, kindly share. Thanks

--
  // PHP Ajax Cookbook -- http://link.packtpub.com/A50biZ //
Email: rrjanbiah-at-Y!com    Blog: http://rajeshanbiah.blogspot.com/

Back to comp.programming | Previous | NextPrevious in thread | Find similar


Thread

What algorithm is this? (Variant of Selection sort?) "R. Rajesh Jeba Anbiah" <ng4rrjanbiah@rediffmail.com> - 2012-02-12 23:36 -0800
  Re: What algorithm is this? (Variant of Selection sort?) Zeljko Vrba <mordor.nospam@fly.srk.fer.hr> - 2012-02-13 07:47 +0000
    Re: What algorithm is this? (Variant of Selection sort?) "R. Rajesh Jeba Anbiah" <ng4rrjanbiah@rediffmail.com> - 2012-02-12 23:55 -0800
      Re: What algorithm is this? (Variant of Selection sort?) pete <pfiland@mindspring.com> - 2012-02-14 10:34 -0500
        Re: What algorithm is this? (Variant of Selection sort?) "R. Rajesh Jeba Anbiah" <ng4rrjanbiah@rediffmail.com> - 2012-02-14 21:04 -0800
          Re: What algorithm is this? (Variant of Selection sort?) pete <pfiland@mindspring.com> - 2012-02-15 01:41 -0500
            Re: What algorithm is this? (Variant of Selection sort?) pete <pfiland@mindspring.com> - 2012-02-22 22:52 -0500
          Re: What algorithm is this? (Variant of Selection sort?) Patricia Shanahan <pats@acm.org> - 2012-02-15 09:45 -0800
  Re: What algorithm is this? (Variant of Selection sort?) Robert Wessel <robertwessel2@yahoo.com> - 2012-02-13 03:59 -0600
    Re: What algorithm is this? (Variant of Selection sort?) "R. Rajesh Jeba Anbiah" <ng4rrjanbiah@rediffmail.com> - 2012-02-13 02:34 -0800

csiph-web