{"id":17069,"date":"2024-04-08T09:08:00","date_gmt":"2024-04-08T03:38:00","guid":{"rendered":"https:\/\/www.mygreatlearning.com\/blog\/data-structures-using-java\/"},"modified":"2025-01-06T19:47:31","modified_gmt":"2025-01-06T14:17:31","slug":"data-structures-using-java","status":"publish","type":"post","link":"https:\/\/www.mygreatlearning.com\/blog\/data-structures-using-java\/","title":{"rendered":"Data Structures in Java - A Beginners Guide"},"content":{"rendered":"\n<p>Data structures are fundamental to any programming language. The choice of a particular data structure has a significant impact on the functionality and performance of Java applications, thus it is worthwhile to master data structures in Java. <\/p>\n\n\n\n<p>This guide will help beginners to understand what is data structures, what is data structures in Java, the types of data structures in Java and many more. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-is-java\"><strong>What is Java?<\/strong><\/h2>\n\n\n\n<p><a href=\"https:\/\/www.mygreatlearning.com\/academy\/learn-for-free\/courses\/java-programming\" target=\"_blank\" rel=\"noreferrer noopener\">Java Programming<\/a> is a high-level programming language created by sun microsystems. This programming language is reliable, object-oriented and secure. Java follows the WORA principle, which stands for \"Write Once Run Anywhere\". You can run a java program as many times as you want on a java supported platform after it is compiled.&nbsp;<\/p>\n\n\n\n    <div class=\"courses-cta-container\">\n        <div class=\"courses-cta-card\">\n            <div class=\"courses-cta-header\">\n                <div class=\"courses-learn-icon\"><\/div>\n                <span class=\"courses-learn-text\">Academy Pro<\/span>\n            <\/div>\n            <p class=\"courses-cta-title\">\n                <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/master-java-programming\" class=\"courses-cta-title-link\">Java Programming Course<\/a>\n            <\/p>\n            <p class=\"courses-cta-description\">Learn Java the right way! Our course teaches you essential programming skills, from coding basics to complex projects, setting you up for success in the tech industry.<\/p>\n            <div class=\"courses-cta-stats\">\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-user-icon\"><\/div>\n                    <span>16.05 Hrs<\/span>\n                <\/div>\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-star-icon\"><\/div>\n                    <span>3 Projects<\/span>\n                <\/div>\n            <\/div>\n            <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/master-java-programming\" class=\"courses-cta-button\">\n                Learn Java Programming\n                <div class=\"courses-arrow-icon\"><\/div>\n            <\/a>\n        <\/div>\n    <\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-are-data-structures\"><strong>What are Data Structures?<\/strong><\/h2>\n\n\n\n<p>A <a href=\"https:\/\/www.mygreatlearning.com\/blog\/data-structure-tutorial-for-beginners\/\" target=\"_blank\" rel=\"noreferrer noopener\">data structure<\/a> is defined as a format for arranging, processing, accessing, and storing data. Data structures are the combination of both simple and complex forms, all of which are made to organise data for a certain use. Users find it simple to access the data they need and use it appropriately thanks to data structures.<\/p>\n\n\n\n<p>To make you understand in simpler terms, look at the below example<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nIf you want to store data in\n\nOne on the other - Stacks\nLinear fashion - Array\/ Linked List\nHierarchical Fashion - Trees\nConnect Nodes - Graph\n\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"what-are-data-structures-in-java\"><strong>What are Data Structures in Java?<\/strong><\/h2>\n\n\n\n<p>Data Structure in java is defined as the collection of data pieces that offers an effective means of storing and organising data in a computer. <a href=\"https:\/\/www.mygreatlearning.com\/academy\/learn-for-free\/courses\/linkedlist\" target=\"_blank\" rel=\"noreferrer noopener\">Linked List<\/a>, Stack, Queue, and arrays are a few examples of <a href=\"https:\/\/www.mygreatlearning.com\/academy\/learn-for-free\/courses\/java-data-structures-for-beginners\" target=\"_blank\" rel=\"noreferrer noopener\">java data structures<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"types-of-data-structures-in-java\"><strong>Types of  Data Structures in Java<\/strong><\/h2>\n\n\n\n<p>Here is the list of some of the common types of data structures in Java: <\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Array<\/li>\n\n\n\n<li>Linked List<\/li>\n\n\n\n<li>Stack&nbsp;<\/li>\n\n\n\n<li>Queue<\/li>\n\n\n\n<li><a href=\"https:\/\/www.mygreatlearning.com\/academy\/learn-for-free\/courses\/binary-trees\" target=\"_blank\" rel=\"noreferrer noopener\">Binary Tree<\/a><\/li>\n\n\n\n<li>Binary Search Tree<\/li>\n\n\n\n<li>Heap<\/li>\n\n\n\n<li>Hashing&nbsp;<\/li>\n\n\n\n<li>Graph<\/li>\n<\/ul>\n\n\n\n<p>Here is the pictorial representation of types of java data structures<\/p>\n\n\n\n<p><\/p>\n\n\n<figure class=\"wp-block-image aligncenter size-full zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/image-6.png\"><img decoding=\"async\" width=\"757\" height=\"646\" src=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/image-6.png\" alt=\"Data Structures in Java\" class=\"wp-image-76709\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/image-6.png 757w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/image-6-300x256.png 300w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/image-6-696x594.png 696w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/image-6-492x420.png 492w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/image-6-150x128.png 150w\" sizes=\"(max-width: 757px) 100vw, 757px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted ghostkit-custom-ZAnUkG has-black-color has-white-background-color has-text-color has-background\"><em>To learn more about <a href=\"https:\/\/www.mygreatlearning.com\/academy\/learn-for-free\/courses\/data-structures-and-algorithms-in-java\" target=\"_blank\" rel=\"noreferrer noopener\">Java Programming<\/a>, you can take up a free online course offered by Great Learning Academy and upskill today. If you are already well-versed with the basics, go ahead and enrol yourself in the <a href=\"https:\/\/www.mygreatlearning.com\/academy\/learn-for-free\/courses\/data-structures-and-algorithms-in-java\" target=\"_blank\" rel=\"noreferrer noopener\">Data Structure &amp; Algorithms in Java for Intermediate Level<\/a>.<\/em><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"further-classification-of-types-of-data-structures\"><strong>Further classification of types of Data Structures<\/strong><\/h3>\n\n\n\n<p>There are two types of Data Structures:-<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Primitive Data Structures<\/li>\n\n\n\n<li>Non-primitive Data Structures<\/li>\n<\/ol>\n\n\n\n<p><strong>Primitive data Structures <\/strong>are also called Primitive Data Types. byte, short,&nbsp; int, float, char, boolean, long, and double are primitive Data types.<\/p>\n\n\n\n<p><strong>Non-primitive data Structures<\/strong> - Non-primitive Data Structures are of two types:-<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Linear Data Structures<\/li>\n\n\n\n<li>Non-linear Data Structures<\/li>\n<\/ol>\n\n\n<figure class=\"wp-block-image aligncenter size-full zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/image-7.png\"><img decoding=\"async\" width=\"994\" height=\"609\" src=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/image-7.png\" alt=\"Non-primitive data Structures in java\" class=\"wp-image-76717\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/image-7.png 994w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/image-7-300x184.png 300w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/image-7-768x471.png 768w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/image-7-696x426.png 696w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/image-7-686x420.png 686w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/image-7-150x92.png 150w\" sizes=\"(max-width: 994px) 100vw, 994px\" \/><\/figure>\n\n\n\n<p><strong>Linear Data Structures<\/strong> - The elements arranged in a linear fashion are called Linear Data Structures. Here, each element is connected to one other element only. Linear Data Structures are as follows:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Arrays&nbsp;<\/strong>\n<ul class=\"wp-block-list\">\n<li>Single dimensional Array<\/li>\n\n\n\n<li>Multidimensional Array<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<ul start=\"2\" class=\"wp-block-list\">\n<li><strong>Stack<\/strong><\/li>\n\n\n\n<li><strong>Queue<\/strong><\/li>\n<\/ul>\n\n\n\n<ul start=\"2\" class=\"wp-block-list\">\n<li><strong>Linked List&nbsp;<\/strong>\n\n\n<ul class=\"wp-block-list\">\n<li>Singly-linked list<\/li>\n\n\n\n<li>Doubly Linked list<\/li>\n\n\n\n<li>Circular Linked List<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p><strong>Non-Linear Data Structures<\/strong> - The elements arranged in a non-linear fashion are called Non-Linear Data Structures. Here, each element is connected to n-other elements. Non-Linear Data Structures are as follows:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Trees<\/strong>\n<ul class=\"wp-block-list\">\n<li>Binary Tree<\/li>\n\n\n\n<li>Binary Search Tree<\/li>\n\n\n\n<li>AVL Tree<\/li>\n\n\n\n<li>Red-Black Tree<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Heap<\/strong>\n<ul class=\"wp-block-list\">\n<li>MaxHeap<\/li>\n\n\n\n<li>MinHeap<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Hash<\/strong>\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/hashset-in-java\/\">HashSet<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/hashmap-in-java\/\">HashMap<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"advantages-of-data-structures-in-java\"><strong>Advantages of Data Structures in java <\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Efficiency<\/li>\n\n\n\n<li>Reusability<\/li>\n\n\n\n<li>Processing Speed<\/li>\n\n\n\n<li>Abstraction <\/li>\n\n\n\n<li>Data Searching<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"classification-of-data-structures\"><strong>Classification of Data Structures<\/strong><\/h2>\n\n\n\n<p><strong>Data Structures can be classified as:-<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Static Data Structures<\/strong> are the Data structures whose size is declared and fixed at Compile Time and cannot be changed later are called Static Data structures. <\/li>\n\n\n\n<li><strong>Example - Arrays<\/strong><\/li>\n\n\n\n<li><strong>Dynamic Data Structures<\/strong> are the Data Structures whose size is not fixed at compile time and can be decided at runtime depending upon requirements are called Dynamic Data structures. <\/li>\n\n\n\n<li><strong>Example - <a href=\"https:\/\/codingzap.com\/binary-search-tree-java\/\">Binary search tree using Java<\/a><\/strong><\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Syntax:<\/strong><\/li>\n<\/ul>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nArray declaration\ndatatype varname &#x5B;]=new datatype&#x5B;size];\u00a0\u00a0\ndatatype&#x5B;] varname=new datatype&#x5B;size];\u00a0\u00a0\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"array\"><strong>Array<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"what-is-an-array\"><strong>What is an Array?<\/strong><\/h3>\n\n\n\n<p>An <a href=\"https:\/\/www.mygreatlearning.com\/blog\/what-is-an-array-learn-more-in-one-read\/\" target=\"_blank\" rel=\"noreferrer noopener\">array<\/a> is the simplest data structure where a collection of similar data elements takes place and each data element can be accessed directly by only using its index number.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"array-advantages\"><strong>Array Advantages<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Random access<\/li>\n\n\n\n<li>Easy sorting and iteration<\/li>\n\n\n\n<li>Replacement of multiple variables<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"array-disadvantages\"><strong>Array Disadvantages<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Size is fixed<\/li>\n\n\n\n<li>Difficult to insert and delete<\/li>\n\n\n\n<li>If capacity is more and occupancy less, most of the array gets wasted&nbsp;<\/li>\n\n\n\n<li>Needs contiguous memory to get allocated<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"array-applications\"><strong>Array Applications<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>For storing information in a linear fashion<\/li>\n\n\n\n<li>Suitable for applications that require frequent searching<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"java-program-using-array\"><strong>Java Program using  Array<\/strong><\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\nimport java.util.*;\n\nclass JavaDemo {\n\tpublic static void main (String&#x5B;] args) {\n\t    int&#x5B;] priceOfPen= new int&#x5B;5];\n\t    Scanner in=new Scanner(System.in);\n\t    for(int i=0;i&lt;priceOfPen.length;i++)\n\t        priceOfPen&#x5B;i]=in.nextInt();\n\n\t    for(int i=0;i&lt;priceOfPen.length;i++)\n\t\t    System.out.print(priceOfPen&#x5B;i]+&quot; &quot;);\n\t}\n}\n\n\nInput:\n23 13 56 78 10\n\nOutput:\n23 13 56 78 10 \n\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe title=\"Data Structures and Algorithms in Java | linked list | java programming | Great Learning\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/4xWOnC7-ke8?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"linked-list\"><strong>Linked List<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"what-is-linked-list\"><strong>What is Linked List?<\/strong><\/h3>\n\n\n\n<p>Linked list data structure helps the required objects to be arranged in a linear order.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"linked-list-advantages\"><strong>Linked List Advantages<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Dynamic in size<\/li>\n\n\n\n<li>No wastage as capacity and size is always equal<\/li>\n\n\n\n<li>Easy insertion and deletion as 1 link manipulation is required<\/li>\n\n\n\n<li>Efficient memory allocation<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"linked-list-disadvantages\"><strong><strong>Linked List<\/strong><\/strong> <strong>Disadvantages<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If head Node is lost, the linked list is lost<\/li>\n\n\n\n<li>No random access is possible<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"linked-list-applications\"><strong>Linked List<\/strong> <strong>Applications<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Suitable where memory is limited&nbsp;<\/li>\n\n\n\n<li>Suitable for applications that require frequent insertion and deletion<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"java-program-on-linked-list\"><strong>Java Program on Linked List<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>\nimport java.util.*;\n\nclass LLNode{\n\n\tint data;\n\tLLNode next;\n\t\n\tLLNode(int data)\n\t{\n\t\tthis.data=data;\n\t\tthis.next=null;\n\t\t\n\t}\n}\n\n\nclass Demo{\n\t\n\tLLNode head;\n\t\n\t\n\tLLNode insertInBeg(int key,LLNode head)\n\t{\n\t\tLLNode ttmp=new LLNode(key);\n\t\t\n\t\tif(head==null)\n\t\t\thead=ttmp;\n\t\t\n\t\telse\n\t\t\t{\n\t\t\t\tttmp.next=head;\n\t\t\t\thead=ttmp;\n\t\t\t}\n\t\treturn head;\n\t}\n\t\n\t\n\tLLNode insertInEnd(int key,LLNode head)\n\t{\n\t\tLLNode ttmp=new LLNode(key);\n\t\tLLNode ttmp1=head;\n\t\t\n\t\tif(ttmp1==null)\n\t\t\thead=ttmp;\n\t\telse\n\t\t{\n\t\t\twhile(ttmp1.next!=null)\n\t\t\t\t\tttmp1=ttmp1.next;\n\t\t\tttmp1.next=ttmp;\n\t\t\t\n\t\t}\n\t\t\n\t\treturn head;\n\t\t\t\n\t}\n\n\n\tLLNode insertAtPos(int key,int pos,LLNode head)\n\t{\n\t\tLLNode ttmp=new LLNode(key);\n\t\t\n\t\tif(pos==1)\n\t\t{\n\t\t\tttmp.next=head;\n\t\t\thead=ttmp;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tLLNode ttmp1=head;\n\t\t\tfor(int i=1;ttmp1!=null &amp;&amp; i&lt;pos;i++)\n\t\t\t\tttmp1=ttmp1.next;\n\t\t\tttmp.next=ttmp1.next;\n\t\t\tttmp1.next=ttmp;\n\t\t}\n\t\t\n\t\treturn head;\n\t}\n\t\n\t\n\tLLNode delete(int pos,LLNode head)\n\t{\n\t\tLLNode ttmp=head;\n\t\tif(pos==1)\n\t\t\thead=ttmp.next;\n\t\telse\n\t\t{\n\t\t\tfor(int i=1;ttmp!=null &amp;&amp; i&lt;pos-1;i++)\n\t\t\t\tttmp=ttmp.next;\n\t\t\tttmp.next=ttmp.next.next;\n\t\t}\n\t\treturn head;\n\t}\n\t\n\tint length(LLNode head)\n\t{\n\t\tLLNode ttmp=head;\n\t\tint c=0;\n\t\tif(ttmp==null)\n\t\t\treturn 0;\n\t\telse\n\t\t{\n\t\t while(ttmp!=null)\n\t\t\t{\tttmp=ttmp.next;\n\t\t\t\tc++;\n\t\t\t}\n\t\t}\n\t\treturn c;\n\t}\n\t\n\t\n\tLLNode reverse(LLNode head)\n\t{\n\t\tLLNode prevLNode=null,curLNode=head,nextLNode=null;\n\t\twhile(curLNode!=null)\n\t\t{\n\t\t\tnextLNode=curLNode.next;\n\t\t\tcurLNode.next=prevLNode;\n\t\t\t\n\t\t\tprevLNode=curLNode;\n\t\t\tcurLNode=nextLNode;\n\t\t}\n\t\t\n\t\thead=prevLNode;\n\t\treturn head;\n\t}\n\t\n\t\n\tvoid display(LLNode head)\n\t{\n\t\tLLNode ttmp=head;\n\t\twhile(ttmp!=null)\n\t\t\t{System.out.print(ttmp.data+\" \");\n\t\t\t ttmp=ttmp.next;\n\t\t\t}\n\t}\n\t\n\tpublic static void main(String&#091;] args)\n\t{\n\t\tLinkedListDemo l=new LinkedListDemo();\n\t\tl.head=null;\n\t\tScanner in=new Scanner(System.in);\n\t\t do\n\t{\n System.out.println(\"n********* MENU *********\");\n\t System.out.println(\"n1.Insert In End\");\n\t System.out.println(\"n2.Insert In Beg\");\n\t System.out.println(\"n3.Insert At A  Particular Pos\");\n\t System.out.println(\"n4.Delete At a Pos\");\n\t System.out.println(\"n5.Length\");\n\t System.out.println(\"n6.Reverse\");\n\t System.out.println(\"n7.Display\");\n\t System.out.println(\"n8.EXIT\");\n\t System.out.println(\"nenter ur choice : \");\n\t int n=in.nextInt();\n\t switch(n)\n\t\t{case 1: System.out.println(\"nenter the value \");\n\t\t\t  l.head=l.insertInEnd(in.nextInt(),l.head);\n\t\t\t break;\n\t\t case 2: System.out.println(\"nenter the value\");\n\t\t\t l.head=l.insertInBeg(in.nextInt(),l.head);\n\t\t\t break;\n\t\t case 3: System.out.println(\"nenter the value\");\n\t\t\t l.head=l.insertAtPos(in.nextInt(),in.nextInt(),l.head);\n\t\t\t break;\n\t\t case 4: \n\t\t\t l.head=l.delete(in.nextInt(),l.head);\n\t\t\t break;\n\t\t case 5: \n\t\t\tSystem.out.println(l.length(l.head));\n\t\t\t break;\n\t\t case 6: \n\t\t\t l.head=l.reverse(l.head);\n\t\t\t break;\n\t\t case 7: \n\t\t\tl.display(l.head);\n\t\t \t\t break;\n\t\t case 8: System.exit(0);\n\t\t \t\t break;\n\t\t default: System.out.println(\"n Wrong Choice!\");\n\t\t \t\t  break;\n\t\t}\n\t System.out.println(\"n do u want to cont... \");\n\t}while(in.nextInt()==1);\n\n }\n}\n\n\n\n\n\nOutput:\n\n********* MENU *********\n\n1.Insert In End\n\n2.Insert In Beg\n\n3.Insert At A  Particular Pos\n\n4.Delete At a Pos\n\n5.Length\n\n6.Reverse\n\n7.Display\n\n8.EXIT\n\nenter ur choice :\n1\n\nenter the value\n23\n\n do u want to cont...\n1\n\n********* MENU *********\n\n1.Insert In End\n\n2.Insert In Beg\n\n3.Insert At A  Particular Pos\n\n4.Delete At a Pos\n\n5.Length\n\n6.Reverse\n\n7.Display\n\n8.EXIT\n\nenter ur choice :\n1\n\nenter the value\n56\n\n do u want to cont...\n1\n\n********* MENU *********\n\n1.Insert In End\n\n2.Insert In Beg\n\n3.Insert At A  Particular Pos\n\n4.Delete At a Pos\n\n5.Length\n\n6.Reverse\n\n7.Display\n\n8.EXIT\n\nenter ur choice :\n2\n\nenter the value\n10\n\n do u want to cont...\n1\n\n********* MENU *********\n\n1.Insert In End\n\n2.Insert In Beg\n\n3.Insert At A  Particular Pos\n\n4.Delete At a Pos\n\n5.Length\n\n6.Reverse\n\n7.Display\n\n8.EXIT\n\nenter ur choice :\n7\n10 23 56\n do u want to cont...\n1\n\n********* MENU *********\n\n1.Insert In End\n\n2.Insert In Beg\n\n3.Insert At A  Particular Pos\n\n4.Delete At a Pos\n\n5.Length\n\n6.Reverse\n\n7.Display\n\n8.EXIT\n\nenter ur choice :\n3\n\nenter the value\n67\n2\n\n do u want to cont...\n1\n\n********* MENU *********\n\n1.Insert In End\n\n2.Insert In Beg\n\n3.Insert At A  Particular Pos\n\n4.Delete At a Pos\n\n5.Length\n\n6.Reverse\n\n7.Display\n\n8.EXIT\n\nenter ur choice :\n7\n10 23 67 56\n do u want to cont...\n1\n\n********* MENU *********\n\n1.Insert In End\n\n2.Insert In Beg\n\n3.Insert At A  Particular Pos\n\n4.Delete At a Pos\n\n5.Length\n\n6.Reverse\n\n7.Display\n\n8.EXIT\n\nenter ur choice :\n4\n2\n\n do u want to cont...\n1\n\n********* MENU *********\n\n1.Insert In End\n\n2.Insert In Beg\n\n3.Insert At A  Particular Pos\n\n4.Delete At a Pos\n\n5.Length\n\n6.Reverse\n\n7.Display\n\n8.EXIT\n\nenter ur choice :\n7\n10 67 56\n do u want to cont...\n1\n\n********* MENU *********\n\n1.Insert In End\n\n2.Insert In Beg\n\n3.Insert At A  Particular Pos\n\n4.Delete At a Pos\n\n5.Length\n\n6.Reverse\n\n7.Display\n\n8.EXIT\n\nenter ur choice :\n6\n\n do u want to cont...\n1\n\n********* MENU *********\n\n1.Insert In End\n\n2.Insert In Beg\n\n3.Insert At A  Particular Pos\n\n4.Delete At a Pos\n\n5.Length\n\n6.Reverse\n\n7.Display\n\n8.EXIT\n\nenter ur choice :\n7\n56 67 10\n do u want to cont...\n\n\n\n\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"stack\"><strong>Stack<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"what-is-a-stack\"><strong>What is a stack?<\/strong><\/h3>\n\n\n\n<p>A stack is a representation of nodes. There are two components to each node: data and next (storing address of next node). Each node's data portion contains the assigned value, and its next pointer directs the user to the node that has the stack's subsequent item. The highest node in the stack is referred to as the top.&nbsp;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"features-of-stack\"><strong>Features of Stack<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Linear Data Structures using Java<\/li>\n\n\n\n<li>Follows LIFO: Last In First Out<\/li>\n\n\n\n<li>Only the top elements are available to be accessed<\/li>\n\n\n\n<li>Insertion and deletion takes place from the top<\/li>\n\n\n\n<li>Eg: a stack of plates, chairs, etc<\/li>\n\n\n\n<li>4 major operations:\n<ul class=\"wp-block-list\">\n<li>push(ele) - used to insert element at top<\/li>\n\n\n\n<li>pop() - removes the top element from stack<\/li>\n\n\n\n<li>isEmpty() - returns true is stack is empty<\/li>\n\n\n\n<li>peek() - to get the top element of the stack<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>All operation works in constant time i.e, O(1)<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"stack-advantages\"><strong>Stack Advantages<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Maintains data in a LIFO manner<\/li>\n\n\n\n<li>The last element is readily available for use<\/li>\n\n\n\n<li>All operations are of O(1) complexity<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"stack-disadvantages\"><strong>Stack Disadvantages<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Manipulation is restricted to the top of the stack<\/li>\n\n\n\n<li>Not much flexible<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"stack-applications\"><strong>Stack Applications<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Recursion<\/li>\n\n\n\n<li>Parsing<\/li>\n\n\n\n<li>Browser<\/li>\n\n\n\n<li>Editors<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"java-program-using-stack\"><strong>Java Program using Stack <\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.*;\n\nclass Stack\n{\n   int&#091;] a;\n   int top;\n   Stack()\n   {\t\n\ta=new int&#091;100];\n\ttop=-1;\n   }\n  \n  void push(int x)\n  {\t\n\tif(top==a.length-1)\n\t  System.out.println(\"overflow\");\n\telse\n\t a&#091;++top]=x;\n   }\n   \n   int pop()\n   {\n     if(top==-1)\n\t\t{System.out.println(\"underflow\");\n\t     return -1;\n\t\t}\n\t else\n\t   return(a&#091;top--]);\n\t}\n\t\n\tvoid display()\n\t{\n\t\tfor(int i=0;i&lt;=top;i++)\n\t\t\tSystem.out.print(a&#091;i]+\" \");\n\t\tSystem.out.println();\t\n\t}\n\t\n\tboolean isEmpty()\n\t{\n\t\tif(top==-1)\n\t\t\treturn true;\n\t\telse \n\t\t\treturn false;\n\t}\n\t\n\tint peek()\n\t{\n\t\tif(top==-1)\n\t\t\treturn -1;\n\t\treturn (a&#091;top]);\n\t}\n\t\n\t\n}\n\npublic class Demo\n{\n\tpublic static void main(String args&#091;])\n\t{\n\t\t\n\t\tStack s=new Stack();\n\t\tScanner in= new Scanner(System.in);\n\t\t\n\t\t do\n\t\t\t{System.out.println(\"n******** MENU *******\");\n\t\t\t System.out.println(\"n1.PUSH\");\n\t\t\t System.out.println(\"n2.POP\");\n\t\t\t System.out.println(\"n3.PEEK\");\n\t\t\t System.out.println(\"n4 IS EMPTY\");\n\t\t\t System.out.println(\"n5.EXIT\");\n\t\t\t System.out.println(\"n enter ur choice : \");\n\t\t\t switch(in.nextInt())\n\t\t\t\t{\n\t\t\t\t case 1: \n\t\t\t\t\t System.out.println(\"nenter the value \");\n\t\t\t\t\t s.push(in.nextInt());\n\t\t\t\t\t break;\n\t\t\t\t case 2: \n\t\t\t\t\tSystem.out.println(\"n popped element : \"+ s.pop());\n\t\t\t\t\t break;\n\t\t\t\t \n\t\t\t\tcase 3: \n\t\t\t\t\tSystem.out.println(\"n top element : \"+ s.peek());\n\t\t\t\t\t break;\n\t\t\t\t case 4: System.out.println(\"n is empty : \"+ s.isEmpty());\n\t\t\t\t\t\t break;\n\t\t\t\t case 5: System.exit(0);\n\t\t\t\t\t\t break;\n\t\t\t\t default: System.out.println(\"n Wrong Choice!\");\n\t\t\t\t\t\t  break;\n\t\t\t\t}\n\t\t\t System.out.println(\"n do u want to cont... \");\n\t\t\t}while(in.nextInt()==1);\n\n\t}\n}\n\n\n\n\n\n\nOutput:\n\n******** MENU *******\n\n1.PUSH\n\n2.POP\n\n3.PEEK\n\n4 IS EMPTY\n\n5.EXIT\n\n enter ur choice :\n1\n\nenter the value\n12\n\n do u want to cont...\n1\n\n******** MENU *******\n\n1.PUSH\n\n2.POP\n\n3.PEEK\n\n4 IS EMPTY\n\n5.EXIT\n\n enter ur choice :\n1\n\nenter the value\n56\n\n do u want to cont...\n1\n\n******** MENU *******\n\n1.PUSH\n\n2.POP\n\n3.PEEK\n\n4 IS EMPTY\n\n5.EXIT\n\n enter ur choice :\n2\n\n popped element : 56\n\n do u want to cont...\n1\n\n******** MENU *******\n\n1.PUSH\n\n2.POP\n\n3.PEEK\n\n4 IS EMPTY\n\n5.EXIT\n\n enter ur choice :\n4\n\n is empty : false\n\n do u want to cont...\n1\n\n******** MENU *******\n\n1.PUSH\n\n2.POP\n\n3.PEEK\n\n4 IS EMPTY\n\n5.EXIT\n\n enter ur choice :\n2\n\n popped element : 12\n\n do u want to cont...\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"java-data-structure-program-of-stack-using-linkedlist\"><strong>Java Data structure program of Stack - using LinkedList<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.*;\n\nclass LNode\n{\n\t int data;\n\t LNode next;\n\t LNode(int d)\n\t {\n\t\tdata=d;\n\t }\n\t \n}\n\n class Stack\n{\n\t LNode push(int d,LNode head){  \n\t\t\n\t\t\t\tLNode tmp1 = new LNode(d);\n\t\t\t\t\n\t\t\t\tif(head==null)\n\t\t\t\t   \n\t\t\t\t\thead=tmp1;\n\t\t\t\t\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\ttmp1.next=head;\n\t\t\t\t\t\n\t\t\t\t\thead=tmp1;\n\t\t\t\t}\n\t\t\t\treturn head;\n\t\t\t }\n\t\t\t \n\t\t\t \n\t LNode pop(LNode head){\n\t\t   \n\t\t    if(head==null)\n\t\t        System.out.println(\"underflow\");\n\t\t   else\n\t\t\t\thead=head.next;\n\t\t\treturn head;\n\t\t }\n\t\n\n\tvoid display(LNode head){\n\t\t\n\t\t\t\tSystem.out.println(\"n list is : \");\n\t\t\t\tif(head==null){\n\t\t\t\t\t\n\t\t\t\t\tSystem.out.println(\"no LNodes\");\n\t\t\t\n\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t \n\t\t\t\tLNode tmp=head;\n\n\t\t\t\twhile(tmp!=null){\n\t\t\t\t\t\t\n\t\t\t\tSystem.out.print(tmp.data+\" \");\n\t\t\t\t\t \n\t\t\t\ttmp=tmp.next;\n\t\t\t\t\t \n\t\t\t\t\t\n\t\t\t\t}\n\t       }\n\n    boolean isEmpty(LNode head)\n\t{\n\t\tif(head==null)\n\t\t\treturn true;\n\t\telse\n\t\t\treturn false;\n\t}\n\t\n\tint peek(LNode head)\n\t{\n\t\tif(head==null)\n\t\t\treturn -1;\n\t\treturn head.data;\n\t}\n\t\n}\n\n\npublic class Demo{\n\t\t\n\t\tpublic static void main(String&#091;] args)\n\t\t{\n\t\tStack s=new Stack();\n\t\tLNode head=null;\n\t\tScanner in=new Scanner(System.in);\n\t\t\n\t\t do\n\t\t\t{System.out.println(\"n******** MENU *******\");\n\t\t\t System.out.println(\"n1.PUSH\");\n\t\t\t System.out.println(\"n2.POP\");\n\t\t\t System.out.println(\"n3.PEEK\");\n\t\t\t System.out.println(\"n4 IS EMPTY\"); \n\t\t\t System.out.println(\"n5 DISPLAY\");\n\t\t\t System.out.println(\"n6.EXIT\");\n\t\t\t System.out.println(\"n enter ur choice : \");\n\t\t\t switch(in.nextInt())\n\t\t\t\t{\n\t\t\t\t case 1: \n\t\t\t\t\t System.out.println(\"nenter the value \");\n\t\t\t\t\t head=s.push(in.nextInt(),head);\n\t\t\t\t\t break;\n\t\t\t\t case 2: \n\t\t\t\t\t head=s.pop(head);\n\t\t\t\t\t break;\n\t\t\t\t \n\t\t\t\tcase 3: \n\t\t\t\tSystem.out.println(\"n top element : \"+ s.peek(head));\n\t\t\t\t\t break;\n\t\t\t\t case 4: \nSystem.out.println(\"n is empty : \"+ s.isEmpty(head));\n\t\t\t\t\t\t break;\n\t\t\t\t case 5: s.display(head); \n\t\t\t\t\t\t break;\n\t\t\t\t case 6: System.exit(0);\n\t\t\t\t\t\t break;\n\t\t\t\t default: System.out.println(\"n Wrong Choice!\");\n\t\t\t\t\t\t  break;\n\t\t\t\t}\n\t\t\t System.out.println(\"n do u want to cont... \");\n\t\t\t}while(in.nextInt()==1);\n\n\t}\n}\n\n\n\n\n\nOutput\n******** MENU *******\n\n1.PUSH\n\n2.POP\n\n3.PEEK\n\n4 IS EMPTY\n\n5 DISPLAY\n\n6.EXIT\n\n enter ur choice :\n1\n\nenter the value\n12\n\n do u want to cont...\n1\n\n******** MENU *******\n\n1.PUSH\n\n2.POP\n\n3.PEEK\n\n4 IS EMPTY\n\n5 DISPLAY\n\n6.EXIT\n\n enter ur choice :\n1\n\nenter the value\n56\n\n do u want to cont...\n1\n\n******** MENU *******\n\n1.PUSH\n\n2.POP\n\n3.PEEK\n\n4 IS EMPTY\n\n5 DISPLAY\n\n6.EXIT\n\n enter ur choice :\n5\n\n list is :\n56 12\n do u want to cont...\n1\n\n******** MENU *******\n\n1.PUSH\n\n2.POP\n\n3.PEEK\n\n4 IS EMPTY\n\n5 DISPLAY\n\n6.EXIT\n\n enter ur choice :\n3\n\n top element : 56\n\n do u want to cont...\n1\n\n******** MENU *******\n\n1.PUSH\n\n2.POP\n\n3.PEEK\n\n4 IS EMPTY\n\n5 DISPLAY\n\n6.EXIT\n\n enter ur choice :\n4\n\n is empty : false\n\n do u want to cont...\n1\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"queue\"><strong>Queue<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"what-is-queue\"><strong>What is Queue?<\/strong><\/h3>\n\n\n\n<p><br>The queue is called an abstract data structure. Data is always added to one end (enqueued), and removed from the other (dequeue). Queue uses the First-In-First-Out approach and data item that was stored initially will be accessed first in a queue.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"features-of-queue\"><strong>Features of Queue<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Linear Data Structure<\/li>\n\n\n\n<li>Follows FIFO: First In First Out<\/li>\n\n\n\n<li>Insertion can take place from the rear end.<\/li>\n\n\n\n<li>Deletion can take place from the front end.<\/li>\n\n\n\n<li>Eg: queue at ticket counters, bus station<\/li>\n\n\n\n<li>4 major operations:\n<ul class=\"wp-block-list\">\n<li>enqueue(ele) - used to insert element at top<\/li>\n\n\n\n<li>dequeue() - removes the top element from queue&nbsp;<\/li>\n\n\n\n<li>peekfirst() - to get the first element of the queue&nbsp;<\/li>\n\n\n\n<li>peeklast() - to get the last element of the queue&nbsp;<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>All operation works in constant time i.e, O(1)<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"queue-advantages\"><strong>Queue Advantages<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Maintains data in FIFO manner<\/li>\n\n\n\n<li>Insertion from beginning and deletion from end takes O(1) time<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"queue-applications\"><strong>Queue Applications<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Scheduling<\/li>\n\n\n\n<li>Maintaining playlist<\/li>\n\n\n\n<li>Interrupt handling<\/li>\n<\/ul>\n\n\n\n<p><strong>Variations in Queue:<\/strong> Two popular variations of queues are&nbsp;<strong>Circular queues<\/strong>&nbsp;and&nbsp;<strong>Dequeues.<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"java-program-of-queue-using-array\"><strong><strong>Java program <\/strong> of Queue- using Array<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>\nimport java.util.*;\n\nclass Queue{\n\n int front;\n int rear;\n int&#091;] arr;\n \n Queue()\n {\n   front=rear=-1;\n   arr=new int&#091;10];\n  }\n  \n  void enqueue(int a)\n  {\n    if(rear==arr.length-1)\n\t\tSystem.out.println(\"overflow\");\n\telse\n\t\tarr&#091;++rear]=a;\n\t\n\tif(front==-1)\n\t\tfront++;\n   }\n   \n   int dequeue()\n   {\n     int x=-1;\n\t if(front==-1)\n\t\tSystem.out.println(\"underflow\");\n\t else\n\t\tx=arr&#091;front++];\n\t if(rear==0)\n\t     rear--;\n\t return x;\n    }\n\t\n\tvoid display()\n\t{\n\t  for(int i=front;i&lt;=rear;i++)\n\t\tSystem.out.print(arr&#091;i]+\" \");\n\n\t System.out.println();\n\n\n\t}\n}\n\npublic class QueueDemo{\n\n\tpublic static void main(String&#091;] args)\n\t{\n\t  Queue ob=new Queue();\n\t  ob.enqueue(1);\n\t  ob.enqueue(2);\n\t  ob.enqueue(3);\n\t  ob.enqueue(4);\n\t  ob.enqueue(5);\n\t  ob.display();\n\t  ob.dequeue();\n\t  ob.display();\n\t }\n}\n\t  \n\n\n\n\nOutput:\n\n\n1 2 3 4 5 \n2 3 4 5 \n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"demonstration-of-queue-using-linkedlist\"><strong>Demonstration of Queue- using LinkedList<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>class LNode{\n\t\n\tint data;\n\tLNode next;\n\n\tLNode(int d)\n\t{\n\t\tdata=d;\n\t}\n}\n\n\nclass Queue{\n\n\tLNode enqueue(LNode head,int a)\n\t{\n\t\tLNode tmp=new LNode(a);\n\t\tif(head==null)\n\t\t\thead=tmp;\n\t\telse\n\t\t { \n\t\t\tLNode tmp1=head;\n\t\t\twhile(tmp1.next!=null)\n\t\t\t\ttmp1=tmp1.next;\n\t\t\t\n\t\t\ttmp1.next=tmp;\n\t\t}\n\t\treturn head;\n\t}\n\t\n\t\n\tLNode dequeue(LNode head)\n\t{\n\t\tif(head==null)\n\t\t        System.out.println(\"underflow\");\n\t\t   else\n\t\t\t\thead=head.next;\n\t\t\treturn head;\n\t}\n\t\n\tvoid display(LNode head)\n\t{\n\t\t\n\t\t\t\tSystem.out.println(\"n list is : \");\n\t\t\t\tif(head==null){\n\t\t\t\t\t\n\t\t\t\t\tSystem.out.println(\"no LNodes\");\n\t\t\t\n\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t \n\t\t\t\tLNode tmp=head;\n\n\t\t\t\twhile(tmp!=null){\n\t\t\t\t\t\t\n\t\t\t\tSystem.out.print(tmp.data+\" \");\n\t\t\t\t\t \n\t\t\t\ttmp=tmp.next;\n\t\t\t\t\t \n\t\t\t\t\t\n\t\t\t\t}\n\t}\n\t\n\t}\n\t\n\tpublic class QueueDemoLL{\n\t\t\n\t\tpublic static void main(String&#091;] args)\n\t\t{\n\t\t\tQueue ob=new Queue();\n\t\t\tLNode head=null;\n\t\t\t\n\t\t\thead=ob.enqueue(head,1);\n\t\t\thead=ob.enqueue(head,2);\n\t\t\thead=ob.enqueue(head,3);\n\t\t\thead=ob.enqueue(head,4);\n\t\t\thead=ob.enqueue(head,5);\n\t\t\tob.display(head);\n\t\t\thead=ob.dequeue(head);\n\t\t\tob.display(head);\n\t\t}\n\t}\n\n\n\n\nOutput\n\nlist is : \n1 2 3 4 5 \nlist is : \n2 3 4 5 \n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"binary-tree\"><strong>Binary Tree<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"what-is-a-binary-tree\"><strong>What is a Binary Tree?<\/strong><\/h3>\n\n\n\n<p>In a <a href=\"https:\/\/www.mygreatlearning.com\/academy\/learn-for-free\/courses\/binary-trees\" target=\"_blank\" rel=\"noreferrer noopener\">binary tree<\/a>, the branches of the tree are made up of up to two child nodes for each node. The left and right nodes are the common names for the two youngsters. Child nodes make references to their parents, whereas parent nodes are nodes with children.<\/p>\n\n\n\n<p><strong>Features of Binary Tree<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Hierarchical&nbsp; Data Structure<\/li>\n\n\n\n<li>The topmost element is known as the root of the tree<\/li>\n\n\n\n<li>Every Node can have at most 2 children in the binary tree<\/li>\n\n\n\n<li>Can access elements randomly using index<\/li>\n\n\n\n<li>Eg: File system hierarchy<\/li>\n\n\n\n<li>Common traversal methods:\n<ul class=\"wp-block-list\">\n<li>preorder(root) : print-left-right<\/li>\n\n\n\n<li>postorder(root) : left-right-print&nbsp;<\/li>\n\n\n\n<li>inorder(root) : left-print-right<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"binary-tree-advantages\"><strong>Binary Tree Advantages<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Can represent data with some relationship<\/li>\n\n\n\n<li>Insertion and search are much more efficient<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"binary-tree-disadvantages\"><strong>Binary Tree Disadvantages<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Sorting is difficult<\/li>\n\n\n\n<li>Not much flexible<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"binary-tree-applications\"><strong>Binary Tree Applications<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>File system hierarchy<\/li>\n\n\n\n<li>Multiple variations of the binary tree have a wide variety of applications<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"demonstration-of-binary-tree\"><strong>Demonstration of Binary Tree<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>class TLNode\n{\n int data;\n TLNode left,right;\n \n TLNode(int d)\n {\n   data=d;\n  }\n }\n \n \npublic class BinaryTree\n{\n   static void preorder(TLNode r)\n   {\n\t\tif(r==null)\n\t\t    return;\n\t\t\n\t\tSystem.out.print(r.data+\" \");\n\t\t\n\t\tpreorder(r.left);\n\t\tpreorder(r.right);\n\t\t\n   }\n   static void inorder(TLNode r)\n   {\n\t\tif(r==null)\n\t\t    return;\n\t\t\n\t\t\n\t\tinorder(r.left);\n\t\tSystem.out.print(r.data+\" \");\n\t\tinorder(r.right);\n\t\t\n   }\n   static void postorder(TLNode r)\n   {\n\t\tif(r==null)\n\t\t    return;\n\t\t\n\t\t\n\t\tpostorder(r.left);\n\t\tpostorder(r.right);\n\t\tSystem.out.print(r.data+\" \");\n\n   }\n     \n    public static void main(String&#091;] args)\n\t{\n\t\tTLNode root=new TLNode(1);\n\t\t\n\t\troot.left=new TLNode(2);\n\t\troot.right=new TLNode(3);\n\t\t\n\t\troot.left.left=new TLNode(4);\n\t\troot.left.right=new TLNode(5);\n\t\t\n\t\troot.right.left=new TLNode(6);\n\t\troot.right.right=new TLNode(7);\n\t\tpreorder(root);\n\t\tSystem.out.println();\n\t\t\n\t\tinorder(root);\n\t\tSystem.out.println();\n\t\t\n\t\tpostorder(root);\n\t\tSystem.out.println();\n\t\t\n\t\t\n\t}\n}\n\n\n\n\t \nOutput\n\t\n1 2 4 5 3 6 7 \n4 2 5 1 6 3 7 \n4 5 2 6 7 3 1 \n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"binary-search-tree\"><strong>Binary Search Tree<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"what-is-a-binary-search-tree\"><strong>What is a Binary Search Tree?<\/strong><\/h3>\n\n\n\n<p>The binary search tree is an advanced algorithm which is used to analyse the nodes, branches and many more. The BST was developed using the architecture of a fundamental binary search algorithm, allowing for quicker node lookups, insertions, and removals.<br><\/p>\n\n\n\n<p><strong>Features of Binary Search Tree<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A binary <a href=\"https:\/\/www.mygreatlearning.com\/blog\/understanding-trees-in-data-structures\/\" target=\"_blank\" rel=\"noreferrer noopener\">tree<\/a> with the additional restriction<\/li>\n\n\n\n<li>Restriction:\n<ul class=\"wp-block-list\">\n<li>The left child must always be less than the root node<\/li>\n\n\n\n<li>The right child must always be greater than the root node<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Insertion, Deletion, Search is much more efficient than a binary tree<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"binary-search-tree-advantages\"><strong>Binary Search Tree<\/strong> <strong>Advantages<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Maintains order in elements<\/li>\n\n\n\n<li>Can easily find the min and max Nodes in the tree<\/li>\n\n\n\n<li>In order, traversal gives sorted elements<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"binary-search-tree-disadvantages\"><strong>Binary Search Tree<\/strong> <strong>Disadvantages<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Random access is not possible<\/li>\n\n\n\n<li>Ordering adds complexity<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"binary-search-tree-applications\"><strong>Binary Search Tree<\/strong> <strong>Applications<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Suitable for sorted hierarchical data<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"demonstration-of-binary-search-tree\"><strong>Demonstration of Binary Search Tree<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>class TLNode{\n\n\tint data;\n\tTLNode left,right;\n\t\n\tTLNode(int d)\n\t{\n\t\tdata=d;\n\t}\n }\n \n public class BST{\n \n\tTLNode root;\n\t\n\tTLNode insert(int d,TLNode root)\n\t{\n\t  if(root==null)\n\t    root=new TLNode(d);\n\t  \n      else if(d&lt;=root.data)\n\t\troot.left=insert(d,root.left);\n\t\n\t  else\n\t\troot.right=insert(d,root.right);\n\t\n\t  return root;\n\t}\n\t\n\tTLNode search(int d,TLNode root)\n\t{\n\t\tif(root.data==d)\n\t\t\treturn root;\n\t\telse if(d&lt;root.data)\n\t\t\treturn search(d,root.left);\n\t    else\n\t\t\treturn search(d,root.right);\n\t}\n\t\n\t\n\t\n\tvoid inorder(TLNode r)\n   {\n\t\tif(r==null)\n\t\t    return;\n\t\t\n\t\t\n\t\tinorder(r.left);\n\t\tSystem.out.println(r.data);\n\t\tinorder(r.right);\n\t\t\n   }\n   \n\nTLNode delete(TLNode root, int data) \n    { \n        \n        if (root == null)  return root; \n \n        if (data &lt; root.data) \n            root.left = delete(root.left, data); \n        else if (data &gt; root.data) \n            root.right = delete(root.right, data); \n  \n        else\n        { \n            \n            if (root.left == null) \n                return root.right; \n            else if (root.right == null) \n                return root.left; \n  \n            \n            root.data = minValue(root.right); \n  \n            root.right = delete(root.right, root.data); \n        } \n  \n        return root; \n    } \t\n   int minValue(TLNode root) \n    { \n        int minv = root.data; \n        while (root.left != null) \n        { \n            minv = root.left.data; \n            root = root.left; \n        } \n        return minv; \n    } \n\n   \n   public static void main(String&#091;] args)\n   {\n\t\tBST ob=new BST();\n\t\tob.root=ob.insert(50,ob.root); \n                ob.root=ob.insert(30,ob.root); \n                ob.root=ob.insert(20,ob.root); \n                ob.root=ob.insert(20,ob.root); \n                ob.root=ob.insert(70,ob.root); \n                ob.root=ob.insert(60,ob.root); \n                ob.root=ob.insert(80,ob.root);    \n\t\tob.root=ob.delete(ob.root,50);\n\t\tSystem.out.println(\"******\" +ob.root.data);\n\t\tob.inorder(ob.root);\n\t\t\n\t\tTLNode find=ob.search(30,ob.root);\n\t\tif(find==null)\n\t\t\tSystem.out.println(\"not found\");\n\t\telse\n\t\t\tSystem.out.println(\"found : \"+find.data);\n\t\t\n\t\t\n\t}\n}\n\n  Output:\n  \n******60\n20\n20\n30\n60\n70\n80\nfound : 30\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe title=\"Trees in Java | Data Structures: Introduction to Trees in Java | Java Programming | Great Learning\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/FxaZu9KeKyI?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"heap\"><strong>Heap<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Binary Heap can be visualized array as a complete binary tree<\/li>\n\n\n\n<li>Arr[0] element will be treated as root<\/li>\n\n\n\n<li>length(A) - size of array<\/li>\n\n\n\n<li>heapSize(A) - size of heap<\/li>\n\n\n\n<li>Generally used when we are dealing with minimum and maximum elements<\/li>\n\n\n\n<li>For ith node<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>(i-1)\/2<\/td><td>Parent<\/td><\/tr><tr><td>(2*i)+1<\/td><td>Left child<\/td><\/tr><tr><td>(2*i)+2<\/td><td>Right Child<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"heap-advantages\"><strong>Heap<\/strong> <strong>Advantages<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Can be of 2 types: min heap and max heap<\/li>\n\n\n\n<li>Min heap keeps the smallest element and top and max keep the largest&nbsp;<\/li>\n\n\n\n<li>O(1) for dealing with min or max elements<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"heap-disadvantages\"><strong>Heap<\/strong> <strong>Disadvantages<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Random access is not possible<\/li>\n\n\n\n<li>Only min or max element is available for accessibility<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"heap-applications\"><strong>Heap<\/strong> <strong>Applications<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Suitable for applications dealing with priority<\/li>\n\n\n\n<li>Scheduling algorithm<\/li>\n\n\n\n<li>caching<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"program-of-max-heap\"><strong>Program of Max Heap<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.*;\n\n\nclass Heap{\n\n\tint heapSize;\n\t\n\tvoid build_max_heap(int&#091;] a)\n\t{\n\t\theapSize=a.length;\n\t\tfor(int i=(heapSize\/2);i&gt;=0;i--)\n\t\t\tmax_heapify(a,i);\n\t\t\n\t}\n\t\n\tvoid max_heapify(int&#091;] a,int i)\n\t{\n\t\tint l=2*i+1;\n\t\tint r=2*i+2;\n\t\tint largest=i;\n\t\tif(l&lt;heapSize &amp;&amp;a&#091;l]&gt;a&#091;largest])\n\t\t\tlargest=l;\n\t\tif(r&lt;heapSize &amp;&amp;a&#091;r]&gt;a&#091;largest])\n\t\t\tlargest=r;\n\t\tif(largest!=i)\n\t\t{\n\t\t\tint t=a&#091;i];\n\t\t\ta&#091;i]=a&#091;largest];\n\t\t\ta&#091;largest]=t;\n\t\t    max_heapify(a,largest);\n\t\t}\n\t\t\n\t}\n\t\n\t\/\/to delete the max element\n\t\n\tint extract_max(int&#091;] a)\n\t{\n\t\tif(heapSize&lt;0)\n\t\t\tSystem.out.println(\"underflow\");\n\t\tint max=a&#091;0];\n\t\ta&#091;0]=a&#091;heapSize-1];\n\t\theapSize--;\n\t\tmax_heapify(a,0);\n\t\treturn max;\n\t}\n\t\n\tvoid increase_key(int&#091;] a,int i,int key)\n\t{\n\t\tif(key&lt;a&#091;i])\n\t\t\tSystem.out.println(\"error\");\n\t\ta&#091;i]=key;\n\t\twhile(i&gt;=0 &amp;&amp; a&#091;(i-1)\/2]&lt;a&#091;i])\n\t\t{\n\t\t\tint t=a&#091;(i-1)\/2];\n\t\t\ta&#091;(i-1)\/2]=a&#091;i];\n\t\t\ta&#091;i]=t;\n\t\t\t\n\t\t\ti=(i-1)\/2;\n\t\t}\n\t}\n\t\n\tvoid print_heap(int a&#091;])\n\t{\n\t\tfor(int i=0;i&lt;heapSize;i++)\n\t\t    System.out.println(a&#091;i]+\" \");\n\t}\n}\n\t\npublic class HeapDemo{\n\t\n\tpublic static void main(String&#091;] args)\n\t{\n\t\tScanner in=new Scanner(System.in);\n\t\tint n=in.nextInt();\n\t\tint a&#091;]=new int&#091;n];\n\t\t\n\t\tSystem.out.println(\"enter the elements of array\");\n\t\t\n\t\tfor(int i=0;i&lt;n;i++)\n\t\t  a&#091;i]=in.nextInt();\n\t         Heap ob=new Heap();\n\t\t\n\t\tob.build_max_heap(a);\n\t\tob.print_heap(a);\n\t\t\n\t\t\n\t\tSystem.out.println(\"maximum element is : \"+ob.extract_max(a));\n\t\tob.print_heap(a);\n\t\tSystem.out.println(\"maximum element is : \"+ob.extract_max(a));\n\t\tob.increase_key(a,6,800);\n\t\tob.print_heap(a);\n\t\t   \n\t}\n\n}\n\nOutput\n7\nenter the elements of array\n50 100 10 1 3 20 5\n100\n50\n20\n1\n3\n10\n5\nmaximum element is : 100\n50\n5\n20\n1\n3\n10\nmaximum element is : 50\n800\n5\n20\n1\n3\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"hashing\"><strong>Hashing<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Uses special Hash function<\/li>\n\n\n\n<li>A hash function maps an element to an address for storage<\/li>\n\n\n\n<li>This provides constant-time access<\/li>\n\n\n\n<li>Collision resolution techniques handle collision<\/li>\n\n\n\n<li>Collision resolution technique\n<ul class=\"wp-block-list\">\n<li>Chaining<\/li>\n\n\n\n<li>Open Addressing<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"hashing-advantages\"><strong>Hashing<\/strong> <strong>Advantages<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The hash function helps in fetching elements in constant time<\/li>\n\n\n\n<li>An efficient way to store elements<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"hashing-disadvantages\"><strong><strong>Hashing<\/strong><\/strong> <strong>Disadvantages<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Collision resolution increases complexity<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"hashing-applications\"><strong><strong>Hashing<\/strong><\/strong> <strong>Applications<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Suitable for the application needs constant time fetching<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"demonstration-of-hashset-to-find-string-has-unique-characters\"><strong>Demonstration of HashSet - to find string has unique characters<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.*;\n\nclass HashSetDemo1{\n\n\tstatic boolean isUnique(String s)\n\t{\n\t\tHashSet&lt;Character&gt; set =new HashSet&lt;Character&gt;();\n\t\t\n\t\tfor(int i=0;i&lt;s.length();i++)\n\t\t    {\n\t\t\t\tchar c=s.charAt(i);\n\t\t\t\tif(c==' ')\n\t\t\t\t\tcontinue;\n\t\t\t\tif(set.add(c)==false)\n\t\t\t\t\treturn false;\n\t\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\treturn true;\n\t}\n\t\n\t\n\tpublic static void main(String&#091;] args)\n\t{\n\t\tString s=\"helo wqty \";\n\t\tboolean ans=isUnique(s);\n\t\tif(ans)\n\t\t\tSystem.out.println(\"string has unique characters\");\n\t\telse\n\t\t\tSystem.out.println(\"string does not have unique characters\");\n\n\t\t\n\t\t\n\t}\n}\n\nOutput:\nstring has unique characters\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"demonstration-of-hashmap-count-the-characters-in-a-string\"><strong>Demonstration of HashMap - count the characters in a string<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.*;\n\nclass HashMapDemo\n{\n\n\tstatic void check(String s)\n\t{\n\t\tHashMap&lt;Character,Integer&gt; map=new HashMap&lt;Character,Integer&gt;();\n\t\tfor(int i=0;i&lt;s.length();i++)\n\t\t\t{char c=s.charAt(i);\n\t\t\t if(!map.containsKey(c))\n\t\t\t\tmap.put(c,1);\n\t\t\t else\n\t\t\t\tmap.put(c,map.get(c)+1);\n\t\t\t}\n\t\t\t\n\t\t\n\t\t\n\t\tIterator&lt;Character&gt; itr = map.keySet().iterator();\n\t\twhile (itr.hasNext()) {\n\t\t\tObject x=itr.next();\n\t\t\tSystem.out.println(\"count of \"+x+\" : \"+map.get(x));\n\t\t}\n\t}\n\t\n\tpublic static void main(String&#091;] args)\n\t{\n\t\tString s=\"hello\";\n\t\tcheck(s);\n\t}\n}\n\nOutput\ncount of e : 1\ncount of h : 1\ncount of l : 2\ncount of o : 1\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"demonstration-of-hashtable-to-find-strings-has-unique-characters\"><strong>Demonstration of HashTable - to find strings has unique characters<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.*; \nclass hashTabledemo { \n\tpublic static void main(String&#091;] arg) \n\t{ \n\t\t\/\/ creating a hash table \n\t\tHashtable&lt;Integer, String&gt; h = \n\t\t\t\t\tnew Hashtable&lt;Integer, String&gt;(); \n\n\t\tHashtable&lt;Integer, String&gt; h1 = \n\t\t\t\t\tnew Hashtable&lt;Integer, String&gt;(); \n\n\t\th.put(3, \"Geeks\"); \n\t\th.put(2, \"forGeeks\"); \n\t\th.put(1, \"isBest\"); \n\n\t\t\/\/ create a clone or shallow copy of hash table h \n\t\th1 = (Hashtable&lt;Integer, String&gt;)h.clone(); \n\n\t\t\/\/ checking clone h1 \n\t\tSystem.out.println(\"values in clone: \" + h1); \n\n\t\t\/\/ clear hash table h \n\t\th.clear(); \n\n\t\t\/\/ checking hash table h \n\t\tSystem.out.println(\"after clearing: \" + h); \n\t\t\t\tSystem.out.println(\"values in clone: \" + h1); \n\n\n\t} \n} \n\nOutput\nvalues in clone: {3=Geeks, 2=forGeeks, 1=isBest}\nafter clearing: {}\nvalues in clone: {3=Geeks, 2=forGeeks, 1=isBest}\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"graph\"><strong>Graph<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Basically it is a group of edges and vertices<\/li>\n\n\n\n<li>Graph representation\n<ul class=\"wp-block-list\">\n<li>G(V, E); where V(G) represents a set of vertices and E(G) represents a set of edges<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>The graph can be directed or undirected<\/li>\n\n\n\n<li>The graph can be connected or disjoint<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"graph-advantages\"><strong>Graph<\/strong> <strong>Advantages<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>finding connectivity<\/li>\n\n\n\n<li>Shortest path<\/li>\n\n\n\n<li>min cost to reach from 1 pt to other<\/li>\n\n\n\n<li>Min spanning tree<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"graph-disadvantages\"><strong>Graph Disadvantages<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Storing graph(Adjacency list and Adjacency matrix) can lead to complexities<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"graph-applications\"><strong>Graph Applications<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Suitable for a circuit network<\/li>\n\n\n\n<li>Suitable for applications like Facebook, LinkedIn, etc<\/li>\n\n\n\n<li>Medical science<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"demonstration-of-graph\"><strong>Demonstration of Graph<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.*;\n\nclass Graph\n{\n\tint v;\n\tLinkedList&lt;Integer&gt; adj&#091;];\n\n\tGraph(int v)\n\t{\n\t\tthis.v=v;\n\t\tadj=new LinkedList&#091;v];\n\t\tfor(int i=0;i&lt;v;i++)\n\t\t\tadj&#091;i]=new LinkedList&lt;Integer&gt;();\n\t}\n\n\n\tvoid addEdge(int u,int v)\n\t{\n\t\tadj&#091;u].add(v);\n\t}\n\t\n\tvoid BFS(int s)\n\t{\n\t\tboolean&#091;] visited=new boolean&#091;v];\n\t\tLinkedList&lt;Integer&gt; q=new LinkedList&lt;Integer&gt;();\n\t\tq.add(s);\n\t\tvisited&#091;s]=true;\n\n\t\twhile(!q.isEmpty())\n\t\t{\n\t\t\tint x=q.poll();\n\t\t\tSystem.out.print(x+\" \");\n\n\t\t\tIterator&lt;Integer&gt; itr=adj&#091;x].listIterator();\n\t\t\twhile(itr.hasNext())\n\t\t\t{\n\t\t\t  int p=itr.next();\n\t\t\t  if(visited&#091;p]==false)\n\t\t\t\t{\n\t\t\t\t\tvisited&#091;p]=true;\n\t\t\t\t\tq.add(p);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\n\t\n\tvoid DFSUtil(int s,boolean&#091;] visited)\n\t{\n\t\tvisited&#091;s]=true;\n\t\tSystem.out.println(s);\n\n\t\tIterator&lt;Integer&gt; itr=adj&#091;s].listIterator();\n\t\twhile(itr.hasNext())\n\t\t{\n\t\t\tint x=itr.next();\n\t\t\tif(visited&#091;x]==false)\n\t\t\t{                                                        \n\t\t\t\t\/\/visited&#091;x]=true;\n\n\t\t\t\tDFSUtil(x,visited);\n\t\t\t} \n\t\t}\n\t}\n\t\n\t\n\tvoid DFS(int s){\n\t\tboolean visited&#091;]=new boolean&#091;v];\n\t\tDFSUtil(s,visited);\n\t}\n\n\tpublic static void main(String&#091;] args)\n\t\t{\n\t\t\tGraph g=new Graph(4);\n\t\t\tg.addEdge(0,1);\n\t\t\tg.addEdge(0,2);\n\t\t\tg.addEdge(1,2);\n\t\t\tg.addEdge(2,0);\n\t\t\tg.addEdge(2,3);\n\t\t\tg.addEdge(3,3);\n\t\t\t\n\t\t\tg.BFS(2);\n\t\t\tg.DFS(2);\n\n\t\t}\n}\n\nOutput:\n2 0 3 1 2\n0\n1\n3\n\n<\/code><\/pre>\n\n\n\n<p>Mastering data structures is what separates a basic coder from a professional software engineer. However, trying to jump into these concepts without a plan can feel like trying to build a house without a blueprint. The best way to turn these theories into actual skill is with a hands-on start. To build your expertise the right way, join our <a href=\"https:\/\/www.mygreatlearning.com\/academy\/learn-for-free\/courses\/java-programming\" target=\"_blank\" rel=\"noreferrer noopener\">free Java Course<\/a>. It is the easiest way for absolute beginners to go from zero experience to a pro with a clear, step-by-step path.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"data-structures-in-java-faqs\"><strong>Data Structures in Java FAQs<\/strong><\/h2>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1714728633119\"><strong class=\"schema-faq-question\"><strong>Can I use Java for data structures?<\/strong><\/strong> <p class=\"schema-faq-answer\">Yes, you can use Java for data structures. Here, Java is just a programming language, and data structures help in storing and organizing the data in the required format.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1714728750438\"><strong class=\"schema-faq-question\"><strong>What are the data structures of Java?<\/strong><\/strong> <p class=\"schema-faq-answer\">Some of the data structures of Java are:Linked Lists<br\/>Arrays<br\/>Stack<br\/>Queue<br\/>Graph<br\/>Set<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1714728767718\"><strong class=\"schema-faq-question\"><strong>Which data structure is best for Java?<\/strong><\/strong> <p class=\"schema-faq-answer\">There is no such best data structure for Java. But programmers will use arrays as it is one of the simplest and most widely used data structures.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1714728786665\"><strong class=\"schema-faq-question\"><strong>What is the fastest data structure in Java?<\/strong><\/strong> <p class=\"schema-faq-answer\">For different problems, different data structures are the fastest. But in general, arrays are the fastest data structures in Java as it is a simple data structure.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1714728804238\"><strong class=\"schema-faq-question\"><strong>Should I learn data structures in Java?<\/strong><\/strong> <p class=\"schema-faq-answer\">Yes, learning data structures in Java helps you in enhancing your programming knowledge. It is said that Data structures + Algorithms = Programs, so learning data structures is important.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1714728826137\"><strong class=\"schema-faq-question\"><strong>Which language is best for DSA?<\/strong><\/strong> <p class=\"schema-faq-answer\">Language is just a medium, but in the current trend, Java or Python is the best language for DSA.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1714728852606\"><strong class=\"schema-faq-question\"><strong>How many data structures are there in Java?<\/strong><\/strong> <p class=\"schema-faq-answer\">There are 2 data structures in Java. They are linear and non-linear (hierarchical) data structures.<\/p> <\/div> <\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>Engaging in the study of Java programming suggests a keen interest in the realm of software development. For those embarking upon this journey with aspirations towards a career in this field, it is recommended to explore <strong><a href=\"https:\/\/www.mygreatlearning.com\/academy\" target=\"_blank\" rel=\"noreferrer noopener\">online courses with certificates<\/a><\/strong> in order to acquire a comprehensive understanding of the development career path and gain valuable credentials.<br><br><\/p>\n\n\n\n<figure class=\"wp-block-table aligncenter\"><table class=\"has-cyan-bluish-gray-background-color has-background\"><tbody><tr><td><a href=\"https:\/\/www.mygreatlearning.com\/software-engineering\/courses\/certificates\" target=\"_blank\" rel=\"noreferrer noopener\">Software engineering courses certificates<\/a><\/td><\/tr><tr><td><a href=\"https:\/\/www.mygreatlearning.com\/software-engineering\/courses\/placements\" target=\"_blank\" rel=\"noreferrer noopener\">Software engineering courses placements<\/a><\/td><\/tr><tr><td><a href=\"https:\/\/www.mygreatlearning.com\/software-engineering\/courses\/syllabus\" target=\"_blank\" rel=\"noreferrer noopener\">Software engineering courses syllabus<\/a><\/td><\/tr><tr><td><a href=\"https:\/\/www.mygreatlearning.com\/software-engineering\/courses\/fees\" target=\"_blank\" rel=\"noreferrer noopener\">Software engineering courses fees<\/a><\/td><\/tr><tr><td><a href=\"https:\/\/www.mygreatlearning.com\/software-engineering\/courses\/eligibility\" target=\"_blank\" rel=\"noreferrer noopener\">Software engineering courses eligibility<\/a><\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Data structures are fundamental to any programming language. The choice of a particular data structure has a significant impact on the functionality and performance of Java applications, thus it is worthwhile to master data structures in Java. This guide will help beginners to understand what is data structures, what is data structures in Java, the [&hellip;]<\/p>\n","protected":false},"author":41,"featured_media":76736,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[25860],"tags":[36826],"content_type":[],"class_list":["post-17069","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software","tag-java"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Data Structures in Java | Great Learning<\/title>\n<meta name=\"description\" content=\"Data Structures in Java: This refers to a way to arrange data in computers. Array, Linked List, Stack, Queue, and Binary Tree are examples.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mygreatlearning.com\/blog\/data-structures-using-java\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Data Structures in Java - A Beginners Guide\" \/>\n<meta property=\"og:description\" content=\"Data Structures in Java: This refers to a way to arrange data in computers. Array, Linked List, Stack, Queue, and Binary Tree are examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mygreatlearning.com\/blog\/data-structures-using-java\/\" \/>\n<meta property=\"og:site_name\" content=\"Great Learning Blog: Free Resources what Matters to shape your Career!\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GreatLearningOfficial\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-04-08T03:38:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-01-06T14:17:31+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/Blog-Featured-Image-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Great Learning Editorial Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/Great_Learning\" \/>\n<meta name=\"twitter:site\" content=\"@Great_Learning\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Great Learning Editorial Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/data-structures-using-java\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/data-structures-using-java\\\/\"},\"author\":{\"name\":\"Great Learning Editorial Team\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\"},\"headline\":\"Data Structures in Java - A Beginners Guide\",\"datePublished\":\"2024-04-08T03:38:00+00:00\",\"dateModified\":\"2025-01-06T14:17:31+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/data-structures-using-java\\\/\"},\"wordCount\":2106,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/data-structures-using-java\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/Blog-Featured-Image-1.png\",\"keywords\":[\"java\"],\"articleSection\":[\"IT\\\/Software Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/data-structures-using-java\\\/#respond\"]}]},{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/data-structures-using-java\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/data-structures-using-java\\\/\",\"name\":\"Data Structures in Java | Great Learning\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/data-structures-using-java\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/data-structures-using-java\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/Blog-Featured-Image-1.png\",\"datePublished\":\"2024-04-08T03:38:00+00:00\",\"dateModified\":\"2025-01-06T14:17:31+00:00\",\"description\":\"Data Structures in Java: This refers to a way to arrange data in computers. Array, Linked List, Stack, Queue, and Binary Tree are examples.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/data-structures-using-java\\\/#breadcrumb\"},\"mainEntity\":[{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/data-structures-using-java\\\/#faq-question-1714728633119\"},{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/data-structures-using-java\\\/#faq-question-1714728750438\"},{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/data-structures-using-java\\\/#faq-question-1714728767718\"},{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/data-structures-using-java\\\/#faq-question-1714728786665\"},{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/data-structures-using-java\\\/#faq-question-1714728804238\"},{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/data-structures-using-java\\\/#faq-question-1714728826137\"},{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/data-structures-using-java\\\/#faq-question-1714728852606\"}],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/data-structures-using-java\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/data-structures-using-java\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/Blog-Featured-Image-1.png\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/Blog-Featured-Image-1.png\",\"width\":1200,\"height\":628,\"caption\":\"Data Structures in Java\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/data-structures-using-java\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"IT\\\/Software Development\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/software\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Data Structures in Java - A Beginners Guide\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"name\":\"Great Learning Blog\",\"description\":\"Learn, Upskill &amp; Career Development Guide and Resources\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"alternateName\":\"Great Learning\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\",\"name\":\"Great Learning\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"width\":900,\"height\":900,\"caption\":\"Great Learning\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/GreatLearningOfficial\\\/\",\"https:\\\/\\\/x.com\\\/Great_Learning\",\"https:\\\/\\\/www.instagram.com\\\/greatlearningofficial\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/in.pinterest.com\\\/greatlearning12\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/beaconelearning\\\/\"],\"description\":\"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.\",\"email\":\"info@mygreatlearning.com\",\"legalName\":\"Great Learning Education Services Pvt. Ltd\",\"foundingDate\":\"2013-11-29\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1001\",\"maxValue\":\"5000\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\",\"name\":\"Great Learning Editorial Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"caption\":\"Great Learning Editorial Team\"},\"description\":\"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.\",\"sameAs\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/\",\"https:\\\/\\\/in.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/Great_Learning\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCObs0kLIrDjX2LLSybqNaEA\"],\"award\":[\"Best EdTech Company of the Year 2024\",\"Education Economictimes Outstanding Education\\\/Edtech Solution Provider of the Year 2024\",\"Leading E-learning Platform 2024\"],\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/author\\\/greatlearning\\\/\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/data-structures-using-java\\\/#faq-question-1714728633119\",\"position\":1,\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/data-structures-using-java\\\/#faq-question-1714728633119\",\"name\":\"Can I use Java for data structures?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Yes, you can use Java for data structures. Here, Java is just a programming language, and data structures help in storing and organizing the data in the required format.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/data-structures-using-java\\\/#faq-question-1714728750438\",\"position\":2,\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/data-structures-using-java\\\/#faq-question-1714728750438\",\"name\":\"What are the data structures of Java?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Some of the data structures of Java are:Linked Lists<br\\\/>Arrays<br\\\/>Stack<br\\\/>Queue<br\\\/>Graph<br\\\/>Set\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/data-structures-using-java\\\/#faq-question-1714728767718\",\"position\":3,\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/data-structures-using-java\\\/#faq-question-1714728767718\",\"name\":\"Which data structure is best for Java?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"There is no such best data structure for Java. But programmers will use arrays as it is one of the simplest and most widely used data structures.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/data-structures-using-java\\\/#faq-question-1714728786665\",\"position\":4,\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/data-structures-using-java\\\/#faq-question-1714728786665\",\"name\":\"What is the fastest data structure in Java?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"For different problems, different data structures are the fastest. But in general, arrays are the fastest data structures in Java as it is a simple data structure.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/data-structures-using-java\\\/#faq-question-1714728804238\",\"position\":5,\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/data-structures-using-java\\\/#faq-question-1714728804238\",\"name\":\"Should I learn data structures in Java?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Yes, learning data structures in Java helps you in enhancing your programming knowledge. It is said that Data structures + Algorithms = Programs, so learning data structures is important.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/data-structures-using-java\\\/#faq-question-1714728826137\",\"position\":6,\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/data-structures-using-java\\\/#faq-question-1714728826137\",\"name\":\"Which language is best for DSA?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Language is just a medium, but in the current trend, Java or Python is the best language for DSA.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/data-structures-using-java\\\/#faq-question-1714728852606\",\"position\":7,\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/data-structures-using-java\\\/#faq-question-1714728852606\",\"name\":\"How many data structures are there in Java?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"There are 2 data structures in Java. They are linear and non-linear (hierarchical) data structures.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Data Structures in Java | Great Learning","description":"Data Structures in Java: This refers to a way to arrange data in computers. Array, Linked List, Stack, Queue, and Binary Tree are examples.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.mygreatlearning.com\/blog\/data-structures-using-java\/","og_locale":"en_US","og_type":"article","og_title":"Data Structures in Java - A Beginners Guide","og_description":"Data Structures in Java: This refers to a way to arrange data in computers. Array, Linked List, Stack, Queue, and Binary Tree are examples.","og_url":"https:\/\/www.mygreatlearning.com\/blog\/data-structures-using-java\/","og_site_name":"Great Learning Blog: Free Resources what Matters to shape your Career!","article_publisher":"https:\/\/www.facebook.com\/GreatLearningOfficial\/","article_published_time":"2024-04-08T03:38:00+00:00","article_modified_time":"2025-01-06T14:17:31+00:00","og_image":[{"width":1200,"height":628,"url":"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/Blog-Featured-Image-1.png","type":"image\/png"}],"author":"Great Learning Editorial Team","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/Great_Learning","twitter_site":"@Great_Learning","twitter_misc":{"Written by":"Great Learning Editorial Team","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mygreatlearning.com\/blog\/data-structures-using-java\/#article","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/data-structures-using-java\/"},"author":{"name":"Great Learning Editorial Team","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad"},"headline":"Data Structures in Java - A Beginners Guide","datePublished":"2024-04-08T03:38:00+00:00","dateModified":"2025-01-06T14:17:31+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/data-structures-using-java\/"},"wordCount":2106,"commentCount":0,"publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/data-structures-using-java\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/Blog-Featured-Image-1.png","keywords":["java"],"articleSection":["IT\/Software Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.mygreatlearning.com\/blog\/data-structures-using-java\/#respond"]}]},{"@type":["WebPage","FAQPage"],"@id":"https:\/\/www.mygreatlearning.com\/blog\/data-structures-using-java\/","url":"https:\/\/www.mygreatlearning.com\/blog\/data-structures-using-java\/","name":"Data Structures in Java | Great Learning","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/data-structures-using-java\/#primaryimage"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/data-structures-using-java\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/Blog-Featured-Image-1.png","datePublished":"2024-04-08T03:38:00+00:00","dateModified":"2025-01-06T14:17:31+00:00","description":"Data Structures in Java: This refers to a way to arrange data in computers. Array, Linked List, Stack, Queue, and Binary Tree are examples.","breadcrumb":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/data-structures-using-java\/#breadcrumb"},"mainEntity":[{"@id":"https:\/\/www.mygreatlearning.com\/blog\/data-structures-using-java\/#faq-question-1714728633119"},{"@id":"https:\/\/www.mygreatlearning.com\/blog\/data-structures-using-java\/#faq-question-1714728750438"},{"@id":"https:\/\/www.mygreatlearning.com\/blog\/data-structures-using-java\/#faq-question-1714728767718"},{"@id":"https:\/\/www.mygreatlearning.com\/blog\/data-structures-using-java\/#faq-question-1714728786665"},{"@id":"https:\/\/www.mygreatlearning.com\/blog\/data-structures-using-java\/#faq-question-1714728804238"},{"@id":"https:\/\/www.mygreatlearning.com\/blog\/data-structures-using-java\/#faq-question-1714728826137"},{"@id":"https:\/\/www.mygreatlearning.com\/blog\/data-structures-using-java\/#faq-question-1714728852606"}],"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mygreatlearning.com\/blog\/data-structures-using-java\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/data-structures-using-java\/#primaryimage","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/Blog-Featured-Image-1.png","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/Blog-Featured-Image-1.png","width":1200,"height":628,"caption":"Data Structures in Java"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mygreatlearning.com\/blog\/data-structures-using-java\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.mygreatlearning.com\/blog\/"},{"@type":"ListItem","position":2,"name":"IT\/Software Development","item":"https:\/\/www.mygreatlearning.com\/blog\/software\/"},{"@type":"ListItem","position":3,"name":"Data Structures in Java - A Beginners Guide"}]},{"@type":"WebSite","@id":"https:\/\/www.mygreatlearning.com\/blog\/#website","url":"https:\/\/www.mygreatlearning.com\/blog\/","name":"Great Learning Blog","description":"Learn, Upskill &amp; Career Development Guide and Resources","publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"alternateName":"Great Learning","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mygreatlearning.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization","name":"Great Learning","url":"https:\/\/www.mygreatlearning.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","width":900,"height":900,"caption":"Great Learning"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/GreatLearningOfficial\/","https:\/\/x.com\/Great_Learning","https:\/\/www.instagram.com\/greatlearningofficial\/","https:\/\/www.linkedin.com\/school\/great-learning\/","https:\/\/in.pinterest.com\/greatlearning12\/","https:\/\/www.youtube.com\/user\/beaconelearning\/"],"description":"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.","email":"info@mygreatlearning.com","legalName":"Great Learning Education Services Pvt. Ltd","foundingDate":"2013-11-29","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1001","maxValue":"5000"}},{"@type":"Person","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad","name":"Great Learning Editorial Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","caption":"Great Learning Editorial Team"},"description":"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.","sameAs":["https:\/\/www.mygreatlearning.com\/","https:\/\/in.linkedin.com\/school\/great-learning\/","https:\/\/x.com\/https:\/\/twitter.com\/Great_Learning","https:\/\/www.youtube.com\/channel\/UCObs0kLIrDjX2LLSybqNaEA"],"award":["Best EdTech Company of the Year 2024","Education Economictimes Outstanding Education\/Edtech Solution Provider of the Year 2024","Leading E-learning Platform 2024"],"url":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},{"@type":"Question","@id":"https:\/\/www.mygreatlearning.com\/blog\/data-structures-using-java\/#faq-question-1714728633119","position":1,"url":"https:\/\/www.mygreatlearning.com\/blog\/data-structures-using-java\/#faq-question-1714728633119","name":"Can I use Java for data structures?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Yes, you can use Java for data structures. Here, Java is just a programming language, and data structures help in storing and organizing the data in the required format.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.mygreatlearning.com\/blog\/data-structures-using-java\/#faq-question-1714728750438","position":2,"url":"https:\/\/www.mygreatlearning.com\/blog\/data-structures-using-java\/#faq-question-1714728750438","name":"What are the data structures of Java?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Some of the data structures of Java are:Linked Lists<br\/>Arrays<br\/>Stack<br\/>Queue<br\/>Graph<br\/>Set","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.mygreatlearning.com\/blog\/data-structures-using-java\/#faq-question-1714728767718","position":3,"url":"https:\/\/www.mygreatlearning.com\/blog\/data-structures-using-java\/#faq-question-1714728767718","name":"Which data structure is best for Java?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"There is no such best data structure for Java. But programmers will use arrays as it is one of the simplest and most widely used data structures.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.mygreatlearning.com\/blog\/data-structures-using-java\/#faq-question-1714728786665","position":4,"url":"https:\/\/www.mygreatlearning.com\/blog\/data-structures-using-java\/#faq-question-1714728786665","name":"What is the fastest data structure in Java?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"For different problems, different data structures are the fastest. But in general, arrays are the fastest data structures in Java as it is a simple data structure.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.mygreatlearning.com\/blog\/data-structures-using-java\/#faq-question-1714728804238","position":5,"url":"https:\/\/www.mygreatlearning.com\/blog\/data-structures-using-java\/#faq-question-1714728804238","name":"Should I learn data structures in Java?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Yes, learning data structures in Java helps you in enhancing your programming knowledge. It is said that Data structures + Algorithms = Programs, so learning data structures is important.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.mygreatlearning.com\/blog\/data-structures-using-java\/#faq-question-1714728826137","position":6,"url":"https:\/\/www.mygreatlearning.com\/blog\/data-structures-using-java\/#faq-question-1714728826137","name":"Which language is best for DSA?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Language is just a medium, but in the current trend, Java or Python is the best language for DSA.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.mygreatlearning.com\/blog\/data-structures-using-java\/#faq-question-1714728852606","position":7,"url":"https:\/\/www.mygreatlearning.com\/blog\/data-structures-using-java\/#faq-question-1714728852606","name":"How many data structures are there in Java?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"There are 2 data structures in Java. They are linear and non-linear (hierarchical) data structures.","inLanguage":"en-US"},"inLanguage":"en-US"}]}},"uagb_featured_image_src":{"full":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/Blog-Featured-Image-1.png",1200,628,false],"thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/Blog-Featured-Image-1-150x150.png",150,150,true],"medium":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/Blog-Featured-Image-1-300x157.png",300,157,true],"medium_large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/Blog-Featured-Image-1-768x402.png",768,402,true],"large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/Blog-Featured-Image-1-1024x536.png",1024,536,true],"1536x1536":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/Blog-Featured-Image-1.png",1200,628,false],"2048x2048":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/Blog-Featured-Image-1.png",1200,628,false],"web-stories-poster-portrait":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/Blog-Featured-Image-1-640x628.png",640,628,true],"web-stories-publisher-logo":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/Blog-Featured-Image-1-96x96.png",96,96,true],"web-stories-thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/07\/Blog-Featured-Image-1-150x79.png",150,79,true]},"uagb_author_info":{"display_name":"Great Learning Editorial Team","author_link":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},"uagb_comment_info":1,"uagb_excerpt":"Data structures are fundamental to any programming language. The choice of a particular data structure has a significant impact on the functionality and performance of Java applications, thus it is worthwhile to master data structures in Java. This guide will help beginners to understand what is data structures, what is data structures in Java, the&hellip;","_links":{"self":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/17069","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/comments?post=17069"}],"version-history":[{"count":145,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/17069\/revisions"}],"predecessor-version":[{"id":117144,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/17069\/revisions\/117144"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media\/76736"}],"wp:attachment":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media?parent=17069"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/categories?post=17069"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/tags?post=17069"},{"taxonomy":"content_type","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/content_type?post=17069"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}