Right, but evaluating tree-size is O(n), even with a binary search tree. Doing 
this on each insertion is slow. 

The following is a possible solution without "do", and it only requires O(log 
n) on a (balanced) search tree:

(define tree5
  (let loop ([tree null] [n 5])
    (define x (random 10))
    (cond
      [(zero? n) tree]
      [(contains? tree x) (loop tree n)]
      [else (loop (insert tree x) (sub1 n))])))

But I thought there must be a more elegant solution using iterations and 
comprehensions. Thank you anyway!

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to