WEL COME PRAVEEN M JIGAJINNI PGT (Computer Science) MTech[IT],MPhil (Comp.Sci), MCA, MSc[IT], PGDCA, ADCA, Dc. Sc. & Engg.

Slides:



Advertisements
Similar presentations
Data Structures Through C
Advertisements

Stacks, Queues, and Linked Lists
CSCE 3110 Data Structures & Algorithm Analysis Stacks and Queues Reading: Chap.3 Weiss.
CS Data Structures ( 資料結構 ) Chapter 3: Stacks and Queues Spring 2012.
Stacks & Their Applications COP Stacks  A stack is a data structure that stores information arranged like a stack.  We have seen stacks before.
C o n f i d e n t i a l Developed By Nitendra NextHome Subject Name: Data Structure Using C Title : Overview of Stack.
CSCE 3110 Data Structures & Algorithm Analysis Queues Reading: Chap. 3 Weiss.
E.G.M. Petrakislists, stacks, queues1 Stacks Stack: restricted variant of list –Elements may by inserted or deleted from only one end  LIFO lists –Top:
COP3538 – Data Structures Using OOP Chapter 4 – Stacks and Queues.
Chapter 3 1. Templates in C++ Template function in C++ makes it easier to reuse classes and functions. A template can be viewed as a variable that can.
Lecture 5 Sept 15 Goals: stacks Implementation of stack applications Postfix expression evaluation Convert infix to postfix.
Stacks CS-240 Dick Steflik. Stacks Last In, First Out operation - LIFO As items are added they are chronologically ordered, items are removed in reverse.
Lecture 7 Sept 16 Goals: stacks Implementation of stack applications Postfix expression evaluation Convert infix to postfix.
E.G.M. Petrakisstacks, queues1 Stacks  Stack: restricted variant of list  elements may by inserted or deleted from only one end : LIFO lists  top: the.
Stacks CS-240 Dick Steflik. Stacks Last In, First Out operation - LIFO As items are added they are chronologically ordered, items are removed in reverse.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Data Structures Stacks.
Stacks CS-240 & CS-341 Dick Steflik. Stacks Last In, First Out operation - LIFO As items are added they are chronologically ordered, items are removed.
The Stack and Queue Types Lecture 10 Hartmut Kaiser
Stack  A stack is a linear data structure or abstract data type for collection of items, with the restriction that items can be added one at a time and.
Ceng-112 Data Structures ITurgut Kalfaoglu 1 Chapter 3 Stacks.
Comp 245 Data Structures Stacks. What is a Stack? A LIFO (last in, first out) structure Access (storage or retrieval) may only take place at the TOP NO.
Stack Applications.
1 Stacks – Chapter 3 A stack is a data structure in which all insertions and deletions of entries are made at one end, called the top of the stack. Alternatively,
CHAPTER 05 Compiled by: Dr. Mohammad Omar Alhawarat Stacks & Queues.
Chapter 4 Stacks Stacks A stack is a linear data structure that can be accessed only at one of its ends for storing and retrieving. Its called.
SAK 3117 Data Structures Chapter 3: STACKS. Objective To introduce: Stack concepts Stack operations Stack applications CONTENT 3.1 Introduction 3.2 Stack.
Data Structures. The Stack: Definition A stack is an ordered collection of items into which new items may be inserted and from which items may be deleted.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 4 Prepared by İnanç TAHRALI.
COP3530 Data Structures600 Stack Stack is one the most useful ADTs. Like list, it is a collection of data items. Supports “LIFO” (Last In First Out) discipline.
Data Structures Stack Namiq Sultan 1. Data Structure Definition: Data structures is a study of different methods of organizing the data and possible operations.
Stack Overview. Stack Stack ADT Basic operations of stack – Pushing, popping etc. Implementations of stacks using – array – linked list.
CHAPTER 3 STACK CSEB324 DATA STRUCTURES & ALGORITHM.
Stacks Stack is a data structure that can be used to store data which can later be retrieved in the reverse or last in first out (LIFO) order. Stack is.
Data Structures & Algorithms
CHP-3 STACKS.
2005MEE Software Engineering Lecture 7 –Stacks, Queues.
Stacks & Queues. Introduction to Stacks and Queues Widely used data structures Ordered List of element Easy to implement Easy to use.
Fall 2006 METU EEEEE 441 S. Ece (GURAN) SCH MIDT EE 441 Data Structures Lecture 6 Stacks and Queues.
1 Data Structures and Algorithms Stack. 2 The Stack ADT Introduction to the Stack data structure Designing a Stack class using dynamic arrays Linked Stacks.
Stacks Chapter 3 Objectives Upon completion you will be able to
Applications of Stack Maitrayee Mukerji. Stacks Last In First Out (LIFO List) ◦ FILO? Insertions and Deletions from the same end called the Top Push(),
 In general, Queue is line of person waiting for their turn at some service counter like ticket window at cinema hall, at bus stand or at railway station.
