Darshan Institute of Engineering & Technology for Diploma Studies Unit 3

Size: px
Start display at page:

Download "Darshan Institute of Engineering & Technology for Diploma Studies Unit 3"

Transcription

1 Linear and Non-Linear Data Structures Linear data structure: Linear data structures are those data structure in which data items are arranged in a linear sequence by physically or logically or both the ways. E.g. array, linked list. Non-Linear data structure: Non linear data structures are those data structure in which data items are not arranged in a sequence. E.g. graph, tree. Stack A stack is a data structure in which elements are added and removed from one end, Last in first out structures (LIFO). In this list insertion and deletions are made at one end called top of stack. For example, consider is a stack of plates on the counter in cafeteria, during the time of dinner, customers take plates from the top of the stack and waiter puts the washed plates on the top of the stack. So a new plate is put on top and old one is yet bottom. Most micro-processor use a stack based architecture. When member function is called it return address and arguments pushed into a stack and when function returns they are popped off. The stack operations are built into the micro-processor. 1) Array- Representation of a stack: Bottom of Stack Top of Stack Bottom Top X X X X X X Bottom of Stack Top of Stack Top X Unused Elements ( Vertical representation of stack ) 1

2 X X X --- X X Bottom of Stack Free Space Top of Stack ( Horizontal representation of stack ) The operation in a stack is representation by using vector consisting of number of elements. A pointer top keeps of the top elements, when stack is empty top has a value 0. Every time a new element is added at top, top is incremented by one. When an element is deleted from a top, top is decremented by one. 2) PUSH and POP Operation on Stack: The stack as an abstract data type (ADT), the operation that add an element to the top of stack is usually called PUSH operation. The operation that takes the top element from the top of stack is called POP operation. When we begin using stack, it should be empty so another necessary operation is one that creates an empty stack. This operation is known as create stack. We must also check that whether a stack contains any elements before we pop it from the stack. We also perform a operation that destroy a stack for leaving the stack empty, this is known as a destroy stack operation. Example: The effect of PUSH and POP operation are easilyunderstand by below: 1. Create stack(empty) or clear stack Empty Stack 2. Push stack (Block 1) push 3. Push (stack, Block 2) 4. Push (stack, Bock 3) Top Top Pop (stack X) pop the top block & put it into X 6. Pop (stack X) X 1 2

3 7. Push (stack X) X 1) PUSH Operation: o In push operation, we can add element to the top of the stack. o So before push operation we must check the stack, it should not be a full. o If stack is already full and when we try to add an element then stack overflow error occurs. o It is called Stack Overflow condition. PUSH (S, Top, X) Algorithm : PUSH(S,Top,X) Step 1 : [ Check for stack over flow] If Top >= N then write( stack over flow ) Step 2 : [increment Top pointer by value one] Top Top+1 Step 3 : [perform Insertion] S [Top] X Step 4 : [Finished] o o o o This function insert an element X to the top of stack which is represented by a vector S containing N elements with Top pointer at top element in the stack. The first step of algorithm checks for overflow condition. If stack is full means Top pointer value reach at size of stack then insertion can t be performed. In second and third step, if stack is not full a Top pointer value increment by one and insert a value at the Top pointer element. 2) POP operation: o In pop operation, we can remove a element from top of the stack. o So before pop operation, user must check the stack should not be a empty. o If stack is empty and we try to pop an element then a stack underflow error occurs. o It is called Stack Underflow condition. Algorithm : POP (S,Top) Step 1 : [check for under flow or check whether the stack is empty] If (Top=0) OR (Top=-1) then write( Stack under flow ) Step 2 : [Decrement pointer/remove the top information] Value S [Top] Top Top 1 Step 3 : [Return former top element of the stack] write(value) Step 4 : [Finished] 3

4 o o o o POP (S, Top) This function removes an element from the top of the stack which is represented by a vector S containing N element with a Top pointer at top element in the stack. The first step of algorithm checks for an underflow condition. If stack is empty means top pointer value is Zero, so we can t pop the element. In second and third step, if stack is not empty then a top element value stored in a variable value and then decremented top pointer by one and then returns at former top element of the stack. 3) Implementation of Stack: o A stack is a list and list can be implemented by two ways: Array (Static Implementation) Pointer (linked List / Dynamic Implementation) Program of Static Implementation of stack: #include<stdio.h> #include<conio.h> #include<process.h> #define MAX 10 int push(int [],int,int); int pop(int [],int,int); void display(int [],int,int); int main() int s[max],top=-1,choice,x,i; printf("\n Enter the choice for stack operation\n"); printf("1.push\n"); printf("2.pop\n"); printf("3.display\n"); printf("4.exit\n"); printf("enter your choice\n"); scanf("%d",&choice); do switch(choice) case 1 : TOP=push(s,TOP,x); break; case 2 : TOP=pop(s,TOP,x); break; case 3 : display(s,top,x); break; default : exit(0); printf("\n Enter the choice for stack operation\n"); printf("1.push\n"); printf("2.pop\n"); printf("3.display\n"); printf("4.exit\n"); printf("enter your choice\n"); 4

5 scanf("%d",&choice); while((choice>0) (choice<=4)); return 0; int push(int s[],int TOP,int x) printf("top is:: %d",top); if(top == MAX) printf("stack IS OVER FLOW"); printf("\nenter the item to be insert in stack"); scanf("%d",&x); TOP=TOP+1; s[top]=x; return TOP; int pop(int s[],int TOP,int x) if(top<0) printf(" STACK IS UNDER FLOW"); x=s[top]; TOP=TOP-1; printf("\n Item to be deleted from stack are:"); printf("%d",x); return TOP; void display(int s[],int TOP,int x) int i; if(top==-1) printf("\n STACK IS EMPTY"); printf("\n stack data are:"); for(i=top;i>=0;i--) printf("%d\n",s[i]); 5

6 4) Application of Stack: Recursion is an important functionality in many progrmming language such as PASCAL, C etc. Stack machine, certain computers performs stack operation at the hardware or machine level. Compailation of infix expression into object code. Representation of Polish Notation. 5) Infix, Prefix and Postfix Forms of Expressions: Polish Notation: One of the major uses of stack is a Polish notation or Polish expression. The process of writing the operations of an expression either before their operands or after operands are called the Polish Notation. The polish notation are classified into three categories: a) Infix b) Prefix c) Postfix a) Infix: o When the operators exist between two operands then the expression is called Infix Expression. o Consider the sum of A and B, we apply operator + between two operands and write the expression sum as A+B. o This expression is called Infix Expression. b) Prefix: o When the operator is written before their operand then the resulting expression is called Prefix Expression. o The operator precedes the two operands, +AB are prefix polish notation of sum. c) Postfix: o When an operator comes after their operands the resulting expression is called postfix expression. o It is also called reverse Polish Notation. o The operator follows the two operands, AB+ is called postfix or reverse polish notation. Rules for converting Infix Notation to the postfix / prefix notation: 1) The operation with highest precedence is converted first and then after a portion of the expression has been converted to postfix. 2) It is to be treated as single operand. 3) We consider five binary operation, such are (+) addition, subtraction (-), multiplication (*), division(/) and exponentiation. The first four are available in C/C++, the fifth exponentiation will be represented by the operator $ or. The value of expression A$B or A B is A raise to B power, for example 3 2 = 9. 4) Take only two operands at a time to convert in a postfix from like A + B AB+ 5) Always convert the parenthesis first. 6) Convert postfix exponentiation second if there are more than one exponentiation in sequence then take order from right to left. 7) Convert in to postfix as multiplication and division operator, left to right. 6

