{"id":2608,"date":"2016-11-23T06:00:58","date_gmt":"2016-11-23T04:00:58","guid":{"rendered":"http:\/\/www.glc.us.es\/~jalonso\/exercitium\/?p=2608"},"modified":"2016-11-30T07:05:07","modified_gmt":"2016-11-30T05:05:07","slug":"maxima-ramificacion","status":"publish","type":"post","link":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/maxima-ramificacion\/","title":{"rendered":"M\u00e1xima ramificaci\u00f3n"},"content":{"rendered":"<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<\/p>\n<pre lang=\"text\">\n     1         1             1          \n    \/ \\       \/ \\           \/ \\   \n   2   3     2   3         2   3  \n       |        \/|\\       \/|\\  |   \n       4       4 5 6     4 5 6 7    \n<\/pre>\n<p>se representan por<\/p>\n<pre lang=\"text\">\n   ej1, ej2, ej3 :: Arbol Int\n   ej1 = N 1 [N 2 [],N 3 [N 4 []]]\n   ej2 = N 1 [N 2 [], N 3 [N 4 [], N 5 [], N 6 []]\n   ej3 = N 1 [N 2 [N 4 [], N 5 [], N 6 []], N 3 [N 7 []]] \n<\/pre>\n<p>En el primer ejemplo la m\u00e1xima ramificaci\u00f3n es 2 (en el nodo 1 que tiene 2 hijos), la del segundo es 3 (en el nodo 3 que tiene 3 hijos) y la del tercero es 3 (en el nodo 3 que tiene 3 hijos).<\/p>\n<p>Definir la funci\u00f3n<\/p>\n<pre lang=\"text\">\n   maximaRamificacion :: Arbol a -> Int\n<\/pre>\n<p>tal que (maximaRamificacion a) es la m\u00e1xima ramificaci\u00f3n del \u00e1rbol a. Por ejemplo,<\/p>\n<pre lang=\"text\">\n   maximaRamificacion ej1  ==  2\n   maximaRamificacion ej2  ==  3\n   maximaRamificacion ej3  ==  3\n<\/pre>\n<h4>Soluciones<\/h4>\n<pre lang=\"haskell\">\ndata Arbol a = N a [Arbol a]\n  deriving Show\n\nej1, ej2 :: Arbol Int\nej1 = N 1 [N 2 [],N 3 [N 4 []]]\nej2 = N 1 [N 2 [], N 3 [N 4 [], N 5 [], N 6 []]]\nej3 = N 1 [N 2 [N 4 [], N 5 [], N 6 []], N 3 [N 7 []]] \n\nmaximaRamificacion :: Arbol a -> Int\nmaximaRamificacion (N _ []) = 0\nmaximaRamificacion (N x xs) =\n  max (length xs) (maximum (map maximaRamificacion xs))\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Los \u00e1rboles se pueden representar mediante el siguiente tipo de datos data Arbol a = N a [Arbol a] deriving Show Por ejemplo, los \u00e1rboles 1 1 1 \/ \\ \/ \\ \/ \\ 2 3 2 3 2 3 | \/|\\ \/|\\ | 4 4 5 6 4 5 6 7 se representan por&#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":[7],"tags":[269,28,10,83,15,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\/2608"}],"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=2608"}],"version-history":[{"count":3,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/2608\/revisions"}],"predecessor-version":[{"id":2639,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/2608\/revisions\/2639"}],"wp:attachment":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/media?parent=2608"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/categories?post=2608"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/tags?post=2608"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}