Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Examples of Data Structures in real life [closed]

In each of the following examples, we need to choose the best data structure(s). Options are: Array, Linked Lists, Stack, Queues, Trees, Graphs, Sets, Hash Tables. This is not homework, however, I am really curious about data structures and I would like the answer to these questions so that I can understand how each structure works.

  1. You have to store social network “feeds”. You do not know the size, and things may need to be dynamically added.
  2. You need to store undo/redo operations in a word processor.
  3. You need to evaluate an expression (i.e., parse).
  4. You need to store the friendship information on a social networking site. I.e., who is friends with who.
  5. You need to store an image (1000 by 1000 pixels) as a bitmap.
  6. To implement printer spooler so that jobs can be printed in the order of their arrival.
  7. To implement back functionality in the internet browser.
  8. To store the possible moves in a chess game.
  9. To store a set of fixed key words which are referenced very frequently.
  10. To store the customer order information in a drive-in burger place. (Customers keep on coming and they have to get their correct food at the payment/food collection window.)
  11. To store the genealogy information of biological species.
like image 305
M Papas Avatar asked Jan 31 '19 17:01

M Papas


1 Answers

  1. Hash table (uniquely identifies each feed while allowing additional feeds to be added (assuming dynamic resizing))
  2. Linked List (doubly-linked: from one node, you can go backwards/forwards one by one)
  3. Tree (integral to compilers/automata theory; rules determine when to branch and how many branches to have. look up parse trees)
  4. Graph (each person is a point, and connections/friendships are an edge)
  5. Array (2-dimensional, 1000x1000, storing color values)
  6. Queue (like a queue/line of people waiting to get through a checkpoint)
  7. Stack (you can add to the stack with each site visited, and pop off as necessary to go back, as long as you don't care about going forward. If you care about forward, this is the same scenario as the word processor, so linked list)
  8. Tree (can follow any game move by move, down from the root to the leaf. Note that this tree is HUGE)
  9. Hash table (If you want to use the keywords as keys, and get all things related to them, I would suggest a hash table with linked lists as the keys' corresponding values. I might be misunderstanding this scenario, the description confuses me a little as to how they are intended to be used)
  10. Queue or Hash Table (if this is a drive thru, assuming people aren't cutting in front of one another, it's like the printer question. If customers are placing orders ahead of time, and can arrive in 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)
  11. Tree (look up phylogenic tree)

If you would like to know more about how each data structure works, here is one of many helpful sites that discusses them in detail.

like image 156
Chris Clayton Avatar answered Sep 28 '22 18:09

Chris Clayton