7 8) Convert in postfix as addition and subtraction left to right. For Example: 1) Convert in to postfix (A + B) * C infix form = (AB+) * C Convert addition first because it has parenthesis and it convert first = (AB+)C* Convert the multiplication = AB+C* Postfix form 2) A + (B * C) Infix form / take first parenthesis = A+ (BC*) Convert multiplication = A(BC*)+ Convert addition = ABC*+ Postfix form Thumb rules for the conversion process are that operator with highest precedence are converted first. Example: Convert following expression in to postfix / reverse polish notation a + (b * c - (m / n p) * t) * s Step 1: a + (b * c - (m / n p ) * t) * s Step 2: a + (b * c - (m n p / ) * t) * s Step 3: a + (b c* (m n p / ) *t) * s Step 4: a + (b c* m n p / t * - ) *s Step 5: a + b c * m n p / t * - s * Step 6: a b c * m n p / t * - s * + Postfix expression Convert following Infix expression in to prefix & postfix form: Infix Prefix Postfix 1) A + B C - + A B C A B + C 2) ( A + B ) * ( C D ) * + A B - C D A B + C D - * 3) A $ B * C - D + E / F / ( G + H ) + - * $ A B C D // E F + G H A B $ C * D E F / G H + / + 4) ( ( A + B ) * C (D - E )) $ - * + A B C D E + F G A B + C * D E - - F G + $ $ (F + G) 5) A B / (C * D $ E ) - A / B * C $ D E A B C D E $ * / Solution: Postfix form conversion 1) A + B - C = A B + - C = A B + C 2) ( A + B ) * ( C D) = ( AB+)* (C D-) = (AB+) (CD-)* = A B + C D - * 7

8 3) A $ B * C - D + E / F / ( G + H) = A $ B * C - D + E / F / (G H+) = (A B $) * C - D + E / F / (G H+) = (A B $ C * - D ) + (E F / G H + /) = A B $ C * D - E F / G H + / + 4) (( A + B ) * C - (D - E)) $ (F + G) = (( A B +) * C - ( D E -)) $ ( F G +) = ( A B + C * D E - - ) $ (F G +) = A B + C * D E - - F G + $ 5) A - B / (C * D $ E) = A - B / (C * D E $) = A - B / (C D E $ *) = A - B C D E $ * / = A B C D E $ */ - Evaluating a postfix operation : Algorithm: Postfix expression Step 1: opndstk empty stack Step 2: [Scan the input string for reading one] While (not end of input) repeat step 3 Symb next to input character Step 3: [check for operand] If (symb is an operand) Then PUSH (opndstk,symb) Else Opnd2 POP (opndstk) [opnd1 and opnd2 are Variables] Opnd1 POP (opndstk) Value result of applying symb to opnd 1 & Opnd 2 push (opndstk, value) Step 4: POP (opndstk) Step 5: [Finished] Each operation in a postfix string refers to the previous two operands in a string. Each time we read an operand and we push it into stack. When we reach on operator, its operand will be the top two element on the stack. We can then pop these two element, perform the indicated operation on them and push the result on the stack. So that it will be available for use as an operand of the next operator. Algorithm to convert infix expression into postfix polish notation : Algorithm : INFIX TO POSTFIX CONVERSION Step 1: define the opndstk as an empty stack Step 2: Scan the infix string as an input string with one by One character reading method. Step 3: While (not end of input string) Fetch one character form input (repeat) string and Store it in to symb variable check whether this symb is an operator or an operand. If (symb is an operand) Then 8

9 PUSH that symb to postfix string post. Else If it is not operand Then check precedence of that fetch symb If precedence is true Then PUSH that symb to a postfix string Do this step until the while condition cannot failed Step 4: now push the symb to opndstk Step 5: [Finished] 6) Recursion Functions: Recursion means a function call itself. Example: The factorial function can be recursively defined as, Factorial (N) = 1 If N = 0 N * FACTORIAL (N - 1) If N > 0 Here, FACTORIAL(N) is defined in terms of FACTORIAL(N-1) which is again defined interms of FACTORIAL(N-2) and this process continue until FACTORIAL(0) is reached. The value of FACTORIAL(0) is defined as 1. There are two important condition that must be satisfied by any recursive function : 1) Each time a function calls itself, it must be nearer in some sense of solution. 2) Terminating condition must be there which can terminates the chain of process. To find factorial value using Recursion. #include <stdio.h> #include <conio.h> main() int I,n,a; int fact(int); printf( \n enter the value of n: ); scanf( %d,&n); a=fact(n); printf( \n the factorial value of n: %d,a); int fact(int x) int f=1; if (x==1) return (f); f=n * fact ( n-1 ); return (f); 9

10 7) To Generate the Fibonacci number using recursion: A fibonacci series is, N Fibo_no (n) = 0 1 If n =0 or n = 1 If n = 2 Fibo_no (n-1) + Fibo_no (n-2) if n > 2 If we consider F 0 = 0 and F 1 = 1 then F 2 = F 0 + F 1 = = 1, similar F 3 = F 2 + F 1 = = 2, and F 4 = F 3 + F 2 = = 3 and so on. It is clear that each succeeding(next) term is the sum of two preceeding(previous) terms, doing this procedure until i becomes less then the value of n. To Generate the Fibonacci number using recursion. #include <stdio.h> void main() int fibo (int); /* function prototype */ int no, i=0; print ( enter the number of steps to generate fibonacci series : ); scanf( %d, &no); while(i<no) printf( %d\t,fib(i)); i++; int fib(int n) if(n==1) (n==0) return (0); if (n==2) return (1); return (fib (n-1) + fib (n-2)); 8) Greatest Common Divisor (GCD): To implement Greatest Common Divisor(GCD) function in a recursive form using following steps: a) If m <= n and n % m = 0 then gcd(n, m) = m(termination step). b) If n < m then gcd(n, m) = gcd(m, n) ( Recursive definition of gcd) c) If n >= m then gcd(n, m) = gcd(m, n % m) (Recursive definition of gcd) Using these 3 rules, the recursive program of greatest common divisor can be written as below: 10

11 Queue #include <stdio.h> int gcd( int,int); void main() int n,m,divisior; printf( enter the two numbers ); scanf( %d%d,&n,&m); divisior=gcd(n,m); printf( the greatest common factor of %d and %d is %d,n,m,divisior); return 0; int gcd(int n,int m) if(m<=n&&n%m==0) retuen m; if(n<m) return gcd(m,n) return gcd(m,n%m); A data structure in which elements are added to one end (rear) and removed from the other end (front) in FIFO (First In First Out) structure. Queue is a data structure that is similar to a stack. But difference is, in a queue to first item inserted is the first to be removed (FIFO). In stack the last item is the first to be removed (LIFO). In queue always addition occurs at rear end and deletion at front end. Elements Entry 1) Array Representation of Queue: Deletion end (Queue) end Insertion A queue has two pointer, from pointer and rear pointer which are pointing to front and rear element of the queue. 11

