Re: Efficient binary search tree stored in a flat array?

2009-07-15 Thread Piet van Oostrum
he array. But then you need >>> > array elements to contain the indices for the children explicitely. >>> And why is this a problem? >DA> Oh, I'm sorry -- I see what you are saying now. You're saying you can >DA> just implement a normal binary search tree

Re: Efficient binary search tree stored in a flat array?

2009-07-14 Thread Paul Rubin
Douglas Alan writes: > I can't see that a binary search tree would typically have > particularly good cache-friendliness, so I can't see why a flat-array > representation, such as is done for a binary heap, would have > particularly worse cache-reference. That is a good p

Re: Efficient binary search tree stored in a flat array?

2009-07-14 Thread Douglas Alan
licitely. > And why is this a problem? Oh, I'm sorry -- I see what you are saying now. You're saying you can just implement a normal binary search tree, but store the tree nodes in an array, as if it were a chunk of memory, and use array indices as pointers, rather than using memor

Re: Efficient binary search tree stored in a flat array?

2009-07-14 Thread Douglas Alan
flat array efficiently (n log n time overall), but it never even seems to bring up the subject as to whether a binary search tree or a treap can also be efficiently maintained in a flat array. Though it may be the case that these questions are left as exercises for the student, and therefore bu

Re: Efficient binary search tree stored in a flat array?

2009-07-14 Thread Douglas Alan
On Jul 14, 8:10 am, Piet van Oostrum wrote: > Of course you can take any BST algorithm and replace pointers by indices > in the array and allocate new elements in the array. But then you need > array elements to contain the indices for the children explicitely. And why is this a problem? This is

Re: Efficient binary search tree stored in a flat array?

2009-07-14 Thread Douglas Alan
On Jul 14, 7:38 am, Florian Brucker wrote: > Douglas Alan wrote: > > Thank you. My question wasn't intended to be Python specific, though. > > I am just curious for purely academic reasons about whether there is > > such an algorithm. All the sources I've skimmed only seem to the > > answer the

Re: Efficient binary search tree stored in a flat array?

2009-07-14 Thread Scott David Daniels
Piet van Oostrum wrote: Douglas Alan (DA) wrote: DA> On Jul 13, 3:57 pm, a...@pythoncraft.com (Aahz) wrote: Still, unless your list is large (more than thousands of elements), that's the way you should go. See the bisect module. Thing is, the speed difference between C and Python means the

Re: Efficient binary search tree stored in a flat array?

2009-07-14 Thread Piet van Oostrum
> Douglas Alan (DA) wrote: >DA> On Jul 13, 3:57 pm, a...@pythoncraft.com (Aahz) wrote: >>> Still, unless your list is large (more than thousands of elements), >>> that's the way you should go.  See the bisect module.  Thing is, the >>> speed difference between C and Python means the constant

Re: Efficient binary search tree stored in a flat array?

2009-07-14 Thread Florian Brucker
Douglas Alan wrote: > Thank you. My question wasn't intended to be Python specific, though. > I am just curious for purely academic reasons about whether there is > such an algorithm. All the sources I've skimmed only seem to the > answer the question via omission. Which is kind of strange, since i

Re: Efficient binary search tree stored in a flat array?

2009-07-13 Thread Douglas Alan
On Jul 13, 3:57 pm, a...@pythoncraft.com (Aahz) wrote: > Still, unless your list is large (more than thousands of elements), > that's the way you should go.  See the bisect module.  Thing is, the > speed difference between C and Python means the constant for insertion > and deletion is very very s

Re: Efficient binary search tree stored in a flat array?

2009-07-13 Thread Aahz
In article , Douglas Alan wrote: > >I couldn't find a good algorithms forum on the Internet, so I guess >I'll ask this question here instead: Is it possible to efficiently >maintain a binary search tree in a flat array (i.e., without using >pointers), as is typical

Re: Efficient binary search tree stored in a flat array?

2009-07-13 Thread Paul Rubin
Douglas Alan writes: > It would also clearly be > possible to store a balanced binary tree in a flat array, storing the > children of the node at index i at indices 2*i and 2*i + 1, just as > one does for a binary heap. But if you do that, I don't know if you > could then do insertions and deletio

Efficient binary search tree stored in a flat array?

