{"id":3730,"date":"2018-02-14T06:00:02","date_gmt":"2018-02-14T04:00:02","guid":{"rendered":"http:\/\/www.glc.us.es\/~jalonso\/exercitium\/?p=3730"},"modified":"2018-02-21T06:35:48","modified_gmt":"2018-02-21T04:35:48","slug":"arboles-binarios-completos","status":"publish","type":"post","link":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/arboles-binarios-completos\/","title":{"rendered":"\u00c1rboles binarios completos"},"content":{"rendered":"<p>Un \u00e1rbol binario completo es un \u00e1rbol en el que cada nodo tiene cero o dos hijos. Por ejemplo, el primero de los siguientes \u00e1rboles es un \u00e1rbol binario completo pero los otros no lo son<\/p>\n<pre lang=\"text\">\n           1              1            1    \n         \/   \\          \/   \\        \/ | \\ \n        2     3        2     3      2  7  3\n       \/ \\            \/            \/ \\      \n      4   5          4            4   5     \n<\/pre>\n<p>Los \u00e1rboles se pueden representar mediante el siguiente tipo de datos<\/p>\n<pre lang=\"text\">\n   data Arbol a = N a [Arbol a]\n     deriving Show\n<\/pre>\n<p>Por ejemplo, los \u00e1rboles los \u00e1rboles anteriores se puede representar por<\/p>\n<pre lang=\"text\">\n   ej1, ej2, ej3 :: Arbol Int\n   ej1 = N 1 [N 2 [N 4 [], N 5 []], N 3 []]\n   ej2 = N 1 [N 2 [N 4 []], N 3 []]\n   ej3 = N 1 [N 2 [N 4 [], N 5 []], N 7 [], N 3 []]\n<\/pre>\n<p>Definir la funci\u00f3n<\/p>\n<pre lang=\"text\">\n   esBinarioCompleto :: Arbol t -> Bool\n<\/pre>\n<p>tal que (esBinarioCompleto a) se verifica si a es un \u00e1rbol binario completo. Por ejemplo,<\/p>\n<pre lang=\"text\">\n   esBinarioCompleto ej1  ==  True\n   esBinarioCompleto ej2  ==  False\n   esBinarioCompleto ej3  ==  False\n<\/pre>\n<h4>Soluciones<\/h4>\n<pre lang=\"haskell\">\ndata Arbol a = N a [Arbol a]\n  deriving Show\n\nej1, ej2, ej3 :: Arbol Int\nej1 = N 1 [N 2 [N 4 [], N 5 []], N 3 []]\nej2 = N 1 [N 2 [N 4 []], N 3 []]\nej3 = N 1 [N 2 [N 4 [], N 5 []], N 7 [], N 3 []]\n          \nesBinarioCompleto :: Arbol t -> Bool\nesBinarioCompleto (N _ []) = True\nesBinarioCompleto (N x as) = length as `elem` [0,2] \n                             && all esBinarioCompleto as\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Un \u00e1rbol binario completo es un \u00e1rbol en el que cada nodo tiene cero o dos hijos. Por ejemplo, el primero de los siguientes \u00e1rboles es un \u00e1rbol binario completo pero los otros no lo son 1 1 1 \/ \\ \/ \\ \/ | \\ 2 3 2 3 2 7 3 \/ \\&#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":[41,269,26,28,11,6],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/3730"}],"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=3730"}],"version-history":[{"count":4,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/3730\/revisions"}],"predecessor-version":[{"id":3804,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/3730\/revisions\/3804"}],"wp:attachment":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/media?parent=3730"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/categories?post=3730"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/tags?post=3730"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}