12 Deletion X X X Pointer Pointer (Vector representation of Queue) Insertion 2) Operation on Queue: a) PUSH b) POP Consider a queue consist of N elements and an element value, which we can insert and delete value from the queue. The value NULL (= -1)of front pointer indicate that queue is empty, so we can not perform delete operation. If rear pointer value is increase and it becomes grater than N (no of element) rear >= N indicates queue is full. So we can not perform insertion operation. How to insert and delete value from the queue and see the position of front and rear pointer in below figure: (Queue in memory) i) Delete first element from queue: Point Point (= + 1 ) When we remove the element value from a queue, a pointer value is increment by one. = + 1 ii) Insert one element in a queue: Point Point (= + 1 ) 12

13 When we insert an element at rear end in a queue, a rear pointer value is increment by one. = + 1 3) Static Implementation of Queues: For writing an algorithm we can define following variables: S -> It is an array having N elements. -> It is pointer which will point to last () end of queue. -> It is pointer which will point to first (front) end of queue. X -> It is variable which will store the value that we want to push or pop from the queue. 1) PUSH (Insertion): If we push or insert an element in a queue at rear end and rear pointer vlaue increment by one(1). Algorithm: PUSH(S, front, rear, x) Step 1: [Check for Queue Over flow ] if rear >=size then write ( Queue is over flow ) Step 2: [Increment Pointer] <- rear + 1 Step 3: [Insert an element at rear of Queue] S [rear] <- x Step 4: [Set the front pointer] if front = -1 then front <- 0 step 5 : [Finished] The first step of algorithm is to check the overflow condition. If queue is already full means rear >= N (Size) and if we try to insert an element in queue then it will indicate an Overflow error. In second step, if queue is not full then we can insert an element in queue. So rear pointer value is increment by one. In third step, perform value of variable X put on to the rear(last) element of queue. 13

14 2) POP (Deletion): If we delete or pop an element from queue at front end and front pointer value increment by one. Algorithm : POP (S, front, rear, x) Step 1: [Check for Queue Under flow ] if (front =-1 OR front = 0) Then Write( Queue is under flow ) Step 2: [Remove an element from queue] x <- S [front] Step 3: [Print the popped element] Write ( x ) Step 4: [Check for empty queue] if front = rear then front <- 0 rear <- 0 front <- front + 1 Step 5: [Finished] The first step in an algorithm is to check the underflow condition. If queue is empty (front = -1) and if we try to delete an element from queue then it will indicate an underflow error. In forth step, If queue is not empty and we want to delete an element from queue. So front pointer value will increment by one. Program of static Implementation of a queue for Insert & Delete Operation. #include<stdio.h> #include<process.h> void Qpush(); void Qpop(); void Qdisplay(); int q[50],front = -1,rear = -1,N,choice; int main() printf("enter size of queue:: "); scanf("%d",&n); printf("enter ur choice:: \n"); printf("1. Push\n"); printf("2. Pop\n"); printf("3. Display\n"); printf("4. \n"); scanf("%d",&choice); do 14

15 switch(choice) case 1: Qpush(); break; case 2: Qpop(); break; case 3: Qdisplay(); break; default: exit(0); printf("enter ur choice:: \n"); printf("1. Push\n"); printf("2. Pop\n"); printf("3. Display\n"); printf("4. \n"); scanf("%d",&choice); while(choice>0 choice<=4); return 0; void Qpush() int x; if(rear == N-1) printf("queue is overflow\n"); printf("enter ur item to be insert in queue:: "); scanf("%d",&x); if(front == -1) front = 0,rear = 0; rear = rear + 1; printf(" is:%d \n",rear); q[rear] = x; void Qpop() int x; if(front == -1 front > rear) printf("queue is underflow\n"); 15

16 printf("ur poped element is:: %d",q[front]); front = front + 1; printf(" is:%d \n",front); void Qdisplay() int i; if(front == -1) printf("queue is underflow"); printf("ur elements of queue are::\n"); for(i=front;i<=rear; i++) printf("%d\n",q[i]); 4) Trace of Simple Queue: The following figures clearly indicate the PUSH and POP operation performed on a queue which will display the front and rear pointer position. Empty Queue 41 Insert Insert 51 16

17 Insert Insert Remove Remove Insert Insert In a last stage, if rear pointer value is same as size of queue ( = Size) means rear pointer points to end of array. Now, suppose we try to insert an element (Value <- 101) into queue then this can be done by moving entire queue to beginning of array. By changing front and rear pointer value accordingly and then insert an element into queue. But for array, such operation is time consuming and expensive. Insert 101 So this type of problem can be solved by using new concept which is called Circular Queue. 17

18 5) Limitation of Single Queue: In a linear queue, frequently we face the problem of overflow of a queue. If queue contain maximum element and we want to insert a new element then this type of problem can be solved by using Circular Queue instead of Linear Queue. Concepts of Circular Queue: Q[n] Q[1] Q[n-1] Q[2] [Circular Queue] Let we have an array Q, that contain N elements in which Q[1] comes after Q[n] in the array. This type of technique is used to construct a queue then queue is called Circular Queue. A queue is called Circular Queue when last element comes just before the first element. In circular queue, when rear pointer is rear = n (Maximum size) and if we try to insert an element then this element assigned to Q[1] instead of increasing rear pointer to n + 1. We reset the rear pointer to 1. Similarly, if front pointer value reach its maximum value (n), front = n and if we remove element from queue then we reset a front pointer to 1 instead of n + 1. Suppose a queue contains only one element that is front = rear <> Null and then we remove an element then front and rear pointer are now assign to Null to indicate that queue is empty. Trace of Circular Queue: To indicate the position of front and rear pointer from below figures, 99 Insert Insert

19 Insert Remove Insert Remove Insert 139 Reset rear Pointer to 1, rear= Insert Remove Remove 129 Reset front Pointer to 1, front=1 19

20 Static Implementation of circular Queues: (A) PUSH(Insertion): Algorithm: PUSH(s, front, rear, x) Step 1: [Check for circular Queue Over flow ] If front = 0 and rear = n-1 Then Write ( circular queue is over flow ) Step 2: [Insert Elements in the circular Queue] Else if front = -1 and rear = -1 <- 0 <- 0 S[rear] <- x Step 3: [Check if the rear at the end of circular queue] Else if front <> 0 and rear = n-1 <- 1[Reset rear pointer] S[rear] <- x Step 4: [Insert the element in circular Queue] Else rear <- rear+1 S[rear] <- x Step 5: [Finished] (B) POP(Deletion): Algorithm: POP(s, front, rear, X) Step 1: [Check for under flow ] If front= -1 Then write( circular queue is under flow ) Step 2: Remove an element from circular queue X <- s[front] Step 3: [Print the popped Element] Write( x ) Step 4: [check whether circular queue is empty or not] If(front = rear) Then front <- -1 rear <- -1 Step 5: [Check front pointer position] Else if front = size <- 0 (Reset front pointer) Else <- front + 1 Step6: [Finished] 20