DATA STRUCURES II CSC QUIZ 1. What is Data Structure ? 2. Mention the classifications of data structure giving example of each. 3. Briefly explain.
STACKS & QUEUES for CLASS XII ( C++).
Chapter 4 Stacks
Data Structure By Amee Trivedi.
Stacks and Queues Chapter 4.
Data Structure Interview Question and Answers
MEMORY REPRESENTATION OF STACKS
Homework 4 questions???.
Objectives In this lesson, you will learn to: Define stacks
Cinda Heeren / Geoffrey Tien
Stacks.
Stack and Queue APURBO DATTA.
Stacks Stack: restricted variant of list
Data Structures – Week #3
Algorithms and Data Structures
Visit for more Learning Resources
COMPUTER 2430 Object Oriented Programming and Data Structures I
CMSC 341 Lecture 5 Stacks, Queues
DATA STRUCTURE QUEUE.
UNIT-I Topics to be covere d 1.Introduction to data structures.
Queues FIFO Enqueue Dequeue Peek.
COMPUTER 2430 Object Oriented Programming and Data Structures I
Stacks and Queues 1.
Stacks CS-240 Dick Steflik.
Data Structures – Week #3
Presented by : Aman Gupta PGT CS KV No.1, Narimedu, Madurai
LINEAR DATA STRUCTURES
DATA STRUCTURES IN PYTHON
Presentation transcript:

WEL COME PRAVEEN M JIGAJINNI PGT (Computer Science) MTech[IT],MPhil (Comp.Sci), MCA, MSc[IT], PGDCA, ADCA, Dc. Sc. & Engg.

In computer science, a data structure is a particular way of organizing data in a computer so that it can be used Data structures provide a means to manage large amounts of data efficiently for uses such as large databases andinternet indexing services. Usually, efficient data structures are key to designing efficient algorithms. Some formal design methods and programming languages emphasize data structures, rather than algorithms, as the key organizing factor in software design. Storing and retrieving can be carried out on data stored in both main memory and in secondary memory. Data Structure

Data structures are generally based on the ability of a computer to fetch and store data at any place in its memory, specified by a pointer – a bit string, representing a memory address, that can be itself stored in memory and manipulated by the program. Thus, the array and record data structures are based on computing the addresses of data items with arithmetic operations; while the linked data structures are based on storing addresses of data items within the structure itself. Many data structures use both principles Data Structure

Primitive types  Boolean, true or false  Character  Floating-point, single-precision real number values  Double, a wider floating-point size  Integer, integral or fixed-precision values  Enumerated type, a small set of uniquely named values Composite types (Sometimes also referred to as Plain old data structures.)  Array  Record (also called tuple or struct or class)  Union  Tagged union (also called a variant, variant record, discriminated union, or disjoint union) Data Structure

Abstract data types  Array  Container  Map/Associative array/Dictionary  Multimap  List  Set  Multiset/Bag Data Structure  Priority queue  Queue  Deque  Stack  String  Tree  Graph

In computer science, a stack is a last in, first out (LIFO) data structure. A stack can is characterized by only two fundamental operations: push and pop. The push operation adds an item to the top of the stack. The pop operation removes an item from the top of the stack, and returns this value to the caller. A stack is a restricted data structure, because only a small number of operations are performed on it. The nature of the pop and push operations also mean that stack elements have a natural order. Elements are removed from the stack in the reverse order to the order of their addition: therefore, the lower elements are those that have been on the stack the longest. One of the common uses of stack is in function call Stack

