[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"doc-seo-670909-105":3,"detail-sidebar-cat-0-en-105":80,"doc-detail-670909-en":130},{"code":4,"msg":5,"data":6},0,"ok",{"site_id":7,"language":8,"slug":9,"title":10,"keywords":11,"description":12,"schema_data":13,"social_meta":73,"head_meta":75,"extra_data":77,"updated_unix":79},105,"en","chapter-20-trees-binary-trees","Chapter 20 - Trees - Binary Trees","","Chapter 20 focuses on non-linear hierarchical data structures, introducing tree terminology and practical uses. It explains how trees differ from linear structures, defines root, parent, children, siblings, levels, height, leaves, internal nodes, subtrees, and empty trees using computer-science drawing conventions. The chapter then presents binary trees and their properties, including traversal for expression evaluation. Finally, it covers Binary Search Trees, specifying ordering rules and describing how searching navigates left and right subtrees to locate a target key.",{"@graph":14,"@context":72},[15,34,55],{"@type":16,"itemListElement":17},"BreadcrumbList",[18,23,27,31],{"item":19,"name":20,"@type":21,"position":22},"https://docshare.wps.com","Home","ListItem",1,{"item":24,"name":25,"@type":21,"position":26},"https://docshare.wps.com/document/","Document",2,{"item":28,"name":29,"@type":21,"position":30},"https://docshare.wps.com/document/technology/","Technology",3,{"item":32,"name":10,"@type":21,"position":33},"https://docshare.wps.com/document/chapter-20-trees-binary-trees/670909/",4,{"url":32,"name":10,"@type":35,"image":36,"author":41,"headline":10,"publisher":44,"fileFormat":47,"inLanguage":8,"description":12,"dateModified":48,"datePublished":49,"encodingFormat":47,"isAccessibleForFree":50,"interactionStatistic":51},"DigitalDocument",{"url":37,"@type":38,"width":39,"height":40},"https://docshare.wps.com/thumbnails/chapter-20-trees-binary-trees/670909.png","ImageObject",300,407,{"name":42,"@type":43},"Chumphorn","Person",{"url":19,"name":45,"@type":46},"DocShare","Organization","application/pdf","2026-11-02","2026-11-01",true,{"@type":52,"interactionType":53,"userInteractionCount":22},"InteractionCounter",{"@type":54},"ViewAction",{"@type":56,"mainEntity":57},"FAQPage",[58,64,68],{"name":59,"@type":60,"acceptedAnswer":61},"What distinguishes trees from linear data structures like arrays and linked lists?","Question",{"text":62,"@type":63},"In a tree, nodes may have more than one successor, reflecting a hierarchical structure rather than a single predecessor-successor chain.","Answer",{"name":65,"@type":60,"acceptedAnswer":66},"How are root, leaves, internal nodes, and levels defined in a tree?",{"text":67,"@type":63},"The root is the unique node without a parent; leaves are nodes with no children; internal nodes are all other nodes. A node’s level is the number of edges from the root.",{"name":69,"@type":60,"acceptedAnswer":70},"What ordering property defines a Binary Search Tree?",{"text":71,"@type":63},"For each node, all values in the left subtree are less than the node’s value, and all values in the right subtree are greater. This ordering holds recursively for every subtree.","https://schema.org",{"og:url":32,"og:type":74,"og:title":10,"og:site_name":45,"og:description":12},"article",{"robots":76,"canonical":32},"index,follow",{"doc_id":78,"site_id":7},670909,1793572670,{"code":4,"msg":81,"data":82},"success",[83,87,91,95,100,104,109,114,119,122,126],{"id":22,"doc_module":4,"doc_module_name":25,"category_name":84,"show_sort_weight":85,"slug":86},"Story & Novel",90,"story-novel",{"id":26,"doc_module":4,"doc_module_name":25,"category_name":88,"show_sort_weight":89,"slug":90},"Literature",80,"literature",{"id":33,"doc_module":4,"doc_module_name":25,"category_name":92,"show_sort_weight":93,"slug":94},"Exam",70,"exam",{"id":96,"doc_module":4,"doc_module_name":25,"category_name":97,"show_sort_weight":98,"slug":99},5,"Comic",60,"comic",{"id":101,"doc_module":4,"doc_module_name":25,"category_name":29,"show_sort_weight":102,"slug":103},6,50,"technology",{"id":105,"doc_module":4,"doc_module_name":25,"category_name":106,"show_sort_weight":107,"slug":108},7,"Healthcare",40,"healthcare",{"id":110,"doc_module":4,"doc_module_name":25,"category_name":111,"show_sort_weight":112,"slug":113},8,"Research & Report",30,"research-report",{"id":115,"doc_module":4,"doc_module_name":25,"category_name":116,"show_sort_weight":117,"slug":118},9,"Religion & Spirituality",20,"religion-spirituality",{"id":117,"doc_module":4,"doc_module_name":25,"category_name":120,"show_sort_weight":117,"slug":121},"World Cup","world-cup",{"id":123,"doc_module":4,"doc_module_name":25,"category_name":124,"show_sort_weight":123,"slug":125},10,"Lifestyle","lifestyle",{"id":127,"doc_module":4,"doc_module_name":25,"category_name":128,"show_sort_weight":96,"slug":129},19,"General","general",{"code":4,"msg":81,"data":131},{"doc_id":78,"user_id":132,"nickname":42,"user_avatar":133,"doc_module":4,"category_id":101,"category_name":29,"doc_title":10,"doc_description":12,"doc_content":134,"file_id":135,"file_url":136,"file_type":137,"file_size":138,"view_count":22,"is_deleted":4,"is_public":22,"is_downloadable":22,"audit_status":22,"page_count":139,"language":140,"language_code":8,"site_id":7,"html_lang":8,"table_of_contents":141,"faqs":142,"seo_title":143,"seo_description":12,"update_tm":79,"read_time":144},2336475401981,"https://ap-avatar.wpscdn.com/avatar/22000c94efd8d5204d?x-image-process=image/resize,m_fixed,w_180,h_180&k=1786935347598174694","Chapter 20  \nBinary Trees  \nThe data structures presented so far are predominantly linear. Every element has one unique predecessor and one unique successor (except the first and last elements). Arrays, and singly linked structures used to implement lists, stacks, and queues all have this linear characteristic. The tree structure presented in this chapter is a hierarchical in that nodes may have more than one successor.  \nGoals  \n Become familiar with tree terminology and some uses of trees  \n Store data in a hierarchical data structure as a Java Collection class  \n Implement binary tree algorithms  \n Implement algorithms for a Binary Search Tree  \n20.1 Trees  \nTrees are often used to store large collections of data in a hierarchical manner where elements are arranged in successive levels. For example, file systems are implemented as a tree structure with the root directory at the highest level. The collection of files and directories are stored as a tree where a directory may have files and other directories. Trees are hierarchical in nature as illustrated in this view of a very small part of a file system (the root directory is signified as /) .  \n. . .  \nEach node in a tree has exactly one parent except for the distinctive node known as the root. Whereas the root of a real tree is usually located in the ground and the leaves are above the root, computer scientists draw trees upside down. This convention allows us to grow trees down from the root since most people find it more natural to write from top to bottom. You are more likely to see the root at the 'top' with the leaves at the 'bottom' of trees. Trees implemented with a linked structure can also be pictured like this:  \nEmpty trees are shown here as /  \n|  | 4 |  |\n| --- | --- | --- |\n\n|  | 5 |  |\n| --- | --- | --- |\n\n|  | 6 |  |\n| --- | --- | --- |\n\nA nonempty tree is a collection of nodes with one node designated as the root. Each node contains a reference to an element and has edges connecting it to other nodes, which are also trees. These other nodes are called children. A tree can be empty have no nodes. Trees may have nodes with two or more children.  \nA leafis a node with no children. In the tree above, the nodes with 4, 5, and 6 are leafs. All nodes that are not leaves are called the internal nodes of a tree, which are 1, 2, and 3 above. A leaf node could later grow a nonempty tree as a child. That leaf node would then become an internal node. Also, an internal node might later have its children become empty trees. That internal node would become a leaf.  \nA tree with no nodes is called an empty tree. A single node by itself can be considered a tree. A structure formed by taking a node N and one or more separate trees and making N the parent of all roots of the trees is also a tree. This recursive definition enables us to construct trees from existing trees. After the construction, the new tree would contain the old trees as subtrees. A subtree is a tree by itself. By definition, the empty tree can also be considered a subtree of every tree.  \nAll nodes with the same parent are called siblings. The level of a node is the number of edges it takes to reach that particular node from the root. For example, the node in the tree above containing J is at level 2. The height of a tree is the level of the node furthest away from its root. These definitions are summarized with a different tree where the letters A through I represent the elements.  \nroot A  \ninternal nodes A B D  \nleaves E F C G H I  \nheight 2  \nlevel of root 0  \nlevel of node with B 1  \nlevel of node with E 2  \nnodes at level 1 3  \nparent of G, H and I D children of B E F  \nA binary tree is a tree where each node has exactly two binary trees, commonly referred to as the left child and right child. Both the left or right trees are also binary trees. They could be empty trees. When both children are empty trees, the node is considered a leaf. Under good circumstances, binary trees have the property that y","cbCaigaSwzBMRcmM","https://ap.wps.com/l/cbCaigaSwzBMRcmM","pdf",322716,14,"English","# Goals\n# 20.1 Trees\n## Binary Search Tree\n## Expression Tree","[{\"question\":\"What distinguishes trees from linear data structures like arrays and linked lists?\",\"answer\":\"In a tree, nodes may have more than one successor, reflecting a hierarchical structure rather than a single predecessor-successor chain.\"},{\"question\":\"How are root, leaves, internal nodes, and levels defined in a tree?\",\"answer\":\"The root is the unique node without a parent; leaves are nodes with no children; internal nodes are all other nodes. A node’s level is the number of edges from the root.\"},{\"question\":\"What ordering property defines a Binary Search Tree?\",\"answer\":\"For each node, all values in the left subtree are less than the node’s value, and all values in the right subtree are greater. This ordering holds recursively for every subtree.\"}]","Chapter 20 - Trees - Binary Trees | PDF",35]