Talk:Stern-Brocot sequence

From Rosetta Code

Finding first occurrences in Python: procedural version

Thanks ‎Ledrug for pointing out a much better way to find first occurrence in the procedural Python example. Once you pointed it out, it became clear why your method worked.

I agree with you keeping it as a comment as well, as it does (at least for me), take another step to see that it works and now we have both methods. (either one of which could be commented). --Paddy3118 (talk) 21:34, 8 December 2014 (UTC)

Algorithm used in the C example is different

The task states a method of calculation that is not used in the current C example. I suggest another example closer to the given algorithm from the task description be used then this C example can be given as an alternative if the algorithm is explained. (I am thinking of starting another task that uses the tree construction and a comparison between the two, but time has not allowed ...). --Paddy3118 (talk) 21:47, 8 December 2014 (UTC)

There's no real difference here: if you look at the n-th element, you obtain the 2n-1 and 2n-th elements, so you can always find each value backwards. The C program doesn't have a problem printing the first members in sequence, so what's wrong with that? --Ledrug (talk) 22:22, 8 December 2014 (UTC)
Hi Ledrug. It was just my perception when doing my background reading - there was the array shuffling of the video, the binary tree, and the function from OEIS... --Paddy3118 (talk) 03:36, 9 December 2014 (UTC)

More functional Python entry

In such entry the "occurs" variable is not defined.

> (its sb variable stores less compared to the procedural version aboveby popping the last element every time around the while loop.

In CPython lists are implemented as arrays dynamic on the right. I don't remember how exactly they (and the append/pop(0) methods) are implemented, but it's not easy to give to such data structure those operations efficient in both space and time. A collections.deque could be better. --bearophile (talk)

Sounds right. I will update it when I truly wake. --Paddy3118 (talk) 03:28, 9 December 2014 (UTC)