Stack using ARRAY Stack using array #include const int size=5 class stack { int a[size]; //array a can store maximum 5 item of type int of the stack int top; //top will point to the last item pushed onto the stack public: stack(){top=-1;} //constructor to create an empty stack, top=-1 indicate that no item is //present in the array void push(int item) { If(top==size-1) cout<<”stack is full, given item cannot be added”;

cout<<”stack is full, given item cannot be added”; else a[++top]=item; //increment top by 1 then item at new position of the top in the array a } int pop() {If (top==-1) {out<<”Stack is empty “; return -1; //-1 indicates empty stack } else return a[top--];//return the item present at the top of the stack then decrement top by 1 } Stack using ARRAY

void main() { stack s1; s1.push(3); s1.push(5); cout<<s1.pop()<<endl; cout<<s1.pop(); } Stack using ARRAY

In Computer Science, a linked list (or more clearly, "singly- linked list") is a data structure that consists of a sequence of nodes each of which contains data and a pointer which points (i.e., a link) to the next node in the sequence. A linked list whose nodes contain two fields: an integer value and a link to the next node LINKED STACK

The main benefit of a linked list over a conventional array is that the list elements can easily be added or removed without reallocation or reorganization of the entire structure because the data items need not be stored contiguously in memory or on disk.Stack using linked lists allow insertion and removal of nodes only at the position where the pointer top is pointing to. LINKED STACK

struct NODE { int Book_No; char Book_Title[20]; NODE *Next; } *top, *newptr, *save; void PUSHBOOK(NODE*); // prototype void POPBOOK( ); // prototype void DISPLAY( ); // prototype LINKED STACK DEFINITION

