What Scenarios of different Data Structures you know?

The data structure is a way of organizing, processing, retrieving, and storing data. There are several basic and advanced types of data structures used in programming, all designed to arrange data to suit a specific purpose. Data structures make it easy for users to access and work with the data they need in appropriate ways. If you have confusion about which data structure will be used when then for that here are some of the Scenarios mentioned that tell how to choose a suitable data structure like Array, Linked Lists, Stack, Queues, Trees, Graphs, Sets, Hash Tables, etc. It may be possible that a particular scenario has more than one data structure. For the given scenario, if you want to conclude or have more scenarios, please do comment.

  1. You have to store social network “feeds” may be in the form of text, or any media. If you do not know the size, things may need to be dynamically added. Then in this case the suitable data structure you can use is the Hash table because it stores data in an associative manner. As in hash table data is stored in an array format, where each data value has its own unique index value. This will help uniquely identify each feed and also the additional feed having dynamic resizing. Dynamic resize means you can post text as a feed after that for any long-length video, and then any set of images, etc.
  2. You must store undo/redo operations in a word processor like MS Word or any other processor. At that time when you use ctrl+z or ctrl+y then for this, the data structure which you are following is a Linked list and that is to be a Doubly-linked list. When you apply to undo an operation, you are moving to the previous operation; when you redo, you will return to the current pointer. This is how a doubly linked list will be used to perform undo/redo operations.
  3. Whenever there is a need for evaluating an expression what kind of data structure is used? When we evaluate an expression at that time, the data structure we prefer is Tree. The tree is a non-linear, hierarchal data structure consisting of nodes. Where the child node has particular operands and the parent node has an operator through which operation is need to be performed. Trees are integral to compilers/automata theory through which it is easy to determine when to branch and how many branches to have.
  1. You want to connect with friends and need to store the friendship information on a social networking site. I.e., who are friends with whom? So in this scenario Graph data structure is preferred. As the graph is a non-linear data structure that has nodes and edges. Each node is considered a person and edges are their relationships among the nodes.
  1. If you need to store an image (1000 by 1000 pixels) as a bitmap. Then for this, we need a data structure that will store information in a linear order and that will be possible through an array which may be in a one-dimensional or two-dimensional data structure.
  1. To implement printer spooler so that jobs can be printed in the order of their arrival. For this, there needs a data structure where you can print a job (any task to print) in a sequential manner, so the best data structure is a Queue( like a queue/line of people waiting to get through a checkpoint) where the job gets started to print from the initial page till the final. The process will continue until the job gets printed.
  1. Implement back functionality in your internet browser. Whenever we visit a website and traverse from one link to another it means we are conducting a push operation and when we reverse in the same form it means we are popping and returning back from where we have started exploring the website. To have this functionality, the best data structure we can use here is Stack. Stack is a linear data structure that follows the principle of Last In First Out.
  1. To store the possible moves in a chess game, the suitable data structure will be the tree. Because through the tree you can follow the game move by move and where necessary backtrack.
  1. Store a set of fixed keywords that are referenced very frequently. In such a scenario Hash Table will be the most suitable data structure. Here focused keywords will be used as keys through which it will be easy to get all related items based on that keyword.
  1. To store the customer order information in a drive-in burger location. Customers keep on coming and they have to get their correct food from the collection window as what they have made payment for. In such a scenario either we go with Queue or Hash Table. If we consider a queue then it will be assumed that people will not bypass another one. But if customers are placing orders ahead of time and can arrive at any order, a hash table would be much better, with an order number or customer name as the key and the order details as the value.

Leave a Reply

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