ϵ">]>
Module |
Remark
11. CVIČENIE Z PREDMETU ÚVOD DO DEKLARATÍVNEHO PROGRAMOVANIA http://ii.fmph.uniba.sk/cl/courses/1-AIN-505-udp/0506ls/ex/ex11.cl |
Remark
Dátum: streda 2. 5. 2006 Odporúčaná verzia CL: 5.81.16 WWW stránka predmetu: http://ii.fmph.uniba.sk/cl/courses/1-AIN-505-udp/0506ls?lang=sk Kontakt na cvičiaceho: mailto:kluka@fmph.uniba.sk |
Remark
The predicate holds if is a code of a binary tree encoded via constructors and (see above). The predicate is a format. You can use it to display values as binary trees in queries, e.g.: Nd(0,Nd(1,Nd(3,E,E),Nd(4,E,E)),Nd(2,E,Nd(6,E,E))) = x & x = t:Bt |
Remark
Assignment 1. Define a predicate (displayed as ) holding if is in the tree as a label (value) of some node. |
Remark
Assignment 2. Define a function (displayed as ) that counts the number of nodes ( ) in the tree . |
Remark
Assignment 3. Define the following functions: (a) yielding the number of empty subtrees ( ) in the tree ; (b) yielding the number of inner nodes in the tree , i.e., nodes ( ) having at least one non-empty subtree; (c) yielding the number of leaves in the tree , i.e., nodes ( ) having both left and right subtrees empty. |
Remark
Assignment 5. (a) Define a function listing values of nodes in the tree in in-order. The function is specified by the following properties: |
Remark
(b) Define a function possessing the property and consequently Do not use concatenation ( ) or any auxiliary function in the definition. |
Remark
Assignment 6. (a) Define a function listing values of nodes in the tree in pre-order, i.e., satisfying: |
Remark
(b) Define a function having the property Do not use concatenation ( ) or any auxiliary function in the definition. |
Remark
Assignment 7. (a) Define a function listing values of nodes in the tree in post-order, i.e., satisfying: |
Query: |
|
Results: |
|