Unit 2 Stacks
Unit 2 Stacks
Data Types, Concept of data structure, Abstract Data Type, Implementation of Data Structure, Introduction to
algorithms, Basics of asymptotic notations.
Definition, Stack as an ADT, Stack operations, Stack Application: Evaluation of infix, postfix, and prefix
expression, Conversion of infix to postfix/prefix expression.
Definition, Queue as an ADT, Primitive operations in Queue, Linear and Circular queue and their application,
Array Based queue implementation, Priority Queue.
1
Unit 4: Lists [9 hours]
Definition, Static and dynamic list structure, Array implementation of lists, Queues as list. Linked List and
linked list as an ADT, Types of Linked List: Singly Linked List, Circular Linked List, Doubly Linked Lists,
Basic operations in linked list: node insertion, deletion, insertion and deletion after and before nodes, Linked
stacks and queues using linked lists.
Principle of Recursion, Comparison between recursion and iteration, Recursion example, Factorial, Fibonacci
sequence, GCD and Tower of Hanoi (TOH) Applications of Recursion.
Introduction, Internal and External Sorting, Insertion Sort, Selection Sort, Bubble Sort, Merge Sort and Quick
Sort, Efficiency of Sorting algorithms.
Introduction to Searching, Search algorithms: Sequential search, Binary search, Efficiency of different search
algorithms, Hashing: hash function, hash table, collision resolution techniques.
Concepts of tree, Basic operation in Binary tree,Tree height, level and depth, Tree search and
insertion/deletions, Binary tree traversals (pre-order, post-order and in-order), AVL balanced tree, Balancing
algorithm.
Represention and applications, Graphs as an ADT, Graph types, Transitive closure, Warshall's algorithm,
Graph traversal, Minimum spanning tree: Kruskal's and Prims algorithms, Shortest-path algorithm Dijkstra's
Algorithm.
2
Laboratory Work:
1. Implementation of Stack
2. Implementation of Linear and Circular Queues
3. Implementation of list and link list: Singly and Doubly
4. Factorial, Fibonacci and TOH using Recursion
5. Implementation of different Sorting Algorithms
6. Implementation of Searching Algorithms
7. Implementation of Binary and AVL tree.
8. Implementation of Tree Traversals
9. Implementation of Graph and its Traversal.
Reference Books:
1. Y. Langsam, M.J. Augenstein and A. M. Tenenbaum, Data Structures using C and C++ 2 nd Edition.
2. G. W. Rowe, Introduction to Data Structure and Algorithms with C and C++.
3. Rajesh K. Shukla, Data Structures using C and C++.
3
Unit 2: The Stack [4 hours]
Definition, Stack as an ADT, Stack operations, Stack Application: Evaluation of infix, postfix, and prefix
expression, Conversion of infix to postfix/prefix expression.
Definition:
A stack is a linear data structure in which an element may be inserted or deleted only at one end called the top
of stack i.e. the elements are removed from stack in reverse order in which they are inserted into the stack. It
uses a variable called top which points the topmost element in the stack. Top is incremented while pushing
(inserting) an element into the stack and decremented while popping (removing) an element from the stack.
Real world scenarios of stack examples are as given;
A stack follows the principle of LIFO (Last In First Out). Majorly, there are two functions for "inserting" and
"deleting" elements are push and pop respectively. Figure below demonstrates how stack's push and pop are
performed;
4
Basic features of stack:
Applications of Stack:
Stack as an ADT
A stack is non-primitive data type and it contains elements of type T. It is a finite sequence of elements of T
type together with the operations as follows;
POP and PUSH operation : POP and PUSH operation is done one by one. We cannot insert or delete elements
in bulk.
PUSH operation:
The push operation is used to insert the elements into the stack. There is a condition of "stack overflow", in
which the push operation cannot be performed. If stack is not overflow, then we can insert the elements one by
one by incrementing the value of Top by one until the condition "stack overflow" occurred. For stack
implementation array is used.
5
Algorithm for PUSH Operation:
Let Stack[maxsize] is an array to implement the stack. The variable top denotes the top of the stack. This
algorithm adds or inserts or push an item at the top of the stack.
POP operation:
Removal or deletion of element from the top of the stack is called pop operation. Unlike incrementing, the top is
decremented by 1 whenever an item is deleted from the stack. There is a condition called "Stack underflow or
empty" which is caused when there is no element in the stack. In that condition, pop operation cannot be
performed.
The algorithm deletes the top elements of the stack and assigns it to a variable element.
1. Start
Implementation of pop algorithm in C-language
2. Check for the stack underflow as
If top<0 then
void pop(){
Print "Stack Underflow"
int item;
Exit the program
if(top<0){
Else
printf("The stack is underflow or empty");
Remove the top element
and set this element to the variable as }
Set, x = Stack[top] else{
Decrement the top by 1 as, item=stack[top];
Top=top-1 top=top-1;
3. Print 'x' is a deleted item from the stack printf("The popped item is = %d", item);
4. Stop }
}
6
PEEK or Display operation:
The display or peek operation involves returning the element which is present at the top of the stack without
deleting. Peek only displays the top elements without popping it.
Complete program that implements all the operations used in Stack implementation using array: [Menu
Driven Program]
#include <stdio.h>
void push();
void pop();
void display();
void main()
{
printf("Enter the number of elements in the stack:\n");
scanf("%d", &n);
printf("-----**Stack Operations using array**-----\n");
while (choice != 4)
{
printf("Choose \n1. Push \n2. Pop \n3. Peek \n4.Exit \n");
scanf("%d", &choice);
switch (choice)
{
case 1:
push();
break;
case 2:
pop();
break;
case 3:
display();
7
break;
case 4:
printf("Exiting..");
break;
default:
printf("Invalid choice: \nEnter Valid Choice:");
}
}
}
void push()
{
int val;
if (top == n)
{
printf("Stack Overflow \n");
}
else
{
printf("Enter the value:\n");
scanf("%d", &val);
top = top + 1;
stack[top] = val;
}
}
void pop()
{
int item;
if (top < 0 || top == -1)
{
printf("The stack is underflow or empty");
}
else
{
item = stack[top];
top = top - 1;
printf("The popped item is = %d \n", item);
}
}
void display()
{
printf("The elements in the stack are:\n");
for (i = top; i >= 0; i--)
{
printf("%d\n", stack[i]);
}
if (top == -1)
{
8
printf("Stack is underflow");
}
}
Stack Application: Conversion and Evaluation of infix, postfix, and prefix expression.
There are a lot of computer applications of stack as described above but here we need to study about the
following applications:
1. Infix Notation:
It is a simple mathematical notation of an expression where an operator is written in between the operands.
For example: a+b (a, b are operands and + is an operator).
2. Prefix Notation:
In this notation, an operator precedes the two operands. i.e. the operator is written before the operands. It is
also called polish notation. E.g. the equivalent prefix expression of a+b infix expression is +ab.
3. Postfix Notation:
Similarly, in postfix expression an operator is written after the two operands. So, the equivalent postfix
expression of a+b is ab+.
Note: Square brackets are used to indicate the portion of conversion in an expression.
9
The above expressions are converted according to the PRECEDENCE RULE provided in the following Table.
Associativity:
It describes the rule where operators with the same precedence appear in an expression. E.g. in an expression
A+B-C, both + and – have the same precedence, then which part of the expression is evaluated first is
determined by associativity. So the expression will be evaluated as (A+B)-C.
Exponentiation:
In case of exponentiation an expression has a right-to-left associativity. Let's understand through an example by
comparing it with binary addition or subtraction.
10
Precedence Rule for Exponentiation, Addition / Subtraction , and Multiplication/ Division is given in the
following table;
Stack Implementation:
11
Tracing an Algorithm to convert infix to postfix notation:
12
Another Way: Also, we can convert the provided infix expression to postfix expression using two different
stacks opstack and poststack.
Following is an algorithm that illustrates the conversion of infix to postfix using opstack(operator stack) and
poststack(output).
1. Start
2. Scan one character at a time of an infix expression from left to right.
3. Opstack=the empty stack
4. Repeat till there is data in infix expression
4.1 If scanned character is '(' then push it to opstack.
4.2 If scanned character is an operand then push it to poststack.
4.3 If scanned character is an operator then check
If(opstack!=-1)
While (precedence(opstack[tos]>=precedence(scanned character)) then
Pop and push it into poststack
Otherwise
Push scanned character into opstack
4.4 If scanned character is ')' then
Pop and push into poststack until '(' not found and ignore both symbols
5. Pop and push into poststack until opstack is not empty
6. Stop
Example 1: ((A-(B+C))*D)$(E+F)
Example 2: (A+B*C$D)/((E+F-G)*H)$I/J
14
Implementation in C-programming to convert an expression from infix-postfix
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
int precedency(char);
void main(){
int i, otos = -1, ptos = -1, len, length;
char infix[100], poststack[100], opstack[100];
printf("Enter a valid infix expression: \n");
gets(infix);
length = strlen(infix);
int poslen=strlen(poststack);
printf("The postfix Expression is:\n");
for (i = 0; i < poslen-1; i++) { // for displaying postfix expression
printf("%c", poststack[i]);
15
}
}
int precedency(char ch){
switch (ch) {
case '$':
return (4);
case '*':
case '/':
return (3);
case '+':
case '-':
return (2);
default:
return (1);
}
}
Output:
Enter a valid infix expression:
(A+B*C$D)/((E+F-G)*H)$/J
The postfix Expression is:
ABCD$*+EF+G-H*$J//
Algorithm:
For this we have to use two stacks one as opstack and another as prestack and top of stack for both are
represented as otos and ptos respectively.
The opstack is used to store operators of given infix expression whereas prestack is used to store the converted
prefix expression.
1. Start
2. Scan one character at a time of an infix expression from right to left.
3. Opstack=the empty stack
4. Repeat till there is data in infix expression
4.1 If scanned character is ')' then push it to opstack.
4.2 If scanned character is an operand then push it to prestack.
4.3 If scanned character is an operator then check
If(opstack!=-1)
While (precedence(opstack[tos]>precedence(scanned character)) then
Pop and push it into prestack
Otherwise
Push scanned character into opstack
16
4.4 If scanned character is '(' then
Pop and push into prestack until ')' not found and ignore both symbols
5 Pop and push into prestack until opstack is not empty.
6 Pop and display prestack in reverse order which gives required prefix expression.
7 Stop.
Tracing
Example 1: (A+B*C$D)/((E+F-G)*H)$I/J
Scan prestack opstack Steps and operations
character
J J ------ 4.2
/ J / 4.3
I JI / 4.2
$ JI /$ 4.3 precedence(/)>precedence($) = false
) JI /$) 4.1
H JIH /$) 4.2
* JIH /$)* 4.3
) JIH /$)*) 4.1
G JIHG /$)*) 4.1
- JIHG /$)*)- 4.3
F JIHGF /$)*)- 4.2
+ JIHGF /$)*)-+ 4.3 precedence(-)>precedence(+) = false, both have equal.
E JIHGFE /$)*)-+ 4.2
( JIHGFE+- /$)* 4.4
( JIHGFE+-* /$ 4.4
/ JIHGFE+-*$ // 4.3 precedence($)>precedence(/) = true
) JIHGFE+-*$ //) 4.1
D JIHGFE+-*$D //) 4.2
$ JIHGFE+-*$D //)$ 4.3
C JIHGFE+-*$DC //)$ 4.2
* JIHGFE+-*$DC$ //)* 4.3 precedence($)>precedence(*) = true
B JIHGFE+-*$DC$B //)* 4.2
+ JIHGFE+-*$DC$B* //)+ 4.3 precedence(*)>precedence(+) = true
A JIHGFE+-*$DC$B*A //)+ 4.2
( JIHGFE+-*$DC$B*A+ // 4.4
---- JIHGFE+-*$DC$B*A+// ----- 5
----- //+A*B$CD$*-+EFGHIJ ----- 6
17
Implementation of Algorithm for converting infix to prefix expression in C-language.
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
int precedency(char);
void main()
{
int i, otos = -1, ptos = -1, length;
char infix[100], prestack[100], opstack[100];
printf("Enter a valid infix expression: \n");
gets(infix);
length = strlen(infix);
Output:
Enter a valid infix expression:
((A-(B+C))*D)$(E+F)
The prefix Expression is:
$*-A+BCD+EF
19
5. After the completion of the iteration when the stack contains only one string then we can treat this string
or expression as an infix expression.
6. Display the result.
7. Stop.
Tracing of Algorithm:
Example 1: Convert the postfix expression AB+C*DE-FG+*- to infix algorithm.
Scanned Action Stack Explanation
Character
A Push A to stack A Step 3
B Push B to stack A,B Step 3
+ Pop B, Pop A , do (A+B) and push back to stack (A+B) Step 4
C Push C to stack (A+B),C Step 3
* Pop C and Pop (A+B) and do (A+B)*C and push back ((A+B)*C Step 4
to stack
D Push D to stack (A+B)*C,D Step 3
E Push E to stack (A+B)*C,D,E Step 3
- Pop E and Pop D and do (D-E) and push back to stack (A+B)*C,(D-E) Step 4
F Push F to stack (A+B)*C,(D-E),F Step 3
G Push G to stack (A+B)*C,(D-E),F,G Step 3
+ Pop G and Pop F and do (F+G) and push back (A+B)*C,(D-E),(F+G) Step 4
* Pop (F+G) and Pop (D-E) and do (F+G)*(D-E) and (A+B)*C, (D-E)*(F+G) Step 4
push back to stack
- Pop (F+G)*(D-E) and Pop (A+B)*C and do (A+B)*C- (A+B)*C- (D-E)*(F+G) Step 4
(F+G)*(D-E) and push back to stack
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char stack[50];
int top = -1;
char pop()
{
return stack[top--];
}
void main()
{
char exp[50];
printf("\nEnter the Postfix Expression : : ");
gets(exp);
convert(exp);
}
Output:
Array exp [] =
A B C - + D E - F G - H + \ *
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
index
* / + H - G F - E D + - C B A
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
index
21
Now the characters are scanned from reverse exp array as follows;
Here the reverse of tmp array = A+B-C*D-E/F-G+H, which is the infix expression as desired output.
22
Tracing of Algorithm(Prefix to Infix):
Example 1: Convert the prefix expression //+A*B$CD$*-+EFGHIJ to infix algorithm. We need to scan from
right to left so lets reverse the expression as: JIHGFE+-*$DC$B*A+//
Scanned Action Stack Explanation
Character
J Push J to stack J Step 2
I Push I to stack J,I Step 2
H Push H to stack J,I,H Step 2
G Push G to stack J,I,H,G Step 2
F Push F to stack J,I,H,G,F Step 2
E Push E to stack J,I,H,G,F,E Step 2
+ Pop E, Pop F , do (E+F) and push back to stack J,I,H,G,(E+F) Step 4
- Pop (E+F), Pop G , do (E+F-G) and push back to J,I,H ,(E+F-G) Step 4
stack
* Pop (E+F-G), Pop H , do (E+F-G)*H and push J,I , (E+F-G)*H Step 4
back to stack
$ Pop (E+F-G)*H, Pop I , do (E+F-G)*H$I and J, (E+F-G)*H$I Step 4
push back to stack
D Push D to stack J, (E+F-G)*H$I, D Step 2
C Push C to stack J, (E+F-G)*H$I, D, C Step 2
$ Pop C, Pop D , do (C$D) and push back to stack J, (E+F-G)*H$I, (C$D) Step 4
B Push B to stack J, (E+F-G)*H$I, (C$D), B Step 2
* Pop B, Pop (C$D) , do (B*C$D) and push back J, (E+F-G)*H$I, (B*C$D) Step 4
to stack
A Push A to stack J, (E+F-G)*H$I, (B*C$D), A Step 2
+ Pop A, Pop (B*C$D), do A+(B*C$D) and push J, (E+F-G)*H$I, A+(B*C$D) Step 4
back to stack
/ Pop A+(B*C$D), Pop (E+F-G)*H$I, do J, A+(B*C$D)/ (E+F-G)*H$I Step 4
A+(B*C$D)/ (E+F-G)*H$I and push back to
stack
/ Pop A+(B*C$D)/ (E+F-G)*H$I, Pop J, do A+(B*C$D)/ (E+F-G)*H$I/J Step 4
A+(B*C$D)/ (E+F-G)*H$I/J and push back to
stack
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char stack[50];
int top = -1;
23
char pop()
{
return stack[top--];
}
void main()
{
char exp[50];
printf("\nEnter the Prefix Expression : : ");
gets(exp);
convert(exp);
}
Output:
Array exp [] =
/ / + A * B $ C D $ * - + E F G H I J
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
index
24
Now the characters are scanned from exp array as follows;
Here the tmp array = A+ B * C $ D / E + F - G * H $ I / J which is the infix expression as desired output.
25
Evaluation of postfix expression
In postfix expressions we do not need any parenthesis, which ever operator comes after operands will be
evaluated first.
Manually evaluating postfix expression:
623+-382/+*2$3+
=65–382/+*2$3+
=1382/+*2$3+
=134+*2$3+
=17*2$3+
= 72$3+
= 49 3 +
= 52
26
Implementation of Evaluation of Postfix Expression:
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
int vstack[100];
int tos = -1;
void push(int val)
{
vstack[++tos] = val;
}
int pop()
{
return vstack[tos--];
}
void main()
{
int i, res, len, op1, op2, value[100];
char postfix[100], ch;
printf("Enter a proper postfix expression:: \t");
gets(postfix);
len = strlen(postfix);
for (i = 0; i < len; i++)
{
if (isalpha(postfix[i]))
{
printf("Enter the value of %c operand:\t", postfix[i]);
scanf("%d", &value[i]);
push(value[i]);
}
else
{
ch = postfix[i];
op2 = pop();
op1 = pop();
switch (ch)
{
case '+':
push(op1 + op2);
break;
case '-':
push(op1 - op2);
break;
case '*':
push(op1 * op2);
break;
case '/':
push(op1 / op2);
27
break;
case '%': // remainder
push(op1 % op2);
break;
case '$':
push(pow(op1, op2));
break;
}
}
}
printf("The result is: %d", pop());
}
Output:
Enter a proper postfix expression:: ab*c-d+
Enter the value of a operand: 1
Enter the value of b operand: 2
Enter the value of c operand: 3
Enter the value of d operand: 4
The result is: 3
Example: +A-/B$CD*E+F-/GHI where A=1, B=2, C=3, D=2, E=1, F=5, G=9, H=3, I=2
So +A-/B$CD*E+F-/GHI = -5, where A=1, B=2, C=3, D=2, E=1, F=5, G=9, H=3, I=2.
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
int vstack[100];
int tos = -1;
void push(int val)
{
vstack[++tos] = val;
}
int pop()
{
return vstack[tos--];
}
void main()
{
int i, res, len, op1, op2, value[100];
char prefix[100], ch;
printf("Enter a proper prefix expression:: \t");
gets(prefix);
len = strlen(prefix);
for (i = len-1; i >= 0; i--)
{
if (isalpha(prefix[i]))//check for letters
{
printf("Enter the value of %c operand:\t", prefix[i]);
scanf("%d", &value[i]);
push(value[i]);//alphabet's value pushed into vstack stack
29
}
else
{
ch = prefix[i];//hold operators
op1 = pop();
op2 = pop();
switch (ch)
{
case '+':
push(op1 + op2);
break;
case '-':
push(op1 - op2);
break;
case '*':
push(op1 * op2);
break;
case '/':
push(op1 / op2);
break;
case '%': // remainder
push(op1 % op2);
break;
case '$':
push(pow(op1, op2));
break;
}
}
}
printf("The result is: %d", pop());
}
Output:
Enter a proper prefix expression :: +a-/b$cd*e+f-/ghi
Enter the value of i operand: 2
Enter the value of h operand: 3
Enter the value of g operand: 9
Enter the value of f operand: 5
Enter the value of e operand: 1
Enter the value of d operand: 2
Enter the value of c operand: 3
Enter the value of b operand: 2
Enter the value of a operand: 1
The result is: -5
30
Evaluation of infix expression
An infix expression is evaluated using two stacks, one for operator and another for operands. An infix string or
expression is read in an array from which symbols/characters are fetched one by one and the following checks
are performed.
Trace of algorithm:
Character Value Operator Stack Operand Stack Operand 2 Operand 1 Result Steps
A 1 1 1
+ + 1 2.1
B 4 1, 4 1
- +, - 1, 4 2.3
C 2 +, - 1, 4, 2 1
* +,-,* 1,4,2 2.3
( +,-,*, ( 1, 4, 2 3
D 8 +,-,*, ( 1, 4, 2, 8 1
+ +,-,*, (,+ 1, 4, 2, 8 2.3
E 3 +,-,*, (,+ 1, 4, 2, 8, 3 1
- +,-,*, (,+,- 1, 4, 2, 8, 3 2.3
F 9 +,-,*, (,+,- 1, 4, 2, 8, 3, 9 1
/ +,-,*, (,+,-,/ 1, 4, 2, 8, 3, 9 2.3
G 3 +,-,*, (,+,-,/ 1, 4, 2, 8, 3, 9, 3 1
) +,-,*, (,+ 1, 4, 2, 8, 3, 3 3 9 9/3=3 4
+,-,* 1, 4, 2, 8, 0 3 3 3-3=0 5
1, 4, 2, 8 0 8 8+0=8 5
31
+,- 1, 4, 16 8 2 2*8=16 5
+ 1,-12 16 4 4-16=- 5
12
null -11 -12 1 1-12=- 6
11
Solution:
A+B-C*(D+E-F/G)
= 1+4-2*(8+3-9/3)
= 1+4-2*(8+3-3)
= 1+4-2*(8+0)
= 1+4-2*8
= 1+4-16
= 1-12
= -11 Answer//
Character Value Operator Stack Operand Stack Operand 2 Operand 1 Result Steps
( ( null 3
A 1 ( 1 1
+ (, + 1 2.1
B 4 (, + 1, 4 1
- (, +, - 1, 4 2.3
C 2 (, +, - 1, 4, 2 1
) (, + 1, 2 2 4 4-2=2 4
….. (, + 1, 2 5
….. null 3 2 1 1+2=3 5
* * 3 2.1
D 8 * 3, 8 1
+ + 24 8 3 3*8=24 2.4
E 3 + 24, 3 1
- +, - 24, 3 2.3
( +, -, ( 24, 3 3
F 9 +, -, ( 24, 3, 9 1
/ +, -, (, / 24, 3, 9 2.3
32
G 3 +, -, (, / 24, 3, 9, 3 1
) +, - 24, 3, 3 3 9 9/3=3 4
…….. + 24, 0 3 3 3-3=0 5
……….. null 24 0 24 0+24=24 6
1. Converting infix to postfix and evaluate using the Postfix Evaluation Algorithm.
2. Converting infix to prefix and evaluate using the Prefix Evaluation Algorithm.
33
Exercises:
1. What is stack? How it different from queue? Show that stack and queue are ADT.
2. How you can convert given infix expression into their equivalent postfix expression?
3. Explain what do you mean by LIFO and FIFO?
4. Evaluate the following postfix expressions using stack.
a. AB-CDEF/+G-*-H-
b. ABCD*-E/+F+GH/-
c. AB+C*DEFG*+/+H-
Where, A=4, B=8, C=2, D=5, E=6, F=9, G=1, H=3.
5. Convert the following infix expressions into prefix and postfix expressions.
a. A*(B+C)/
b. (A*(B+(C/D)))
6. Write a program to implement the operations of Stack.
7. Write down basic operations of stack and also describes push and pop functions of stack.
8. Trace the algorithm to convert given infix to postfix expressions:
a. (A+B)*C+D/(E+F*G)-H
b. A+((B-C*D)/E)+F-G/H
c. (A*B+C)/D-E/(F+G)
d. A-B-C*(D+E/F-G)-H
e. A*B/C+(D+E-(F*(G/H)))
f. ((H*((((A+((B+C)*D))*F)*G)*E))+J)
9. When stack is empty and is full? Describe the display algorithm in stack.
10. What are infix, prefix and postfix notations?
11. Explain the infix to postfix conversion expression with proper example.
12. Write a program to convert the infix expression to postfix expression.
13. Explain the infix to prefix conversion expression with proper example.
14. Write a program to convert the infix expression to prefix expression.
15. Explain the postfix evaluation algorithm with an implementation.
16. Explain the prefix evaluation algorithm with an implementation.
17. Which notation is best for computer applications, infix, and postfix or prefix notations? Why?
34