void PUSHBOOK(NODE *np) { if(top==NULL) top=np; else {save=top; top=np; np->Next=save; } LINKED STACK – PUSH OPERATION

void POPBOOK( ) { if (top != NULL) { Stack *Temp; Temp = top; //Ignore the following line while evaluation cout Bno Bname<<”deleted”<<endl; top = top ->Next; delete Temp; } else cout<<”Stack Empty”; } LINKED STACK – POP OPERATION

void DISPLAY() { Node *Temp = Top; while (Temp! = NULL) { cout Bno Bname<<endl ; Temp = Temp -> Link; } LINKED STACK – DISPLAY OPERATION

Application of stacks in infix expression to postfix expression conversion Infix expr - operand1 operator operand2 for ex: a+b Postfix expr - operand1 operand2 operator for ex ab+ Prefix expr - operator operand1 operand2 for ex +ab APPLICATIONS OF STACK

Some example of infix expression and their corresponding postfix expression Infix expressionpostfix expression a*(b-c)/eabc-*e/ (a+b)*(c-d)/eab+cd-*e/ (a+b*c)/(d-e)+fabc*+de-/f+ APPLICATIONS OF STACK

For example convert the infix expression (A+B)*(C-D)/E into postfix expression showing stack status after every step. CONVERSION

Symbol scannedStack statusPostfix expr ( ((( A A +((+A B AB )( *(* ((*( C AB+C -(*(-AB+C D(*(-AB+CD )(*AB+CD- /(/AB+CD-* E(/AB+CD-*E )AB+CD-*E/ Answer : AB+CD-*E/

Evaluate the following postfix expression showing stack status after every step 8, 2, +, 5, 3, -, *, 4 / CONVERSION

scannedStack statusOperation performed 8 8Push 8 2 8, 2Push Op2=pop() i.e 2 Op1=pop() i.e 8 Push(op1+op2) i.e , 5Push(5) 3 10, 5, 3Push(3) - 10, 2Op2=pop() i.e. 3 Op1=pop() i.e. 5 Push(op1-op2) i.e , 2, +, 5, 3, -, *, 4 /

CONVERSION scannedStack statusOperation performed *20 Op2=pop() i.e. 2 Op1=pop() i.e. 10 Push(op1-op2) i.e. 10*2 4 20, 4Push 4 / 5Op2=pop() i.e. 4 Op1=pop() i.e. 20 Push(op1/op2) i.e. 20/4 NULLFinal result 5Pop 5 and return 5 8, 2, +, 5, 3, -, *, 4 / Answer : 5

Evaluate the following Boolean postfix expression showing stack status after every step. True, False, True, AND, OR, False, NOT, AND CONVERSION

scannedStack statusOperation performed True Push True FalseTrue, FalsePush False TrueTrue, False, TruePush True ANDTrue, FalseOp2=pop() i.e. True Op1=pop() i.e. False Push(Op2 AND Op1) i.e. False AND True=False ORTrueOp2=pop() i.e. False Op1=pop() i.e. True Push(Op2 OR Op1) i.e. True OR False=True True, False, True, AND, OR, False, NOT, AND

CONVERSION ScannedStack statusOperation Performed FalseTrue, FalsePush False NOTTrue, TrueOp1=pop() i.e. False Push(NOT False) i.e. NOT False=True ANDTrueOp2=pop() i.e. True Op1=pop() i.e. True Push(Op2 AND Op1) i.e. True AND True=True NULLFinal result TruePop True and Return True True, False, True, AND, OR, False, NOT, AND Answer :True

Queue is a linear data structure which follows First In First Out (FIFO) rule in which a new item is added at the rear end and deletion of item is from the front end of the queue. In a FIFO data structure, the first element added to the queue will be the first one to be removed. QUEUE

#include const int size=5; class queue {int front, rear; int a[size]; public: queue(){frot=0;rear=0;} //Constructor to create an empty queue void addQ() { if(rear==size) cout<<”queue is full<<endl; else a[rear++]=item; } QUEUE USING ARRAY

int delQ() {if(front==rear) {cout<<”queue is empty”<<endl; return 0;} else return a[front++]; } void main() { queue q1; q1.addQ(3); // CONTD… QUEUE USING ARRAY

q1.addQ(5) ; q1.addQ(7) ; cout<<q1.delQ()<<endl ; } Output is Queue is empty QUEUE USING ARRAY

struct NODE { char Name[20]; NODE *Link; } *R,*F; void INSERT(); void DELETE(); LINKED QUEUE DEFINITION

void INSERT() { NODE *Temp; Temp=new NODE; gets(Temp->Name); Temp->Link=NULL; if (Rear==NULL) { Rear=Temp;Front=Temp; } else {Rear->Link=Temp; Rear=Temp; } LINKED QUEUE – PUSH OPERATION

void DELETE() { if(Front==NULL) // OR if(!Front) cout<<”\n Queue Underflow\n”; else { NODE *Temp; Temp=Front; Front=Front->Link; delete Temp; if (Front==NULL) Rear=NULL; } LINKED QUEUE – POP OPERATION

void DELETE() { if(Front==NULL) // OR if(!Front) cout<<”\n Queue Underflow\n”; else { NODE *Temp; Temp=Front; Front=Front->Link; delete Temp; if (Front==NULL) Rear=NULL; } LINKED QUEUE – DISPLAY OPERATION

Circular queues overcome the problem of unutilised space in linear queues implemented as array. In circular queue using array the rear and front moves in a circle from 0,1,2…size-1,0, and so on. #include const int size=4; class Cqueue { int a[size]; int front,rear,anyitem; public: void Cqueue(){front=0;rear=0;anyitem=0;} void addCQ(int item); int delCQ(); }; Circular Queue using Array

void Cqueue::addCQ(int item) { If(front==rear && anyitem>0) cout<<”Cqueue is full”<<endl; else { a[rear]=item; rear=(rear+1)%size; //rear will move in circular order anyitem++; //value of the anyitem contains no of items present in the queue } Circular Queue using Array

int Cqueue::delCQ() { if(front==rear&& anyitem==0) cout<<”Cqueue is empty”<<endl; return 0; //0 indicate that Cqueue is empty else { int r=a[front]; front=(front+1)/size; anyitem--; } Circular Queue using Array

void main() { Cqueue q1; q1.addCQ(3); q1.addCQ(5) ; cout<<q1.delCQ()<<endl ; q1.addCQ(7) ; cout<<q1.delCQ()<<endl ; q1.addCQ(8) ; q1.addCQ(9) ; cout<<q1.delCQ()<<endl; } Output is Circular Queue using Array

? Any Questions Please

Thank You Very Much