SlideShare a Scribd company logo
1 of 19
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

What's hot

Data abstraction the walls
Data abstraction the wallsData abstraction the walls
Data abstraction the wallsHoang Nguyen
 
Data structure and its types
Data structure and its typesData structure and its types
Data structure and its typesNavtar Sidhu Brar
 
Stacks and queues
Stacks and queuesStacks and queues
Stacks and queuesAbbott
 
Stack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi LecturerStack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi Lecturergomathi chlm
 
Data structure lecture 1
Data structure lecture 1Data structure lecture 1
Data structure lecture 1Kumar
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structureVivek Kumar Sinha
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data StructureRabin BK
 
Abstract data types (adt) intro to data structure part 2
Abstract data types (adt)   intro to data structure part 2Abstract data types (adt)   intro to data structure part 2
Abstract data types (adt) intro to data structure part 2Self-Employed
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structureZaid Shabbir
 
Introduction to data structure by anil dutt
Introduction to data structure by anil duttIntroduction to data structure by anil dutt
Introduction to data structure by anil duttAnil Dutt
 
Data structures and algorithm analysis in java
Data structures and algorithm analysis in javaData structures and algorithm analysis in java
Data structures and algorithm analysis in javaMuhammad Aleem Siddiqui
 
Data structures (introduction)
 Data structures (introduction) Data structures (introduction)
Data structures (introduction)Arvind Devaraj
 

What's hot (20)

Data abstraction the walls
Data abstraction the wallsData abstraction the walls
Data abstraction the walls
 
Computer Science-Data Structures :Abstract DataType (ADT)
Computer Science-Data Structures :Abstract DataType (ADT)Computer Science-Data Structures :Abstract DataType (ADT)
Computer Science-Data Structures :Abstract DataType (ADT)
 
Sorting
SortingSorting
Sorting
 
02 Stack
02 Stack02 Stack
02 Stack
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
Data structures
Data structuresData structures
Data structures
 
Link List
Link ListLink List
Link List
 
Data structure and its types
Data structure and its typesData structure and its types
Data structure and its types
 
Stacks and queues
Stacks and queuesStacks and queues
Stacks and queues
 
Stack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi LecturerStack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi Lecturer
 
Introduction to data structure and algorithms
Introduction to data structure and algorithmsIntroduction to data structure and algorithms
Introduction to data structure and algorithms
 
Data structure lecture 1
Data structure lecture 1Data structure lecture 1
Data structure lecture 1
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structure
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
 
Abstract data types (adt) intro to data structure part 2
Abstract data types (adt)   intro to data structure part 2Abstract data types (adt)   intro to data structure part 2
Abstract data types (adt) intro to data structure part 2
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structure
 
Introduction to data structure by anil dutt
Introduction to data structure by anil duttIntroduction to data structure by anil dutt
Introduction to data structure by anil dutt
 
Data structures and algorithm analysis in java
Data structures and algorithm analysis in javaData structures and algorithm analysis in java
Data structures and algorithm analysis in java
 
Data structures project
Data structures projectData structures project
Data structures project
 
Data structures (introduction)
 Data structures (introduction) Data structures (introduction)
Data structures (introduction)
 

Similar to Data Structures

Similar to Data Structures (20)

stack.pptx
stack.pptxstack.pptx
stack.pptx
 
2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS
 
STACK.pptx
STACK.pptxSTACK.pptx
STACK.pptx
 
Data structure , stack , queue
Data structure , stack , queueData structure , stack , queue
Data structure , stack , queue
 
Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1
 
TSAT Presentation1.pptx
TSAT Presentation1.pptxTSAT Presentation1.pptx
TSAT Presentation1.pptx
 
Data structures
Data structuresData structures
Data structures
 
stacks and queues for public
stacks and queues for publicstacks and queues for public
stacks and queues for public
 
Stack in Sata Structure
Stack in Sata StructureStack in Sata Structure
Stack in Sata Structure
 
Data Structures 2
Data Structures 2Data Structures 2
Data Structures 2
 
Stack and Queue.pptx
Stack and Queue.pptxStack and Queue.pptx
Stack and Queue.pptx
 
Data strucer
Data strucerData strucer
Data strucer
 
Queue ADT for data structure for computer
Queue ADT for data structure for computerQueue ADT for data structure for computer
Queue ADT for data structure for computer
 
Stacks
StacksStacks
Stacks
 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
 
01-Introduction of DSA-1.pptx
01-Introduction of DSA-1.pptx01-Introduction of DSA-1.pptx
01-Introduction of DSA-1.pptx
 
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queuesFallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
 
Unit 1.ppt
Unit 1.pptUnit 1.ppt
Unit 1.ppt
 
Unit i(dsc++)
Unit i(dsc++)Unit i(dsc++)
Unit i(dsc++)
 
linked list in c++
linked list in c++linked list in c++
linked list in c++
 

More from Dr.Umadevi V

computer architecture 4
computer architecture 4 computer architecture 4
computer architecture 4 Dr.Umadevi V
 
Computer architecture 3
Computer architecture 3Computer architecture 3
Computer architecture 3Dr.Umadevi V
 
computer architecture
computer architecture computer architecture
computer architecture Dr.Umadevi V
 
computer architecture
computer architecture computer architecture
computer architecture Dr.Umadevi V
 
Multiple access techniques for wireless communication
Multiple access techniques for wireless communicationMultiple access techniques for wireless communication
Multiple access techniques for wireless communicationDr.Umadevi V
 

More from Dr.Umadevi V (11)

Data Structures 8
Data Structures 8Data Structures 8
Data Structures 8
 
Data Structures 7
Data Structures 7Data Structures 7
Data Structures 7
 
Data Structures 6
Data Structures 6Data Structures 6
Data Structures 6
 
Data Structures 5
Data Structures 5Data Structures 5
Data Structures 5
 
Data Structures 4
Data Structures 4Data Structures 4
Data Structures 4
 
Data Structures 3
Data Structures 3Data Structures 3
Data Structures 3
 
computer architecture 4
computer architecture 4 computer architecture 4
computer architecture 4
 
Computer architecture 3
Computer architecture 3Computer architecture 3
Computer architecture 3
 
computer architecture
computer architecture computer architecture
computer architecture
 
computer architecture
computer architecture computer architecture
computer architecture
 
Multiple access techniques for wireless communication
Multiple access techniques for wireless communicationMultiple access techniques for wireless communication
Multiple access techniques for wireless communication
 

Recently uploaded

Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 

Recently uploaded (20)

Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 

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