SlideShare a Scribd company logo
1
Introduction to Data
Structures
Session I
Dr. V.Umadevi M.Sc(CS &IT). M.Tech (IT)., M.Phil., PhD., D.Litt.,
Director, Department of Computer Science, Jairams Arts and
Science College, Karur.
Data Structures & Algorithms
2
• Introduction to Data Structures
• Primitive Data Structures
• Types of Data structures
– Stacks
– Queues
– Lists
• Stack
– Basic Operation of Stack
– Operations on the Data Structures
– Applications of Infix, Postfix and Prefix
Data Structures & Algorithms
Introduction to Data Structures
3
Data Structures & Algorithms
• A Computer is a machine that manipulates information.
• Computer science studies includes:
– How information is organized in a computer
– How it can be manipulated
– How it can be utilized
Introduction to Data Structures
• Data is represented by the values held temporarily in the program’s data
area or recorded permanently on a file
• Different data values may be related to each other which need to be
organized to form a proper data structure.
• Program follow certain rules to access manipulate and process the
structured data.
Information – Processed data given as output
Data – Raw facts and figures given as input
4
Data Structures & Algorithms
• Organization of data in a computer's memory or in a file.
• Proper choice of a data structure can lead to more
efficient programs.
• Example: Array, Stack, Queue, Linked list, Tree and
Graph.
• Represented as follows:
Data structure=Data organization + allowed operations.
Data Structure
5
Primitive Data structure
• Data structures typically are directly operated upon by the machine
level instructions.
• Primitive data constitute the numbers and characters, which are
built into a programming language.
• Examples are: Integer, Boolean and Characters.
• Other data structures can be constructed from one or more
primitives.
• Simple data structures built from primitives are Strings, Arrays,
and Records
Data Structures & Algorithms
6
Types of Data Structures
– Linear data structure.
– Non-Linear data structure.
• Various names used for naming the elements of a data structure
( Commonly used names are data element, data item,
item aggregate, node list and data object)
• Various data structures are used depending upon the needs and convenience
Data Structures & Algorithms
7
Data Structures & Algorithms
•Elements or items form a sequence one after the other.
•Linear list can be realized in memory using either an
array or
a linked list structure.
•Data is also stored in memory locations by means of
pointers.
Examples are: Arrays, Stacks, Queues and Linked list.
Linear Data Structure
8
Linear Data Structures Types
• Arrays - elements stored in memory locations in a sequential
order
• Stack is an ordered collection of data items
– inserted or deleted from one end i.e., Last In First Out (LIFO)
principle.
• Queue is an ordered list
– inserted at one end and are retrieved from the other end i.e., First
in First out (FIFO) principle.
• Linked Lists -elements stored in memory locations by means of
pointers (chain of structures).
Data Structures & Algorithms
9
Non-Linear Data Structures
• Represents the hierarchical relationship between individual data
items.
• Examples are : Trees, Graphs
• Tree - hierarchical relation between its elements.
• Graph - collection of node and edges
– Node - data element
– Edge - path between two nodes.
Data Structures & Algorithms
10
Operations on the Data Structures
Data Structures & Algorithms
• Traversal-is a technique in which each element is processed individually
and separately.
• Search-is an activity in which a particular record or item is to be found.
• Insertion- is a process in which a new element is added into the structure.
• Deletion- is a process in which a given item is removed from the structure
• Sorting-is a process in which all elements are arranged in a specific order
so that each item can be retrieved easily.
• Merging-is a process in which two structures are combined into a single
structure.
11
Stack
• Ordered collection of items
• Item may be inserted or deleted only from the top of the stack.
• Works on Last In First Out (LIFO) concept.
• Helps backtracking or to return to the previous state.
Data Structures & Algorithms
12
Basic Stack Operations
Createstack Create and Initializes a stack to be empty before it is first used
Push adds an item to a stack
Pop extracts the most recently pushed item from the stack
( removing an item from the stack.)
Full returns non-zero if the stack is full
Empty returns non-zero if the stack is empty
Data Structures & Algorithms
13
Declaration of Stack
• For Contiguous implementation, set an array which hold the entries in the
stack and a counter.
• Create and Initializes a stack to be empty before it is first used
Data Structures & Algorithms
Push and Pop
• Stack is implemented using ‘Push’ and ‘Pop’ operations.
• Operations during implementation should be done with care;
For e.g.,
• popping an item from an empty stack
• pushing an item into a stack that is full should not be done.
[Create stack: create and initialize the stack to be empty]
void Createstack (stack sptr)
return [ sptr.top=0 ]
14
Algorithm for push
Procedure push [s,top ,x]
[this procedure inserts an element [x] to the top of the stack.]
[check for stack overflow, maxstack is constant for maximum size]
[allowed for stacks]
if top> maxstack then
write (“Stack overflow”)
exit
[increment top]
top=top+1
[insert element]
s[top]=x
[finished]
End push
Push Operation
Data Structures & Algorithms
• First step of the algorithm checks for an overflow condition.
• Such a condition exits then the insertion cannot be performed and an
appropriate error message result.
15
Pop Operation
Algorithm for pop
Procedure pop [s, top, x ]
[ this function removes the top element from a stack.]
[check for underflow on stack]
if top <=0 then
write (“Stack is Underflow”) exit
[Pop element from stack]
x=s [top]
[decrement pointer]
top = top-1
End pop
• First step itself checking underflow condition
• If exist an appropriate error message will display and the
procedure is terminated
Data Structures & Algorithms
16
Other operations
[Full: returns non-zero if the stack is full]
boolean_type full(stack_type sptr)
{return sptr .top>=MAXSTACK;}
[Empty: returns non-zero if the stack is empty]
boolean - type empty (stack_type sptr)
{return sptr .top<=0;}
Data Structures & Algorithms
17
Application of Stack
Stack based Language (Re_expressing the expression)
– Computers solve arithmetic expressions by restructuring them so that
the order of each calculation is embedded in the expression.
– Once converted, to the required notation (Either Prefix or Postfix), an
expression can be solved.
Types of Expression
• Any expression represent in 3 ways
• Infix, Prefix and Postfix.
• Expression 4 + 5 * 5 is represented as follows:
– Infix - Operators are embedded between operands- 4+5*5.
– Prefix - Operators precede the operands- + 4 * 5 5
– Postfix - Operators follow the operands- 4 5 5 * +
– Default representation of mathematical expression is Infix (or Polish)
notation.
Data Structures & Algorithms
18
Conversion of Expression-
• Infix to Postfix
– Applying the precedence rule first for operators
– Place the Operators follow the operands
– For e.g., an expression A+(B*C)
• A + ( B * C) -Parenthesis for emphasis
• A + ( BC *) -Convert the multiplication
• A (BC *) + -Convert the addition
• ABC * + -Postfix Form
• Infix to Prefix
– Applying the precedence rule first for operators
– Place operators precede the operands
– For e.g., an expression A+(B*C)
• A + ( B * C) -Parenthesis for emphasis
• A + (* BC) -Convert the multiplication
• + A ( * BC ) -Convert the addition
• * + ABC -Prefix Form
Data Structures & Algorithms
19
• Scratch pad
– Use to write down instructions that cannot be acted upon
immediately.
– Example of this is the rat-in-maze problem.
– Use to solve the problem of traversing a maze.
– Keep track of previously explored routes, or else an infinite loop
could occur.
• Text Editor
– Characters are pushed on a stack as the user enters text.
– Commands to delete one character or a command to delete a
series of characters would also push a character on a stack.
– Example, an identifier to delete one character would pop the
stack once.
– Example, an identifier to delete a sentence would pop all
characters until the stack is empty or a period is encountered.
Data Structures & Algorithms

