title: Java - tree data structure with multiple nodes - how to search efficiently
body: <p>I am searching for a implementation/data structure for some categories and child categories that i have.  I am thinking to use a search tree but not sure how to begin implementation. </p>
  
  <p>Let me show you what the data looks like. its acutally coming to me as a json structure from back end but it looks like this:</p>
  
  <pre><code>  [
      {
        "id": 94,
        "category_name": "New In", //this is the category category_name
        "description": "",
        "children": [ //this is the category children which can also be a sub-category
          {
            "id": 322,
            "category_name": "New Studio",
            "description": "Chic, sophisticated and polished with a classic edge."
          },
          {
            "id": 365,
            "category_name": "New Soho",
            "description": "Fresh, eclectic, and trendy. Oozes effortless cool."
          },
          {
            "id": 809,
            "category_name": "Summer Collection",
            "description": "Your ultimate summer look"
          }
        ]
      },
      {
        "id": 12,
        "category_name": "Clothes",
        "description": "",
        "children": [
          {
            "id": 22,
            "category_name": "All Clothes",
            "description": ""
          },
          {
            "id": 63,
            "category_name": "Tops",
            "description": "",
            "children": [
              {
                "id": 5,
                "category_name": "All Tops",
                "description": ""
              }
  
            ]
          },
          {
            "id": 641,
            "category_name": "Accessories",
            "description": "",
            "children": [
              {
                "id": 61,
                "category_name": "All Accessories",
                "description": ""
              },
              {
                "id": 622,
                "category_name": "Jewelry",
                "description": "",
                "children": [ // here is an example of a child that is a sub-category also
                  {
                    "id": 52,
                    "category_name": "All Jewelry",
                    "description": ""
                  },
                  {
                    "id": 68,
                    "name": "Necklaces",
                    "description": ""
                  },
                  {
                    "id": 69,
                    "name": "Bracelets",
                    "description": ""
                  },
  
                ]
              },
  
    ]
  </code></pre>
  
  <p>so if i had to draw this out it would look something like this:</p>
  
  <p><a href="https://i.stack.imgur.com/X3vjd.png" rel="noreferrer"><img src="https://i.stack.imgur.com/X3vjd.png" alt="enter image description here"></a></p>
  
  <p>So i want to be able to get path to anything.  So for example if i want to search for Necklaces, then i want as well as getting a necklace to get the path of : Categories/Accessories/Jewelry/Necklaces</p>
  
  <p>Is there a built in data structure for this ? i am coding in java.  I suppose i also need the nodes sorted in some kind of order maybe A-Z. </p>
  
  <p>so far i have this:</p>
  
  <pre><code>class Node{
   String label;
   List&lt;Node&gt; children;
  }
  </code></pre>
  
  <p>but then how to search ? and is there a better data structure ? I do not want to iterate over all the nodes during a search, is there a way to sort the tree so i dont have to do that ? How i have it now i'd have to iterate over all the children. is there a way to maybe sort alphaetically perhaps or some kind of sort that would make the lookup faster ?</p>