<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Egbojoy on Medium]]></title>
        <description><![CDATA[Stories by Egbojoy on Medium]]></description>
        <link>https://medium.com/@egbojoy19?source=rss-58aee5f55e5b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*MVhgdbTJ_PuYH75Q</url>
            <title>Stories by Egbojoy on Medium</title>
            <link>https://medium.com/@egbojoy19?source=rss-58aee5f55e5b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 11:04:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@egbojoy19/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Understanding Trees in Java.]]></title>
            <link>https://medium.com/@egbojoy19/understanding-trees-in-java-bf0475f1bdfb?source=rss-58aee5f55e5b------2</link>
            <guid isPermaLink="false">https://medium.com/p/bf0475f1bdfb</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[trees]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Egbojoy]]></dc:creator>
            <pubDate>Sat, 29 Aug 2026 13:15:23 GMT</pubDate>
            <atom:updated>2026-08-29T13:15:23.078Z</atom:updated>
            <content:encoded><![CDATA[<p>Have you ever been to a family gathering? Probably during Christmas. Notice how your cousins, your siblings, and you all share the same grandpa. And somehow, you all have a connection one way or another with each other. That’s the basic concept of a tree.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/927/1*vJgL4adFBpNZhc-DR6TwUQ.png" /></figure><p>In the tree above, the root node (the very top of the family, with no one above it) is <strong>Grandpa</strong>. He branches into two <strong>parent nodes</strong>, your dad and your aunt, and each of them branches further into <strong>child nodes</strong>: you, your sibling, and your cousins. Notice that you and your sibling share the same parent, which makes you connected. So do your cousins, one level over. Everyone eventually traces back to that one root at the top.</p><p>This exact idea, one starting point branching downward into connected pieces, is how trees work in programming too. Instead of grandpas and cousins, we deal with <strong>nodes</strong> holding data, connected to other nodes below them.</p><p>In this article, we’ll break down what a tree is, why it matters, and how to build a simple one in Java.</p><h3>What Is a Tree?</h3><p>A tree is a data structure made up of <strong>nodes</strong> connected by edges, arranged in a parent-child hierarchy. Unlike a linked list, where each element points to just one “next” element, a tree node can point to multiple children.</p><p>• <strong>Root</strong> — the topmost node, with no parent. (Grandpa)</p><p>• <strong>Parent / Child</strong> — a node directly connected to another node below it. (Your dad is a parent; you’re his child)</p><p>• <strong>Leaf</strong> — a node with no children. (You, your sibling, and your cousins; nobody branches off below them)</p><p>• <strong>Edge</strong> — the connection between two nodes. (The line linking Grandpa to your dad)</p><ul><li><strong>Height</strong> — the number of edges on the longest path from a node down to a leaf.</li></ul><h3>Why Trees Matter in Java</h3><p><strong>· Faster searching</strong> — trees help programs find things quickly, like flipping to a page in a book instead of reading it cover to cover. In practice, this is why Java’s TreeMap and TreeSet can look things up in a fraction of the time a plain list would take.</p><p>· <strong>Organizing nested stuff</strong> — folders in folders, menus with submenus, website structure — trees are how that’s represented. Java’s file-handling tools and DOM parsers work this way under the hood.</p><p>· <strong>Understanding code </strong>— tools that check or run your Java code first break it into a tree to make sense of it. The Javac compiler itself does this before turning your code into something the computer can run.</p><p>· <strong>Good habit for problem-solving</strong> — trees teach you to think in terms of “smaller pieces branching from a bigger one,” which shows up a lot in programming, especially once recursion enters the picture.</p><h3><strong>Creating aTreeSet</strong></h3><p>Study this code that demonstrates how a TreeSet works in Java:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/771/1*iwJqMfSXIfd7O65qQgHMXQ.png" /></figure><p>Now let’s break down what’s happening, line by line.</p><p><strong>1. Creating the TreeSet</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/1*_R_-POCOpqPz8_FAL6_r8w.png" /></figure><p>This creates an empty TreeSet that will hold String values. Under the hood, it&#39;s backed by a tree structure, so anything you put in gets automatically sorted and duplicates get automatically rejected.</p><p><strong>2. Adding elements</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/689/1*dJFx4CNNJWuwuwEBaBQ7dw.png" /></figure><p>5 courses were added in a random order. But because it’s a TreeSet, they don&#39;t stay in the order you inserted them, they get sorted automatically, alphabetically for strings.</p><p><strong>3. Printing the set</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/593/1*K_PSnGJcBbOEmo1ih9v8KA.png" /></figure><p>This will print:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UU_ax_LV3uLHNqFC_QkxZg.png" /></figure><p><strong>4. Removing an element</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/567/1*-kuHcj26xyjUH91V6SB9ew.png" /></figure><p>This finds and removes that specific value.</p><p><strong>5. Checking the size</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/446/1*etfdFWD131YSaqqnUhKGBw.png" /></figure><p>After the removal, this prints 4, since one of the original 5 courses was removed.</p><p><strong>The big takeaway:</strong> A TreeSet is basically a TreeMap with only keys, no values.&quot; It gives you three things for free just by using it: automatic sorting, no duplicates allowed, and efficient add/remove/search, all because it&#39;s a tree, not a plain list.</p><p>Trees might look intimidating at first, with their recursive definitions and unfamiliar vocabulary, but the family gathering analogy from the start still holds: it’s really just connected pieces branching from one starting point. Once that clicks, everything else follows naturally.</p><p>The best way to make this stick is to open your own IDE and try it yourself. Swap the courses in the TreeSet example for something you&#39;re interested in, add a few more elements, try removing one you didn&#39;t expect to, and watch how the tree keeps everything sorted no matter what order you put things in.</p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bf0475f1bdfb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>