LIFO vs FIFO Approach in Programming

Last updated on

Last night, when I was crossing my sister’s room. I observed that-

She was little confused. I asked, what’s an issue?🤔

She said, she was confused between LIFO vs FIFO approach in programming.

Because most students get confused when something is last, whether it mean the most recent one or the final one?😕

After that, I shared my own analogy with her that I built during college to remember this concept.

Before, jumping to the analogy of LIFO and FIFO. Let’s clarify the meaning of this abbreviations.

What are LIFO and FIFO?

LIFO and FIFO are the two different approaches to organizing and manipulating the data structure in computing.

LIFO means Last In First Out, a method for handling data structures where the last entered element will be processed first and the first entered element will be processed last.

FIFO means First In First Out, a method for handling data structures where the first entered element will be processed first and the last entered element will be processed last.

The Analogy

Let’s visualize these two complicated methods with fun.

Situation 1: (LIFO – Last In First Out)

Suppose you are at the party, And now its time for diner, You went to pick the plate for yourself.

Everyone knows, how plates are arranged at parties. One over other, Right?

Something like this, recognized?

LIFO approach
Figure: 1 (LIFO approach in programming)

According to figure 1, as shown above, we can conclude that:

  • There is no special exit way to take out plates i.e. only one way to put the plates in or to take out the plates.
  • It means that the plate which entered last will be the first to take out.

Right?

So, this organization of data structure is the LIFO type of organization.

This LIFO technique is also referred to as the stack. In this technique, the first item on the stack entered have to wait until every other item comes out.

Situation 2: (FIFO – First In First Out)

Suppose, you went to the shopping mall to buy groceries.

After taking all the items, now it’s time to pay the bill.

We all know that at paying time all person should stand in a queue. Right?

I’ll show you, something like this:

FIFO approach
Figure: 2 (FIFO approach in programming)

According to the figure shown above, we can conclude that:

  • There is a separate entry and an exit door, i.e. people who entered from the right side can’t go back from the right side, they need to take the left exit door.
  • It means that the first person to come in will be the first to go out.

Right?

So, this organization of data structure is the FIFO type of organization.

This FIFO technique is also referred to as the queue. In this technique, the first item entered in the queue will be the first to come out from the queue.

👀Wrapping up

It’s a wrap. Many times it seems too confusing when acronyms are used, yet the underlying concept behind it is so simple.

In those concepts, always try to understand the topic with real world examples like above.👆

I hope, this helped you to clear your confusion with fun, although if you have any query about LIFO or FIFO, let me know in the comment section.


Comments

2 responses to “LIFO vs FIFO Approach in Programming”

  1. Sunita Avatar
    Sunita

    Very Helpful.

  2. festus quainoo Avatar
    festus quainoo

    nice summary for my presentation

Leave a Reply

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