[plt-scheme] simple scheme idiom for generalized maximum?

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Wed Sep 23 14:19:23 EDT 2009

The real objection is complexity: longest-string should be  
O(length(l)) but sort pushes it up to O(n log n) or whatever.

My response is use argmax or define the problem as 'give me the n  
longest strings'.


On Sep 23, 2009, at 2:15 PM, John Clements wrote:

>
> On Sep 23, 2009, at 11:12 AM, Matthias Felleisen wrote:
>
>>
>> (define (longest-string los)
>> (first (sort los > #:key string-length)))
>>
>
> I thought of that, but it seems like the wrong program: I don't want  
> the list sorted, I just want the maximum.
>
> I suppose that from a purely declarative standpoint, you could argue  
> that this doesn't necessarily imply extra computation, but that  
> seems like a stretch.
>
> John
>



Posted on the users mailing list.