More Related Content

PPTX
Queues
nidhisatija1
 
PPTX
Presentation on queue
Rojan Pariyar
 
PPTX
Stack and queue
CHANDAN KUMAR
 
PPTX
DATA STRUCTURE IN C LANGUAGE
shubhamrohiwal6
 
PDF
Data Structures 01
Budditha Hettige
 
PPTX
Stack data structure in Data Structure using C
Meghaj Mallick
 
PPTX
Ds stack & queue
Sunipa Bera
 
Queues
nidhisatija1
 
Presentation on queue
Rojan Pariyar
 
Stack and queue
CHANDAN KUMAR
 
DATA STRUCTURE IN C LANGUAGE
shubhamrohiwal6
 
Data Structures 01
Budditha Hettige
 
Stack data structure in Data Structure using C
Meghaj Mallick
 
Ds stack & queue
Sunipa Bera
 

What's hot (20)

PPT
Data abstraction the walls
Hoang Nguyen
 
PPTX
Computer Science-Data Structures :Abstract DataType (ADT)
St Mary's College,Thrissur,Kerala
 
PDF
Sorting
Budditha Hettige
 
PDF
02 Stack
Budditha Hettige
 
PPT
Abstract data types
Poojith Chowdhary
 
PPT
Data structures
Manaswi Sharma
 
