CINXE.COM

Arbre binari - Viquipèdia, l'enciclopèdia lliure

<!DOCTYPE html> <html class="client-nojs vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-sticky-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-feature-night-mode-enabled skin-theme-clientpref-day vector-toc-available" lang="ca" dir="ltr"> <head> <meta charset="UTF-8"> <title>Arbre binari - Viquipèdia, l'enciclopèdia lliure</title> <script>(function(){var className="client-js vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-sticky-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-feature-night-mode-enabled skin-theme-clientpref-day vector-toc-available";var cookie=document.cookie.match(/(?:^|; )cawikimwclientpreferences=([^;]+)/);if(cookie){cookie[1].split('%2C').forEach(function(pref){className=className.replace(new RegExp('(^| )'+pref.replace(/-clientpref-\w+$|[^\w-]+/g,'')+'-clientpref-\\w+( |$)'),'$1'+pref+'$2');});}document.documentElement.className=className;}());RLCONF={"wgBreakFrames":false,"wgSeparatorTransformTable":[",\t.",".\t,"],"wgDigitTransformTable":["",""], "wgDefaultDateFormat":"dmy","wgMonthNames":["","gener","febrer","març","abril","maig","juny","juliol","agost","setembre","octubre","novembre","desembre"],"wgRequestId":"7f2f7d1f-b8cb-46f2-bd1e-431ae6ef44fe","wgCanonicalNamespace":"","wgCanonicalSpecialPageName":false,"wgNamespaceNumber":0,"wgPageName":"Arbre_binari","wgTitle":"Arbre binari","wgCurRevisionId":33790776,"wgRevisionId":33790776,"wgArticleId":557301,"wgIsArticle":true,"wgIsRedirect":false,"wgAction":"view","wgUserName":null,"wgUserGroups":["*"],"wgCategories":["Pàgines amb enllaç commonscat des de Wikidata","Control d'autoritats","Estructura de dades"],"wgPageViewLanguage":"ca","wgPageContentLanguage":"ca","wgPageContentModel":"wikitext","wgRelevantPageName":"Arbre_binari","wgRelevantArticleId":557301,"wgIsProbablyEditable":true,"wgRelevantPageIsProbablyEditable":true,"wgRestrictionEdit":[],"wgRestrictionMove":[],"wgNoticeProject":"wikipedia","wgCiteReferencePreviewsActive":true,"wgMediaViewerOnClick":true, "wgMediaViewerEnabledByDefault":true,"wgPopupsFlags":0,"wgVisualEditor":{"pageLanguageCode":"ca","pageLanguageDir":"ltr","pageVariantFallbacks":"ca"},"wgMFDisplayWikibaseDescriptions":{"search":true,"watchlist":true,"tagline":true,"nearby":true},"wgWMESchemaEditAttemptStepOversample":false,"wgWMEPageLength":10000,"wgRelatedArticlesCompat":[],"wgCentralAuthMobileDomain":false,"wgEditSubmitButtonLabelPublish":true,"wgULSPosition":"interlanguage","wgULSisCompactLinksEnabled":false,"wgVector2022LanguageInHeader":true,"wgULSisLanguageSelectorEmpty":false,"wgWikibaseItemId":"Q380172","wgCheckUserClientHintsHeadersJsApi":["brands","architecture","bitness","fullVersionList","mobile","model","platform","platformVersion"],"GEHomepageSuggestedEditsEnableTopics":true,"wgGETopicsMatchModeEnabled":false,"wgGEStructuredTaskRejectionReasonTextInputEnabled":false,"wgGELevelingUpEnabledForUser":false};RLSTATE={"ext.globalCssJs.user.styles":"ready","site.styles":"ready","user.styles":"ready", "ext.globalCssJs.user":"ready","user":"ready","user.options":"loading","ext.cite.styles":"ready","ext.pygments":"ready","ext.math.styles":"ready","skins.vector.search.codex.styles":"ready","skins.vector.styles":"ready","skins.vector.icons":"ready","ext.wikimediamessages.styles":"ready","ext.visualEditor.desktopArticleTarget.noscript":"ready","ext.uls.interlanguage":"ready","wikibase.client.init":"ready","wikibase.client.data-bridge.externalModifiers":"ready","ext.wikimediaBadges":"ready"};RLPAGEMODULES=["ext.cite.ux-enhancements","ext.pygments.view","mediawiki.page.media","site","mediawiki.page.ready","mediawiki.toc","skins.vector.js","ext.centralNotice.geoIP","ext.centralNotice.startUp","ext.gadget.UkensKonkurranse","ext.gadget.refToolbar","ext.gadget.charinsert","ext.gadget.AltresViccionari","ext.gadget.purgetab","ext.gadget.DocTabs","ext.gadget.switcher","ext.urlShortener.toolbar","ext.centralauth.centralautologin","mmv.bootstrap","ext.popups", "ext.visualEditor.desktopArticleTarget.init","ext.visualEditor.targetLoader","ext.echo.centralauth","ext.eventLogging","ext.wikimediaEvents","ext.navigationTiming","ext.uls.interface","ext.cx.eventlogging.campaigns","ext.cx.uls.quick.actions","wikibase.client.vector-2022","wikibase.client.data-bridge.init","ext.checkUser.clientHints","ext.growthExperiments.SuggestedEditSession","oojs-ui.styles.icons-media","oojs-ui-core.icons","wikibase.sidebar.tracking"];</script> <script>(RLQ=window.RLQ||[]).push(function(){mw.loader.impl(function(){return["user.options@12s5i",function($,jQuery,require,module){mw.user.tokens.set({"patrolToken":"+\\","watchToken":"+\\","csrfToken":"+\\"}); }];});});</script> <link rel="stylesheet" href="/w/load.php?lang=ca&amp;modules=ext.cite.styles%7Cext.math.styles%7Cext.pygments%2CwikimediaBadges%7Cext.uls.interlanguage%7Cext.visualEditor.desktopArticleTarget.noscript%7Cext.wikimediamessages.styles%7Cskins.vector.icons%2Cstyles%7Cskins.vector.search.codex.styles%7Cwikibase.client.data-bridge.externalModifiers%7Cwikibase.client.init&amp;only=styles&amp;skin=vector-2022"> <script async="" src="/w/load.php?lang=ca&amp;modules=startup&amp;only=scripts&amp;raw=1&amp;skin=vector-2022"></script> <meta name="ResourceLoaderDynamicStyles" content=""> <link rel="stylesheet" href="/w/load.php?lang=ca&amp;modules=site.styles&amp;only=styles&amp;skin=vector-2022"> <meta name="generator" content="MediaWiki 1.44.0-wmf.4"> <meta name="referrer" content="origin"> <meta name="referrer" content="origin-when-cross-origin"> <meta name="robots" content="max-image-preview:standard"> <meta name="format-detection" content="telephone=no"> <meta name="viewport" content="width=1120"> <meta property="og:title" content="Arbre binari - Viquipèdia, l&#039;enciclopèdia lliure"> <meta property="og:type" content="website"> <link rel="preconnect" href="//upload.wikimedia.org"> <link rel="alternate" media="only screen and (max-width: 640px)" href="//ca.m.wikipedia.org/wiki/Arbre_binari"> <link rel="alternate" type="application/x-wiki" title="Modifica" href="/w/index.php?title=Arbre_binari&amp;action=edit"> <link rel="apple-touch-icon" href="/static/apple-touch/wikipedia.png"> <link rel="icon" href="/static/favicon/wikipedia.ico"> <link rel="search" type="application/opensearchdescription+xml" href="/w/rest.php/v1/search" title="Viquipèdia (ca)"> <link rel="EditURI" type="application/rsd+xml" href="//ca.wikipedia.org/w/api.php?action=rsd"> <link rel="canonical" href="https://ca.wikipedia.org/wiki/Arbre_binari"> <link rel="license" href="https://creativecommons.org/licenses/by-sa/4.0/deed.ca"> <link rel="alternate" type="application/atom+xml" title="Canal de sindicació Atom Viquipèdia" href="/w/index.php?title=Especial:Canvis_recents&amp;feed=atom"> <link rel="dns-prefetch" href="//meta.wikimedia.org" /> <link rel="dns-prefetch" href="//login.wikimedia.org"> </head> <body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject mw-editable page-Arbre_binari rootpage-Arbre_binari skin-vector-2022 action-view"><a class="mw-jump-link" href="#bodyContent">Vés al contingut</a> <div class="vector-header-container"> <header class="vector-header mw-header"> <div class="vector-header-start"> <nav class="vector-main-menu-landmark" aria-label="Lloc"> <div id="vector-main-menu-dropdown" class="vector-dropdown vector-main-menu-dropdown vector-button-flush-left vector-button-flush-right" > <input type="checkbox" id="vector-main-menu-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-main-menu-dropdown" class="vector-dropdown-checkbox " aria-label="Menú principal" > <label id="vector-main-menu-dropdown-label" for="vector-main-menu-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-menu mw-ui-icon-wikimedia-menu"></span> <span class="vector-dropdown-label-text">Menú principal</span> </label> <div class="vector-dropdown-content"> <div id="vector-main-menu-unpinned-container" class="vector-unpinned-container"> <div id="vector-main-menu" class="vector-main-menu vector-pinnable-element"> <div class="vector-pinnable-header vector-main-menu-pinnable-header vector-pinnable-header-unpinned" data-feature-name="main-menu-pinned" data-pinnable-element-id="vector-main-menu" data-pinned-container-id="vector-main-menu-pinned-container" data-unpinned-container-id="vector-main-menu-unpinned-container" > <div class="vector-pinnable-header-label">Menú principal</div> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-main-menu.pin">mou a la barra lateral</button> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-main-menu.unpin">amaga</button> </div> <div id="p-navigation" class="vector-menu mw-portlet mw-portlet-navigation" > <div class="vector-menu-heading"> Navegació </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="n-mainpage-description" class="mw-list-item"><a href="/wiki/Portada" title="Visiteu la pàgina principal [z]" accesskey="z"><span>Portada</span></a></li><li id="n-randompage" class="mw-list-item"><a href="/wiki/Especial:Article_aleatori" title="Carrega una pàgina a l’atzar [x]" accesskey="x"><span>Article a l'atzar</span></a></li><li id="n-Articles-de-qualitat" class="mw-list-item"><a href="/wiki/Viquip%C3%A8dia:Articles_de_qualitat"><span>Articles de qualitat</span></a></li> </ul> </div> </div> <div id="p-Comunitat" class="vector-menu mw-portlet mw-portlet-Comunitat" > <div class="vector-menu-heading"> Comunitat </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="n-portal" class="mw-list-item"><a href="/wiki/Viquip%C3%A8dia:Portal" title="Sobre el projecte, què podeu fer, on trobareu les coses"><span>Portal viquipedista</span></a></li><li id="n-Agenda-d&#039;actes" class="mw-list-item"><a href="/wiki/Viquip%C3%A8dia:Trobades"><span>Agenda d'actes</span></a></li><li id="n-recentchanges" class="mw-list-item"><a href="/wiki/Especial:Canvis_recents" title="Una llista dels canvis recents al wiki [r]" accesskey="r"><span>Canvis recents</span></a></li><li id="n-La-taverna" class="mw-list-item"><a href="/wiki/Viquip%C3%A8dia:La_taverna"><span>La taverna</span></a></li><li id="n-contactpage" class="mw-list-item"><a href="/wiki/Viquip%C3%A8dia:Contacte"><span>Contacte</span></a></li><li id="n-Xat" class="mw-list-item"><a href="/wiki/Viquip%C3%A8dia:Canals_IRC"><span>Xat</span></a></li><li id="n-help" class="mw-list-item"><a href="/wiki/Viquip%C3%A8dia:Ajuda" title="El lloc per a saber més coses"><span>Ajuda</span></a></li> </ul> </div> </div> </div> </div> </div> </div> </nav> <a href="/wiki/Portada" class="mw-logo"> <img class="mw-logo-icon" src="/static/images/icons/wikipedia.png" alt="" aria-hidden="true" height="50" width="50"> <span class="mw-logo-container skin-invert"> <img class="mw-logo-wordmark" alt="Viquipèdia" src="/static/images/mobile/copyright/wikipedia-wordmark-ca.svg" style="width: 7.5em; height: 1.4375em;"> <img class="mw-logo-tagline" alt="l&#039;Enciclopèdia Lliure" src="/static/images/mobile/copyright/wikipedia-tagline-ca.svg" width="120" height="14" style="width: 7.5em; height: 0.875em;"> </span> </a> </div> <div class="vector-header-end"> <div id="p-search" role="search" class="vector-search-box-vue vector-search-box-collapses vector-search-box-show-thumbnail vector-search-box-auto-expand-width vector-search-box"> <a href="/wiki/Especial:Cerca" class="cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only search-toggle" title="Cerca a la Viquipèdia [f]" accesskey="f"><span class="vector-icon mw-ui-icon-search mw-ui-icon-wikimedia-search"></span> <span>Cerca</span> </a> <div class="vector-typeahead-search-container"> <div class="cdx-typeahead-search cdx-typeahead-search--show-thumbnail cdx-typeahead-search--auto-expand-width"> <form action="/w/index.php" id="searchform" class="cdx-search-input cdx-search-input--has-end-button"> <div id="simpleSearch" class="cdx-search-input__input-wrapper" data-search-loc="header-moved"> <div class="cdx-text-input cdx-text-input--has-start-icon"> <input class="cdx-text-input__input" type="search" name="search" placeholder="Cerca a Viquipèdia" aria-label="Cerca a Viquipèdia" autocapitalize="sentences" title="Cerca a la Viquipèdia [f]" accesskey="f" id="searchInput" > <span class="cdx-text-input__icon cdx-text-input__start-icon"></span> </div> <input type="hidden" name="title" value="Especial:Cerca"> </div> <button class="cdx-button cdx-search-input__end-button">Cerca</button> </form> </div> </div> </div> <nav class="vector-user-links vector-user-links-wide" aria-label="Eines personals"> <div class="vector-user-links-main"> <div id="p-vector-user-menu-preferences" class="vector-menu mw-portlet emptyPortlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> </ul> </div> </div> <div id="p-vector-user-menu-userpage" class="vector-menu mw-portlet emptyPortlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> </ul> </div> </div> <nav class="vector-appearance-landmark" aria-label="Aparença"> <div id="vector-appearance-dropdown" class="vector-dropdown " title="Change the appearance of the page&#039;s font size, width, and color" > <input type="checkbox" id="vector-appearance-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-appearance-dropdown" class="vector-dropdown-checkbox " aria-label="Aparença" > <label id="vector-appearance-dropdown-label" for="vector-appearance-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-appearance mw-ui-icon-wikimedia-appearance"></span> <span class="vector-dropdown-label-text">Aparença</span> </label> <div class="vector-dropdown-content"> <div id="vector-appearance-unpinned-container" class="vector-unpinned-container"> </div> </div> </div> </nav> <div id="p-vector-user-menu-notifications" class="vector-menu mw-portlet emptyPortlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> </ul> </div> </div> <div id="p-vector-user-menu-overflow" class="vector-menu mw-portlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="pt-sitesupport-2" class="user-links-collapsible-item mw-list-item user-links-collapsible-item"><a data-mw="interface" href="//donate.wikimedia.org/wiki/Special:FundraiserRedirector?utm_source=donate&amp;utm_medium=sidebar&amp;utm_campaign=C13_ca.wikipedia.org&amp;uselang=ca" class=""><span>Donatius</span></a> </li> <li id="pt-createaccount-2" class="user-links-collapsible-item mw-list-item user-links-collapsible-item"><a data-mw="interface" href="/w/index.php?title=Especial:Crea_compte&amp;returnto=Arbre+binari" title="Us animem a crear un compte i iniciar una sessió, encara que no és obligatori" class=""><span>Crea un compte</span></a> </li> <li id="pt-login-2" class="user-links-collapsible-item mw-list-item user-links-collapsible-item"><a data-mw="interface" href="/w/index.php?title=Especial:Registre_i_entrada&amp;returnto=Arbre+binari" title="Us animem a registrar-vos, però no és obligatori [o]" accesskey="o" class=""><span>Inicia la sessió</span></a> </li> </ul> </div> </div> </div> <div id="vector-user-links-dropdown" class="vector-dropdown vector-user-menu vector-button-flush-right vector-user-menu-logged-out" title="Més opcions" > <input type="checkbox" id="vector-user-links-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-user-links-dropdown" class="vector-dropdown-checkbox " aria-label="Eines personals" > <label id="vector-user-links-dropdown-label" for="vector-user-links-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-ellipsis mw-ui-icon-wikimedia-ellipsis"></span> <span class="vector-dropdown-label-text">Eines personals</span> </label> <div class="vector-dropdown-content"> <div id="p-personal" class="vector-menu mw-portlet mw-portlet-personal user-links-collapsible-item" title="Menú d&#039;usuari" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="pt-sitesupport" class="user-links-collapsible-item mw-list-item"><a href="//donate.wikimedia.org/wiki/Special:FundraiserRedirector?utm_source=donate&amp;utm_medium=sidebar&amp;utm_campaign=C13_ca.wikipedia.org&amp;uselang=ca"><span>Donatius</span></a></li><li id="pt-createaccount" class="user-links-collapsible-item mw-list-item"><a href="/w/index.php?title=Especial:Crea_compte&amp;returnto=Arbre+binari" title="Us animem a crear un compte i iniciar una sessió, encara que no és obligatori"><span class="vector-icon mw-ui-icon-userAdd mw-ui-icon-wikimedia-userAdd"></span> <span>Crea un compte</span></a></li><li id="pt-login" class="user-links-collapsible-item mw-list-item"><a href="/w/index.php?title=Especial:Registre_i_entrada&amp;returnto=Arbre+binari" title="Us animem a registrar-vos, però no és obligatori [o]" accesskey="o"><span class="vector-icon mw-ui-icon-logIn mw-ui-icon-wikimedia-logIn"></span> <span>Inicia la sessió</span></a></li> </ul> </div> </div> <div id="p-user-menu-anon-editor" class="vector-menu mw-portlet mw-portlet-user-menu-anon-editor" > <div class="vector-menu-heading"> Pàgines per a editors no registrats <a href="/wiki/Ajuda:Introducci%C3%B3" aria-label="Vegeu més informació sobre l&#039;edició"><span>més informació</span></a> </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="pt-anoncontribs" class="mw-list-item"><a href="/wiki/Especial:Contribucions_pr%C3%B2pies" title="Una llista de les modificacions fetes des d&#039;aquesta adreça IP [y]" accesskey="y"><span>Contribucions</span></a></li><li id="pt-anontalk" class="mw-list-item"><a href="/wiki/Especial:Discussi%C3%B3_personal" title="Discussió sobre les edicions per aquesta adreça ip. [n]" accesskey="n"><span>Discussió per aquest IP</span></a></li> </ul> </div> </div> </div> </div> </nav> </div> </header> </div> <div class="mw-page-container"> <div class="mw-page-container-inner"> <div class="vector-sitenotice-container"> <div id="siteNotice"><!-- CentralNotice --></div> </div> <div class="vector-column-start"> <div class="vector-main-menu-container"> <div id="mw-navigation"> <nav id="mw-panel" class="vector-main-menu-landmark" aria-label="Lloc"> <div id="vector-main-menu-pinned-container" class="vector-pinned-container"> </div> </nav> </div> </div> <div class="vector-sticky-pinned-container"> <nav id="mw-panel-toc" aria-label="Contingut" data-event-name="ui.sidebar-toc" class="mw-table-of-contents-container vector-toc-landmark"> <div id="vector-toc-pinned-container" class="vector-pinned-container"> <div id="vector-toc" class="vector-toc vector-pinnable-element"> <div class="vector-pinnable-header vector-toc-pinnable-header vector-pinnable-header-pinned" data-feature-name="toc-pinned" data-pinnable-element-id="vector-toc" > <h2 class="vector-pinnable-header-label">Contingut</h2> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-toc.pin">mou a la barra lateral</button> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-toc.unpin">amaga</button> </div> <ul class="vector-toc-contents" id="mw-panel-toc-list"> <li id="toc-mw-content-text" class="vector-toc-list-item vector-toc-level-1"> <a href="#" class="vector-toc-link"> <div class="vector-toc-text">Inici</div> </a> </li> <li id="toc-Definició_de_teoria_de_grafs" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#Definició_de_teoria_de_grafs"> <div class="vector-toc-text"> <span class="vector-toc-numb">1</span> <span>Definició de teoria de grafs</span> </div> </a> <ul id="toc-Definició_de_teoria_de_grafs-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Tipus_d&#039;arbres_binaris" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#Tipus_d&#039;arbres_binaris"> <div class="vector-toc-text"> <span class="vector-toc-numb">2</span> <span>Tipus d'arbres binaris</span> </div> </a> <ul id="toc-Tipus_d&#039;arbres_binaris-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Implementació_en_C" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#Implementació_en_C"> <div class="vector-toc-text"> <span class="vector-toc-numb">3</span> <span>Implementació en C</span> </div> </a> <ul id="toc-Implementació_en_C-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Recorreguts_sobre_arbres_binaris" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#Recorreguts_sobre_arbres_binaris"> <div class="vector-toc-text"> <span class="vector-toc-numb">4</span> <span>Recorreguts sobre arbres binaris</span> </div> </a> <button aria-controls="toc-Recorreguts_sobre_arbres_binaris-sublist" class="cdx-button cdx-button--weight-quiet cdx-button--icon-only vector-toc-toggle"> <span class="vector-icon mw-ui-icon-wikimedia-expand"></span> <span>Commuta la subsecció Recorreguts sobre arbres binaris</span> </button> <ul id="toc-Recorreguts_sobre_arbres_binaris-sublist" class="vector-toc-list"> <li id="toc-Recorreguts_en_profunditat" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Recorreguts_en_profunditat"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.1</span> <span>Recorreguts en profunditat</span> </div> </a> <ul id="toc-Recorreguts_en_profunditat-sublist" class="vector-toc-list"> <li id="toc-Recorregut_en_preordre" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Recorregut_en_preordre"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.1.1</span> <span>Recorregut en preordre</span> </div> </a> <ul id="toc-Recorregut_en_preordre-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Recorregut_en_postordre" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Recorregut_en_postordre"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.1.2</span> <span>Recorregut en postordre</span> </div> </a> <ul id="toc-Recorregut_en_postordre-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Recorregut_en_inordre" class="vector-toc-list-item vector-toc-level-3"> <a class="vector-toc-link" href="#Recorregut_en_inordre"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.1.3</span> <span>Recorregut en inordre</span> </div> </a> <ul id="toc-Recorregut_en_inordre-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Recorreguts_en_amplitud_(o_per_nivells)" class="vector-toc-list-item vector-toc-level-2"> <a class="vector-toc-link" href="#Recorreguts_en_amplitud_(o_per_nivells)"> <div class="vector-toc-text"> <span class="vector-toc-numb">4.2</span> <span>Recorreguts en amplitud (o per nivells)</span> </div> </a> <ul id="toc-Recorreguts_en_amplitud_(o_per_nivells)-sublist" class="vector-toc-list"> </ul> </li> </ul> </li> <li id="toc-Mètodes_per_a_emmagatzemar_arbres_binaris" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#Mètodes_per_a_emmagatzemar_arbres_binaris"> <div class="vector-toc-text"> <span class="vector-toc-numb">5</span> <span>Mètodes per a emmagatzemar arbres binaris</span> </div> </a> <ul id="toc-Mètodes_per_a_emmagatzemar_arbres_binaris-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Codificació_d&#039;arbres_n-aris_com_a_arbres_binaris" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#Codificació_d&#039;arbres_n-aris_com_a_arbres_binaris"> <div class="vector-toc-text"> <span class="vector-toc-numb">6</span> <span>Codificació d'arbres n-aris com a arbres binaris</span> </div> </a> <ul id="toc-Codificació_d&#039;arbres_n-aris_com_a_arbres_binaris-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Vegeu_també" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#Vegeu_també"> <div class="vector-toc-text"> <span class="vector-toc-numb">7</span> <span>Vegeu també</span> </div> </a> <ul id="toc-Vegeu_també-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Referències" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#Referències"> <div class="vector-toc-text"> <span class="vector-toc-numb">8</span> <span>Referències</span> </div> </a> <ul id="toc-Referències-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Bibliografia" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#Bibliografia"> <div class="vector-toc-text"> <span class="vector-toc-numb">9</span> <span>Bibliografia</span> </div> </a> <ul id="toc-Bibliografia-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Enllaços_externs" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#Enllaços_externs"> <div class="vector-toc-text"> <span class="vector-toc-numb">10</span> <span>Enllaços externs</span> </div> </a> <ul id="toc-Enllaços_externs-sublist" class="vector-toc-list"> </ul> </li> </ul> </div> </div> </nav> </div> </div> <div class="mw-content-container"> <main id="content" class="mw-body"> <header class="mw-body-header vector-page-titlebar"> <nav aria-label="Contingut" class="vector-toc-landmark"> <div id="vector-page-titlebar-toc" class="vector-dropdown vector-page-titlebar-toc vector-button-flush-left" > <input type="checkbox" id="vector-page-titlebar-toc-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-page-titlebar-toc" class="vector-dropdown-checkbox " aria-label="Commuta la taula de continguts." > <label id="vector-page-titlebar-toc-label" for="vector-page-titlebar-toc-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-listBullet mw-ui-icon-wikimedia-listBullet"></span> <span class="vector-dropdown-label-text">Commuta la taula de continguts.</span> </label> <div class="vector-dropdown-content"> <div id="vector-page-titlebar-toc-unpinned-container" class="vector-unpinned-container"> </div> </div> </div> </nav> <h1 id="firstHeading" class="firstHeading mw-first-heading"><span class="mw-page-title-main">Arbre binari</span></h1> <div id="p-lang-btn" class="vector-dropdown mw-portlet mw-portlet-lang" > <input type="checkbox" id="p-lang-btn-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-p-lang-btn" class="vector-dropdown-checkbox mw-interlanguage-selector" aria-label="Vés a un article en una altra llengua. Disponible en 40 llengües" > <label id="p-lang-btn-label" for="p-lang-btn-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--action-progressive mw-portlet-lang-heading-40" aria-hidden="true" ><span class="vector-icon mw-ui-icon-language-progressive mw-ui-icon-wikimedia-language-progressive"></span> <span class="vector-dropdown-label-text">40 llengües</span> </label> <div class="vector-dropdown-content"> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li class="interlanguage-link interwiki-ar mw-list-item"><a href="https://ar.wikipedia.org/wiki/%D8%B4%D8%AC%D8%B1%D8%A9_%D8%AB%D9%86%D8%A7%D8%A6%D9%8A%D8%A9" title="شجرة ثنائية - àrab" lang="ar" hreflang="ar" data-title="شجرة ثنائية" data-language-autonym="العربية" data-language-local-name="àrab" class="interlanguage-link-target"><span>العربية</span></a></li><li class="interlanguage-link interwiki-az mw-list-item"><a href="https://az.wikipedia.org/wiki/%C4%B0kilik_a%C4%9Fac" title="İkilik ağac - azerbaidjanès" lang="az" hreflang="az" data-title="İkilik ağac" data-language-autonym="Azərbaycanca" data-language-local-name="azerbaidjanès" class="interlanguage-link-target"><span>Azərbaycanca</span></a></li><li class="interlanguage-link interwiki-bg mw-list-item"><a href="https://bg.wikipedia.org/wiki/%D0%94%D0%B2%D0%BE%D0%B8%D1%87%D0%BD%D0%BE_%D0%B4%D1%8A%D1%80%D0%B2%D0%BE" title="Двоично дърво - búlgar" lang="bg" hreflang="bg" data-title="Двоично дърво" data-language-autonym="Български" data-language-local-name="búlgar" class="interlanguage-link-target"><span>Български</span></a></li><li class="interlanguage-link interwiki-bs mw-list-item"><a href="https://bs.wikipedia.org/wiki/Binarno_stablo" title="Binarno stablo - bosnià" lang="bs" hreflang="bs" data-title="Binarno stablo" data-language-autonym="Bosanski" data-language-local-name="bosnià" class="interlanguage-link-target"><span>Bosanski</span></a></li><li class="interlanguage-link interwiki-cs mw-list-item"><a href="https://cs.wikipedia.org/wiki/Bin%C3%A1rn%C3%AD_strom" title="Binární strom - txec" lang="cs" hreflang="cs" data-title="Binární strom" data-language-autonym="Čeština" data-language-local-name="txec" class="interlanguage-link-target"><span>Čeština</span></a></li><li class="interlanguage-link interwiki-de mw-list-item"><a href="https://de.wikipedia.org/wiki/Bin%C3%A4rbaum" title="Binärbaum - alemany" lang="de" hreflang="de" data-title="Binärbaum" data-language-autonym="Deutsch" data-language-local-name="alemany" class="interlanguage-link-target"><span>Deutsch</span></a></li><li class="interlanguage-link interwiki-el mw-list-item"><a href="https://el.wikipedia.org/wiki/%CE%94%CF%85%CE%B1%CE%B4%CE%B9%CE%BA%CF%8C_%CE%B4%CE%AD%CE%BD%CF%84%CF%81%CE%BF" title="Δυαδικό δέντρο - grec" lang="el" hreflang="el" data-title="Δυαδικό δέντρο" data-language-autonym="Ελληνικά" data-language-local-name="grec" class="interlanguage-link-target"><span>Ελληνικά</span></a></li><li class="interlanguage-link interwiki-en mw-list-item"><a href="https://en.wikipedia.org/wiki/Binary_tree" title="Binary tree - anglès" lang="en" hreflang="en" data-title="Binary tree" data-language-autonym="English" data-language-local-name="anglès" class="interlanguage-link-target"><span>English</span></a></li><li class="interlanguage-link interwiki-eo mw-list-item"><a href="https://eo.wikipedia.org/wiki/Duuma_arbo" title="Duuma arbo - esperanto" lang="eo" hreflang="eo" data-title="Duuma arbo" data-language-autonym="Esperanto" data-language-local-name="esperanto" class="interlanguage-link-target"><span>Esperanto</span></a></li><li class="interlanguage-link interwiki-es mw-list-item"><a href="https://es.wikipedia.org/wiki/%C3%81rbol_binario" title="Árbol binario - espanyol" lang="es" hreflang="es" data-title="Árbol binario" data-language-autonym="Español" data-language-local-name="espanyol" class="interlanguage-link-target"><span>Español</span></a></li><li class="interlanguage-link interwiki-et mw-list-item"><a href="https://et.wikipedia.org/wiki/Kahendpuu" title="Kahendpuu - estonià" lang="et" hreflang="et" data-title="Kahendpuu" data-language-autonym="Eesti" data-language-local-name="estonià" class="interlanguage-link-target"><span>Eesti</span></a></li><li class="interlanguage-link interwiki-fa mw-list-item"><a href="https://fa.wikipedia.org/wiki/%D8%AF%D8%B1%D8%AE%D8%AA_%D8%AF%D9%88%D8%AF%D9%88%DB%8C%DB%8C" title="درخت دودویی - persa" lang="fa" hreflang="fa" data-title="درخت دودویی" data-language-autonym="فارسی" data-language-local-name="persa" class="interlanguage-link-target"><span>فارسی</span></a></li><li class="interlanguage-link interwiki-fi mw-list-item"><a href="https://fi.wikipedia.org/wiki/Bin%C3%A4%C3%A4ripuu" title="Binääripuu - finès" lang="fi" hreflang="fi" data-title="Binääripuu" data-language-autonym="Suomi" data-language-local-name="finès" class="interlanguage-link-target"><span>Suomi</span></a></li><li class="interlanguage-link interwiki-fr mw-list-item"><a href="https://fr.wikipedia.org/wiki/Arbre_binaire" title="Arbre binaire - francès" lang="fr" hreflang="fr" data-title="Arbre binaire" data-language-autonym="Français" data-language-local-name="francès" class="interlanguage-link-target"><span>Français</span></a></li><li class="interlanguage-link interwiki-he mw-list-item"><a href="https://he.wikipedia.org/wiki/%D7%A2%D7%A5_%D7%91%D7%99%D7%A0%D7%90%D7%A8%D7%99" title="עץ בינארי - hebreu" lang="he" hreflang="he" data-title="עץ בינארי" data-language-autonym="עברית" data-language-local-name="hebreu" class="interlanguage-link-target"><span>עברית</span></a></li><li class="interlanguage-link interwiki-hi mw-list-item"><a href="https://hi.wikipedia.org/wiki/%E0%A4%AC%E0%A4%BE%E0%A4%87%E0%A4%A8%E0%A4%B0%E0%A5%80_%E0%A4%9F%E0%A5%8D%E0%A4%B0%E0%A5%80" title="बाइनरी ट्री - hindi" lang="hi" hreflang="hi" data-title="बाइनरी ट्री" data-language-autonym="हिन्दी" data-language-local-name="hindi" class="interlanguage-link-target"><span>हिन्दी</span></a></li><li class="interlanguage-link interwiki-hr mw-list-item"><a href="https://hr.wikipedia.org/wiki/Binarno_stablo" title="Binarno stablo - croat" lang="hr" hreflang="hr" data-title="Binarno stablo" data-language-autonym="Hrvatski" data-language-local-name="croat" class="interlanguage-link-target"><span>Hrvatski</span></a></li><li class="interlanguage-link interwiki-id mw-list-item"><a href="https://id.wikipedia.org/wiki/Pohon_biner" title="Pohon biner - indonesi" lang="id" hreflang="id" data-title="Pohon biner" data-language-autonym="Bahasa Indonesia" data-language-local-name="indonesi" class="interlanguage-link-target"><span>Bahasa Indonesia</span></a></li><li class="interlanguage-link interwiki-is mw-list-item"><a href="https://is.wikipedia.org/wiki/Tv%C3%ADundatr%C3%A9" title="Tvíundatré - islandès" lang="is" hreflang="is" data-title="Tvíundatré" data-language-autonym="Íslenska" data-language-local-name="islandès" class="interlanguage-link-target"><span>Íslenska</span></a></li><li class="interlanguage-link interwiki-it mw-list-item"><a href="https://it.wikipedia.org/wiki/Albero_binario" title="Albero binario - italià" lang="it" hreflang="it" data-title="Albero binario" data-language-autonym="Italiano" data-language-local-name="italià" class="interlanguage-link-target"><span>Italiano</span></a></li><li class="interlanguage-link interwiki-ja mw-list-item"><a href="https://ja.wikipedia.org/wiki/%E4%BA%8C%E5%88%86%E6%9C%A8" title="二分木 - japonès" lang="ja" hreflang="ja" data-title="二分木" data-language-autonym="日本語" data-language-local-name="japonès" class="interlanguage-link-target"><span>日本語</span></a></li><li class="interlanguage-link interwiki-ko mw-list-item"><a href="https://ko.wikipedia.org/wiki/%EC%9D%B4%EC%A7%84_%ED%8A%B8%EB%A6%AC" title="이진 트리 - coreà" lang="ko" hreflang="ko" data-title="이진 트리" data-language-autonym="한국어" data-language-local-name="coreà" class="interlanguage-link-target"><span>한국어</span></a></li><li class="interlanguage-link interwiki-lmo mw-list-item"><a href="https://lmo.wikipedia.org/wiki/Alber_binari" title="Alber binari - llombard" lang="lmo" hreflang="lmo" data-title="Alber binari" data-language-autonym="Lombard" data-language-local-name="llombard" class="interlanguage-link-target"><span>Lombard</span></a></li><li class="interlanguage-link interwiki-mn mw-list-item"><a href="https://mn.wikipedia.org/wiki/%D0%A5%D0%BE%D1%91%D1%80%D1%82%D1%8B%D0%BD_%D0%BC%D0%BE%D0%B4" title="Хоёртын мод - mongol" lang="mn" hreflang="mn" data-title="Хоёртын мод" data-language-autonym="Монгол" data-language-local-name="mongol" class="interlanguage-link-target"><span>Монгол</span></a></li><li class="interlanguage-link interwiki-pl mw-list-item"><a href="https://pl.wikipedia.org/wiki/Drzewo_binarne" title="Drzewo binarne - polonès" lang="pl" hreflang="pl" data-title="Drzewo binarne" data-language-autonym="Polski" data-language-local-name="polonès" class="interlanguage-link-target"><span>Polski</span></a></li><li class="interlanguage-link interwiki-pt mw-list-item"><a href="https://pt.wikipedia.org/wiki/%C3%81rvore_bin%C3%A1ria" title="Árvore binária - portuguès" lang="pt" hreflang="pt" data-title="Árvore binária" data-language-autonym="Português" data-language-local-name="portuguès" class="interlanguage-link-target"><span>Português</span></a></li><li class="interlanguage-link interwiki-ro mw-list-item"><a href="https://ro.wikipedia.org/wiki/Arbore_binar" title="Arbore binar - romanès" lang="ro" hreflang="ro" data-title="Arbore binar" data-language-autonym="Română" data-language-local-name="romanès" class="interlanguage-link-target"><span>Română</span></a></li><li class="interlanguage-link interwiki-ru mw-list-item"><a href="https://ru.wikipedia.org/wiki/%D0%94%D0%B2%D0%BE%D0%B8%D1%87%D0%BD%D0%BE%D0%B5_%D0%B4%D0%B5%D1%80%D0%B5%D0%B2%D0%BE" title="Двоичное дерево - rus" lang="ru" hreflang="ru" data-title="Двоичное дерево" data-language-autonym="Русский" data-language-local-name="rus" class="interlanguage-link-target"><span>Русский</span></a></li><li class="interlanguage-link interwiki-sh mw-list-item"><a href="https://sh.wikipedia.org/wiki/Binarno_stablo" title="Binarno stablo - serbocroat" lang="sh" hreflang="sh" data-title="Binarno stablo" data-language-autonym="Srpskohrvatski / српскохрватски" data-language-local-name="serbocroat" class="interlanguage-link-target"><span>Srpskohrvatski / српскохрватски</span></a></li><li class="interlanguage-link interwiki-simple mw-list-item"><a href="https://simple.wikipedia.org/wiki/Binary_tree" title="Binary tree - Simple English" lang="en-simple" hreflang="en-simple" data-title="Binary tree" data-language-autonym="Simple English" data-language-local-name="Simple English" class="interlanguage-link-target"><span>Simple English</span></a></li><li class="interlanguage-link interwiki-sk mw-list-item"><a href="https://sk.wikipedia.org/wiki/Bin%C3%A1rny_strom_(te%C3%B3ria_grafov)" title="Binárny strom (teória grafov) - eslovac" lang="sk" hreflang="sk" data-title="Binárny strom (teória grafov)" data-language-autonym="Slovenčina" data-language-local-name="eslovac" class="interlanguage-link-target"><span>Slovenčina</span></a></li><li class="interlanguage-link interwiki-sl mw-list-item"><a href="https://sl.wikipedia.org/wiki/Dvoji%C5%A1ko_drevo" title="Dvojiško drevo - eslovè" lang="sl" hreflang="sl" data-title="Dvojiško drevo" data-language-autonym="Slovenščina" data-language-local-name="eslovè" class="interlanguage-link-target"><span>Slovenščina</span></a></li><li class="interlanguage-link interwiki-sq mw-list-item"><a href="https://sq.wikipedia.org/wiki/Pem%C3%ABt_binare" title="Pemët binare - albanès" lang="sq" hreflang="sq" data-title="Pemët binare" data-language-autonym="Shqip" data-language-local-name="albanès" class="interlanguage-link-target"><span>Shqip</span></a></li><li class="interlanguage-link interwiki-sr mw-list-item"><a href="https://sr.wikipedia.org/wiki/%D0%91%D0%B8%D0%BD%D0%B0%D1%80%D0%BD%D0%BE_%D1%81%D1%82%D0%B0%D0%B1%D0%BB%D0%BE" title="Бинарно стабло - serbi" lang="sr" hreflang="sr" data-title="Бинарно стабло" data-language-autonym="Српски / srpski" data-language-local-name="serbi" class="interlanguage-link-target"><span>Српски / srpski</span></a></li><li class="interlanguage-link interwiki-sv mw-list-item"><a href="https://sv.wikipedia.org/wiki/Bin%C3%A4rtr%C3%A4d" title="Binärträd - suec" lang="sv" hreflang="sv" data-title="Binärträd" data-language-autonym="Svenska" data-language-local-name="suec" class="interlanguage-link-target"><span>Svenska</span></a></li><li class="interlanguage-link interwiki-th mw-list-item"><a href="https://th.wikipedia.org/wiki/%E0%B8%95%E0%B9%89%E0%B8%99%E0%B9%84%E0%B8%A1%E0%B9%89%E0%B9%81%E0%B8%9A%E0%B8%9A%E0%B8%97%E0%B8%A7%E0%B8%B4%E0%B8%A0%E0%B8%B2%E0%B8%84" title="ต้นไม้แบบทวิภาค - tai" lang="th" hreflang="th" data-title="ต้นไม้แบบทวิภาค" data-language-autonym="ไทย" data-language-local-name="tai" class="interlanguage-link-target"><span>ไทย</span></a></li><li class="interlanguage-link interwiki-uk mw-list-item"><a href="https://uk.wikipedia.org/wiki/%D0%94%D0%B2%D1%96%D0%B9%D0%BA%D0%BE%D0%B2%D0%B5_%D0%B4%D0%B5%D1%80%D0%B5%D0%B2%D0%BE" title="Двійкове дерево - ucraïnès" lang="uk" hreflang="uk" data-title="Двійкове дерево" data-language-autonym="Українська" data-language-local-name="ucraïnès" class="interlanguage-link-target"><span>Українська</span></a></li><li class="interlanguage-link interwiki-vi mw-list-item"><a href="https://vi.wikipedia.org/wiki/C%C3%A2y_nh%E1%BB%8B_ph%C3%A2n" title="Cây nhị phân - vietnamita" lang="vi" hreflang="vi" data-title="Cây nhị phân" data-language-autonym="Tiếng Việt" data-language-local-name="vietnamita" class="interlanguage-link-target"><span>Tiếng Việt</span></a></li><li class="interlanguage-link interwiki-zh mw-list-item"><a href="https://zh.wikipedia.org/wiki/%E4%BA%8C%E5%8F%89%E6%A0%91" title="二叉树 - xinès" lang="zh" hreflang="zh" data-title="二叉树" data-language-autonym="中文" data-language-local-name="xinès" class="interlanguage-link-target"><span>中文</span></a></li><li class="interlanguage-link interwiki-zh-yue mw-list-item"><a href="https://zh-yue.wikipedia.org/wiki/%E4%BA%8C%E5%85%83%E6%A8%B9" title="二元樹 - cantonès" lang="yue" hreflang="yue" data-title="二元樹" data-language-autonym="粵語" data-language-local-name="cantonès" class="interlanguage-link-target"><span>粵語</span></a></li> </ul> <div class="after-portlet after-portlet-lang"><span class="wb-langlinks-edit wb-langlinks-link"><a href="https://www.wikidata.org/wiki/Special:EntityPage/Q380172#sitelinks-wikipedia" title="Modifica enllaços interlingües" class="wbc-editpage">Modifica els enllaços</a></span></div> </div> </div> </div> </header> <div class="vector-page-toolbar"> <div class="vector-page-toolbar-container"> <div id="left-navigation"> <nav aria-label="Espais de noms"> <div id="p-associated-pages" class="vector-menu vector-menu-tabs mw-portlet mw-portlet-associated-pages" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="ca-nstab-main" class="selected vector-tab-noicon mw-list-item"><a href="/wiki/Arbre_binari" title="Vegeu el contingut de la pàgina [c]" accesskey="c"><span>Pàgina</span></a></li><li id="ca-talk" class="new vector-tab-noicon mw-list-item"><a href="/w/index.php?title=Discussi%C3%B3:Arbre_binari&amp;action=edit&amp;redlink=1" rel="discussion" class="new" title="Discussió sobre el contingut d&#039;aquesta pàgina (encara no existeix) [t]" accesskey="t"><span>Discussió</span></a></li> </ul> </div> </div> <div id="vector-variants-dropdown" class="vector-dropdown emptyPortlet" > <input type="checkbox" id="vector-variants-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-variants-dropdown" class="vector-dropdown-checkbox " aria-label="Canvia la variant de llengua" > <label id="vector-variants-dropdown-label" for="vector-variants-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet" aria-hidden="true" ><span class="vector-dropdown-label-text">català</span> </label> <div class="vector-dropdown-content"> <div id="p-variants" class="vector-menu mw-portlet mw-portlet-variants emptyPortlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> </ul> </div> </div> </div> </div> </nav> </div> <div id="right-navigation" class="vector-collapsible"> <nav aria-label="Vistes"> <div id="p-views" class="vector-menu vector-menu-tabs mw-portlet mw-portlet-views" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="ca-view" class="selected vector-tab-noicon mw-list-item"><a href="/wiki/Arbre_binari"><span>Mostra</span></a></li><li id="ca-edit" class="vector-tab-noicon mw-list-item"><a href="/w/index.php?title=Arbre_binari&amp;action=edit" title="Modifica el codi font d&#039;aquesta pàgina [e]" accesskey="e"><span>Modifica</span></a></li><li id="ca-history" class="vector-tab-noicon mw-list-item"><a href="/w/index.php?title=Arbre_binari&amp;action=history" title="Versions antigues d&#039;aquesta pàgina [h]" accesskey="h"><span>Mostra l'historial</span></a></li> </ul> </div> </div> </nav> <nav class="vector-page-tools-landmark" aria-label="Eines de la pàgina"> <div id="vector-page-tools-dropdown" class="vector-dropdown vector-page-tools-dropdown" > <input type="checkbox" id="vector-page-tools-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-page-tools-dropdown" class="vector-dropdown-checkbox " aria-label="Eines" > <label id="vector-page-tools-dropdown-label" for="vector-page-tools-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet" aria-hidden="true" ><span class="vector-dropdown-label-text">Eines</span> </label> <div class="vector-dropdown-content"> <div id="vector-page-tools-unpinned-container" class="vector-unpinned-container"> <div id="vector-page-tools" class="vector-page-tools vector-pinnable-element"> <div class="vector-pinnable-header vector-page-tools-pinnable-header vector-pinnable-header-unpinned" data-feature-name="page-tools-pinned" data-pinnable-element-id="vector-page-tools" data-pinned-container-id="vector-page-tools-pinned-container" data-unpinned-container-id="vector-page-tools-unpinned-container" > <div class="vector-pinnable-header-label">Eines</div> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-page-tools.pin">mou a la barra lateral</button> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-page-tools.unpin">amaga</button> </div> <div id="p-cactions" class="vector-menu mw-portlet mw-portlet-cactions emptyPortlet vector-has-collapsible-items" title="Més opcions" > <div class="vector-menu-heading"> Accions </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="ca-more-view" class="selected vector-more-collapsible-item mw-list-item"><a href="/wiki/Arbre_binari"><span>Mostra</span></a></li><li id="ca-more-edit" class="vector-more-collapsible-item mw-list-item"><a href="/w/index.php?title=Arbre_binari&amp;action=edit" title="Modifica el codi font d&#039;aquesta pàgina [e]" accesskey="e"><span>Modifica</span></a></li><li id="ca-more-history" class="vector-more-collapsible-item mw-list-item"><a href="/w/index.php?title=Arbre_binari&amp;action=history"><span>Mostra l'historial</span></a></li> </ul> </div> </div> <div id="p-tb" class="vector-menu mw-portlet mw-portlet-tb" > <div class="vector-menu-heading"> General </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="t-whatlinkshere" class="mw-list-item"><a href="/wiki/Especial:Enlla%C3%A7os/Arbre_binari" title="Una llista de totes les pàgines wiki que enllacen amb aquesta [j]" accesskey="j"><span>Què hi enllaça</span></a></li><li id="t-recentchangeslinked" class="mw-list-item"><a href="/wiki/Especial:Seguiment/Arbre_binari" rel="nofollow" title="Canvis recents a pàgines enllaçades des d&#039;aquesta pàgina [k]" accesskey="k"><span>Canvis relacionats</span></a></li><li id="t-specialpages" class="mw-list-item"><a href="/wiki/Especial:P%C3%A0gines_especials" title="Llista totes les pàgines especials [q]" accesskey="q"><span>Pàgines especials</span></a></li><li id="t-permalink" class="mw-list-item"><a href="/w/index.php?title=Arbre_binari&amp;oldid=33790776" title="Enllaç permanent a aquesta revisió de la pàgina"><span>Enllaç permanent</span></a></li><li id="t-info" class="mw-list-item"><a href="/w/index.php?title=Arbre_binari&amp;action=info" title="Més informació sobre aquesta pàgina"><span>Informació de la pàgina</span></a></li><li id="t-cite" class="mw-list-item"><a href="/w/index.php?title=Especial:Citau&amp;page=Arbre_binari&amp;id=33790776&amp;wpFormIdentifier=titleform" title="Informació sobre com citar aquesta pàgina"><span>Citau aquest article</span></a></li><li id="t-urlshortener" class="mw-list-item"><a href="/w/index.php?title=Especial:UrlShortener&amp;url=https%3A%2F%2Fca.wikipedia.org%2Fwiki%2FArbre_binari"><span>Obtén una URL abreujada</span></a></li><li id="t-urlshortener-qrcode" class="mw-list-item"><a href="/w/index.php?title=Especial:QrCode&amp;url=https%3A%2F%2Fca.wikipedia.org%2Fwiki%2FArbre_binari"><span>Descarrega el codi QR</span></a></li> </ul> </div> </div> <div id="p-coll-print_export" class="vector-menu mw-portlet mw-portlet-coll-print_export" > <div class="vector-menu-heading"> Imprimeix/exporta </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="coll-create_a_book" class="mw-list-item"><a href="/w/index.php?title=Especial:Llibre&amp;bookcmd=book_creator&amp;referer=Arbre+binari"><span>Crea un llibre</span></a></li><li id="coll-download-as-rl" class="mw-list-item"><a href="/w/index.php?title=Especial:DownloadAsPdf&amp;page=Arbre_binari&amp;action=show-download-screen"><span>Baixa com a PDF</span></a></li><li id="t-print" class="mw-list-item"><a href="/w/index.php?title=Arbre_binari&amp;printable=yes" title="Versió per a impressió d&#039;aquesta pàgina [p]" accesskey="p"><span>Versió per a impressora</span></a></li> </ul> </div> </div> <div id="p-wikibase-otherprojects" class="vector-menu mw-portlet mw-portlet-wikibase-otherprojects" > <div class="vector-menu-heading"> En altres projectes </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li class="wb-otherproject-link wb-otherproject-commons mw-list-item"><a href="https://commons.wikimedia.org/wiki/Category:Binary_trees" hreflang="en"><span>Commons</span></a></li><li id="t-wikibase" class="wb-otherproject-link wb-otherproject-wikibase-dataitem mw-list-item"><a href="https://www.wikidata.org/wiki/Special:EntityPage/Q380172" title="Enllaç a l&#039;element del repositori de dades connectat [g]" accesskey="g"><span>Element a Wikidata</span></a></li> </ul> </div> </div> </div> </div> </div> </div> </nav> </div> </div> </div> <div class="vector-column-end"> <div class="vector-sticky-pinned-container"> <nav class="vector-page-tools-landmark" aria-label="Eines de la pàgina"> <div id="vector-page-tools-pinned-container" class="vector-pinned-container"> </div> </nav> <nav class="vector-appearance-landmark" aria-label="Aparença"> <div id="vector-appearance-pinned-container" class="vector-pinned-container"> <div id="vector-appearance" class="vector-appearance vector-pinnable-element"> <div class="vector-pinnable-header vector-appearance-pinnable-header vector-pinnable-header-pinned" data-feature-name="appearance-pinned" data-pinnable-element-id="vector-appearance" data-pinned-container-id="vector-appearance-pinned-container" data-unpinned-container-id="vector-appearance-unpinned-container" > <div class="vector-pinnable-header-label">Aparença</div> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-appearance.pin">mou a la barra lateral</button> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-appearance.unpin">amaga</button> </div> </div> </div> </nav> </div> </div> <div id="bodyContent" class="vector-body" aria-labelledby="firstHeading" data-mw-ve-target-container> <div class="vector-body-before-content"> <div class="mw-indicators"> </div> <div id="siteSub" class="noprint">De la Viquipèdia, l&#039;enciclopèdia lliure</div> </div> <div id="contentSub"><div id="mw-content-subtitle"></div></div> <div id="mw-content-text" class="mw-body-content"><div class="mw-content-ltr mw-parser-output" lang="ca" dir="ltr"><p>En <a href="/wiki/Ci%C3%A8ncies_de_la_computaci%C3%B3" title="Ciències de la computació">ciències de la computació</a>, un <b>arbre binari</b> és una <a href="/wiki/Estructura_de_dades" title="Estructura de dades">estructura de dades</a> en la qual cada node sempre té un fill esquerre i un fill dret. No poden tenir més de dos fills (d'ací el nom "binari"). Si algun fill té com a referència <b>null</b>, és a dir que no emmagatzema cap dada, llavors aquest és dit un node extern. En el cas contrari, el fill és dit un node intern. </p><p>Usos comuns dels arbres binaris són els <a href="/wiki/Arbre_binari_de_cerca" title="Arbre binari de cerca">arbres binaris de cerca</a>, els <a href="/wiki/Monticle_binari" title="Monticle binari">monticles binaris</a> i la <a href="/wiki/Codificaci%C3%B3_de_Huffman" title="Codificació de Huffman">codificació de Huffman</a>. </p> <meta property="mw:PageProp/toc" /> <div class="mw-heading mw-heading2"><h2 id="Definició_de_teoria_de_grafs"><span id="Definici.C3.B3_de_teoria_de_grafs"></span>Definició de teoria de grafs</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Arbre_binari&amp;action=edit&amp;section=1" title="Modifica la secció: Definició de teoria de grafs"><span>modifica</span></a><span class="mw-editsection-bracket">]</span></span></div> <figure class="mw-default-size" typeof="mw:File/Thumb"><a href="/wiki/Fitxer:Binary_tree_(oriented_digraph).png" class="mw-file-description"><img src="//upload.wikimedia.org/wikipedia/commons/thumb/3/36/Binary_tree_%28oriented_digraph%29.png/220px-Binary_tree_%28oriented_digraph%29.png" decoding="async" width="220" height="194" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/commons/3/36/Binary_tree_%28oriented_digraph%29.png 1.5x" data-file-width="260" data-file-height="229" /></a><figcaption>Un arbre binari senzill de grandària 9 i altura 3, amb un node arrel el valor de la qual és 2</figcaption></figure> <p>En la <a href="/wiki/Teoria_de_grafs" title="Teoria de grafs">teoria de grafs</a>, s'usa la següent definició: «Un arbre binari és un graf connex, acíclic i no dirigit tal que el grau de cada vèrtex no és major a 3». D'aquesta forma només existeix un camí entre un parell de nodes.<sup id="cite_ref-Knuth1997_1-0" class="reference"><a href="#cite_note-Knuth1997-1"><span class="cite-bracket">&#91;</span>1<span class="cite-bracket">&#93;</span></a></sup> </p><p>Un arbre binari amb arrelat és com un graf que té un dels seus vèrtexs, dit <i>arrel</i>, de grau no major a 2.<sup id="cite_ref-2" class="reference"><a href="#cite_note-2"><span class="cite-bracket">&#91;</span>2<span class="cite-bracket">&#93;</span></a></sup> Amb l'arrel escollida, cada vèrtex tindrà un únic pare, i mai més de dos fills.<sup id="cite_ref-HsuLin2008_3-0" class="reference"><a href="#cite_note-HsuLin2008-3"><span class="cite-bracket">&#91;</span>3<span class="cite-bracket">&#93;</span></a></sup> Si refusem el requeriment de la connectivitat, permetent múltiples components connectats en el graf, anomenarem a aquesta última estructura un <i>bosc</i>.<sup id="cite_ref-Mazur2010_4-0" class="reference"><a href="#cite_note-Mazur2010-4"><span class="cite-bracket">&#91;</span>4<span class="cite-bracket">&#93;</span></a></sup> </p> <div class="mw-heading mw-heading2"><h2 id="Tipus_d'arbres_binaris"><span id="Tipus_d.27arbres_binaris"></span>Tipus d'arbres binaris</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Arbre_binari&amp;action=edit&amp;section=2" title="Modifica la secció: Tipus d&#039;arbres binaris"><span>modifica</span></a><span class="mw-editsection-bracket">]</span></span></div> <ul><li>Un <b>arbre binari</b> és un arbre <b>amb arrel</b> en la qual cada node té com a màxim dos fills.</li> <li>Un <b>arbre binari ple</b> és un arbre en el qual cada node té zero o dos fills.<sup id="cite_ref-5" class="reference"><a href="#cite_note-5"><span class="cite-bracket">&#91;</span>5<span class="cite-bracket">&#93;</span></a></sup><sup id="cite_ref-Rosen2011_6-0" class="reference"><a href="#cite_note-Rosen2011-6"><span class="cite-bracket">&#91;</span>6<span class="cite-bracket">&#93;</span></a></sup></li> <li>Un <b>arbre binari perfecte</b> és un arbre binari ple en el qual totes les <b>fulles</b> (vèrtex amb zero fills) estan a la mateixa profunditat (distància des de l&#39;<b>arrel</b>, també dita <b>altura</b>).<sup id="cite_ref-7" class="reference"><a href="#cite_note-7"><span class="cite-bracket">&#91;</span>7<span class="cite-bracket">&#93;</span></a></sup></li> <li>De vegades un arbre binari perfecte és denominat <b>arbre binari complet</b>.<sup id="cite_ref-complete_binary_tree_8-0" class="reference"><a href="#cite_note-complete_binary_tree-8"><span class="cite-bracket">&#91;</span>8<span class="cite-bracket">&#93;</span></a></sup> Uns altres defineixen un arbre <b>binari complet</b> com un arbre binari ple en el qual totes les fulles estan a profunditat <i>n</i> o <i>n-1</i>, per a alguna <i>n</i>.</li></ul> <p>Un <b>arbre binari</b> és un arbre en el qual cap node pot tenir més de dos subarbres. En un arbre binari cada node pot tenir zero, un o dos fills (subarbres). Es coneix el node de l'esquerra com a fill esquerre i el node de la dreta com a fill dret. </p> <div class="mw-heading mw-heading2"><h2 id="Implementació_en_C"><span id="Implementaci.C3.B3_en_C"></span>Implementació en C</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Arbre_binari&amp;action=edit&amp;section=3" title="Modifica la secció: Implementació en C"><span>modifica</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Un arbre binari pot declarar-se de diverses maneres. Algunes d'elles són: </p><p>Estructura amb maneig de memòria dinàmica, sent <i>t</i> el punter que apunta a l'arbre de tipus <i>tTree</i>: </p> <div class="mw-highlight mw-highlight-lang-c mw-content-ltr" dir="ltr"><pre><span></span><span class="k">typedef</span><span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="nc">tTree</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">key</span><span class="p">;</span> <span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="nc">tTree</span><span class="w"> </span><span class="o">*</span><span class="n">hLeft</span><span class="p">,</span><span class="w"> </span><span class="o">*</span><span class="n">hRight</span><span class="p">;</span> <span class="p">}</span><span class="w"> </span><span class="n">tTree</span><span class="p">;</span> <span class="k">typedef</span><span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="nc">tTree</span><span class="w"> </span><span class="o">*</span><span class="n">t</span><span class="p">;</span> </pre></div> <p>Estructura amb un <a href="/wiki/Vector_(programaci%C3%B3)" title="Vector (programació)">vector</a> indexat: </p> <div class="mw-highlight mw-highlight-lang-c mw-content-ltr" dir="ltr"><pre><span></span><span class="k">typedef</span><span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="nc">tTree</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">key</span><span class="p">;</span> <span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">hLeft</span><span class="p">,</span><span class="w"> </span><span class="n">hRight</span><span class="p">;</span> <span class="p">};</span> <span class="n">tTree</span><span class="w"> </span><span class="n">tree</span><span class="p">[</span><span class="n">NUMBER_OF_NODES</span><span class="p">];</span> </pre></div> <p>En el cas d'un arbre binari quasi-complet (o un arbre complet), pot utilitzar-se un senzill arranjament d'enters amb tantes posicions com nodes haja de tenir l'arbre. La informació de la ubicació del node en l'arbre és implícita a cada posició de l'arranjament. Així, si un node està en la posició <i>*i</i>, els seus fills es troben en les posicions 2<i>i</i>+1 i 2<i>i</i>+2, mentre que el seu pare (si en té), es troba en la posició <a href="/wiki/Truncament" title="Truncament">truncament</a> ((<i>i</i>-1)/2) (suposant que l'arrel està en la posició zero). Aquest mètode es beneficia d'un emmagatzematge més compacte i una millor localitat de referència, particularment durant un recorregut en preordre. L'estructura per a aquest cas seria per tant: </p> <div class="mw-highlight mw-highlight-lang-c mw-content-ltr" dir="ltr"><pre><span></span><span class="kt">int</span><span class="w"> </span><span class="n">tree</span><span class="p">[</span><span class="n">NUMBER_OF_NODES</span><span class="p">];</span> </pre></div> <div class="mw-heading mw-heading2"><h2 id="Recorreguts_sobre_arbres_binaris">Recorreguts sobre arbres binaris</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Arbre_binari&amp;action=edit&amp;section=4" title="Modifica la secció: Recorreguts sobre arbres binaris"><span>modifica</span></a><span class="mw-editsection-bracket">]</span></span></div> <div class="mw-heading mw-heading3"><h3 id="Recorreguts_en_profunditat">Recorreguts en profunditat</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Arbre_binari&amp;action=edit&amp;section=5" title="Modifica la secció: Recorreguts en profunditat"><span>modifica</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>El mètode d'aquest recorregut és tractar de trobar de la capçalera a l'arrel en node d'unitat binària Ara passem a veure la implementació dels diferents recorreguts: </p> <div class="mw-heading mw-heading4"><h4 id="Recorregut_en_preordre">Recorregut en preordre</h4><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Arbre_binari&amp;action=edit&amp;section=6" title="Modifica la secció: Recorregut en preordre"><span>modifica</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>En aquest tipus de recorregut es realitza certa acció (potser simplement imprimir per pantalla el valor de la clau d'eixe node) sobre el node actual i posteriorment es tracta el subarbre esquerre i quan s'haja conclòs, el subarbre dret. En l'arbre de la figura el recorregut en preordre seria: 2, 7, 2, 6, 5, 11, 5, 9 i 4. </p> <div class="mw-highlight mw-highlight-lang-c mw-content-ltr" dir="ltr"><pre><span></span><span class="kt">void</span><span class="w"> </span><span class="nf">preorder</span><span class="p">(</span><span class="n">tTree</span><span class="w"> </span><span class="o">*</span><span class="n">a</span><span class="p">)</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">a</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="nb">NULL</span><span class="p">)</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="n">treat</span><span class="p">(</span><span class="n">a</span><span class="p">);</span><span class="w"> </span><span class="c1">// Realitza una operació al node a</span> <span class="w"> </span><span class="n">preorder</span><span class="p">(</span><span class="n">a</span><span class="o">-&gt;</span><span class="n">hLeft</span><span class="p">);</span> <span class="w"> </span><span class="n">preorder</span><span class="p">(</span><span class="n">a</span><span class="o">-&gt;</span><span class="n">hRight</span><span class="p">);</span> <span class="w"> </span><span class="p">}</span> <span class="p">}</span> </pre></div> <p>Implementació en pseudocodi de forma iterativa: </p> <pre>push(s, NULL); // Inserim en una pila (stack) el valor NULL, per a assegurar-nos que estiga buida push(s, root); // Inserim el node arrel MENTRE (s &lt;&gt; NULL) FER p = pop(s); // Traiem un element de la pila treat(p); // Realitzem operacions sobre el node p SI (I(p) &lt;&gt; NULL) LLAVORS push(s, D(p)); // Si p té arbre dret SI (D(p) &lt;&gt; NULL) LLAVORS push(s, I(p)); // Si p té arbre esquerre FI_MENTRE </pre> <div class="mw-heading mw-heading4"><h4 id="Recorregut_en_postordre">Recorregut en postordre</h4><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Arbre_binari&amp;action=edit&amp;section=7" title="Modifica la secció: Recorregut en postordre"><span>modifica</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>En aquest cas es tracta primer el subarbre esquerre, després el dret i finalment el node actual. En l'arbre de la figura el recorregut en postordre seria: 2, 5, 11, 6, 7, 4, 9, 5 i 2. </p> <div class="mw-highlight mw-highlight-lang-c mw-content-ltr" dir="ltr"><pre><span></span><span class="kt">void</span><span class="w"> </span><span class="nf">postorder</span><span class="p">(</span><span class="n">tTree</span><span class="w"> </span><span class="o">*</span><span class="n">a</span><span class="p">)</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">a</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="nb">NULL</span><span class="p">)</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="n">postorder</span><span class="p">(</span><span class="n">a</span><span class="o">-&gt;</span><span class="n">hLeft</span><span class="p">);</span> <span class="w"> </span><span class="n">postorder</span><span class="p">(</span><span class="n">a</span><span class="o">-&gt;</span><span class="n">hRight</span><span class="p">);</span> <span class="w"> </span><span class="n">treat</span><span class="p">(</span><span class="n">a</span><span class="p">);</span><span class="w"> </span><span class="c1">// Realitza una operació al node a</span> <span class="w"> </span><span class="p">}</span> <span class="p">}</span> </pre></div> <div class="mw-heading mw-heading4"><h4 id="Recorregut_en_inordre">Recorregut en inordre</h4><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Arbre_binari&amp;action=edit&amp;section=8" title="Modifica la secció: Recorregut en inordre"><span>modifica</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>En aquest cas es tracta primer el subarbre esquerre, seguit del node actual i finalment el subarbre dret. En un arbre binari de cerca, aquest recorregut donaria els valors clau dels nodes ordenats de menor a major. A l'arbre de la figura, la seqüència de nodes visitats mitjançant aquest recorregut és la següent: 2, 7, 5, 6, 11, 2, 5, 4 i 9. </p> <div class="mw-highlight mw-highlight-lang-c mw-content-ltr" dir="ltr"><pre><span></span><span class="kt">void</span><span class="w"> </span><span class="nf">inorder</span><span class="p">(</span><span class="n">tTree</span><span class="w"> </span><span class="o">*</span><span class="n">a</span><span class="p">)</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">a</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="nb">NULL</span><span class="p">)</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="n">inorder</span><span class="p">(</span><span class="n">a</span><span class="o">-&gt;</span><span class="n">hLeft</span><span class="p">);</span> <span class="w"> </span><span class="n">treat</span><span class="p">(</span><span class="n">a</span><span class="p">);</span><span class="w"> </span><span class="c1">// Realitza una operació al node a</span> <span class="w"> </span><span class="n">inorder</span><span class="p">(</span><span class="n">a</span><span class="o">-&gt;</span><span class="n">hRight</span><span class="p">);</span> <span class="w"> </span><span class="p">}</span> <span class="p">}</span> </pre></div> <div class="mw-heading mw-heading3"><h3 id="Recorreguts_en_amplitud_(o_per_nivells)"><span id="Recorreguts_en_amplitud_.28o_per_nivells.29"></span>Recorreguts en amplitud (o per nivells)</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Arbre_binari&amp;action=edit&amp;section=9" title="Modifica la secció: Recorreguts en amplitud (o per nivells)"><span>modifica</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>En aquest cas el recorregut es realitza en ordre pels diferents nivells de l'arbre. Així, es començaria tractant el nivell 1, que només conté el node arrel, seguidament el nivell 2, el 3 i així successivament. En l'arbre de la figura el recorregut en amplitud seria: 2, 7, 5, 2, 6, 9, 5, 11 i 4. </p><p>Al contrari que en els mètodes de recorregut en profunditat, el recorregut per nivells no és de naturalesa recursiva. Per això, s'ha d'utilitzar una cua per a recordar els subarbres esquerres i dret de cada node. </p><p>Pseudocodi: </p> <pre>enqueue(root); MENTRE queue_no_buida() FER node = dequeue(); // Treure el node de la cua treat(node); // Realitza una operació al node enqueue_descendents(node); // Fica a la cua els fills del node actual FI_MENTRE</pre> <p>Implementació en C: </p> <div class="mw-highlight mw-highlight-lang-c mw-content-ltr" dir="ltr"><pre><span></span><span class="kt">void</span><span class="w"> </span><span class="nf">amplitude</span><span class="p">(</span><span class="n">tTree</span><span class="w"> </span><span class="o">*</span><span class="n">a</span><span class="p">)</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="n">tQueue</span><span class="w"> </span><span class="n">queue</span><span class="p">;</span> <span class="w"> </span><span class="n">tTree</span><span class="w"> </span><span class="o">*</span><span class="n">aux</span><span class="p">;</span> <span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">a</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="nb">NULL</span><span class="p">)</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="n">createQueue</span><span class="p">(</span><span class="n">queue</span><span class="p">);</span> <span class="w"> </span><span class="n">enqueue</span><span class="p">(</span><span class="n">queue</span><span class="p">,</span><span class="w"> </span><span class="n">a</span><span class="p">);</span> <span class="w"> </span><span class="k">while</span><span class="w"> </span><span class="p">(</span><span class="o">!</span><span class="n">emptyQueue</span><span class="p">(</span><span class="n">queue</span><span class="p">))</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="n">dequeue</span><span class="p">(</span><span class="n">queue</span><span class="p">,</span><span class="w"> </span><span class="n">aux</span><span class="p">);</span> <span class="w"> </span><span class="n">treat</span><span class="p">(</span><span class="n">aux</span><span class="p">)</span><span class="w"> </span><span class="c1">// Realitza una operació al node</span> <span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">aux</span><span class="o">-&gt;</span><span class="n">hLeft</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="nb">NULL</span><span class="p">)</span><span class="w"> </span><span class="n">enqueue</span><span class="p">(</span><span class="n">queue</span><span class="p">,</span><span class="w"> </span><span class="n">aux</span><span class="o">-&gt;</span><span class="n">hLeft</span><span class="p">);</span> <span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">aux</span><span class="o">-&gt;</span><span class="n">hRight</span><span class="o">!=</span><span class="w"> </span><span class="nb">NULL</span><span class="p">)</span><span class="w"> </span><span class="n">enqueue</span><span class="p">(</span><span class="n">queue</span><span class="p">,</span><span class="w"> </span><span class="n">aux</span><span class="o">-&gt;</span><span class="n">hRight</span><span class="p">);</span> <span class="w"> </span><span class="p">}</span> <span class="w"> </span><span class="p">}</span> <span class="p">}</span> </pre></div> <p>Per a fer un recorregut en amplària, la idea és anar guardant en una cua els fills del node que s'estan visitant i el següent a visitar és el pròxim node de la cua. </p> <div class="mw-heading mw-heading2"><h2 id="Mètodes_per_a_emmagatzemar_arbres_binaris"><span id="M.C3.A8todes_per_a_emmagatzemar_arbres_binaris"></span>Mètodes per a emmagatzemar arbres binaris</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Arbre_binari&amp;action=edit&amp;section=10" title="Modifica la secció: Mètodes per a emmagatzemar arbres binaris"><span>modifica</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Els arbres binaris poden ser construïts a partir de <a href="/wiki/Llenguatges_de_programaci%C3%B3" class="mw-redirect" title="Llenguatges de programació">llenguatges de programació</a> de diverses formes. En un llenguatge amb <a href="/w/index.php?title=Registres&amp;action=edit&amp;redlink=1" class="new" title="Registres (encara no existeix)">registres</a> i <a href="/w/index.php?title=Refer%C3%A8ncies&amp;action=edit&amp;redlink=1" class="new" title="Referències (encara no existeix)">referències</a>, els arbres binaris són construïts típicament amb una estructura de nodes i punters en la qual s'emmagatzemen dades, cadascun d'aquests nodes té una referència o punter a un node esquerre i a un node dret denominats fills. A vegades, també conté un punter a un únic node. Si un node té menys de dos fills, alguns dels punters dels fills poden ser definits com a nuls per a indicar que no disposa d'aquest node. En la figura adjunta es pot observar l'estructura d'aquesta implementació. </p><p>Els arbres binaris també poden ser emmagatzemats com una <a href="/w/index.php?title=Estructura_de_dades_impl%C3%ADcita&amp;action=edit&amp;redlink=1" class="new" title="Estructura de dades implícita (encara no existeix)">estructura de dades implícita</a> en <a href="/wiki/Vector_(programaci%C3%B3)" title="Vector (programació)">vectors</a>, i si l'arbre és un arbre binari complet, aquest mètode no desaprofita l'espai en memòria. Prendrem com a notació la següent: si un node té un índex i, els seus fills es troben en índexs 2*i + 1 i 2*i + 2, mentre que els seus pares (si els té) es troba en l'índex <span class="mwe-math-element"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \left\lfloor {\frac {i-1}{2}}\right\rfloor }"> <semantics> <mrow class="MJX-TeXAtom-ORD"> <mstyle displaystyle="true" scriptlevel="0"> <mrow> <mo>&#x230A;</mo> <mrow class="MJX-TeXAtom-ORD"> <mfrac> <mrow> <mi>i</mi> <mo>&#x2212;<!-- − --></mo> <mn>1</mn> </mrow> <mn>2</mn> </mfrac> </mrow> <mo>&#x230B;</mo> </mrow> </mstyle> </mrow> <annotation encoding="application/x-tex">{\displaystyle \left\lfloor {\frac {i-1}{2}}\right\rfloor }</annotation> </semantics> </math></span><img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/35dc2d601bbd9aff8f1ed1c4b2323122f2403317" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -2.505ex; width:8.352ex; height:6.176ex;" alt="{\displaystyle \left\lfloor {\frac {i-1}{2}}\right\rfloor }"></span>(partint que l'arrel tinga índex zero). Aquest mètode té com a avantatges el tenir emmagatzemats les dades de forma més compacta i per tenir una forma més ràpida i eficient de localitzar les dades en particular durant un preordre transversal. No obstant això, balafia molt espai en memòria. </p> <center> <p><span class="mw-default-size" typeof="mw:File"><a href="/wiki/Fitxer:Lista_nodos.JPG" class="mw-file-description" title="Llista de nodes"><img alt="Llista de nodes" src="//upload.wikimedia.org/wikipedia/commons/2/26/Lista_nodos.JPG" decoding="async" width="300" height="75" class="mw-file-element" data-file-width="300" data-file-height="75" /></a></span> </p> </center> <div class="mw-heading mw-heading2"><h2 id="Codificació_d'arbres_n-aris_com_a_arbres_binaris"><span id="Codificaci.C3.B3_d.27arbres_n-aris_com_a_arbres_binaris"></span>Codificació d'arbres n-aris com a arbres binaris</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Arbre_binari&amp;action=edit&amp;section=11" title="Modifica la secció: Codificació d&#039;arbres n-aris com a arbres binaris"><span>modifica</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Hi ha un mapeig d'un a un entre els arbres generals i arbres binaris, el qual en particular és usat en <a href="/wiki/Lisp" title="Lisp">Lisp</a> per a representar arbres generals com a arbres binaris. Cada node N ordenat en l'arbre correspon a un node N 'en l'arbre binari; el fill de l'esquerra de’ N és el node corresponent al primer fill de N, i el fill dret de N' és el node corresponent al següent germà de N, és a dir, el pròxim node en ordre entre els fills dels pares de N. </p><p>Aquesta representació com a arbre binari d'un arbre general, es coneix de vegades com un arbre binari primer fill germà, o un arbre doblement encadenat. </p><p>Una manera de pensar sobre açò és que els fills de cada node estiguen en una llista enllaçada, encadenats juntament amb el camp dret, i el node només té un punter al començament o el cap d'aquesta llista, a través del seu camp esquerre. </p><p>Per exemple, en l'arbre de l'esquerra, l'A té 6 fills (B, C, D, E, F, G). Pot ser convertit en l'arbre binari de la dreta. </p><p>Un exemple de transformar l'arbre n-ari a un arbre binari Com passar d'arbres n-aris a arbres FLOFO. </p><p>L'arbre binari pot ser pensat com l'arbre original inclinat cap als costats, amb les vores negres esquerres representant el primer fill i els blaus representat els següents germans. </p><p>Les fulles de l'arbre de l'esquerra serien escrites en Lisp com: </p> <pre>(((M N) H I) C D ((O) (P)) F (L)) </pre> <p>Que s'executarà en la memòria com l'arbre binari de la dreta, sense cap mena de lletres en aquells nodes que tenen un fill esquerre. </p> <div class="mw-heading mw-heading2"><h2 id="Vegeu_també"><span id="Vegeu_tamb.C3.A9"></span>Vegeu també</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Arbre_binari&amp;action=edit&amp;section=12" title="Modifica la secció: Vegeu també"><span>modifica</span></a><span class="mw-editsection-bracket">]</span></span></div> <ul><li><a href="/wiki/Arbre_(estructura_de_dades)" title="Arbre (estructura de dades)">Arbre (estructura de dades)</a></li> <li><a href="/wiki/Arbre_multibranca" class="mw-redirect" title="Arbre multibranca">Arbre multibranca</a></li> <li><a href="/wiki/Arbre_binari_de_cerca" title="Arbre binari de cerca">Arbre binari de cerca</a></li> <li><a href="/wiki/Arbre_de_Fibonacci" title="Arbre de Fibonacci">Arbre de Fibonacci</a></li> <li><a href="/w/index.php?title=Partici%C3%B3_d%27espai_binari&amp;action=edit&amp;redlink=1" class="new" title="Partició d&#39;espai binari (encara no existeix)">Partició d'espai binari</a></li></ul> <div class="mw-heading mw-heading2"><h2 id="Referències"><span id="Refer.C3.A8ncies"></span>Referències</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Arbre_binari&amp;action=edit&amp;section=13" title="Modifica la secció: Referències"><span>modifica</span></a><span class="mw-editsection-bracket">]</span></span></div> <div class="reflist &#123;&#123;#if: &#124; references-column-count references-column-count-&#123;&#123;&#123;col&#125;&#125;&#125;" style="list-style-type: decimal;"> <div class="mw-references-wrap"><ol class="references"> <li id="cite_note-Knuth1997-1"><span class="mw-cite-backlink"><a href="#cite_ref-Knuth1997_1-0">↑</a></span> <span class="reference-text"><span class="citation book" style="font-style:normal">Knuth. <i>The Art Of Computer Programming, Volume 1, 3/E</i>.&#32; Pearson Education,&#32;1997,&#32;p.&#160;363. <span style="font-size:90%; white-space:nowrap;"><a href="/wiki/Especial:Fonts_bibliogr%C3%A0fiques/0-201-89683-4" title="Especial:Fonts bibliogràfiques/0-201-89683-4">ISBN 0-201-89683-4</a></span>.</span><span class="Z3988" title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=book&amp;rft.btitle=The+Art+Of+Computer+Programming%2C+Volume+1%2C+3%2FE&amp;rft.au=Knuth&amp;rft.date=1997&amp;rft.pub=Pearson+Education&amp;rft.pages=363&amp;rft.isbn=0-201-89683-4"><span style="display: none;">&#160;</span></span></span> </li> <li id="cite_note-2"><span class="mw-cite-backlink"><a href="#cite_ref-2">↑</a></span> <span class="reference-text"><span class="citation book" style="font-style:normal">Kenneth Rosen. <i>Discrete Mathematics and Its Applications, 7th edition</i>.&#32; McGraw-Hill Science,&#32;2011,&#32;p.&#160;749. <span style="font-size:90%; white-space:nowrap;"><a href="/wiki/Especial:Fonts_bibliogr%C3%A0fiques/978-0-07-338309-5" title="Especial:Fonts bibliogràfiques/978-0-07-338309-5">ISBN 978-0-07-338309-5</a></span>.</span><span class="Z3988" title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=book&amp;rft.btitle=Discrete+Mathematics+and+Its+Applications%2C+7th+edition&amp;rft.au=Kenneth+Rosen&amp;rft.date=2011&amp;rft.pub=McGraw-Hill+Science&amp;rft.pages=749&amp;rft.isbn=978-0-07-338309-5"><span style="display: none;">&#160;</span></span></span> </li> <li id="cite_note-HsuLin2008-3"><span class="mw-cite-backlink"><a href="#cite_ref-HsuLin2008_3-0">↑</a></span> <span class="reference-text"><span class="citation book" style="font-style:normal">Lih-Hsing Hsu;&#32;Cheng-Kuan Lin <a rel="nofollow" class="external text" href="https://books.google.cat/books?id=vbxdqhDKOSYC&amp;pg=PA66"><i>Graph Theory and Interconnection Networks</i></a>.&#32; CRC Press,&#32;2008,&#32;p.&#160;66. <span style="font-size:90%; white-space:nowrap;"><a href="/wiki/Especial:Fonts_bibliogr%C3%A0fiques/978-1-4200-4482-9" title="Especial:Fonts bibliogràfiques/978-1-4200-4482-9">ISBN 978-1-4200-4482-9</a></span>.</span><span class="Z3988" title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=book&amp;rft.btitle=Graph+Theory+and+Interconnection+Networks&amp;rft.date=2008&amp;rft.pub=CRC+Press&amp;rft.pages=66&amp;rft.isbn=978-1-4200-4482-9&amp;rft_id=https%3A%2F%2Fbooks.google.cat%2Fbooks%3Fid%3DvbxdqhDKOSYC%26pg%3DPA66"><span style="display: none;">&#160;</span></span></span> </li> <li id="cite_note-Mazur2010-4"><span class="mw-cite-backlink"><a href="#cite_ref-Mazur2010_4-0">↑</a></span> <span class="reference-text"><span class="citation book" style="font-style:normal">David R. Mazur. <a rel="nofollow" class="external text" href="https://books.google.cat/books?id=yI4Jx5Obr08C&amp;pg=PA246"><i>Combinatorics: A Guided Tour</i></a>.&#32; Mathematical Association of America,&#32;2010,&#32;p.&#160;246. <span style="font-size:90%; white-space:nowrap;"><a href="/wiki/Especial:Fonts_bibliogr%C3%A0fiques/978-0-88385-762-5" title="Especial:Fonts bibliogràfiques/978-0-88385-762-5">ISBN 978-0-88385-762-5</a></span>.</span><span class="Z3988" title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=book&amp;rft.btitle=Combinatorics%3A+A+Guided+Tour&amp;rft.au=David+R.+Mazur&amp;rft.date=2010&amp;rft.pub=Mathematical+Association+of+America&amp;rft.pages=246&amp;rft.isbn=978-0-88385-762-5&amp;rft_id=https%3A%2F%2Fbooks.google.cat%2Fbooks%3Fid%3DyI4Jx5Obr08C%26pg%3DPA246"><span style="display: none;">&#160;</span></span></span> </li> <li id="cite_note-5"><span class="mw-cite-backlink"><a href="#cite_ref-5">↑</a></span> <span class="reference-text">Richard Stanley, Enumerative Combinatorics, volume 2, p.36</span> </li> <li id="cite_note-Rosen2011-6"><span class="mw-cite-backlink"><a href="#cite_ref-Rosen2011_6-0">↑</a></span> <span class="reference-text"><span class="citation book" style="font-style:normal">Kenneth Rosen. <i>Discrete Mathematics and Its Applications 7th edition</i>.&#32; McGraw-Hill Science,&#32;2011,&#32;p.&#160;352–353. <span style="font-size:90%; white-space:nowrap;"><a href="/wiki/Especial:Fonts_bibliogr%C3%A0fiques/978-0-07-338309-5" title="Especial:Fonts bibliogràfiques/978-0-07-338309-5">ISBN 978-0-07-338309-5</a></span>.</span><span class="Z3988" title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=book&amp;rft.btitle=Discrete+Mathematics+and+Its+Applications+7th+edition&amp;rft.au=Kenneth+Rosen&amp;rft.date=2011&amp;rft.pub=McGraw-Hill+Science&amp;rft.pages=352%E2%80%93353&amp;rft.isbn=978-0-07-338309-5"><span style="display: none;">&#160;</span></span></span> </li> <li id="cite_note-7"><span class="mw-cite-backlink"><a href="#cite_ref-7">↑</a></span> <span class="reference-text"><span class="citation" style="font-style:normal">«<a rel="nofollow" class="external text" href="https://xlinux.nist.gov/dads/HTML/perfectBinaryTree.html">perfect binary tree</a>».&#32; <a href="/wiki/NIST" class="mw-redirect" title="NIST">NIST</a>.</span></span> </li> <li id="cite_note-complete_binary_tree-8"><span class="mw-cite-backlink"><a href="#cite_ref-complete_binary_tree_8-0">↑</a></span> <span class="reference-text"><span class="citation" style="font-style:normal">«<a rel="nofollow" class="external text" href="https://xlinux.nist.gov/dads/HTML/completeBinaryTree.html">complete binary tree</a>».&#32; NIST.</span></span> </li> </ol></div></div> <div class="mw-heading mw-heading2"><h2 id="Bibliografia">Bibliografia</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Arbre_binari&amp;action=edit&amp;section=14" title="Modifica la secció: Bibliografia"><span>modifica</span></a><span class="mw-editsection-bracket">]</span></span></div> <ul><li><a href="/wiki/Donald_Knuth" title="Donald Knuth">Donald Knuth</a>. <i><a href="/wiki/The_Art_of_Computer_Programming" title="The Art of Computer Programming">The Art of Computer Programming</a> vol 1. Fundamental Algorithms</i>, Third Edition. Addison-Wesley, 1997. <a href="/wiki/Especial:Fonts_bibliogr%C3%A0fiques/0-201-89683-4" title="Especial:Fonts bibliogràfiques/0-201-89683-4">ISBN 0-201-89683-4</a>. Secció 2.3, especialment sub-seccions 2.3.1–2.3.2 (pp.&#160;318–348).</li></ul> <div class="mw-heading mw-heading2"><h2 id="Enllaços_externs"><span id="Enlla.C3.A7os_externs"></span>Enllaços externs</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Arbre_binari&amp;action=edit&amp;section=15" title="Modifica la secció: Enllaços externs"><span>modifica</span></a><span class="mw-editsection-bracket">]</span></span></div> <style data-mw-deduplicate="TemplateStyles:r33663753">.mw-parser-output .side-box{margin:4px 0;box-sizing:border-box;border:1px solid #aaa;font-size:88%;line-height:1.25em;background-color:#f9f9f9;display:flow-root}.mw-parser-output .side-box-abovebelow,.mw-parser-output .side-box-text{padding:0.25em 0.9em}.mw-parser-output .side-box-image{padding:2px 0 2px 0.9em;text-align:center}.mw-parser-output .side-box-imageright{padding:2px 0.9em 2px 0;text-align:center}@media(min-width:500px){.mw-parser-output .side-box-flex{display:flex;align-items:center}.mw-parser-output .side-box-text{flex:1;min-width:0}}@media(min-width:720px){.mw-parser-output .side-box{width:238px}.mw-parser-output .side-box-right{clear:right;float:right;margin-left:1em}.mw-parser-output .side-box-left{margin-right:1em}.mw-parser-output .side-box-center{clear:both;margin:auto}}</style><div class="side-box metadata side-box-right plainlinks"> <div class="side-box-flex"> <div class="side-box-image"><span typeof="mw:File"><span><img alt="" src="//upload.wikimedia.org/wikipedia/commons/thumb/4/4a/Commons-logo.svg/30px-Commons-logo.svg.png" decoding="async" width="30" height="40" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/4/4a/Commons-logo.svg/45px-Commons-logo.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/4/4a/Commons-logo.svg/59px-Commons-logo.svg.png 2x" data-file-width="1024" data-file-height="1376" /></span></span></div> <div class="side-box-text plainlist">A <span class="plainlinks"><a class="external text" href="https://commons.wikimedia.org/wiki/P%C3%A0gina_principal?uselang=ca">Wikimedia Commons</a></span> hi ha contingut multimèdia relatiu a: <i><b><a href="https://commons.wikimedia.org/wiki/Category:Binary_trees" class="extiw" title="commons:Category:Binary trees">Arbre binari</a></b></i></div></div> </div> <ul><li><a rel="nofollow" class="external text" href="http://cslibrary.stanford.edu/110/BinaryTrees.html">Definicions d'arbres binaris i implementacions en C i Java</a> <style data-mw-deduplicate="TemplateStyles:r33711417">.mw-parser-output .languageicon{font-size:0.95em;color:#555;background-color:inherit}@media screen{html.skin-theme-clientpref-night .mw-parser-output .languageicon{background-color:inherit;color:white}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .languageicon{background-color:inherit;color:white}}</style><span class="languageicon" title="En anglès">(anglès)</span></li> <li><a rel="nofollow" class="external text" href="http://mmengineer.blogspot.com/2007/10/aboles-binarios-de-busqueda-php.html">Arbre binari de recerca en PHP</a> <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r33711417"><span class="languageicon" title="En castellà">(castellà)</span></li> <li><a rel="nofollow" class="external text" href="http://www.brpreiss.com/books/opus4/html/page355.html">Demostració per inducció dels arbres binaris</a> <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r33711417"><span class="languageicon" title="En anglès">(anglès)</span></li> <li><a rel="nofollow" class="external text" href="http://piergiu.wordpress.com/2010/02/21/balanced-binary-search-tree-on-array/">Balanced binary search tree on array</a> Com crear de baix a dalt una llista d'Ahnentafel, o un arbre de cerca binari equilibrat <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r33711417"><span class="languageicon" title="En anglès">(anglès)</span></li> <li><a rel="nofollow" class="external text" href="http://www.cpphub.com/search/label/Binary%20trees">Binary trees and Implementation of the same with working code examples</a> <link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r33711417"><span class="languageicon" title="En anglès">(anglès)</span></li></ul> <p><span style="display: none;" class="interProject"><a href="https://ca.wiktionary.org/wiki/arbre_binari" class="extiw" title="wikt:arbre binari">Viccionari</a></span> </p> <div role="navigation" class="navbox" aria-label="Navbox" style="padding:3px"><table class="nowraplinks hlist navbox-inner" style="border-spacing:0;background:transparent;color:inherit"><tbody><tr><th scope="row" class="navbox-group" style="width:1%"><a href="/wiki/Control_d%27autoritats" title="Control d&#39;autoritats">Registres d'autoritat</a></th><td class="navbox-list navbox-odd" style="text-align:left;border-left-width:2px;border-left-style:solid;width:100%;padding:0px"><div style="padding:0em 0.25em"> <ul><li><a href="/wiki/Gemeinsame_Normdatei" title="Gemeinsame Normdatei">GND</a> <span class="uid"> (<a rel="nofollow" class="external text" href="http://d-nb.info/gnd/4145532-0">1</a>)</span></li></ul> </div></td></tr></tbody></table></div> <!-- NewPP limit report Parsed by mw‐web.eqiad.main‐7f58d5dcf5‐4bcl4 Cached time: 20241110225513 Cache expiry: 2592000 Reduced expiry: false Complications: [show‐toc] CPU time usage: 0.163 seconds Real time usage: 0.765 seconds Preprocessor visited node count: 2047/1000000 Post‐expand include size: 12051/2097152 bytes Template argument size: 2891/2097152 bytes Highest expansion depth: 12/100 Expensive parser function count: 7/500 Unstrip recursion depth: 0/20 Unstrip post‐expand size: 20770/5000000 bytes Lua time usage: 0.035/10.000 seconds Lua memory usage: 1094806/52428800 bytes Number of Wikibase entities loaded: 1/400 --> <!-- Transclusion expansion time report (%,ms,calls,template) 100.00% 691.563 1 -total 9.85% 68.101 1 Plantilla:Commonscat 8.80% 60.848 1 Plantilla:Sister 8.37% 57.860 1 Plantilla:Caixa_lateral 6.85% 47.344 1 Plantilla:Referències 4.03% 27.855 5 Plantilla:Ref-llibre 2.60% 17.998 1 Plantilla:ISBN 2.36% 16.293 1 Plantilla:Autoritat 1.11% 7.689 2 Plantilla:Ref-web 1.03% 7.103 4 Plantilla:En --> <!-- Saved in parser cache with key cawiki:pcache:idhash:557301-0!canonical and timestamp 20241110225513 and revision id 33790776. Rendering was triggered because: page-view --> </div><!--esi <esi:include src="/esitest-fa8a495983347898/content" /> --><noscript><img src="https://login.wikimedia.org/wiki/Special:CentralAutoLogin/start?type=1x1" alt="" width="1" height="1" style="border: none; position: absolute;"></noscript> <div class="printfooter" data-nosnippet="">Obtingut de «<a dir="ltr" href="https://ca.wikipedia.org/w/index.php?title=Arbre_binari&amp;oldid=33790776">https://ca.wikipedia.org/w/index.php?title=Arbre_binari&amp;oldid=33790776</a>»</div></div> <div id="catlinks" class="catlinks" data-mw="interface"><div id="mw-normal-catlinks" class="mw-normal-catlinks"><a href="/wiki/Especial:Categorias" title="Especial:Categorias">Categoria</a>: <ul><li><a href="/wiki/Categoria:Estructura_de_dades" title="Categoria:Estructura de dades">Estructura de dades</a></li></ul></div><div id="mw-hidden-catlinks" class="mw-hidden-catlinks mw-hidden-cats-hidden">Categories ocultes: <ul><li><a href="/wiki/Categoria:P%C3%A0gines_amb_enlla%C3%A7_commonscat_des_de_Wikidata" title="Categoria:Pàgines amb enllaç commonscat des de Wikidata">Pàgines amb enllaç commonscat des de Wikidata</a></li><li><a href="/wiki/Categoria:Control_d%27autoritats" title="Categoria:Control d&#039;autoritats">Control d'autoritats</a></li></ul></div></div> </div> </main> </div> <div class="mw-footer-container"> <footer id="footer" class="mw-footer" > <ul id="footer-info"> <li id="footer-info-lastmod"> La pàgina va ser modificada per darrera vegada el 17 ago 2024 a les 11:57.</li> <li id="footer-info-copyright">El text està disponible sota la <a href="/wiki/Viquip%C3%A8dia:Text_de_la_llic%C3%A8ncia_de_Creative_Commons_Reconeixement-Compartir_Igual_4.0_No_adaptada" title="Viquipèdia:Text de la llicència de Creative Commons Reconeixement-Compartir Igual 4.0 No adaptada"> Llicència de Creative Commons Reconeixement i Compartir-Igual</a>; es poden aplicar termes addicionals. Vegeu les <a class="external text" href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Terms_of_Use/ca">Condicions d'ús</a>. Wikipedia&#174; (Viquipèdia™) és una <a href="/wiki/Marca_comercial" title="Marca comercial">marca registrada</a> de <a rel="nofollow" class="external text" href="https://www.wikimediafoundation.org">Wikimedia Foundation, Inc</a>.<br /></li> </ul> <ul id="footer-places"> <li id="footer-places-privacy"><a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Privacy_policy">Política de privadesa</a></li> <li id="footer-places-about"><a href="/wiki/Viquip%C3%A8dia:Quant_a_la_Viquip%C3%A8dia">Quant al projecte Viquipèdia</a></li> <li id="footer-places-disclaimers"><a href="/wiki/Viquip%C3%A8dia:Av%C3%ADs_d%27exempci%C3%B3_de_responsabilitat">Descàrrec de responsabilitat</a></li> <li id="footer-places-wm-codeofconduct"><a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Universal_Code_of_Conduct">Codi de conducta</a></li> <li id="footer-places-developers"><a href="https://developer.wikimedia.org">Desenvolupadors</a></li> <li id="footer-places-statslink"><a href="https://stats.wikimedia.org/#/ca.wikipedia.org">Estadístiques</a></li> <li id="footer-places-cookiestatement"><a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Cookie_statement">Declaració de cookies</a></li> <li id="footer-places-mobileview"><a href="//ca.m.wikipedia.org/w/index.php?title=Arbre_binari&amp;mobileaction=toggle_view_mobile" class="noprint stopMobileRedirectToggle">Versió per a mòbils</a></li> </ul> <ul id="footer-icons" class="noprint"> <li id="footer-copyrightico"><a href="https://wikimediafoundation.org/" class="cdx-button cdx-button--fake-button cdx-button--size-large cdx-button--fake-button--enabled"><img src="/static/images/footer/wikimedia-button.svg" width="84" height="29" alt="Wikimedia Foundation" loading="lazy"></a></li> <li id="footer-poweredbyico"><a href="https://www.mediawiki.org/" class="cdx-button cdx-button--fake-button cdx-button--size-large cdx-button--fake-button--enabled"><img src="/w/resources/assets/poweredby_mediawiki.svg" alt="Powered by MediaWiki" width="88" height="31" loading="lazy"></a></li> </ul> </footer> </div> </div> </div> <div class="vector-settings" id="p-dock-bottom"> <ul></ul> </div><script>(RLQ=window.RLQ||[]).push(function(){mw.config.set({"wgHostname":"mw-web.codfw.main-f69cdc8f6-rt2p2","wgBackendResponseTime":165,"wgPageParseReport":{"limitreport":{"cputime":"0.163","walltime":"0.765","ppvisitednodes":{"value":2047,"limit":1000000},"postexpandincludesize":{"value":12051,"limit":2097152},"templateargumentsize":{"value":2891,"limit":2097152},"expansiondepth":{"value":12,"limit":100},"expensivefunctioncount":{"value":7,"limit":500},"unstrip-depth":{"value":0,"limit":20},"unstrip-size":{"value":20770,"limit":5000000},"entityaccesscount":{"value":1,"limit":400},"timingprofile":["100.00% 691.563 1 -total"," 9.85% 68.101 1 Plantilla:Commonscat"," 8.80% 60.848 1 Plantilla:Sister"," 8.37% 57.860 1 Plantilla:Caixa_lateral"," 6.85% 47.344 1 Plantilla:Referències"," 4.03% 27.855 5 Plantilla:Ref-llibre"," 2.60% 17.998 1 Plantilla:ISBN"," 2.36% 16.293 1 Plantilla:Autoritat"," 1.11% 7.689 2 Plantilla:Ref-web"," 1.03% 7.103 4 Plantilla:En"]},"scribunto":{"limitreport-timeusage":{"value":"0.035","limit":"10.000"},"limitreport-memusage":{"value":1094806,"limit":52428800}},"cachereport":{"origin":"mw-web.eqiad.main-7f58d5dcf5-4bcl4","timestamp":"20241110225513","ttl":2592000,"transientcontent":false}}});});</script> <script type="application/ld+json">{"@context":"https:\/\/schema.org","@type":"Article","name":"Arbre binari","url":"https:\/\/ca.wikipedia.org\/wiki\/Arbre_binari","sameAs":"http:\/\/www.wikidata.org\/entity\/Q380172","mainEntity":"http:\/\/www.wikidata.org\/entity\/Q380172","author":{"@type":"Organization","name":"Contributors to Wikimedia projects"},"publisher":{"@type":"Organization","name":"Wikimedia Foundation, Inc.","logo":{"@type":"ImageObject","url":"https:\/\/www.wikimedia.org\/static\/images\/wmf-hor-googpub.png"}},"datePublished":"2009-11-21T00:49:24Z","dateModified":"2024-08-17T10:57:11Z"}</script> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10