A data structure is a collection of values(data), a way of organizing and storing data in a computer, so that it can be accessed and modified efficiently. In other words, it’s like a storage that helps us to organize data, so that we can go into the storage and get data fast and easier.

Each data type has a number of bits associated with it and that needs to get stored in the system, and the system allocates that storage and then the CPU reads from that storage.

There are several different types of data structures. Each data structure is good and is specialized for its own thing. Some of the most commonly used data structures include arrays, linked lists, stacks, queues, trees, and graphs.

Now let’s do an example of how the same data can be organized in a variety of ways

  • This program works with 2 pieces of data, outputting 2 strings to make a full name. This data is organized in a way of 2 independent strings, and each contained within a single variable.
  • And here, the same data can also be stored in an array

Data structure prefers to how data is organized, but it doesn’t just matter for organization’s sake. It can significantly impact how fast your code run; Therefore, understanding data structures and their performance is very important.

Data Operations

Now let analyze the common ways our code might interact with data structures.

There are 4 basic ways which we refer to as operations:

  • Read: Reading refers to looking something up at a particular spot within the data structure – the process of retrieving data. In array, the read operation would typically involve specifying an index and retrieving the value stored at that index. In a linked list, the read operation would typically involve starting at the head of the list and following the pointers until you reach the desired node.
  • Search: Searching refers to looking for a value within a data structure – the process of finding an item stored in the data structure. In an array, the search operation would typically involve iterating over each element in the array and comparing it to the item being searched for. In a linked list, the search operation would typically involve starting at the head of the list and following the pointers until you find the desired node.
  • Insert: Insertion refers to the process of adding a new value to the data structure. In an array, the insert operation would typically involve adding the new item to the end of the array and updating the size of the array. In a linked list, the insert operation would typically involve creating a new node, updating the pointers of the existing nodes to include the new node, and updating the head or tail of the list as necessary.
  • Delete: Deletion refers to the process of removing a value from the data structure. In an array, this mean removing one of the values from the array, and the process involve shifting all elements after the deleted element to fill the gap, and updating the size of the array. In a linked list, the delete operation would typically involve updating the pointers of the surrounding nodes to exclude the node being deleted, and potentially updating the head or tail of the list as necessary.

Conclusion

Data structures provide a way of organizing and storing data in a way that makes it easy to access and manipulate, and they play a critical role in the design and implementation of algorithms, software systems, and applications. Having a good understanding of data structures can help you make informed decisions about how to store and manage data in your applications, and can enable you to write more efficient and effective algorithms. In addition, understanding data structures can also help you to appreciate the trade-offs involved in different approaches to data management, and can give you insight into how different data structures are best suited to different types of data and use cases.

By Tam Lee

Leave a Reply

Your email address will not be published. Required fields are marked *