comp.lang.ada
 help / color / mirror / Atom feed
From: Austin Obyrne <austin.obyrne@hotmail.com>
Subject: Re: My Invention of "Bug Sort".
Date: Wed, 20 Jun 2012 01:32:44 -0700 (PDT)
Date: 2012-06-20T01:32:44-07:00	[thread overview]
Message-ID: <5c5aa9d4-fcfe-46fb-9b85-762518651455@googlegroups.com> (raw)
In-Reply-To: <698085ff-6ca3-4a0e-b963-11bdcf11e6b5@googlegroups.com>

On Tuesday, June 19, 2012 11:39:07 PM UTC+1, (unknown) wrote:
> On Tuesday, June 19, 2012 12:13:28 AM UTC-7, Austin Obyrne wrote:
> > 
> > Each change in ‘NextNum’ is trapped as it is computed by a ‘bug’ strategically placed in the lines of source code. 
> 
> "Bug" in engineering is a euphemism for "error"; this usage goes back at least to the 19th century. You might want to choose another name.
> 
> > Q := NextNum(I);
> > I_NUM(Q):= I_NUM(Q)+1;
> 
> This is straightforward, and probably very good for your specific needs. Specialized sorting algorithms like this can do much better than general ones. Like all specialized algorithms, this one has a number of shortcomings as a general sorting algorithm, not least of which is its restriction to sorting values of discrete types only.
> 
> It is hardly instantaneous. A complexity analysis is interesting:
> 
> Most sorting algorithms' complexity analyses are based only on N, the number of values (the number of times Q gets a value in the example). This algorithm must also take into account the number of possible values Q may have. If Q is of type T, this is T'Pos (T'Last) - T'Pos (T'First) + 1. I'll call this value M. M may be less than, equal to, or greater than N. For convenience, I'll define
> 
> B = Max (M, N)
> 
> First, time complexity: The algorithm must initialize the array I_Num to all zeros; this is O(M). It then increments the corresponding value of I_Num for each value of Q encountered; this is O(N). Finally, it must traverse I_Num to do something with the resulting values; this is O(M). So the overall time complexity is O(B). Linear time complexity, which is very good. No general sorting algorithm is linear.
> 
> Now space complexity: The algorithm needs the space for I_Num, which is O(M). Depending on what you do with the results, you may need to transform I_Num into the corresponding sorted sequence. For example, if you're sorting the values (3, 7, 1), you often want to end up with an array (1 => 1, 2 => 3, 3 => 7). Such a sequence is O(N). So the space complexity is at least O(M), and may be O(N) (if that's larger). To be safe for all cases we must call it O(B). Several sorting algorithms have O(N) space requirements, so that's not necessarily a problem.
> 
> For the following discussions, I'll presume the following declarations:
> 
> Q     : TQ;
> I_Num : array (TQ) of TI;
> 
> An implementation of this must take into account a number of factors specific to the problem being solved. TI must be large enough to hold the maximum number of times a given value of Q may occur, but small enough that I_Num can be declared. If a component of I_Num overflows, you'll either get incorrect results (TI is a modular integer type) or and exception (TI is a signed integer type).
> 
> I_Num'Size will be 2 ** (TQ'Size + TI'Size); that must fit in memory. If parts of I_Num have to be swapped to disk, this could result in absolute times slower than a general, in-place algorithm.
> 
> This could also be slower if M >> N.
> 
> This is a form of insertion sort, in which values are sorted as they are encountered. In this it is similar to an ordered-tree insertion sort, in which values are inserted into an ordered, balanced, binary tree (or equivalent structure) as they are encountered. This is another general sorting algorithm that is O(N log N).
> 
> An interesting approach, and probably well suited to your specific problem area, but I doubt it will replace general sort algorithms.



<< This is straightforward, and probably very good for your specific needs.

I think this sums it up completely. I realise now that this is a can of worms when taken as general sort program and probably no better than any other.

I think the fact that it works concurrently with the main program amd requires no extra handling of data after it has been computed is a plus?.

Question: In a real world situation could this sort mechanism be done by a 'tasking' package in Ada. 

Many thanks for your excellent and informed analysis.

Austin O'Byrne

Many thanks for your excellent analysis



  reply	other threads:[~2012-06-20  8:32 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-19  7:13 My Invention of "Bug Sort" Austin Obyrne
2012-06-19 11:55 ` Peter C. Chapin
2012-06-19 13:01   ` Austin Obyrne
2012-06-19 22:39 ` ggsub
2012-06-20  8:32   ` Austin Obyrne [this message]
2012-06-20 19:45     ` ggsub
2012-06-20 10:57   ` Austin Obyrne
2012-06-20 12:47     ` Manuel Collado
2012-06-20 12:51       ` Manuel Collado
2012-06-20 13:13         ` Manuel Collado
2012-06-20 15:17         ` Austin Obyrne
2012-06-22 20:31           ` Randy Brukardt
2012-06-20 19:38     ` ggsub
2012-06-20 23:59   ` Austin Obyrne
2012-06-21  1:17     ` Jeffrey R. Carter
2012-06-21  5:13       ` Simon Wright
2012-06-21  7:23         ` Manuel Collado
2012-06-21 11:50           ` Austin Obyrne
2012-06-21 12:09             ` Dmitry A. Kazakov
2012-06-22 20:37               ` Randy Brukardt
2012-06-22 21:16                 ` Simon Wright
2012-06-26 22:29                   ` Randy Brukardt
2012-06-28 19:05                     ` Niklas Holsti
2012-07-03  2:05                       ` Randy Brukardt
2012-06-28 20:59                     ` Simon Wright
2012-07-03  2:11                       ` Randy Brukardt
2012-07-03  9:47                         ` Simon Wright
2012-06-21 18:45             ` Jeffrey Carter
2012-06-22  6:52               ` Austin Obyrne
2012-06-21 15:10         ` Adam Beneschan
2012-06-21 18:24         ` Jeffrey Carter
2012-06-21  7:24       ` Austin Obyrne
2012-06-19 22:56 ` Martin Trenkmann
2012-06-20  0:11 ` robin.vowels
2012-06-20  8:51   ` Austin Obyrne
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox