answersLogoWhite

0


Best Answer

Advantages (Pros)

* Easy to get started

* Low Hardware Requirement

* Cross- Platform

* Anyone with access can edit the program

Disadvantages (Cons)

* Inflexible

* Lack of scalability

* Unable to Copy & Paste

User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

7y ago

A stack is a last-in, first-out (LIFO) data structure. We primarily use stacks to implement backtracking algorithms -- a means of retracing our steps to return the system (or at least part of the system) to an earlier state. We can think of backtracking algorithms as algorithms that leave a trail of breadcrumbs behind them. Of course, breadcrumb trails are the stuff of Fairy Tales, however a stack achieves the same thing.

Divide-and-conquer algorithms typically use a recursive function, however a recursive function is no different to an iterative function that employs a local stack. With recursion, a stack is provided automatically by the programming language. This particular stack is known as the call stack, however the name is a misnomer because every thread of execution in a process has its own thread-local call stack so a multi-threaded process may have more than one active call stack. However, thread-local stacks are used by functions, and from the perspective of an instance of a function, there can be only one call stack, so we simply refer to it as the stack.

All stacks provide the same four services: they allow us to push and pop values at the top of the stack; to examine the value on top of the stack (if any), and; to determine if the stack is empty or not. We're generally not concerned with how many elements are currently on the stack, thus a stack does not maintain a count of its elements; it is enough to know that if the stack is not empty, then we can pop a value from the stack. Although the call stack has limited storage (it is fixed-length), stacks in general are only limited by available memory.

A stack can be implemented using an array, a list, or both. Arrays are generally more efficient, particularly if we can make do with a fixed-length stack. With variable-length stacks, we need to allocate memory in advance to minimise the need to reallocate with every push. As the stack grows, reallocation becomes more expensive, so it can often pay to use a forward list to keep track of smaller, fixed-length allocations. This also makes it easier to release allocations that are no longer required (i.e., keep no more than one unused allocation to allow for expansion).

Stacks have far fewer operations than those provided by either arrays or lists. With object-oriented programming languages, this isn't a problem as we can easily provide container adaptors to eliminate those interfaces we do not need. But with languages like C, the onus of responsibility lies entirely with the programmer to ensure the stack remains in a valid state. The call stack doesn't suffer from these problems hence C programmer prefer to use recursive function calls to implement a stack. Nevertheless, recursive function calls have a runtime cost that could be reduced with an iterative function employing a local stack. As with most choices of this nature, only a real-world performance test will determine the optimal solution -- there is no one-size fits all solution.

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

Stacks are data structures that employ the last-in, first out (LIFO) principal. They can be likened to a stack of plates. The last plate added to the stack is the first to be removed from the stack.

The advantage of a stack is that it ensures data can be stored in the same order it was added to the structure, and that the data is removed in the reverse order. This is useful in backtracking algorithms and is the primary storage mechanism employed by procedure calls, making use of a special structure known as the call stack.

For instance, when one function calls another function, the called function needs some way of determining the return path to the caller. This is achieved by pushing the return address (the address of the next instruction after the function call) onto the call stack, and then passing control to the called function. The called function can then pop the return address off the call stack in order to return control back to the calling function.

This is clearly an over-simplification of the process as the call stack is also used to store the calling function's local variables, to pass arguments to the called function and to receive values from the called function. Even if the called function invokes other functions which themselves may invoke other function calls, the return path to the original caller is never lost because its return address remains on the stack until the original called function is ready to return. In other words, the stack will grow with each function call, and shrink with each return statement.

Recursive functions (functions that call themselves) can also make use of the call stack in order to remember the "state" of each instance of the function, and thus provide a backtracking mechanism as the calls return, effectively "winding" and "unwinding" the call stack. In effect, the call stack behaves like a trail of breadcrumbs.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

A typical stack is an area of computer memory with a fixed origin and a variable size. Initially the size of the stack is zero. Astack pointer, usually in the form of a hardware register, points to the most recently referenced location on the stack; when the stack has a size of zero, the stack pointer points to the origin of the stack.

It helps you save data, its bases on LIFO, i.e last in first out. Its one sided. uses push and pop functions generally.

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

Arrays are best suited to static structures, where the size does not change, or changes very little, and where constant-time random access is a major feature. Queues and stacks are highly dynamic structures that only require constant-time access to the head and/or tail elements, and are therefore best implemented using a dynamic structure based upon a singly-linked list. Although you could use a vector in C++ (a dynamic array), a list would still be far more efficient since random access is not a requirement. Note that the C++ standard library already includes highly optimised queue and stack templates, so other than the need to understand how they work, there is no need to roll your own.

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

we can use stack internally in every program,but the disadvantage of stack is we cant resize,no searching,takes more memory means we create memory statically.

This answer is:
User Avatar

User Avatar

Wiki User

8y ago

Stacks are advantageous in enabling simple backtracking algorithms. That is the sole purpose of a stack, so there are no disadvantages as such.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What are the advantages and disadvantages of data structure stack?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

List advantages and disadvantages for data structure diagrams?

uqwyhvxuyhasbxiuqa


Can stack be called fifo data structure?

No. A stack is a LIFO (Last In First Out) data structure.A queue is a FIFO (First In First Out) data structure.


What are advantages of stack?

some disadvantages created in stack using array then that problem solve to linked list use in stack.First advantage for size of stack not limited in linked list using.second essay to stack programme implement using only one pointer.


Explain The merits of using a deque to implement a stack in data structure?

Explain The merits of using a deque to implement a stack in data structure


What is the resource requirement of stack in a data structure?

no answer


Which type of data structure is used in ATM to take the printout of last 5 transactions?

stack data structure.


Advantages and disadvantages of manual data processing?

disadvantages in data manual processing


What are the advantages and disadvantages of data collection methods in statistics?

There are both advantages and disadvantages of data collection methods in statistics. The main advantages are the metrics and correlation one can draw from statistics. The disadvantages stem from sampling errors.


What are the advantages and disadvantages of data compression?

hahaaha


What are the advantages and disadvantages of automated data capture?

They have no eyes


What is a stack in data structure?

A stack is a linear data structure that follows the Last In, First Out (LIFO) principle, where elements are added and removed from the same end called the top. Elements can only be added or removed from the top of the stack, making it a simple and efficient data structure for storing and accessing data.


Advantages and disadvantages of object oriented databases?

advantages of object oriented data base