Stacks and queues are two similar abstract data types (ADT) that build on the linked list, though they can be implemented using vectors or arrays, instead. They limit the base ADT’s functionality by restricting access to elements at either end of the list. The queue allows reading elements from the tail; the stack, conversely, grants read access to the elements at its head. Both ADTs only allow elements to be added at the head. Thus, the queue is a first in, first out (FIFO) structure, while the stack is a first in, last out (FILO) structure.
These ADTs are useful for situations where elements are added onto the structure over time but should be accessed or processed only in the same order they were added or the opposite. For instance, stacks are often used as part of undo/redo functionality in applications (Geeksforgeeks, 2021). Queues, meanwhile, see use in order processing or message routing systems to ensure requests are processed in the order they were created (Tang, 2013). Ultimately, the critical factors in deciding to use stacks or queues rather than other ADTs are the necessity to only access data in a specific order. The decision between a queue and a stack depends on the specific order in question, as described by the structures’ FIFO or FILO definitions.
Various sorting algorithms allow one to order a set of data in a list or array according to some comparable attribute. Alphabetical ordering and order by number are some of the most obvious examples. One can combine algorithms for efficiency and effectiveness; for instance, binary search is generally an efficient search algorithm; however, it can only work on an ordered collection. Therefore, it stands to reason that a collection (array or list) that must be searched often should be sorted first to achieve higher efficiency and, thus, better performance. Furthermore, one can use a sorting or search algorithm when adding new elements to a collection to ensure that the data contained within is always sorted. This approach saves processing time on searching for specific elements at the cost of performance when adding new elements.
Reference
Geeksforgeeks.com (2021). Implement Undo and Redo features of a Text Editor.
Tang, D (2013). CS240 — Lecture Notes: Queues. Cpp.edu. Web.