Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Tue, 14 Feb 2012 09:34:40 -0600 Message-ID: <4F3A7F10.6F65@mindspring.com> Date: Tue, 14 Feb 2012 10:34:40 -0500 From: pete Reply-To: pfiland@mindspring.com Organization: PF X-Mailer: Mozilla 3.04Gold (WinNT; I) MIME-Version: 1.0 Newsgroups: comp.programming Subject: Re: What algorithm is this? (Variant of Selection sort?) References: <1bbf76cc-241c-4936-bf52-3d48e1180c41@kn4g2000pbc.googlegroups.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 49 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 4.154.223.189 X-Trace: sv3-Z918QqTVOuOv1oLjWpzuFBOPh6i39p57DNONbDhKwfdIZ8Y2IVu+qkdn7C6D3pZ897TS6wFylQ8EI/3!reE0HhL2PMTBIvCTFnjUbEvEPia4TsBKoYuoakuay1dKhO5MihQxII5Fsus2IIOXv6ccw7WyNeqj!ROglP2187Vc= X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2714 Xref: x330-a1.tempe.blueboxinc.net comp.programming:1319 R. Rajesh Jeba Anbiah wrote: > > On Feb 13, 12:47 pm, Zeljko Vrba wrote: > > On 2012-02-13, R. Rajesh Jeba Anbiah wrote: > > > > > $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 > > > > Looks like textbook implementation of Bubble sort. > > Yes, found in textbook only. But, it's not a Bubble sort. Right? > http://en.wikipedia.org/wiki/Bubble_sort It looks a lot like bubble sort, but it is not bubble sort. Bubble sort works by swapping adjacent elements. The algorithm which you have shown, swaps elements which are not adjacent. I would just call your algorithm "simple selection sort", while realizing that there are variations on the way that it can be implemented. Selection sorts, sort from one end to the other. Knuth classifies heapsort as belonging to the selection sort family of algorithms. As heapsort is typically implementd for sorting arrays: the last element is sorted first, and then the next to last, and so on. -- pete