Q:

Data structure methods on clojure

How can I transform this list:
'((A B) (A C) (C D) (B D) (D E) (D F))

Into something like 
'(A (B (nil)) (C (D ((F (nil)) (E (nil))))))

Or whatever list best represent the tree:
          A
         / \       
        B   C
            |
            D
           / \
          E   F

Note that as C was the first to claim D as its child, the (B D) didn't add the D as the child of B.

A:

first of all i would clean up the data, removing all the unnecessary pairs (in your case '(B D)), and build the adjacency map:
user> (def data '((A B) (A C) (C D) (B D) (D E) (D F)))
#'user/data

user> (def nodes-map (group-by first
                               (apply sorted-set-by 
                                      #(compare (second %1) (second %2))
                                      data)))
#'user/nodes-map

user> nodes-map
{A [(A B) (A C)], C [(C D)], D [(D E) (D F)]}

i removed the garbage using sorted-set, using the fact that it treats items to be equal using comparator, and keep only the first of them (in this case it considers (C D) and(B D) to be equal)
then i would construct the tree, using recursive function:
user> (defn to-tree [start nodes]
        (list start
              (if-let [connections (seq (nodes start))]
                (map #(to-tree (second %) nodes) connections)
                '(nil))))
#'user/to-tree

user> (to-tree 'A nodes-map)
(A ((B (nil)) (C ((D ((E (nil)) (F (nil))))))))

