Table of Contents
Introduction
Commonly abbreviated as DS, Data Structures are means to store a collection or list of data in an organized manner. Instead of allocating single variables, groups of data can be efficiently stored in various data structures that JAVA offers. Data Structures in Java are encapsulated in the utility package. Therefore, if you want to use any of the various data structures, you will need to make the following import in your code:
import java.util.*;
Most data structures follow the convention of storing elements that are of the same type. For example, if you have initialized an integer type array, you will not be able to store strings inside it. A data type mismatch error will occur.
Types of Data Structures in JAVA
- Arrays – Arrays are defined as a collection of items stored at contiguous memory locations. Each element of the array can be uniquely identified using the index value. The first element has the index 0, the 2nd element ha san index of 1 and so on.
- Linked List – This is a linear data structure where every node points to the next node in line. Items are not stored in contiguous memory therefore this DS is memory efficient.
- Stack – Stack is also another linear data structure. It works like a pile of cards stacked on top of one another. It follows LIFO (Last In first out).
- Queue – Queue is an open-ended stack that follows a linear pattern. Normally it follows FIFO (First In First Out). Queues can be of various types. The circular queue is commonly used to solve various logical problems.
- Binary Tree – A binary tree is a hierarchical data structure. If one were to visualize it, a Binary Tree will take the shape of an inverted tree thus the name. The topmost node is called the root. Elements right below the root are called children. A node with no children is called a tree.
0 Comments