MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: Re: Another question on lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg80720] Re: [mg80711] Re: [mg80641] Re: [mg80618] Another question on lists
  • From: DrMajorBob <drmajorbob at bigfoot.com>
  • Date: Thu, 30 Aug 2007 02:30:49 -0400 (EDT)
  • References: <27088617.1188205442155.JavaMail.root@m35> <200708280603.CAA14009@smc.vnet.net> <11155728.1188404471045.JavaMail.root@m35> <op.txt02ysvqu6oor@monster.gateway.2wire.net> <26602305.1188412032980.JavaMail.root@m35>
  • Reply-to: drmajorbob at bigfoot.com

I tried to verify that, but didn't get very far... since getting a list 
of lists takes SEVERAL orders of magnitude more time than finding its longest  
sublist. That's probably true no matter how the lists are found,  
generated, read from a file, etc.

Bobby

On Wed, 29 Aug 2007 12:51:58 -0500, Carl Woll <carlw at wolfram.com> wrote:

> DrMajorBob wrote:
>
>> So the simplest method is
>>
>> Last@Sort@sample
>
> Except that Sort[sample] is an O(n log n) operation, and  
> Ordering[sample, -1] is an O(n) operation.
>
> Carl
>
>>
>> Bobby
>>
>> On Wed, 29 Aug 2007 03:24:08 -0500, Carl Woll <carlw at wolfram.com> wrote:
>>
>>> DrMajorBob wrote:
>>>
>>>> Here's an example:
>>>>
>>>> sample = Array[
>>>>   RandomInteger[{1, 10}, {RandomInteger[{3, 10}]}] &, {15}]
>>>> Length /@ %
>>>>
>>>> {{5, 7, 7, 1, 2, 5, 2, 7, 3}, {3, 4, 3, 8, 8}, {1, 4, 6, 6, 1, 6,
>>>>   3}, {4, 6, 1, 9, 9, 7, 3, 5, 10}, {9, 1, 4, 2, 7, 1, 5}, {2, 8, 2 ,
>>>>   4, 7, 3, 8}, {2, 10, 4, 7, 2, 10, 3}, {10, 5, 10, 6, 5, 10, 4, 3,
>>>>   4}, {5, 2, 3, 10, 8}, {5, 1, 7}, {1, 5, 8, 4, 8, 5, 8, 2}, {3, 3, 8,
>>>>    5, 1, 7}, {6, 10, 1, 6, 3, 5, 7, 6, 1, 7}, {3, 5, 1, 6, 6}, {10,
>>>>   10, 9, 3, 9}}
>>>>
>>>> {9, 5, 7, 9, 7, 7, 7, 9, 5, 3, 8, 6, 10, 5, 5}
>>>>
>>>> Last@SortBy[sample, Length]
>>>>
>>>> {6, 10, 1, 6, 3, 5, 7, 6, 1, 7}
>>>>
>>>> or
>>>>
>>>> sample[[Ordering[sample, -1, Length[#1] < Length[#2] &]]]
>>>>
>>>> {{6, 10, 1, 6, 3, 5, 7, 6, 1, 7}}
>>>>
>>>>
>>> Just a minor comment that the third argument of Ordering is not needed
>>> in this case, since the default order used sorts by length of list
>>> first. Try:
>>>
>>> sample[[Ordering[sample,-1]]]
>>>
>>> instead.
>>>
>>> Carl Woll
>>> Wolfram Research
>>>
>>>> Bobby
>>>>
>>>> On Sun, 26 Aug 2007 22:20:22 -0500, Mauricio Esteban Cuak
>>>> <cuak2000 at gmail.com> wrote:
>>>>
>>>>
>>>>
>>>>> Hello again.Thank you very much for your previous help. However, I
>>>>> seem to stumble on another rock:
>>>>>
>>>>> I  have a list of n sub-lists with different number of elements. I
>>>>> want to select the list with the highest number of elements.
>>>>> I tried to combine the Select function with Lenght but couldn't do 
>>>>> it:
>>>>>
>>>>> Select[list, Length /@ list >= Max[Length /@ list] &]
>>>>>
>>>>> Thanks for reading.
>>>>>
>>>>> Regards,
>>>>>
>>>>> cd
>>>>>
>>>>> P.D.: Any tips,websites, books, on how to learn some basic  
>>>>> programming
>>>>> on Mathematica?
>>>>> I'm slowly beginning to read "The Mathematica Book"...should I just
>>>>> concentrate on that?
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>
>>
>>
>
>



-- 

DrMajorBob at bigfoot.com


  • Prev by Date: Re: Problems minimizing an overconstrained system
  • Next by Date: Input cell Word Wrapping
  • Previous by thread: Re: Re: Re: Another question on lists
  • Next by thread: Re: Another question on lists