Post Reply 
Little problem(s) July 2022
07-07-2022, 11:42 AM
Post: #21
RE: Little problem(s) July 2022
(07-06-2022 01:29 PM)John Keith Wrote:  This is a very good solution, especially for languages that have sets or binary trees as data types.
On the HP48, unfortunately, a UserRPL implementation would be slower than one using POS.

Solution only need O(1) array lookup, not "weird" data types.

With numbers sorted, if two ends add up to required sum, we find the pair.
If more than required sum, throw away the big one.
If less, throw away the small one.

Rinse and repeat, we can find a pair (or, all of them!), with required sum, in O(n)

Of course, depending on list size, worse algorithm may be faster.
Hybrid sorting algorithms switch over algorithms, depending on data, to gain efficiency.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Little problem(s) July 2022 - pier4r - 07-04-2022, 06:04 PM
RE: Little problem(s) July 2022 - pauln - 07-05-2022, 01:01 AM
RE: Little problem(s) July 2022 - pier4r - 07-05-2022, 10:00 AM
RE: Little problem(s) July 2022 - pier4r - 07-05-2022, 01:56 PM
RE: Little problem(s) July 2022 - Albert Chan - 07-07-2022 11:42 AM
RE: Little problem(s) July 2022 - pier4r - 07-07-2022, 10:51 AM
RE: Little problem(s) July 2022 - DavidM - 07-07-2022, 12:02 PM
RE: Little problem(s) July 2022 - DavidM - 07-07-2022, 03:09 PM
RE: Little problem(s) July 2022 - pier4r - 07-07-2022, 05:19 PM
RE: Little problem(s) July 2022 - Werner - 07-06-2022, 07:48 AM
RE: Little problem(s) July 2022 - DavidM - 07-07-2022, 05:27 PM
RE: Little problem(s) July 2022 - pier4r - 07-07-2022, 05:37 PM
RE: Little problem(s) July 2022 - pauln - 07-11-2022, 05:34 AM
RE: Little problem(s) July 2022 - pauln - 07-11-2022, 10:32 PM



User(s) browsing this thread: 7 Guest(s)