{"id":2033,"date":"2016-01-27T06:00:15","date_gmt":"2016-01-27T04:00:15","guid":{"rendered":"http:\/\/www.glc.us.es\/~jalonso\/exercitium\/?p=2033"},"modified":"2016-02-03T07:55:05","modified_gmt":"2016-02-03T05:55:05","slug":"de-arboles-a-listas","status":"publish","type":"post","link":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/de-arboles-a-listas\/","title":{"rendered":"De \u00e1rboles a listas"},"content":{"rendered":"<p>Los \u00e1rboles binarios con datos en nodos y hojas se definen por<\/p>\n<pre lang=\"text\">\n   data Arbol a = H a | N a (Arbol a) (Arbol a) deriving Show\n<\/pre>\n<p>Por ejemplo, el \u00e1rbol<\/p>\n<pre lang=\"text\">\n          3\n         \/ \\\n        \/   \\\n       4     7\n      \/ \\   \/ \\\n     5   0 0   3\n    \/ \\\n   2   0   \n<\/pre>\n<p>se representa por<\/p>\n<pre lang=\"text\">\n   ejArbol :: Arbol Integer\n   ejArbol = N 3 (N 4 (N 5 (H 2)(H 0)) (H 0)) (N 7 (H 0) (H 3))\n<\/pre>\n<p>Definir la funci\u00f3n<\/p>\n<pre lang=\"text\">\n   sucesores :: Arbol a -> [(a,[a])]\n<\/pre>\n<p>tal que (sucesores t) es la lista de los pares formados por los elementos del \u00e1rbol t junto con sus sucesores. Por ejemplo,<\/p>\n<pre lang=\"text\">\n   \u03bb> sucesores ejArbol\n   [(3,[4,7]),(4,[5,0]),(5,[2,0]),(2,[]),(0,[]),(0,[]),\n    (7,[0,3]),(0,[]),(3,[])]\n<\/pre>\n<h4>Soluciones<\/h4>\n<pre lang=\"haskell\">\ndata Arbol a = H a | N a (Arbol a) (Arbol a) deriving Show\n\nejArbol :: Arbol Integer\nejArbol = N 3 (N 4 (N 5 (H 2)(H 0)) (H 0)) (N 7 (H 0) (H 3))\n\nsucesores :: Arbol a -> [(a,[a])]\nsucesores (H x)     = [(x,[])]\nsucesores (N x i d) = (x, [raiz i, raiz d]) : sucesores i ++ sucesores d\n\nraiz :: Arbol a -> a\nraiz (H x)      = x\nraiz (N x _ _ ) = x \n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Los \u00e1rboles binarios con datos en nodos y hojas se definen por data Arbol a = H a | N a (Arbol a) (Arbol a) deriving Show Por ejemplo, el \u00e1rbol 3 \/ \\ \/ \\ 4 7 \/ \\ \/ \\ 5 0 0 3 \/ \\ 2 0 se representa por ejArbol ::&#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":[5],"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\/2033"}],"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=2033"}],"version-history":[{"count":4,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/2033\/revisions"}],"predecessor-version":[{"id":2075,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/2033\/revisions\/2075"}],"wp:attachment":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/media?parent=2033"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/categories?post=2033"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/tags?post=2033"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}