# which one of the following is an application of stack data structure? managing function calls the stock span problem arithmetic expression evaluation all of the above

### Mohammed

Guys, does anyone know the answer?

get which one of the following is an application of stack data structure? managing function calls the stock span problem arithmetic expression evaluation all of the above from screen.

## Data Structures

A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.

## Data Structures | Stack | Question 2

Last Updated : 08 Jan, 2013

Which one of the following is an application of Stack Data Structure?

**(A)**Managing function calls

**(B)**The stock span problem

**(C)**Arithmetic expression evaluation

**(D)**All of the above

**Answer:**

**(D)**

**Explanation:**See http://en.wikipedia.org/wiki/Stack_(abstract_data_type)#Applications

Previous

Data Structures | Stack | Question 1

Next

Data Structures | Stack | Question 3

RECOMMENDED ARTICLES

Page : 1 2 3 4 5 6

Data Structures | Stack | Question 1

08, Jan 13

Data Structures | Stack | Question 3

05, Feb 13

Data Structures | Stack | Question 4

09, Feb 13

Data Structures | Stack | Question 5

09, Feb 13

Data Structures | Stack | Question 6

20, Feb 13

Data Structures | Stack | Question 7

20, Feb 13

Data Structures | Stack | Question 8

20, Feb 13

Difference between Stack and Queue Data Structures

23, Jan 19

Data Structures | Linked List | Question 1

05, Jan 13

Data Structures | Linked List | Question 2

10, Jan 13

Data Structures | Linked List | Question 3

11, Jan 13

Data Structures | Queue | Question 2

11, Jan 13

Data Structures | Binary Trees | Question 1

18, Jan 13

Data Structures | Tree Traversals | Question 1

18, Jan 13

Data Structures | Binary Trees | Question 15

18, Jan 13

Data Structures | Tree Traversals | Question 2

18, Jan 13

Data Structures | Tree Traversals | Question 3

18, Jan 13

Data Structures | Binary Trees | Question 3

18, Jan 13

Data Structures | Binary Trees | Question 4

18, Jan 13

Data Structures | Binary Trees | Question 15

18, Jan 13

Data Structures | Binary Trees | Question 6

18, Jan 13

Data Structures | Heap | Question 1

31, Jan 13

Data Structures | Tree Traversals | Question 4

01, Feb 13

Data Structures | Linked List | Question 4

01, Feb 13

Article Contributed By :

GeeksforGeeks Vote for difficulty Article Tags : Data Structures

Data Structures-Stack

Data Structures Practice Tags : Data Structures Data Structures Report Issue

## Solved 1. Which one of the following is an application of

Answer to Solved 1. Which one of the following is an application of

Skip to main content

**Question:** 1. Which One Of The Following Is An Application Of Stack Data Structure? A. Managing Function Calls B. The Stock Span Problem C. Arithmetic Expression Evaluation D. All Of The Above 2. Write A Function ReplaceAll(Stack S, Int OldV, Int NewV) That Replaces All Instances Of The Value OldV With The Value NewV For The Two Classes ArrayStack And

**1. Which one of the following is an application of Stack Data Structure?**

A. Managing function calls

B. The stock span problem

C. Arithmetic expression evaluation

D. All of the above

**2. Write a function replaceAll(Stack s, int oldV, int newV) that replaces all instances of the value oldV with the value newV for the two classes ArrayStack and Node Stack**

**ArrayStack.java:**

public class ArrayStack implements StackInterface {

private T[] stack; // array of stack entries

private int topIndex; // index of top entry

private static final int DEFAULT_INITIAL_CAPACITY = 50;

public ArrayStack() {

this(DEFAULT_INITIAL_CAPACITY);

}

public ArrayStack(int initialCapacity) {

// the cast is safe because the new array contains null entries

@SuppressWarnings("unchecked")

T[] tempStack = (T[]) new Object[initialCapacity];

stack = tempStack; topIndex = -1; }

private void ensureCapacity() {

if (topIndex == stack.length - 1) // if array is full,

// double size of array

{

stack = Arrays.copyOf(stack, 2 * stack.length);

}

} // end ensureCapacity

@Override

public void push(T entry) {

ensureCapacity(); topIndex++;

stack[topIndex] = entry;

} @Override public T pop() { T top = null; if (!isEmpty()) {

top = stack[topIndex];

stack[topIndex] = null;

topIndex--; } // end if return top; } @Override public T peek() { T top = null; if (!isEmpty()) {

top = stack[topIndex];

} return top; } @Override

public boolean isEmpty() {

return topIndex < 0;

} }

**NodeStack.java:**

public class NodeStack implements StackInterface {

private Node topNode;

public NodeStack() {

topNode = null; } @Override

public void push(Char entry) {

Node newNode = new Node(entry, topNode);

topNode = newNode; } @Override public Char pop() { Char top = peek();

if (topNode != null) {

topNode = topNode.getNext();

} return top; } @Override

public Char peek() {

Char top = null;

if (topNode != null) {

top = topNode.getItem();

} return top; } @Override

public boolean isEmpty() {

return topNode == null;

} class Node {

public Char getItem() {

return item; }

public void setItem(Char item) {

this.item = item; }

public Node getNext() {

return next; }

public void setNext(Node next) {

this.next = next; } Char item; Node next; Node(Char item) { this(item, null); }

Node(Char item, Node next) {

this.item = item; this.next = next; } @Override

public String toString() {

return item.toString();

} } }

