{"id":2900,"date":"2017-02-08T06:00:04","date_gmt":"2017-02-08T04:00:04","guid":{"rendered":"http:\/\/www.glc.us.es\/~jalonso\/exercitium\/?p=2900"},"modified":"2017-02-15T07:01:41","modified_gmt":"2017-02-15T05:01:41","slug":"caminos-desde-la-raiz-en-un-arbol-binario","status":"publish","type":"post","link":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/caminos-desde-la-raiz-en-un-arbol-binario\/","title":{"rendered":"Caminos desde la ra\u00edz en un \u00e1rbol binario"},"content":{"rendered":"<p>Los \u00e1rboles binarios se pueden representar con el de tipo de dato algebraico<\/p>\n<pre lang=\"text\">\n   data Arbol = H\n              | N Int Arbol Arbol\n     deriving Show\n<\/pre>\n<p>Por ejemplo, los \u00e1rboles<\/p>\n<pre lang=\"text\">\n       3                7       \n      \/ \\              \/ \\      \n     2   4            5   8     \n    \/ \\   \\          \/   \/ \\    \n   1   7   5        6   4   9   \n<\/pre>\n<p>se representan por<\/p>\n<pre lang=\"text\">\n   ej1, ej2 :: Arbol\n   ej1 = N 3 (N 2 (N 1 H H) (N 7 H H)) (N 4 H (N 5 H H))\n   ej2 = N 7 (N 5 (N 6 H H) H) (N 8 (N 4 H H) (N 9 H H))\n<\/pre>\n<p>Definir la funci\u00f3n<\/p>\n<pre lang=\"text\">\n   caminosDesdeRaiz :: Arbol -> [[Int]]\n<\/pre>\n<p>tal que (caminosDesdeRaiz a) es la lista de las caminosDesdeRaiz desde la ra\u00edz de a hasta cualquiera de sus nodos. Por ejemplo.<\/p>\n<pre lang=\"text\">\n   \u03bb> caminosDesdeRaiz ej1\n   [[3],[3,2],[3,2,1],[3,2,7],[3,4],[3,4,5]]\n   \u03bb> caminosDesdeRaiz ej2\n   [[7],[7,5],[7,5,6],[7,8],[7,8,4],[7,8,9]]\n<\/pre>\n<h4>Soluciones<\/h4>\n<pre lang=\"haskell\">\ndata Arbol = H\n           | N Int Arbol Arbol\n  deriving Show\n\nej1, ej2 :: Arbol\nej1 = N 3 (N 2 (N 1 H H) (N 7 H H)) (N 4 H (N 5 H H))\nej2 = N 7 (N 5 (N 6 H H) H) (N 8 (N 4 H H) (N 9 H H))\n  \ncaminosDesdeRaiz :: Arbol -> [[Int]]\ncaminosDesdeRaiz H = []\ncaminosDesdeRaiz (N x i d) =\n  [x] : [x:ys | ys <- caminosDesdeRaiz i ++ caminosDesdeRaiz d]\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Los \u00e1rboles binarios se pueden representar con el de tipo de dato algebraico data Arbol = H | N Int Arbol Arbol deriving Show Por ejemplo, los \u00e1rboles 3 7 \/ \\ \/ \\ 2 4 5 8 \/ \\ \\ \/ \/ \\ 1 7 5 6 4 9 se representan por ej1, ej2&#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,6],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/2900"}],"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=2900"}],"version-history":[{"count":3,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/2900\/revisions"}],"predecessor-version":[{"id":2953,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/2900\/revisions\/2953"}],"wp:attachment":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/media?parent=2900"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/categories?post=2900"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/tags?post=2900"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}