Talk:Stern-Brocot sequence: Difference between revisions

+ two notes on Python code
(+ two notes on Python code)
Line 8:
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 ...). --[[User:Paddy3118|Paddy3118]] ([[User talk: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? --[[User:Ledrug|Ledrug]] ([[User talk:Ledrug|talk]]) 22:22, 8 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. --[[User:Bearophile|bearophile]] ([[User talk:Bearophile|talk]])