2009-07-13 Thread Douglas Alan
I couldn't find a good algorithms forum on the Internet, so I guess I'll ask this question here instead: Is it possible to efficiently maintain a binary search tree in a flat array (i.e., without using pointers), as is typically done for a binary heap? It *is* possible, of course,

Re: String Concatenation O(n^2) (was: Re: Explaining Implementing a Binary Search Tree.)

2008-06-21 Thread Bart Kastermans
On Jun 17, 1:01 am, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Mon, 16 Jun 2008 07:34:06 -0300, Bart Kastermans <[EMAIL PROTECTED]> > escribió: > > > Summary: can't verify big O claim, how to properly time this? > > > This is interesting.  I had never attempted to verify a big O > > state

Re: String Concatenation O(n^2) (was: Re: Explaining Implementing a Binary Search Tree.)

2008-06-16 Thread Gabriel Genellina
En Mon, 16 Jun 2008 07:34:06 -0300, Bart Kastermans <[EMAIL PROTECTED]> escribió: > Summary: can't verify big O claim, how to properly time this? > > This is interesting. I had never attempted to verify a big O > statement > before, and decided that it would be worth trying. So I wrote some > c

Re: String Concatenation O(n^2) (was: Re: Explaining Implementing a Binary Search Tree.)

2008-06-16 Thread Ian Kelly
On Mon, Jun 16, 2008 at 12:07 PM, Alex Elder <[EMAIL PROTECTED]> wrote: > I found this article useful when dealing with strings in Python: > >http://www.skymind.com/~ocrow/python_string/ > > It may help squeeze some more time out of your code. 8-) Things seem to have changed since then. I

Re: String Concatenation O(n^2) (was: Re: Explaining Implementing a Binary Search Tree.)

2008-06-16 Thread Jean-Paul Calderone
On Mon, 16 Jun 2008 11:30:19 -0600, Ian Kelly <[EMAIL PROTECTED]> wrote: On Mon, Jun 16, 2008 at 11:09 AM, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote: It will depend what version of Python you're using and the *exact* details of the code in question. An optimization was introduced where, if

Re: String Concatenation O(n^2) (was: Re: Explaining Implementing a Binary Search Tree.)

2008-06-16 Thread Alex Elder
I found this article useful when dealing with strings in Python: http://www.skymind.com/~ocrow/python_string/ It may help squeeze some more time out of your code. 8-) Alex. -- http://mail.python.org/mailman/listinfo/python-list

Re: String Concatenation O(n^2) (was: Re: Explaining Implementing a Binary Search Tree.)

2008-06-16 Thread Ian Kelly
On Mon, Jun 16, 2008 at 11:09 AM, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote: > It will depend what version of Python you're using and the *exact* details > of the code in question. An optimization was introduced where, if the > string being concatenated to is not referred to anywhere else, it

Re: String Concatenation O(n^2) (was: Re: Explaining Implementing a Binary Search Tree.)

2008-06-16 Thread Jean-Paul Calderone
On Mon, 16 Jun 2008 10:41:05 -0600, Ian Kelly <[EMAIL PROTECTED]> wrote: On Mon, Jun 16, 2008 at 4:34 AM, Bart Kastermans <[EMAIL PROTECTED]> wrote: This is interesting. I had never attempted to verify a big O statement before, and decided that it would be worth trying. So I wrote some code to

Re: String Concatenation O(n^2) (was: Re: Explaining Implementing a Binary Search Tree.)

2008-06-16 Thread Ian Kelly
On Mon, Jun 16, 2008 at 4:34 AM, Bart Kastermans <[EMAIL PROTECTED]> wrote: > This is interesting. I had never attempted to verify a big O > statement > before, and decided that it would be worth trying. So I wrote some > code to > collect data, and I can't find that it goes quadratic. I have th

String Concatenation O(n^2) (was: Re: Explaining Implementing a Binary Search Tree.)

2008-06-16 Thread Bart Kastermans
Summary: can't verify big O claim, how to properly time this? On Jun 15, 2:34 pm, "Terry Reedy" <[EMAIL PROTECTED]> wrote: > "Bart Kastermans" <[EMAIL PROTECTED]> wrote in message > > news:[EMAIL PROTECTED] > |I wrote a binary search tree in pytho

Re: Explaining Implementing a Binary Search Tree.

2008-06-15 Thread Terry Reedy
"Bart Kastermans" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] |I wrote a binary search tree in python, explaining as I was doing it | how and why I did it. I am very interested in receiving comments on | the code, process, and anything else that will impr