21 Program of Static Implementation of Circular Queue for Insertion and Deletion operation. #include<stdio.h> #include<process.h> void CQpush(); void CQpop(); void CQdisplay(); int s[10],n,choice,front = -1,rear = -1; int main() printf("enter size of circular queue\n"); scanf("%d",&n); printf("enter one of following choice:: \n"); printf("1. Push\n"); printf("2. Pop\n"); printf("3. Display\n"); printf("4. \n"); scanf("%d",&choice); do switch(choice) case 1: CQpush(); break; case 2: CQpop(); break; case 3: CQdisplay(); break; default: exit(0); printf("1. Push\n"); printf("2. Pop\n"); printf("3. Display\n"); printf("4. \n"); scanf("%d",&choice); while(choice>0 choice<=4); return 0; void CQpush() int x; printf("enter ur element to inser in the circular queue::"); scanf("%d",&x); if((front == 0 && rear == N-1) rear == front-1 ) printf("queue is overflow\n"); if(rear == N-1 && front!=0) rear=0; 21

22 s[rear]=x; if(front == -1 && rear == -1 ) rear = 0; front = 0; s[rear]=x; rear = rear +1; s[rear] = x; printf(" value is:: %d\t & front value is:: %d\n",rear,front); void CQpop() int x; if(front == -1 ) printf("queue is underflow\n"); x = s[front]; printf("element to be poped is :: %d\n",x); if(front == rear ) front = -1;rear = -1; if(front == N-1) front = 0; front = front + 1; printf(" value is:: %d\t & front value is:: %d\n",rear,front); void CQdisplay() if(front!= -1 && rear!= -1) if(front<=rear) printf("elements of queue are::\n"); for (int i=front; i<=rear;i++) 22

23 printf("%d\n",s[i]); printf("elements of queue are::\n"); for(int i=front; i<n; i++) printf("%d\n",s[i]); for(int i=0;i<=rear;i++) printf("%d\n",s[i]); Application of Queue Queue is widely used in simulation work. In mailbox application when we save the message to communicate between two user or processes in a system is work according to queue. A computer processor also maintain buffers in the form of queue for incoming resources requests. In operating system, process scheduling or disk scheduling algorithms uses queue concept. 23

Lecture Data Structure Stack

Lecture Data Structure Stack Lecture Data Structure Stack 1.A stack :-is an abstract Data Type (ADT), commonly used in most programming languages. It is named stack as it behaves like a real-world stack, for example a deck of cards

More information

STACKS 3.1 INTRODUCTION 3.2 DEFINITION

STACKS 3.1 INTRODUCTION 3.2 DEFINITION STACKS 3 3.1 INTRODUCTION A stack is a linear data structure. It is very useful in many applications of computer science. It is a list in which all insertions and deletions are made at one end, called

More information

Darshan Institute of Engineering & Technology for Diploma Studies Unit 1

Darshan Institute of Engineering & Technology for Diploma Studies Unit 1 Darshan Institute of Engineering & Technology for Diploma Studies Unit 1 Introduction Computer is an electronic machine which is used for data processing and manipulation. In order to make computer work

More information

DEEPIKA KAMBOJ UNIT 2. What is Stack?

DEEPIKA KAMBOJ UNIT 2. What is Stack? What is Stack? UNIT 2 Stack is an important data structure which stores its elements in an ordered manner. You must have seen a pile of plates where one plate is placed on top of another. Now, when you

More information

Prepared By:- Dinesh Sharma Asstt. Professor, CSE & IT Deptt. ITM Gurgaon

Prepared By:- Dinesh Sharma Asstt. Professor, CSE & IT Deptt. ITM Gurgaon Data Structures &Al Algorithms Prepared By:- Dinesh Sharma Asstt. Professor, CSE & IT Deptt. ITM Gurgaon What is Data Structure Data Structure is a logical relationship existing between individual elements

More information

Data Structure using C++ Lecture 04. Data Structures and algorithm analysis in C++ Chapter , 3.2, 3.2.1

Data Structure using C++ Lecture 04. Data Structures and algorithm analysis in C++ Chapter , 3.2, 3.2.1 Data Structure using C++ Lecture 04 Reading Material Data Structures and algorithm analysis in C++ Chapter. 3 3.1, 3.2, 3.2.1 Summary Stack Operations on a stack Representing stacks Converting an expression

More information

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) WINTER 18 EXAMINATION Subject Name: Data Structure using C Model wer Subject Code: 22317 Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given

More information

Some Applications of Stack. Spring Semester 2007 Programming and Data Structure 1

Some Applications of Stack. Spring Semester 2007 Programming and Data Structure 1 Some Applications of Stack Spring Semester 2007 Programming and Data Structure 1 Arithmetic Expressions Polish Notation Spring Semester 2007 Programming and Data Structure 2 What is Polish Notation? Conventionally,

More information

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) WINTER 18 EXAMINATION Subject Name: Data Structure Model wer Subject Code: 17330 Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in

More information

STACKS. A stack is defined in terms of its behavior. The common operations associated with a stack are as follows:

STACKS. A stack is defined in terms of its behavior. The common operations associated with a stack are as follows: STACKS A stack is a linear data structure for collection of items, with the restriction that items can be added one at a time and can only be removed in the reverse order in which they were added. The

More information

Basically queue is nothing but an array or a vector with a maximum capacity of size. Front=1 Front=1 REAR=2. Front=1 REAR=3 Front=1 REAR=4 Q is Full

Basically queue is nothing but an array or a vector with a maximum capacity of size. Front=1 Front=1 REAR=2. Front=1 REAR=3 Front=1 REAR=4 Q is Full Queue A Queue is defined as linear list in which insertion is taking place at one end and deletion is taking place at the other end. The end where insertion is taking place is called as rear end. The end

More information

Data Structures. Chapter 06. 3/10/2016 Md. Golam Moazzam, Dept. of CSE, JU

Data Structures. Chapter 06. 3/10/2016 Md. Golam Moazzam, Dept. of CSE, JU Data Structures Chapter 06 1 Stacks A stack is a list of elements in which an element may be inserted or deleted only at one end, called the top of the stack. This means that elements are removed from

More information

Application of Stack (Backtracking)

Application of Stack (Backtracking) Application of Stack (Backtracking) Think of a labyrinth or maze How do you find a way from an entrance to an exit? Once you reach a dead end, you must backtrack. But backtrack to where? to the previous

More information

Vivekananda College of Engineering & Technology. Data Structures and Applications

Vivekananda College of Engineering & Technology. Data Structures and Applications Vivekananda College of Engineering & Technology [Sponsored by Vivekananda Vidyavardhaka Sangha, Puttur ] Affiliated to Visvesvaraya Technological University Approved by AICTE New Delhi & Govt of Karnataka

More information

Class / Sem: I CSE / II Semester Subject Code: CS 6202 Subject: Programming and Data Structures I Prepared by T. Vithya Unit IV - LINEAR DATA STRUCTURES STACKS AND QUEUES Stack ADT Evaluating arithmetic

More information

Lecture No.04. Data Structures

Lecture No.04. Data Structures Lecture No.04 Data Structures Josephus Problem #include "CList.cpp" void main(int argc, char *argv[]) { CList list; int i, N=10, M=3; for(i=1; i

More information

