What is Fixed Capacity Queue, it’s real life applications in AI and how to implement Priority Queue?

Neeraj Nawale
5 min readFeb 8, 2022

--

This article contains information about how fixed capacity queue is better than non-fixed capacity queue, some real world example of queue data structure in Artificial Intelligence and how to implement Priority queue without any in-built function.

What is Queue?

Queue is a linear data structure which follows FIFO (First In First Out) principle. In a FIFO data structure, the first element added to the queue will be the first one to be removed. Queues are frequently used in computer programming and typical example is creation of a Job Queue by an Operating System. Queue can be implemented either by Array or Linked List.

Types of Queue

There are mainly two types of queue.
1. Non-Fixed Capacity Queue
2. Fixed Capacity Queue

  • Non-Fixed Capacity Queue ::
    This type is queue, user can append data as long as he/she wants or unless the RAM gets full.
  • Fixed Capacity Queue ::
    Fixed Capacity or size means, developer sets a limit on how many elements can be queued.

Why “Fixed Capacity” is better than “Non-Fixed Capacity” Queue?

Mostly in each application or system Fixed capacity is preferred over Non-Fixed capacity queue. One of the reason is Time and Space complexity.
For non-fixed capacity queue, time as well as space complexity is O(n) as, it totally depend on number of elements present or appended (i.e. “n”) whereas for fixed capacity queue, both complexities are almost constant i.e. O(1) means, append and delete operation is much faster and convenient than non-fixed capacity queue.

There are tons of scenario and one of the common scenario is “messaging”.
WhatsApp uses queue data structure to send and receive messages in FIFO manner. A queue is maintained on their server for each user which contains messages to be delivered to user.
Let’s say, on an occasion/festival, tons of messages are send, around 10 million and developer has created the queue using Array. So, if new message is to be appended, it should be added at last and is a big deal to traverse the array till last element which will result in huge complexity. Another case might be, to create new queue on same RAM and then, append the last message.
Hence, it’s not the right approach to use Non-fixed capacity and Fixed capacity queue can be used.

Fixed capacity queue helps to resolve typical problems and approach is like, a fixed size queue is initialized to add or remove data. Two pointers or index are created to track added element and removed element and it works in circular manner as well.

Real Life Applications of Queue in Artificial Intelligence

  • Banks
    AI is used in banking, which is so far higher value for banks, is in fraud detection. It can be hard for humans to understand patterns, but machines are good at it. Managing queue will resolve challenges in terms of operational efficiency as well as cost involved in training fraud reviewers for particular fraud types. Also, will help to optimize the business process by responding to Fraud incident in efficient and effective manner.
  • Social Media
    Queue is used for scheduling social media posts. Machine learning algorithms are used to design your feed based on your interests.
    1. Tailwind’s focus on assisting you with your visual marketing. It features drag-and-drop functionality that makes it easy for marketers to upload, tag and publish their Pinterest and Instagram posts in bulk. Users can shuffle their post queue, to ensure that they keep variety in their posts.
    2. Crowdfire claims to be the first social media management app that supports posting to TikTok. Crowdfire keeps a queue of content and schedules your posts to go out at the optimal times for your audience.
    3. Socialoomph provides some excellent scheduling and queuing power but is less user-friendly than much of the competition. As a result, it is particularly suitable for social media managers with above-average computing and coding skills. Socialoomph uses queues well. You have multiple ways to automatically fill up “never-go-dry” queues for each social account.
  • Queue management systems combining IoT security cameras and AI video analytics help businesses improve customer experience in stores by reducing waiting times at checkouts. During the COVID 19 pandemic, smart queue management also includes monitoring and ensuring compliance with social distance rules.
  • Travel
    Google maps are used to track or provide shortest path, finding most promising route first, queue is used to keep track of unexplored routes.
  • ChatBots
    Almost every household has a virtual assistant that controls their appliances at home. A few examples include Siri, Cortana, and Alexa, which are gaining popularity because of the user experience they provide. Queue is used to maintain the upcoming songs. Also, chatbots can be used to control the devices at your house, book cabs, make phone calls, order your favorite food, etc. these all are handled using a queue.
  • Other applications
    1. Pizza order system is implemented using FIFO principle.
    2. Printer, to print job in order.
    3. CPU Scheduling → To share a resource among multiple customers.
    4. Transfer network packet in Routers or switch.
    5. Keyboard buffering is done using queue data structure.
    6. Load balancing and Interrupt Handling in Operating System.

Priority Queue

In data structures, queue plays a vital role in each aspect. Simple queue, circular queue, etc. are different forms of queue used in industry. One of the most commonly used form is Priority Queue.
A Priority Queue is different from a normal queue, because instead of being a “first-in-first-out”, values come out in order by priority. It is an abstract data type that captures the idea of a container whose elements have “priorities” attached to them. An element of highest priority always appears at the front of the queue. If that element is removed, the next highest priority element advances to the front.

In above applications as well, priority queue is used much frequently. Another use case of priority queue is to “provide service to patient based on emergency”. Given below is the approach and code (without any in-built function) to solve this use case ::

Approach ::

  1. Define priorities, “3” = serious patient, “2” = half serious and “1” = general checkup.
  2. Create a user defined data type for Patient and Database.
  3. Insert patient based on its type. (serious patient = first priority, half serious patient = second priority, general checkup = least priority).
  4. Provide service to patient with highest priority.
  5. Display database to understand patient data in priority queue form.

I’ve create a code to implement above approach in C++ language and used Singly Linked List to create as well as implement priority queue.

Source Code → Click here

Conclusion

Queue is an important and powerful data structure used in almost every trending technology. Priority queue improves the performance of queue in much better and easy way.

Keep Learning
Keep Coding
Thank YOU…!!

--

--

No responses yet