{"id":4685,"date":"2019-02-06T06:00:35","date_gmt":"2019-02-06T04:00:35","guid":{"rendered":"http:\/\/www.glc.us.es\/~jalonso\/exercitium\/?p=4685"},"modified":"2019-03-06T08:49:37","modified_gmt":"2019-03-06T06:49:37","slug":"exterior-de-arboles","status":"publish","type":"post","link":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/exterior-de-arboles\/","title":{"rendered":"Exterior de \u00e1rboles"},"content":{"rendered":"<p>Los \u00e1rboles binarios con datos en las hojas y los nodos se definen por<\/p>\n<pre lang=\"text\"> \n   data Arbol = H Int\n              | N Int Arbol Arbol \n     deriving Show\n<\/pre>\n<p>Por ejemplo, los \u00e1rboles<\/p>\n<pre lang=\"text\"> \n          3               3               3     \n         \/ \\             \/ \\             \/ \\    \n        \/   \\           \/   \\           \/   \\   \n       2     8         2     8         2     8  \n      \/ \\   \/ \\       \/ \\   \/ \\       \/ \\   \/ \\ \n     5   7 6   9     5   7 6   9     5   7 6   9\n    \/ \\                   \/ \\                 \/ \\   \n   1   4                 1   4               1   4  \n<\/pre>\n<p>se representan por<\/p>\n<pre lang=\"text\"> \n   ejArbol1, ejArbol2, ejArbol3 :: Arbol \n   ejArbol1 = N 3\n                (N 2 \n                   (N 5 (H 1) (H 4))\n                   (H 7))\n                (N 8 (H 6) (H 9))\n   ejArbol2 = N 3\n                (N 2 (H 5) (H 7))\n                (N 8 (N 6 (H 1) (H 4))\n                     (H 9))\n   ejArbol3 = N 3\n                (N 2 (H 5) (H 7))\n                (N 8 (H 6)\n                     (N 9 (H 1) (H 4)))\n<\/pre>\n<p>Definir la funci\u00f3n<\/p>\n<pre lang=\"text\"> \n   exterior :: Arbol -> [Int]\n<\/pre>\n<p>tal que (exterior a) es la lista de los elementos exteriores del \u00e1rbol a. Por ejemplo,<\/p>\n<pre lang=\"text\"> \n   exterior ejArbol1  ==  [3,2,5,1,4,7,6,9,8]\n   exterior ejArbol2  ==  [3,2,5,7,1,4,9,8]\n   exterior ejArbol3  ==  [3,2,5,7,6,1,4,9,8]\n<\/pre>\n<p>El orden de los elementos es desde la ra\u00edz hasta el extremo inferior izquierdo desde \u00e9l hasta el inferior derecho y desde \u00e9l hasta la ra\u00edz.<\/p>\n<h4>Soluciones<\/h4>\n<pre lang=\"haskell\">\ndata Arbol = H Int\n           | N Int Arbol Arbol \n  deriving Show\n\nejArbol1, ejArbol2, ejArbol3 :: Arbol \nejArbol1 = N 3\n             (N 2 \n                (N 5 (H 1) (H 4))\n                (H 7))\n             (N 8 (H 6) (H 9))\nejArbol2 = N 3\n             (N 2 (H 5) (H 7))\n             (N 8 (N 6 (H 1) (H 4))\n                  (H 9))\nejArbol3 = N 3\n             (N 2 (H 5) (H 7))\n             (N 8 (H 6)\n                  (N 9 (H 1) (H 4)))\n\nexterior :: Arbol -> [Int]\nexterior a =\n  ramaIzquierda a ++ hojas a ++ reverse (tail (ramaDerecha a))\n\n-- (ramaIzquierda a) es la rama izquierda del \u00e1rbol a. Por ejemplo,\n--    ramaIzquierda ejArbol1  ==  [3,2,5]\n--    ramaIzquierda ejArbol3  ==  [3,2]\nramaIzquierda :: Arbol -> [Int]\nramaIzquierda (H _)     = []\nramaIzquierda (N x i _) = x : ramaIzquierda i\n\n-- (ramaDerecha a) es la rama derecha del \u00e1rbol a. Por ejemplo,\n--    ramaDerecha ejArbol1  ==  [3,8]\n--    ramaDerecha ejArbol3  ==  [3,8,9]\nramaDerecha :: Arbol -> [Int]\nramaDerecha (H _)     = []\nramaDerecha (N x _ d) = x : ramaDerecha d\n\n-- (hojas a) es la lista de las hojas del \u00e1rbol a. Por ejemplo,\n--    hojas ejArbol1  ==  [1,4,7,6,9]\n--    hojas ejArbol3  ==  [5,7,6,1,4]\nhojas :: Arbol -> [Int]\nhojas (H x)     = [x]\nhojas (N _ i d) = hojas i ++ hojas d\n<\/pre>\n<h4>Pensamiento<\/h4>\n<blockquote><p>\n\u00bfD\u00f3nde est\u00e1 la utilidad<br \/>\nde nuestras utilidades?<br \/>\nVolvamos a la verdad:<br \/>\nvanidad de vanidades.<\/p>\n<p>Antonio Machado\n<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Los \u00e1rboles binarios con datos en las hojas y los nodos se definen por data Arbol = H Int | N Int Arbol Arbol deriving Show Por ejemplo, los \u00e1rboles 3 3 3 \/ \\ \/ \\ \/ \\ \/ \\ \/ \\ \/ \\ 2 8 2 8 2 8 \/ \\ \/ \\&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"footnotes":"","_jetpack_memberships_contains_paid_content":false},"categories":[4],"tags":[269,285,6,32,45],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/4685"}],"collection":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/comments?post=4685"}],"version-history":[{"count":6,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/4685\/revisions"}],"predecessor-version":[{"id":4799,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/4685\/revisions\/4799"}],"wp:attachment":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/media?parent=4685"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/categories?post=4685"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/tags?post=4685"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}