## Expert Answer

ANSWER:- QUESTION 1 :- d. All of the above => Managing function calls (for example, whenever recursion is used, stack is generally used to that we could return to that point where we started the recu…

View the full answer

© 2003-2022 Chegg Inc. All rights reserved.

## Applications of Stack in Data Structure

Applications of Stack in Data Structure with Introduction, Asymptotic Analysis, Array, Pointer, Structure, Singly Linked List, Doubly Linked List, Graph, Tree, B Tree, B+ Tree, Avl Tree etc.

## Applications of Stack in Data Structure:

In this article, we will understand the Applications of Stack in the data structure.

## What do you mean by Stack?

A Stack is a widely used linear data structure in modern computers in which insertions and deletions of an element can occur only at one end, i.e., top of the Stack. It is used in all those applications in which data must be stored and retrieved in the last.

An everyday analogy of a stack data structure is a stack of books on a desk, Stack of plates, table tennis, Stack of bootless, Undo or Redo mechanism in the Text Editors, etc.

### Following is the various Applications of Stack in Data Structure:

Evaluation of Arithmetic Expressions

Backtracking Delimiter Checking Reverse a Data

Processing Function Calls

## 1. Evaluation of Arithmetic Expressions

A stack is a very effective data structure for evaluating arithmetic expressions in programming languages. An arithmetic expression consists of operands and operators.

In addition to operands and operators, the arithmetic expression may also include parenthesis like "left parenthesis" and "right parenthesis".

**Example: A + (B - C)**

To evaluate the expressions, one needs to be aware of the standard precedence rules for arithmetic expression. The precedence rules for the five basic arithmetic operators are:

Operators Associativity Precedence

^ exponentiation Right to left Highest followed by *Multiplication and /division

*Multiplication, /division Left to right Highest followed by + addition and - subtraction

+ addition, - subtraction Left to right lowest

### Evaluation of Arithmetic Expression requires two steps:

First, convert the given expression into special notation.

Evaluate the expression in this new notation.

### Notations for Arithmetic Expression

There are three notations to represent an arithmetic expression:

Infix Notation Prefix Notation Postfix Notation

**Infix Notation**

The infix notation is a convenient way of writing an expression in which each operator is placed between the operands. Infix expressions can be parenthesized or unparenthesized depending upon the problem requirement.

**Example:**A + B, (C - D) etc.

All these expressions are in infix notation because the operator comes between the operands.

**Prefix Notation**

The prefix notation places the operator before the operands. This notation was introduced by the Polish mathematician and hence often referred to as polish notation.

**Example:**+ A B, -CD etc.

All these expressions are in prefix notation because the operator comes before the operands.

**Postfix Notation**

The postfix notation places the operator after the operands. This notation is just the reverse of Polish notation and also known as Reverse Polish notation.

**Example:**AB +, CD+, etc.

All these expressions are in postfix notation because the operator comes after the operands.

**Conversion of Arithmetic Expression into various Notations:**

Infix Notation Prefix Notation Postfix Notation

A * B * A B AB*

(A+B)/C /+ ABC AB+C/

(A*B) + (D-C) +*AB - DC AB*DC-+

**Let's take the example of Converting an infix expression into a postfix expression.**

In the above example, the only change from the postfix expression is that the operator is placed before the operands rather than between the operands.

**Evaluating Postfix expression:**

Stack is the ideal data structure to evaluate the postfix expression because the top element is always the most recent operand. The next element on the Stack is the second most recent operand to be operated on.

Before evaluating the postfix expression, the following conditions must be checked. If any one of the conditions fails, the postfix expression is invalid.

When an operator encounters the scanning process, the Stack must contain a pair of operands or intermediate results previously calculated.

When an expression has been completely evaluated, the Stack must contain exactly one value.

**Example:**

Now let us consider the following infix expression 2 * (4+3) - 5.

Its equivalent postfix expression is 2 4 3 + * 5.

The following step illustrates how this postfix expression is evaluated.

## 2. Backtracking

Backtracking is another application of Stack. It is a recursive algorithm that is used for solving the optimization problem.

## 3. Delimiter Checking

The common application of Stack is delimiter checking, i.e., parsing that involves analyzing a source program syntactically. It is also called parenthesis checking. When the compiler translates a source program written in some programming language such as C, C++ to a machine language, it parses the program into multiple individual parts such as variable names, keywords, etc. By scanning from left to right. The main problem encountered while translating is the unmatched delimiters. We make use of different types of delimiters include the parenthesis checking (,), curly braces {,} and square brackets [,], and common delimiters /* and */. Every opening delimiter must match a closing delimiter, i.e., every opening parenthesis should be followed by a matching closing parenthesis. Also, the delimiter can be nested. The opening delimiter that occurs later in the source program should be closed before those occurring earlier.

Guys, does anyone know the answer?