PDF
Link List
Budditha Hettige
 
PPTX
Data structure and its types
Navtar Sidhu Brar
 
PDF
Stacks and queues
Abbott
 
PPTX
Stack and Queue by M.Gomathi Lecturer
gomathi chlm
 
PPTX
Introduction to data structure and algorithms
Research Scholar in Manonmaniam Sundaranar University
 
PPT
Data structure lecture 1
Kumar
 
PPTX
Introduction to data structure
Vivek Kumar Sinha
 
PPTX
Stack Data Structure
Rabin BK
 
PPT
Abstract data types (adt) intro to data structure part 2
Self-Employed
 
PDF
Introduction to data structure
Zaid Shabbir
 
PPT
Introduction to data structure by anil dutt
Anil Dutt
 
PDF
Data structures and algorithm analysis in java
Muhammad Aleem Siddiqui
 
DOC
Data structures project
sachinrajsachin
 
PDF
Data structures (introduction)
Arvind Devaraj
 
Data abstraction the walls
Hoang Nguyen
 
Computer Science-Data Structures :Abstract DataType (ADT)
St Mary's College,Thrissur,Kerala
 
Abstract data types
Poojith Chowdhary
 
Data structures
Manaswi Sharma
 
Link List
Budditha Hettige
 
Data structure and its types
Navtar Sidhu Brar
 
Stacks and queues
Abbott
 
Stack and Queue by M.Gomathi Lecturer
gomathi chlm
 
Introduction to data structure and algorithms
Research Scholar in Manonmaniam Sundaranar University
 
Data structure lecture 1
Kumar
 
Introduction to data structure
Vivek Kumar Sinha
 
Stack Data Structure
Rabin BK
 
Abstract data types (adt) intro to data structure part 2
Self-Employed
 
Introduction to data structure
Zaid Shabbir
 
Introduction to data structure by anil dutt
Anil Dutt
 
Data structures and algorithm analysis in java
Muhammad Aleem Siddiqui
 
Data structures project
sachinrajsachin
 
Data structures (introduction)
Arvind Devaraj
 
Ad

Similar to Data Structures (20)

PPTX
chapter three ppt.pptx
selemonGamo
 
DOCX
Data structure and algorithm.
Abdul salam
 
PPTX
data structures with algorithms vtu 2023 notes.pptx
hemanthkumar40680
 
PDF
DS UNIT 1.pdf
SeethaDinesh
 
PDF
DS UNIT 1.pdf
SeethaDinesh
 
PPT
Unit i(dsc++)
Durga Devi
 
PPTX
Data_structures_and_algorithm_Lec_1.pptx
aamirali1061a
 
PPTX
Data_structures_and_algorithm_Lec_1.pptx
aamirali1061a
 
PPTX
Data Structure and Algorithms
Sumathi MathanMohan
 
PPTX
STACK AND QUEUE CIRCULAR QUEUE PPTS.pptx
sunitha1792
 
PDF
Unit-I PPT hususi sisooshsgv. Eijeieieooekejj
sanketkurve7
 
PPTX
EE-232-LEC-01 Data_structures.pptx
iamultapromax
 
PPTX
Lecture 01 Intro to DSA
Nurjahan Nipa
 
PPTX
01-Introduction of DSA-1.pptx
DwijBaxi
 
PPTX
ds bridge.pptx
GOOGLEINTERNETCAFE1
 
PPT
DATA STRUCTURE AND ALGORITHMS
removed_8057d320f6c8601c14a895598b86eacb
 
PPTX
1-Introduction to Data Structures beginner.pptx
231b209
 
PPTX
Chapter 1 _edited.pptx.software engineering
kuruabeje7
 
