ϵ">]>
Literature.
[1] J. Komara. Specification and Verification of Programs. Online.
[2] Ján Kľuka. Úvod do deklaratívneho programovania. Online.
[CL] Discrimination on the constructors of binary trees. Example(s):
[CL] Formatting the output. Use the format to display numbers as binary trees. Try out the following simple queries
171386336145149 = t:Bt
1,10,(1,11,(0,0),0,0),(1,12,(0,0),0,0) = t:Bt
Size and depth of binary trees. Define the functions and computing respectively the size and the depth of the binary tree . Note that we have
Reflection function. Define the function which yields the mirror's image of the binary tree .
Isomorphic binary trees. Given binary trees and , the predicate holds if the trees and are isomorphic (of the same shape).
Fast programs for tree traversals. Save the concatenation in the definition of each tree traversal function.
Exercise. (1 bonus point) Define the function which creates perfect binary tree of depth with values stored in in breadth-first order. We have
Hint. Define first an auxiliary function such that
Here the is dyadic concatenation.
Problem. Given a tree, create a new tree of the same shape, but with the values at the nodes replaced by the numbers 0,1,2... in a fixed order.
Exercise. Define the function such that
Remark. Implement the function with the help of the size function .
Hint. Define first an auxiliary function such that
Exercise. Define the function such that
Remark. Implement the function with the help of the size function .