The Queues. Front. Rear. Front. Rear. Rear = 0 Front = 0. Fig Queue is empty. Fig push(10) Rear = 1 Front = 0. Fig. 4.3.

The Queues. Front. Rear. Front. Rear. Rear = 0 Front = 0. Fig Queue is empty. Fig push(10) Rear = 1 Front = 0. Fig. 4.3. 4 The Queues A queue is logically a first in first out (FIFO or first come first serve) linear data structure. The concept of queue can be understood by our real life problems. For example a customer come

More information

UNIT-2 Stack & Queue

UNIT-2 Stack & Queue UNIT-2 Stack & Queue 59 13. Stack A stack is an Abstract Data Type (ADT), commonly used in most programming languages. It is named stack as it behaves like a real-world stack, for example a deck of cards

More information

Stack. 4. In Stack all Operations such as Insertion and Deletion are permitted at only one end. Size of the Stack 6. Maximum Value of Stack Top 5

Stack. 4. In Stack all Operations such as Insertion and Deletion are permitted at only one end. Size of the Stack 6. Maximum Value of Stack Top 5 What is Stack? Stack 1. Stack is LIFO Structure [ Last in First Out ] 2. Stack is Ordered List of Elements of Same Type. 3. Stack is Linear List 4. In Stack all Operations such as Insertion and Deletion

More information

EC8393FUNDAMENTALS OF DATA STRUCTURES IN C Unit 3

EC8393FUNDAMENTALS OF DATA STRUCTURES IN C Unit 3 UNIT 3 LINEAR DATA STRUCTURES 1. Define Data Structures Data Structures is defined as the way of organizing all data items that consider not only the elements stored but also stores the relationship between

More information

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in themodel answer scheme. 2) The model answer and the answer written by candidate may

More information

STACKS AND QUEUES. Problem Solving with Computers-II

STACKS AND QUEUES. Problem Solving with Computers-II STACKS AND QUEUES Problem Solving with Computers-II 2 Stacks container class available in the C++ STL Container class that uses the Last In First Out (LIFO) principle Methods i. push() ii. iii. iv. pop()

More information

VTU NOTES QUESTION PAPERS NEWS RESULTS FORUMS THE STACK

VTU NOTES QUESTION PAPERS NEWS RESULTS FORUMS THE STACK Contents: Definition and Examples Representing stacks in C Example: infix, prefix, and postfix Exercises THE STACK Definition and Examples A stack is an ordered collection of items into which new items

More information

Introduction to Data Structure

Introduction to Data Structure Introduction to Data Structure Introduction to Data Structure Computer is an electronic machine which is used for data processing and manipulation. When programmer collects such type of data for processing,

More information

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) WINTER 16 EXAMINATION Model Answer Subject Code:

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) WINTER 16 EXAMINATION Model Answer Subject Code: Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme. 2) The model answer and the answer written by candidate

More information

DS Assignment II. Full Sized Image

DS Assignment II. Full Sized Image DS Assignment II 1. A) For the Towers of Hanoi problem, show the call tree during the recursive call Towers(3, A, C, B). In the tree, label the root node as Towers (3, A, C, B) while marking all the intermediate

More information

Formal Languages and Automata Theory, SS Project (due Week 14)

Formal Languages and Automata Theory, SS Project (due Week 14) Formal Languages and Automata Theory, SS 2018. Project (due Week 14) 1 Preliminaries The objective is to implement an algorithm for the evaluation of an arithmetic expression. As input, we have a string

More information

NCS 301 DATA STRUCTURE USING C

NCS 301 DATA STRUCTURE USING C NCS Data Structure Using C -8- NCS DATA STRUCTURE USING C Unit- Part- Stack Hammad Mashkoor Lari Assistant Professor Allenhouse Institute of Technology www.ncsds.wordpress.com Introduction Stack is a non

More information

CS6202 - PROGRAMMING & DATA STRUCTURES I Unit IV Part - A 1. Define Stack. A stack is an ordered list in which all insertions and deletions are made at one end, called the top. It is an abstract data type

More information

Data Structures. Lecture 5 : The Queues

Data Structures. Lecture 5 : The Queues 0 Data Structures Lecture 5 : Dr. Essam Halim Houssein Lecturer, Faculty of Computers and Informatics, Benha University http://bu.edu.eg/staff/esamhalim14 2 A queue is logically a first in first out (FIFO

More information

Data Structures & Algorithm Analysis. Lecturer: Souad Alonazi

Data Structures & Algorithm Analysis. Lecturer: Souad Alonazi Data Structures & Algorithm Analysis Lec(3) Stacks Lecturer: Souad Alonazi What is a stack? Stores a set of elements in a particular order Stack principle: LAST IN FIRST OUT = LIFO It means: the last element

More information

CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-0-0)

CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-0-0) CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-0-0) Class Teacher: Pralay Mitra Department of Computer Science and Engineering Indian Institute of Technology Kharagpur Conceptual Idea

More information

DHANALAKSHMI COLLEGE OF ENGINEERING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING EC6301 OBJECT ORIENTED PROGRAMMING AND DATA STRUCTURES

DHANALAKSHMI COLLEGE OF ENGINEERING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING EC6301 OBJECT ORIENTED PROGRAMMING AND DATA STRUCTURES DHANALAKSHMI COLLEGE OF ENGINEERING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING EC6301 OBJECT ORIENTED PROGRAMMING AND DATA STRUCTURES UNIT III LINEAR DATA STRUCTURES PART A 1. What is meant by data

More information

Introduction. Problem Solving on Computer. Data Structures (collection of data and relationships) Algorithms

Introduction. Problem Solving on Computer. Data Structures (collection of data and relationships) Algorithms Introduction Problem Solving on Computer Data Structures (collection of data and relationships) Algorithms 1 Objective of Data Structures Two Goals: 1) Identify and develop useful high-level data types

More information

Solution: The examples of stack application are reverse a string, post fix evaluation, infix to postfix conversion.

Solution: The examples of stack application are reverse a string, post fix evaluation, infix to postfix conversion. 1. What is the full form of LIFO? The full form of LIFO is Last In First Out. 2. Give some examples for stack application. The examples of stack application are reverse a string, post fix evaluation, infix

More information

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) WINTER 17 EXAMINATION Subject Name: Data Structure Using C Model Answer Subject Code: 17330 Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as

More information

The Bucharest University of Economic Studies. Data Structures. ADTs-Abstract Data Types Stacks and Queues

The Bucharest University of Economic Studies. Data Structures. ADTs-Abstract Data Types Stacks and Queues The Bucharest University of Economic Studies Data Structures ADTs-Abstract Data Types Stacks and Queues Agenda Definition Graphical representation Internal interpretation Characteristics Operations Implementations

More information

Stacks. stacks of dishes or trays in a cafeteria. Last In First Out discipline (LIFO)

Stacks. stacks of dishes or trays in a cafeteria. Last In First Out discipline (LIFO) Outline stacks stack ADT method signatures array stack implementation linked stack implementation stack applications infix, prefix, and postfix expressions 1 Stacks stacks of dishes or trays in a cafeteria

More information

COMPUTER ARCHITECTURE AND PARALEL PROCESSING STUDY NOTES

