Data Structures: Are you LIFO or FIFO?

Brad Hankee
Code a la Carte
Published in
2 min readMar 19, 2017

Our coverage on data structures was interesting to say the least. We got to learn how at the basic level data can be organized in order to be utilized later on. To say this is important is an understatement. Data is very essential to computers. One of the concepts I took away was realizing two forms of structuring data:

  • LIFO
  • FIFO

LIFO is Last In First Out and FIFO is First In First Out. To clarify, here is an example of each that you may encounter in your daily life.

LIFO: On a grocery store shelf lets assume they stock from the back to the front. So if the shelf is empty the first can of beans will go in the back then the shelf will be filled to the front. When I come by to buy the beans to make my famous refried beans for Cinco de Mayo I will pull the can from the front. So the last can to be filled is the first one in my cart.

FIFO: When you go into a mini mart and head back to the cooler to grab your bottle of water you will be taking the one in front such as the previous example. However; these coolers are normally filled form the back so if the space is empty the first bottle will be filled from the back ending up in the front of the cooler with each additional bottle being filled towards the back. So the first one you are taking was the first one that was filled in the cooler.

Two ways that correlate to these methods are stacks and queues. A stack is an example of LIFO since each piece of data would be on top of each other. In contrast a queue would be an example of FIFO since it moves in a linear fashion like standing in line for a rental car.

An introductory set of data that we have been introduced to is an array. An array can be a set or anything from integers, strings, tuples, objects ect. Arrays can be very versatile in how they are managed due to some of the tools associated with them.

For example “pop” is a way of removing the last element and “shift” removes the first element. Just by these two functions it is easy to tell how powerful just an array can be structuring data types.

--

--

Brad Hankee
Code a la Carte

Full stack developer / foodie that writes about daily learnings.