PPTX
Chapter 1 _edited.pptx.software engineering
kuruabeje7
 
PPTX
introduction of Data strutter and algirithm.pptx
ssuser7b3003
 
chapter three ppt.pptx
selemonGamo
 
Data structure and algorithm.
Abdul salam
 
data structures with algorithms vtu 2023 notes.pptx
hemanthkumar40680
 
DS UNIT 1.pdf
SeethaDinesh
 
DS UNIT 1.pdf
SeethaDinesh
 
Unit i(dsc++)
Durga Devi
 
Data_structures_and_algorithm_Lec_1.pptx
aamirali1061a
 
Data_structures_and_algorithm_Lec_1.pptx
aamirali1061a
 
Data Structure and Algorithms
Sumathi MathanMohan
 
STACK AND QUEUE CIRCULAR QUEUE PPTS.pptx
sunitha1792
 
Unit-I PPT hususi sisooshsgv. Eijeieieooekejj
sanketkurve7
 
EE-232-LEC-01 Data_structures.pptx
iamultapromax
 
Lecture 01 Intro to DSA
Nurjahan Nipa
 
01-Introduction of DSA-1.pptx
DwijBaxi
 
ds bridge.pptx
GOOGLEINTERNETCAFE1
 
DATA STRUCTURE AND ALGORITHMS
removed_8057d320f6c8601c14a895598b86eacb
 
1-Introduction to Data Structures beginner.pptx
231b209
 
Chapter 1 _edited.pptx.software engineering
kuruabeje7
 
Chapter 1 _edited.pptx.software engineering
kuruabeje7
 
introduction of Data strutter and algirithm.pptx
ssuser7b3003
 
Ad

More from Dr.Umadevi V (12)

PPT
Data Structures 8
Dr.Umadevi V
 
PPT
Data Structures 7
Dr.Umadevi V
 
PPT
Data Structures 6
Dr.Umadevi V
 
PPT
Data Structures 5
Dr.Umadevi V
 
PPT
Data Structures 4
Dr.Umadevi V
 
PPT
Data Structures 3
Dr.Umadevi V
 
PPT
Data Structures 2
Dr.Umadevi V
 
PPT
computer architecture 4
Dr.Umadevi V
 
PPT
Computer architecture 3
Dr.Umadevi V
 
PPT
computer architecture
Dr.Umadevi V
 
PPT
computer architecture
Dr.Umadevi V
 
PPTX
Multiple access techniques for wireless communication
Dr.Umadevi V
 
Data Structures 8
Dr.Umadevi V
 
Data Structures 7
Dr.Umadevi V
 
Data Structures 6
Dr.Umadevi V
 
Data Structures 5
Dr.Umadevi V
 
Data Structures 4
Dr.Umadevi V
 
Data Structures 3
Dr.Umadevi V
 
Data Structures 2
Dr.Umadevi V
 
computer architecture 4
Dr.Umadevi V
 
Computer architecture 3
Dr.Umadevi V
 
computer architecture
Dr.Umadevi V
 
computer architecture
Dr.Umadevi V
 
Multiple access techniques for wireless communication
Dr.Umadevi V
 

Recently uploaded (20)

PPTX
How to Track Skills & Contracts Using Odoo 18 Employee
Celine George
 
DOCX
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
PPTX
Sonnet 130_ My Mistress’ Eyes Are Nothing Like the Sun By William Shakespear...
DhatriParmar
 
PPTX
Cleaning Validation Ppt Pharmaceutical validation
Ms. Ashatai Patil
 
PDF
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
PDF
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
PPTX
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
PPTX
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
PDF
Biological Classification Class 11th NCERT CBSE NEET.pdf
NehaRohtagi1
 
PPTX
BASICS IN COMPUTER APPLICATIONS - UNIT I
suganthim28
 
PDF
Module 2: Public Health History [Tutorial Slides]
JonathanHallett4
 
PPTX
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
PPTX
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
PPTX
Care of patients with elImination deviation.pptx
AneetaSharma15
 
PPTX
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
PDF
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 
PPTX
Artificial-Intelligence-in-Drug-Discovery by R D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
PPTX
Basics and rules of probability with real-life uses
ravatkaran694
 
PPTX
Command Palatte in Odoo 18.1 Spreadsheet - Odoo Slides
Celine George
 