COMPUTER ARCHITECTURE AND PARALEL PROCESSING STUDY NOTES COMPUTER ARCHITECTURE AND PARALEL PROCESSING STUDY NOTES UNIT 1 INTRODUCTION Central Processing unit (CPU): Alternately referred to as a processor, central processor, or microprocessor, the CPU is the

More information

Data Structures. Lecture 4 : The Queues. Dr. Essam Halim Houssein Lecturer, Faculty of Computers and Informatics, Benha University

Data Structures. Lecture 4 : The Queues. Dr. Essam Halim Houssein Lecturer, Faculty of Computers and Informatics, Benha University 0 Data Structures Lecture 4 : Dr. Essam Halim Houssein Lecturer, Faculty of Computers and Informatics, Benha University 2 A queue is logically a first in first out (FIFO or first come first serve) linear

More information

Lecture 4 Stack and Queue

Lecture 4 Stack and Queue Lecture 4 Stack and Queue Bo Tang @ SUSTech, Spring 2018 Our Roadmap Stack Queue Stack vs. Queue 2 Stack A stack is a sequence in which: Items can be added and removed only at one end (the top) You can

More information

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours TED (10)-3071 Reg. No.. (REVISION-2010) (Maximum marks: 100) Signature. FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours PART

More information

Data Structure using C++ Lecture 04. Data Structures and algorithm analysis in C++ Chapter , 3.2, 3.2.1

Data Structure using C++ Lecture 04. Data Structures and algorithm analysis in C++ Chapter , 3.2, 3.2.1 Data Structure using C++ Lecture 04 Reading Material Data Structures and algorithm analysis in C++ Chapter. 3 3.1, 3.2, 3.2.1 Summary Infix to Postfix Example 1: Infix to Postfix Example 2: Postfix Evaluation

More information

Stacks. CONTENTS 3.1 Introduction 1. Stack as an abstract data type 2. Representation of a Stack as an array 3.2Applications of Stack.

Stacks. CONTENTS 3.1 Introduction 1. Stack as an abstract data type 2. Representation of a Stack as an array 3.2Applications of Stack. Stacks CONTENTS 3.1 Introduction 1. Stack as an abstract data type 2. Representation of a Stack as an array 3.2Applications of Stack Hours: 12 Marks: 18 3.1 Introduction to Stacks 1. Stack as Abstract

More information

UNIT-II. Part-2: CENTRAL PROCESSING UNIT

UNIT-II. Part-2: CENTRAL PROCESSING UNIT Page1 UNIT-II Part-2: CENTRAL PROCESSING UNIT Stack Organization Instruction Formats Addressing Modes Data Transfer And Manipulation Program Control Reduced Instruction Set Computer (RISC) Introduction:

More information

Linked List. April 2, 2007 Programming and Data Structure 1

Linked List. April 2, 2007 Programming and Data Structure 1 Linked List April 2, 2007 Programming and Data Structure 1 Introduction head A linked list is a data structure which can change during execution. Successive elements are connected by pointers. Last element

More information

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- OCTOBER, 2012 DATA STRUCTURE

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- OCTOBER, 2012 DATA STRUCTURE TED (10)-3071 Reg. No.. (REVISION-2010) Signature. FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- OCTOBER, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours (Maximum marks: 100)

More information

Stack and Its Implementation

Stack and Its Implementation Stack and Its Implementation Tessema M. Mengistu Department of Computer Science Southern Illinois University Carbondale tessema.mengistu@siu.edu Room - 3131 1 Definition of Stack Usage of Stack Outline

More information

Infix to Postfix Conversion

Infix to Postfix Conversion Infix to Postfix Conversion Infix to Postfix Conversion Stacks are widely used in the design and implementation of compilers. For example, they are used to convert arithmetic expressions from infix notation

More information

1 P age DS & OOPS / UNIT II

1 P age DS & OOPS / UNIT II UNIT II Stacks: Definition operations - applications of stack. Queues: Definition - operations Priority queues - De que Applications of queue. Linked List: Singly Linked List, Doubly Linked List, Circular

More information

FUNCTIONS. Without return With return Without return With return. Example: function with arguments and with return value

FUNCTIONS. Without return With return Without return With return. Example: function with arguments and with return value FUNCTIONS Definition: A is a set of instructions under a name that carries out a specific task, assigned to it. CLASSIFICATION of s: 1. User defined s (UDF) 2. Library s USER DEFINED FUNCTIONS Without

More information

MODULE V: POINTERS & PREPROCESSORS

MODULE V: POINTERS & PREPROCESSORS MODULE V: POINTERS & PREPROCESSORS INTRODUCTION As you know, every variable is a memory-location and every memory-location has its address defined which can be accessed using ampersand(&) operator, which

More information

Content: Learning Objectives

Content: Learning Objectives 1 BLOOM PUBLIC CHOOL Vasant Kunj, New Delhi Lesson Plan Class: XII ubject: Computer cience Month : July No of s: 21 Chapter:Data structure: Linked List TTT: 8 WT: 12 Content: Learning Objectives At the

More information

Types of Data Structures

Types of Data Structures DATA STRUCTURES material prepared by: MUKESH BOHRA Follow me on FB : http://www.facebook.com/mukesh.sirji4u The logical or mathematical model of data is called a data structure. In other words, a data

More information

Revision Statement while return growth rate asymptotic notation complexity Compare algorithms Linear search Binary search Preconditions: sorted,

Revision Statement while return growth rate asymptotic notation complexity Compare algorithms Linear search Binary search Preconditions: sorted, [1] Big-O Analysis AVERAGE(n) 1. sum 0 2. i 0. while i < n 4. number input_number(). sum sum + number 6. i i + 1 7. mean sum / n 8. return mean Revision Statement no. of times executed 1 1 2 1 n+1 4 n

More information

First Semester - Question Bank Department of Computer Science Advanced Data Structures and Algorithms...

First Semester - Question Bank Department of Computer Science Advanced Data Structures and Algorithms... First Semester - Question Bank Department of Computer Science Advanced Data Structures and Algorithms.... Q1) What are some of the applications for the tree data structure? Q2) There are 8, 15, 13, and

More information

Chapter 2. Stack & Queues. M hiwa ahmad aziz

Chapter 2. Stack & Queues.   M hiwa ahmad aziz . Chapter 2 Stack & Queues www.raparinweb.com M hiwa ahmad aziz 1 Stack A stack structure with a series of data elements that Allows access to only the last item inserted. An item is inserted or removed

More information

Programming & Data Structure Laboratory. Day 2, July 24, 2014

Programming & Data Structure Laboratory. Day 2, July 24, 2014 Programming & Data Structure Laboratory Day 2, July 24, 2014 Loops Pre and post test loops for while do-while switch-case Pre-test loop and post-test loop Condition checking True Loop Body False Loop Body

More information

Linked List in Data Structure. By Prof. B J Gorad, BECSE, M.Tech CST, PHD(CSE)* Assistant Professor, CSE, SITCOE, Ichalkaranji,Kolhapur, Maharashtra

Linked List in Data Structure. By Prof. B J Gorad, BECSE, M.Tech CST, PHD(CSE)* Assistant Professor, CSE, SITCOE, Ichalkaranji,Kolhapur, Maharashtra Linked List in Data Structure By Prof. B J Gorad, BECSE, M.Tech CST, PHD(CSE)* Assistant Professor, CSE, SITCOE, Ichalkaranji,Kolhapur, Maharashtra Linked List Like arrays, Linked List is a linear data

