I am in a course where I have to use beginning student with list
abbreviation in Racket to do assignments.
Below is my code for unique-right, which is supposed to return a list which
has only the right most occurrences of the elements of list.
The restriction in doing the asisngment is that I c
In Beginning Student with List Abbreviations
I am struggling to come up with functions to remove duplicates from a list
while maintaining the order of the list.
one function to remove duplicates from the left,
i.e. 1 2 1 3 2 4 5 -> 1 2 3 4 5
and one from the right.
i.e. 1 2 1 3 2 4 5 -> 1 3
In Beginning Student with List Abbreviations
I am struggling to come up with functions to remove duplicates from a list
while maintaining the order of the list.
one function to remove duplicates from the left,
i.e. 1 2 1 3 2 4 5 -> 1 2 3 4 5
and one from the right.
i.e. 1 2 1 3 2 4 5 -> 1 3
> it only requires O(log n) on a (balanced) search tree:
sorry, O(log n) for conttains?
and O(n log n) in total
--
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
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))
I try to fill a binary tree with 5 random numbers, avoiding duplicates. Is
there a more elegant way than this (using "Iterations and Comprehensions")?
(define tree4
(do ([x (random 10) (random 10)]
[c #f (contains? tree x)]
[tree null (if c tree (insert tree x))]
[i 0 (if c
6 matches
Mail list logo