How to Track Skills & Contracts Using Odoo 18 Employee
Celine George
 
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
Sonnet 130_ My Mistress’ Eyes Are Nothing Like the Sun By William Shakespear...
DhatriParmar
 
Cleaning Validation Ppt Pharmaceutical validation
Ms. Ashatai Patil
 
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
Biological Classification Class 11th NCERT CBSE NEET.pdf
NehaRohtagi1
 
BASICS IN COMPUTER APPLICATIONS - UNIT I
suganthim28
 
Module 2: Public Health History [Tutorial Slides]
JonathanHallett4
 
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
Care of patients with elImination deviation.pptx
AneetaSharma15
 
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 
Artificial-Intelligence-in-Drug-Discovery by R D Jawarkar.pptx
Rahul Jawarkar
 
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
Basics and rules of probability with real-life uses
ravatkaran694
 
Command Palatte in Odoo 18.1 Spreadsheet - Odoo Slides
Celine George
 

Data Structures

  • 1. 1 Introduction to Data Structures Session I Dr. V.Umadevi M.Sc(CS &IT). M.Tech (IT)., M.Phil., PhD., D.Litt., Director, Department of Computer Science, Jairams Arts and Science College, Karur. Data Structures & Algorithms
  • 2. 2 • Introduction to Data Structures • Primitive Data Structures • Types of Data structures – Stacks – Queues – Lists • Stack – Basic Operation of Stack – Operations on the Data Structures – Applications of Infix, Postfix and Prefix Data Structures & Algorithms Introduction to Data Structures
  • 3. 3 Data Structures & Algorithms • A Computer is a machine that manipulates information. • Computer science studies includes: – How information is organized in a computer – How it can be manipulated – How it can be utilized Introduction to Data Structures • Data is represented by the values held temporarily in the program’s data area or recorded permanently on a file • Different data values may be related to each other which need to be organized to form a proper data structure. • Program follow certain rules to access manipulate and process the structured data. Information – Processed data given as output Data – Raw facts and figures given as input
  • 4. 4 Data Structures & Algorithms • Organization of data in a computer's memory or in a file. • Proper choice of a data structure can lead to more efficient programs. • Example: Array, Stack, Queue, Linked list, Tree and Graph. • Represented as follows: Data structure=Data organization + allowed operations. Data Structure
  • 5. 5 Primitive Data structure • Data structures typically are directly operated upon by the machine level instructions. • Primitive data constitute the numbers and characters, which are built into a programming language. • Examples are: Integer, Boolean and Characters. • Other data structures can be constructed from one or more primitives. • Simple data structures built from primitives are Strings, Arrays, and Records Data Structures & Algorithms
  • 6. 6 Types of Data Structures – Linear data structure. – Non-Linear data structure. • Various names used for naming the elements of a data structure ( Commonly used names are data element, data item, item aggregate, node list and data object) • Various data structures are used depending upon the needs and convenience Data Structures & Algorithms
  • 7. 7 Data Structures & Algorithms •Elements or items form a sequence one after the other. •Linear list can be realized in memory using either an array or a linked list structure. •Data is also stored in memory locations by means of pointers. Examples are: Arrays, Stacks, Queues and Linked list. Linear Data Structure
  • 8. 8 Linear Data Structures Types • Arrays - elements stored in memory locations in a sequential order • Stack is an ordered collection of data items – inserted or deleted from one end i.e., Last In First Out (LIFO) principle. • Queue is an ordered list – inserted at one end and are retrieved from the other end i.e., First in First out (FIFO) principle. • Linked Lists -elements stored in memory locations by means of pointers (chain of structures). Data Structures & Algorithms
  • 9. 9 Non-Linear Data Structures • Represents the hierarchical relationship between individual data items. • Examples are : Trees, Graphs • Tree - hierarchical relation between its elements. • Graph - collection of node and edges – Node - data element – Edge - path between two nodes. Data Structures & Algorithms
  • 10. 10 Operations on the Data Structures Data Structures & Algorithms • Traversal-is a technique in which each element is processed individually and separately. • Search-is an activity in which a particular record or item is to be found. • Insertion- is a process in which a new element is added into the structure. • Deletion- is a process in which a given item is removed from the structure • Sorting-is a process in which all elements are arranged in a specific order so that each item can be retrieved easily. • Merging-is a process in which two structures are combined into a single structure.
  • 11. 11 Stack • Ordered collection of items • Item may be inserted or deleted only from the top of the stack. • Works on Last In First Out (LIFO) concept. • Helps backtracking or to return to the previous state. Data Structures & Algorithms
  • 12. 12 Basic Stack Operations Createstack Create and Initializes a stack to be empty before it is first used Push adds an item to a stack Pop extracts the most recently pushed item from the stack ( removing an item from the stack.) Full returns non-zero if the stack is full Empty returns non-zero if the stack is empty Data Structures & Algorithms
  • 13. 13 Declaration of Stack • For Contiguous implementation, set an array which hold the entries in the stack and a counter. • Create and Initializes a stack to be empty before it is first used Data Structures & Algorithms Push and Pop • Stack is implemented using ‘Push’ and ‘Pop’ operations. • Operations during implementation should be done with care; For e.g., • popping an item from an empty stack • pushing an item into a stack that is full should not be done. [Create stack: create and initialize the stack to be empty] void Createstack (stack sptr) return [ sptr.top=0 ]
  • 14. 14 Algorithm for push Procedure push [s,top ,x] [this procedure inserts an element [x] to the top of the stack.] [check for stack overflow, maxstack is constant for maximum size] [allowed for stacks] if top> maxstack then write (“Stack overflow”) exit [increment top] top=top+1 [insert element] s[top]=x [finished] End push Push Operation Data Structures & Algorithms • First step of the algorithm checks for an overflow condition. • Such a condition exits then the insertion cannot be performed and an appropriate error message result.
  • 15. 15 Pop Operation Algorithm for pop Procedure pop [s, top, x ] [ this function removes the top element from a stack.] [check for underflow on stack] if top <=0 then write (“Stack is Underflow”) exit [Pop element from stack] x=s [top] [decrement pointer] top = top-1 End pop • First step itself checking underflow condition • If exist an appropriate error message will display and the procedure is terminated Data Structures & Algorithms
  • 16. 16 Other operations [Full: returns non-zero if the stack is full] boolean_type full(stack_type sptr) {return sptr .top>=MAXSTACK;} [Empty: returns non-zero if the stack is empty] boolean - type empty (stack_type sptr) {return sptr .top<=0;} Data Structures & Algorithms
  • 17. 17 Application of Stack Stack based Language (Re_expressing the expression) – Computers solve arithmetic expressions by restructuring them so that the order of each calculation is embedded in the expression. – Once converted, to the required notation (Either Prefix or Postfix), an expression can be solved. Types of Expression • Any expression represent in 3 ways • Infix, Prefix and Postfix. • Expression 4 + 5 * 5 is represented as follows: – Infix - Operators are embedded between operands- 4+5*5. – Prefix - Operators precede the operands- + 4 * 5 5 – Postfix - Operators follow the operands- 4 5 5 * + – Default representation of mathematical expression is Infix (or Polish) notation. Data Structures & Algorithms
  • 18. 18 Conversion of Expression- • Infix to Postfix – Applying the precedence rule first for operators – Place the Operators follow the operands – For e.g., an expression A+(B*C) • A + ( B * C) -Parenthesis for emphasis • A + ( BC *) -Convert the multiplication • A (BC *) + -Convert the addition • ABC * + -Postfix Form • Infix to Prefix – Applying the precedence rule first for operators – Place operators precede the operands – For e.g., an expression A+(B*C) • A + ( B * C) -Parenthesis for emphasis • A + (* BC) -Convert the multiplication • + A ( * BC ) -Convert the addition • * + ABC -Prefix Form Data Structures & Algorithms
  • 19. 19 • Scratch pad – Use to write down instructions that cannot be acted upon immediately. – Example of this is the rat-in-maze problem. – Use to solve the problem of traversing a maze. – Keep track of previously explored routes, or else an infinite loop could occur. • Text Editor – Characters are pushed on a stack as the user enters text. – Commands to delete one character or a command to delete a series of characters would also push a character on a stack. – Example, an identifier to delete one character would pop the stack once. – Example, an identifier to delete a sentence would pop all characters until the stack is empty or a period is encountered. Data Structures & Algorithms