More information

Solution for Data Structure

Solution for Data Structure Solution for Data Structure May 2016 INDEX Q1 a 2-3 b 4 c. 4-6 d 7 Q2- a 8-12 b 12-14 Q3 a 15-18 b 18-22 Q4- a 22-35 B..N.A Q5 a 36-38 b N.A Q6- a 39-42 b 43 1 www.brainheaters.in Q1) Ans: (a) Define ADT

More information

S.Y. Diploma : Sem. III [CO/CM/IF/CD/CW] Data Structure using C

S.Y. Diploma : Sem. III [CO/CM/IF/CD/CW] Data Structure using C S.Y. Diploma : Sem. III [CO/CM/IF/CD/CW] Data Structure using C Time: 3 Hrs.] Prelim Question Paper Solution [Marks : 100 Q.1 (a) Attempt any SIX of the following : [12] Q.1 (a) (i) Define time complexity

More information

Linear Data Structure

Linear Data Structure Linear Data Structure Definition A data structure is said to be linear if its elements form a sequence or a linear list. Examples: Array Linked List Stacks Queues Operations on linear Data Structures Traversal

More information

Government Girls Polytechnic, Bilaspur

Government Girls Polytechnic, Bilaspur Government Girls Polytechnic, Bilaspur Name of the Lab: Programming Lab Practical: Data Structure Lab Class: 4 th Semester (Computer Science & Engineering) Teachers Assessment: 30 End Semester Examination:70

More information

ADVANCED DATA STRUCTURES USING C++ ( MT-CSE-110 )

ADVANCED DATA STRUCTURES USING C++ ( MT-CSE-110 ) ADVANCED DATA STRUCTURES USING C++ ( MT-CSE-110 ) Unit - 2 By: Gurpreet Singh Dean Academics & H.O.D. (C.S.E. / I.T.) Yamuna Institute of Engineering & Technology, Gadholi What is a Stack? A stack is a

More information

12 Abstract Data Types

12 Abstract Data Types 12 Abstract Data Types 12.1 Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: Define the concept of an abstract data type (ADT). Define

More information

Frequently asked Data Structures Interview Questions

Frequently asked Data Structures Interview Questions Frequently asked Data Structures Interview Questions Queues Data Structure Interview Questions How is queue different from a stack? The difference between stacks and queues is in removing. In a stack we

More information

Operators and Expressions:

Operators and Expressions: Operators and Expressions: Operators and expression using numeric and relational operators, mixed operands, type conversion, logical operators, bit operations, assignment operator, operator precedence

More information

Stack ADT. ! push(x) puts the element x on top of the stack! pop removes the topmost element from the stack.

Stack ADT. ! push(x) puts the element x on top of the stack! pop removes the topmost element from the stack. STACK Stack ADT 2 A stack is an abstract data type based on the list data model All operations are performed at one end of the list called the top of the stack (TOS) LIFO (for last-in first-out) list is

More information

MAHARASHTRASTATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

MAHARASHTRASTATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) Subject Code: 17330 Model Answer Page 1/ 22 Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme. 2) The model

More information

15. Stacks and Queues

15. Stacks and Queues COMP1917 15s2 15. Stacks and Queues 1 COMP1917: Computing 1 15. Stacks and Queues Reading: Moffat, Section 10.1-10.2 Overview Stacks Queues Adding to the Tail of a List Efficiency Issues Queue Structure

More information

Answers. 1. (A) Attempt any five : 20 Marks

Answers. 1. (A) Attempt any five : 20 Marks Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme. 2) The model answer and the answer written by candidate

More information

UNIT VI. STACKS AND QUEUES

UNIT VI. STACKS AND QUEUES UNIT VI. STACKS AND QUEUES Syllabus: /*-------------------------------------------------------------------------*/ Stack: Definition: "Stack is an ordered collection of data elements having similar data

More information

Introduction to Data Structures & Algorithms S.GokulaKrishnan B.Tech.,M.Tech.,[Ph.D] Assistant Professor[Stage-I] Department of Computer Science and

Introduction to Data Structures & Algorithms S.GokulaKrishnan B.Tech.,M.Tech.,[Ph.D] Assistant Professor[Stage-I] Department of Computer Science and Introduction to Data Structures & Algorithms S.GokulaKrishnan B.Tech.,M.Tech.,[Ph.D] Assistant Professor[Stage-I] Department of Computer Science and Engineering Sri Chandrasekharendra Saraswathi Viswa

More information

Top of the Stack. Stack ADT

Top of the Stack. Stack ADT Module 3: Stack ADT Dr. Natarajan Meghanathan Professor of Computer Science Jackson State University Jackson, MS 39217 E-mail: natarajan.meghanathan@jsums.edu Stack ADT Features (Logical View) A List that

More information

CHARUTAR VIDYA MANDAL S SEMCOM Vallabh Vidyanagar

