From: Radu Grigore <radugrigore@gmail.com>
To: fa.caml@googlegroups.com
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Priority queues, reloaded
Date: Sat, 2 Jul 2011 15:42:07 -0700 (PDT) [thread overview]
Message-ID: <43c8bcb0-e306-421f-a379-43dd4e7de4a0@glegroupsg2000goo.googlegroups.com> (raw)
In-Reply-To: <30775f1d-9cce-4c46-b7f0-62cdcf9e52cf@glegroupsg2000goo.googlegroups.com>
I asked:
> How is that [a leftist heap implementation] better than using Set?
and Andrew answered:
> Sets are not heaps ; they can't have multiple copies of the same element.
I asked my question in the context of Andrew's original query:
> I'd love to hear about efficient-yet-easy/fast-to-implement options.
I meant to ask why would it be easier/faster to implement a leftist heap. Of course, if leftist heaps can do something that an implementation based on Set can't then that would be a problem. Also, if an implementation based on Set would be much slower or memory hungry, that would also be a problem. But it was already explained by others for Dijsktra at least the lack of Decrease-Key is not a problem, and (asymptotic) performance is not an issue.
You now bring up the question of multiplicity, which may be important if you try to, say, find the top K elements in a stream. Again, a Set based implementation is much simpler than the leftist heaps that were posted already. Here it is.
module S = Set.Make (struct type t = int*int*int let compare = compare end)
let uid = ref 0
let push pq p x = incr uid; S.add (p, x, !uid) pq
let pop pq = let (_,x,_) as k = S.min_elt pq in (x, S.remove k, pq)
With a time limit of three hours this is what I'd do. In a real program, I'd probably go for binomial heaps if imperative is OK, or maxiphobic heaps if persistence is important.
next prev parent reply other threads:[~2011-07-02 22:42 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <fa.V8myB/rA6OKILQg+GW40f8c1BGo@ifi.uio.no>
2011-07-02 12:24 ` Radu Grigore
2011-07-02 19:05 ` Andrew
2011-07-02 22:42 ` Radu Grigore [this message]
2011-07-10 17:55 ` Jon Harrop
2011-07-09 18:45 james woodyatt
[not found] ` <14B0DF03-EF83-4568-AB34-6B51BCE4B574@recoil.org>
2011-07-09 18:56 ` james woodyatt
[not found] <848371343.3424870.1309454037170.JavaMail.root@zmbs3.inria.fr>
2011-06-30 18:03 ` Daniel de Rauglaudre
[not found] <sfid-j-20110630-131704-+2.76-1@multi.osbf.lua>
2011-06-30 17:13 ` Andrew
2011-06-30 17:26 ` Gabriel Scherer
2011-06-30 18:14 ` Jean-Christophe Filliâtre
2011-06-30 18:36 ` Jean-Christophe Filliâtre
2011-07-09 9:02 ` Jon Harrop
2011-07-09 19:22 ` Jean-Christophe Filliâtre
2011-07-10 18:04 ` Jon Harrop
2011-06-30 19:13 ` Andrew
2011-06-30 22:17 ` Wojciech Meyer
2011-07-02 1:49 ` Norman Ramsey
2011-07-09 9:05 ` Jon Harrop
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=43c8bcb0-e306-421f-a379-43dd4e7de4a0@glegroupsg2000goo.googlegroups.com \
--to=radugrigore@gmail.com \
--cc=caml-list@inria.fr \
--cc=fa.caml@googlegroups.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox