Data structures in Java

This post is mainly for beginners in data structures. It covers the very basic explanation of what data structures are, why are they useful, the advantages of data structures, some real time applications of data structures and some commonly used data structures in Java.

Explanation:

Data structures are a way of organizing the information to perform some useful tasks in an efficient way. They help to store and process the data in an efficient manner by defining the time and the space required to store and process the data.

The array data structure has fixed size and can store information of similar data type. Arrays are not dynamic in nature and can be used in applications where the number of elements to store is known in advanced. For example, if you want to sort a sequence of numbers then arrays can be used.

Arrays in Java

Advantages of data structures:

  1. Data structures help to design efficient algorithms.
  2. They occupy minimum space and also represent the complexity of information.
  3. Allows easy processing of data.
  4. We can use data structures as per our requirement. For example we can use array data structure if we know we want to process a fix size of information. And in case of dynamic size of information we can use an array list or a linked list.
  5. Data structures can be used for implementing real time applications like games, text editors and many complex algorithms can be implemented using them.

Commonly used data structures:

  • Array
  • Stack
  • Queue
  • Linked list
  • Heap
  • Binary tree
  • Binary search tree
  • Graph

Real time applications of data structures:

  1. Stack: Stack data structure is used to implement undo functionality in applications like Microsoft word. All the text that we type is stored on stack and undo operation pops the text from the stack. Another application is the back button in browsers. As we traverse the web pages, the URL’s of the pages are stored on the stack. The top URL represents the current page we are viewing. When we press the back button, the URL at the top of the stack is popped. And the previous URL which we visited is now the topmost element on the stack and hence the previous page is visible to the user.
  2. Graphs: Graphs are used to represent relationships between entities.A very common example can be the network connections between people on LinkedIn or Facebook. Where people represent the nodes of the graph and the connection between them represent the the edges between the nodes. Another example of graphs are Google Maps where the locations represent the nodes of the graph and the route between the locations represent the edges between the nodes.
  3. Set: Set data structure can be used in applications like membership information where duplicate entries are not allowed. It can also be used in application like where there is a need to maintain student records based on some unique field.

Please feel free to provide your feedback in below comments section. If you liked the blog and if it helped you please like and share. Happy learning..!!

Design a site like this with WordPress.com
Get started