CHARUTAR VIDYA MANDAL S SEMCOM Vallabh Vidyanagar CHARUTAR VIDYA MANDAL S SEMCOM Vallabh Vidyanagar Faculty Name: Ami D. Trivedi Class: FYBCA Subject: US02CBCA01 (Advanced C Programming and Introduction to Data Structures) *UNIT 3 (Introduction to Data

More information

Data Structures II Lesson 1 (Circular Queue)

Data Structures II Lesson 1 (Circular Queue) Data Structures II Lesson 1 (Circular Queue) Introduction The circular queue: is a queue where the last location in it is linked to the first location As shown in figure 1, location (5) which is the last

More information

DS Lab Manual -17CS33

DS Lab Manual -17CS33 Chethan Raj C Assistant Professor Dept. of CSE 6. Design, Develop and Implement a menu driven Program in C for the following operations on Circular QUEUE of Characters (Array Implementation of Queue with

More information

Arrays and Linked Lists

Arrays and Linked Lists Arrays and Linked Lists Abstract Data Types Stacks Queues Priority Queues and Deques John Edgar 2 And Stacks Reverse Polish Notation (RPN) Also known as postfix notation A mathematical notation Where every

More information

INSTITUTE OF AERONAUTICAL ENGINEERING

INSTITUTE OF AERONAUTICAL ENGINEERING INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad - 500 043 COMPUTER SCIENCE AND ENGINEERING TUTORIAL QUESTION BANK Course Name Course Code Class Branch DATA STRUCTURES ACS002 B. Tech

More information

UNIT 3: QUEUE Programs demonstrated in class. Tojo Mathew Asst. Professor CSE Dept., NIE Mysuru.

UNIT 3: QUEUE Programs demonstrated in class. Tojo Mathew Asst. Professor CSE Dept., NIE Mysuru. UNIT 3: QUEUE Programs demonstrated in class. Tojo Mathew Asst. Professor CSE Dept., NIE Mysuru. Table of Contents 1. Simple Queue Implementation with arrays...3 2. Circular queue with global container

More information

Lab 7 1 Due Thu., 6 Apr. 2017

Lab 7 1 Due Thu., 6 Apr. 2017 Lab 7 1 Due Thu., 6 Apr. 2017 CMPSC 112 Introduction to Computer Science II (Spring 2017) Prof. John Wenskovitch http://cs.allegheny.edu/~jwenskovitch/teaching/cmpsc112 Lab 7 - Using Stacks to Create a

More information

09 STACK APPLICATION DATA STRUCTURES AND ALGORITHMS REVERSE POLISH NOTATION

09 STACK APPLICATION DATA STRUCTURES AND ALGORITHMS REVERSE POLISH NOTATION DATA STRUCTURES AND ALGORITHMS 09 STACK APPLICATION REVERSE POLISH NOTATION IMRAN IHSAN ASSISTANT PROFESSOR, AIR UNIVERSITY, ISLAMABAD WWW.IMRANIHSAN.COM LECTURES ADAPTED FROM: DANIEL KANE, NEIL RHODES

More information

Chapter 4 Functions By C.K. Liang

Chapter 4 Functions By C.K. Liang 1 Chapter 4 Functions By C.K. Liang What you should learn? 2 To construct programs modularly from small pieces called functions Math functions in C standard library Create new functions Pass information

More information

Top of the Stack. Stack ADT

Top of the Stack. Stack ADT Module 3: Stack ADT Dr. Natarajan Meghanathan Professor of Computer Science Jackson State University Jackson, MS 39217 E-mail: natarajan.meghanathan@jsums.edu Stack ADT Features (Logical View) A List that

More information

BSc.(Hons.) Business Information Systems, BSc. (Hons.) Computer Science with Network Security, BSc.(Hons.) Software Engineering

BSc.(Hons.) Business Information Systems, BSc. (Hons.) Computer Science with Network Security, BSc.(Hons.) Software Engineering BSc.(Hons.) Business Information Systems, BSc. (Hons.) Computer Science with Network Security, BSc.(Hons.) Software Engineering Cohorts BIS/04 Full Time - BCNS/04 Full Time SE/04 Full Time Examinations

More information

Stacks. Chapter 5. Copyright 2012 by Pearson Education, Inc. All rights reserved

Stacks. Chapter 5. Copyright 2012 by Pearson Education, Inc. All rights reserved Stacks Chapter 5 Contents Specifications of the ADT Stack Using a Stack to Process Algebraic Expressions A Problem Solved: Checking for Balanced Delimiters in an Infix Algebraic Expression A Problem Solved:

More information

#06 More Structures LIFO FIFO. Contents. Queue vs. Stack 3. Stack Operations. Pop. Push. Stack Queue Hash table

#06 More Structures LIFO FIFO. Contents. Queue vs. Stack 3. Stack Operations. Pop. Push. Stack Queue Hash table Contents #06 More Structures -07 FUNDAMENTAL PROGRAMMING I Stack Queue Hash table DEPARTMENT OF COMPUTER ENGINEERING, PSU v. Queue vs. Stack Stack Operations IN IN OUT Push: add an item to the top Pop:

More information

Stacks, Queues (cont d)

Stacks, Queues (cont d) Stacks, Queues (cont d) CSE 2011 Winter 2007 February 1, 2007 1 The Adapter Pattern Using methods of one class to implement methods of another class Example: using List to implement Stack and Queue 2 1

More information

A. Year / Module Semester Subject Topic 2016 / V 2 PCD Pointers, Preprocessors, DS

A. Year / Module Semester Subject Topic 2016 / V 2 PCD Pointers, Preprocessors, DS Syllabus: Pointers and Preprocessors: Pointers and address, pointers and functions (call by reference) arguments, pointers and arrays, address arithmetic, character pointer and functions, pointers to pointer,initialization

More information

Write a program to implement stack or any other data structure in Java ASSIGNMENT NO 15

Write a program to implement stack or any other data structure in Java ASSIGNMENT NO 15 Write a program to implement stack or any other data structure in Java ASSIGNMENT NO 15 Title: Demonstrate implementation of data structure in Java Objectives: To learn implementation of data structure

More information

Stack. Data structure with Last-In First-Out (LIFO) behavior. Out

Stack. Data structure with Last-In First-Out (LIFO) behavior. Out Stack and Queue 1 Stack Data structure with Last-In First-Out (LIFO) behavior In Out C B A B C 2 Typical Operations Pop on Stack Push isempty: determines if the stack has no elements isfull: determines

More information

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Computer Science and Engineering

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Computer Science and Engineering USN 1 P E PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Computer Science and Engineering SOLUTION FOR INTERNAL ASSESSMENT TEST 2 Date : 6/10/2017 Marks:

More information

Queue: Queue Representation: Basic Operations:

Queue: Queue Representation: Basic Operations: Queue: Queue is an abstract data structure, somewhat similar to Stacks. Unlike stacks, a queue is open at both its ends. One end is always used to insert data (enqueue) and the other is used to remove

More information

Sample Question Paper

Sample Question Paper Scheme - I Sample Question Paper Marks : 70 Time: 3 Hrs. Q.1) Attempt any FIVE of the following. 10 Marks a. Write any four applications of data structure. b. Sketch the diagram of circular queue. c. State

More information

Programming and Data Structure Solved. MCQs- Part 2

Programming and Data Structure Solved. MCQs- Part 2 Programming and Data Structure Solved MCQs- Part 2 Programming and Data Structure Solved MCQs- Part 2 Unsigned integers occupies Two bytes Four bytes One byte Eight byte A weather forecasting computation

More information

Outline. Introduction Stack Operations Stack Implementation Implementation of Push and Pop operations Applications. ADT for stacks

Outline. Introduction Stack Operations Stack Implementation Implementation of Push and Pop operations Applications. ADT for stacks Stack Chapter 4 Outline Introduction Stack Operations Stack Implementation Implementation of Push and Pop operations Applications Recursive Programming Evaluation of Expressions ADT for stacks Introduction

More information

Unit III Functions. C functions can be classified into two categories, namely, library functions and user defined functions.

Unit III Functions. C functions can be classified into two categories, namely, library functions and user defined functions. Unit III Functions Functions: Function Definition, Function prototype, types of User Defined Functions, Function calling mechanisms, Built-in string handling and character handling functions, recursion,

More information

Unit-2. Stacks: Introduction-Definition-Representation of Stack-Operations on Stacks- Applications of Stacks.

Unit-2. Stacks: Introduction-Definition-Representation of Stack-Operations on Stacks- Applications of Stacks. Unit-2 Stacks: Introduction-Definition-Representation of Stack-Operations on Stacks- Applications of Stacks. Queues: Introduction, Definition- Representations of Queues- Various Queue Structures- Applications

More information

Prepared By: Ms. Nidhi Solanki (Assist. Prof.) Page 1

Prepared By: Ms. Nidhi Solanki (Assist. Prof.) Page 1 QUESTION BANK ON COURSE: 304: PRELIMINARIES: 1. What is array of pointer, explain with appropriate example? 2 2. Differentiate between call by value and call by reference, give example. 3. Explain pointer

More information

Prepared by Mrs.D.Maladhy (AP/IT/RGCET) Page 1

Prepared by Mrs.D.Maladhy (AP/IT/RGCET) Page 1 Basics : Abstract Data Type(ADT) introduction to data structures representation - implementation Stack and list: representing stack implementation application balancing symbols conversion of infix to postfix

More information