Explaining Implementing a Binary Search Tree.

2008-06-15 Thread Bart Kastermans
I wrote a binary search tree in python, explaining as I was doing it how and why I did it. I am very interested in receiving comments on the code, process, and anything else that will improve my coding or writing. I wrote this all up in my blog at: http://kasterma.wordpress.com/2008/06/15

Re: Binary search tree

2007-11-13 Thread Scott Sandeman-Allen
On 11/13/07, Terry Reedy ([EMAIL PROTECTED]) wrote: >"Scott SA" <[EMAIL PROTECTED]> wrote in message >news:[EMAIL PROTECTED] >| On 11/12/07, Scott SA ([EMAIL PROTECTED]) wrote: >| I decided to test the speeds of the four methods: >| >|set_example >|s = set() >|for url in urls

Re: Binary search tree

2007-11-13 Thread Gabriel Genellina
En Mon, 12 Nov 2007 16:21:36 -0300, Scott SA <[EMAIL PROTECTED]> escribió: > I decided to test the speeds of the four methods: (but one should always check for correctness before checking speed) > def dict_example(urls): > d = {} > for url in urls: > if url in d: > d[

Re: Binary search tree

2007-11-12 Thread Terry Reedy
"Scott SA" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | On 11/12/07, Scott SA ([EMAIL PROTECTED]) wrote: | I decided to test the speeds of the four methods: | |set_example |s = set() |for url in urls: |if not url in s: |s.add(url)

Re: Binary search tree

2007-11-12 Thread Scott SA
On 11/12/07, Scott SA ([EMAIL PROTECTED]) wrote: Uhm sorry, there is a slightly cleaner way of running the second option I presented (sorry for the second post). >If you would find an index and count useful, you could do something like this: > >for idx in range(len(urls)): >uniqu

Re: Binary search tree

2007-11-12 Thread Scott SA
>> > more than one time(can't be more than twice). >> >> > I thought to put them into binary search tree, this way they'll be >> > sorted and I'll be able to check if the URL already exist. >> >> What about a set ? >> >> s = set() &

Re: Binary search tree

2007-11-12 Thread Martin v. Löwis
> Now, I can see that this method has some superfluous data (the `1` > that is assigned to the dict). So I suppose this is less memory > efficient. But is this slower then? As both implementations use hashes > of the URL to access the data. Just asking out of curiosity ;) Performance-wise, there i

Re: Binary search tree

2007-11-12 Thread Michel Albert
On Nov 9, 11:45 pm, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] a écrit : > > > Hi, > > > I have to get list of URLs one by one and to find the URLs that I have > > more than one time(can't be more than twice). > > > I though

Re: Binary search tree

2007-11-09 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : > Hi, > > I have to get list of URLs one by one and to find the URLs that I have > more than one time(can't be more than twice). > > I thought to put them into binary search tree, this way they'll be > sorted and I'll be able to c

Re: Binary search tree

2007-11-09 Thread D.Hering
On Nov 9, 4:06 pm, [EMAIL PROTECTED] wrote: > Hi, > > I have to get list of URLs one by one and to find the URLs that I have > more than one time(can't be more than twice). > > I thought to put them into binary search tree, this way they'll be > sorted and I'll

Re: Binary search tree

2007-11-09 Thread Jake McKnight
> [EMAIL PROTECTED] wrote: > > Hi, > > > > I have to get list of URLs one by one and to find the URLs that I have > > more than one time(can't be more than twice). > > > > I thought to put them into binary search tree, this way they'll be > > s

Re: Binary search tree

2007-11-09 Thread Neil Cerutti
On 2007-11-09, Larry Bates <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: >> I have to get list of URLs one by one and to find the URLs >> that I have more than one time(can't be more than twice). >> >> I thought to put them into binary search tree,

Re: Binary search tree

2007-11-09 Thread Larry Bates
[EMAIL PROTECTED] wrote: > Hi, > > I have to get list of URLs one by one and to find the URLs that I have > more than one time(can't be more than twice). > > I thought to put them into binary search tree, this way they'll be > sorted and I'll be ab

Binary search tree

2007-11-09 Thread maxim . novak
Hi, I have to get list of URLs one by one and to find the URLs that I have more than one time(can't be more than twice). I thought to put them into binary search tree, this way they'll be sorted and I'll be able to check if the URL already exist. Couldn't find any python lib