KEMBAR78
The Stack in Data structure and algorithm | PPT
Module I
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, he would
required to store all of them in computers main memory.
Module I
Introduction to Data Structure
What is Data Structure?
“It is set of procedures to define ,store ,access and manipulate data”
OR
“The organized collection of data is called data structure”
OR
“The logical or mathematical model of a particular organization of
data is called data structure “
Module I
Introduction to Data Structure
Basic Terminologies
The following are some fundamental terminologies used whenever the data
structures are involved:
1.Data: We can define data as an elementary value or a collection of
values. For example, the Employee's name and ID are the data
related to the Employee.
2.Data Items: A Single unit of value is known as Data Item.
3.Group Items: Data Items that have subordinate data items are
known as Group Items. For example, an employee's name can have
a first, middle, and last name.
4.Elementary Items: Data Items that are unable to divide into sub-
items are known as Elementary Items. For example, the ID of an
Employee.
5.Entity and Attribute: A class of certain objects is represented by
an Entity. It consists of different Attributes. Each Attribute
symbolizes the specific property of that Entity. For example,
Attributes ID Name Gender Job Title
Values 1234 Stacey M. Hill Female Software
Developer
Module I
Introduction to Data Structure
Basic Terminologies
The term "information" is sometimes utilized for data with given
attributes of meaningful or processed data.
1.Field: A single elementary unit of information symbolizing the
Attribute of an Entity is known as Field.
2.Record: A collection of different data items are known as a Record.
For example, if we talk about the employee entity, then its name, id,
address, and job title can be grouped to form the record for the
employee.
3.File: A collection of different Records of one entity type is known as
a File. For example, if there are 100 employees, there will be 25
records in the related file containing data about each employee.
Module I
Introduction to Data Structure
Concepts of Data Structure
Understanding the Need for Data Structures :
As applications are becoming more complex and the amount of data is
increasing every day, which may lead to problems with data searching,
processing speed, multiple requests handling, and many more. Data
Structures support different methods to organize, manage, and store
data efficiently. With the help of Data Structures, we can easily traverse
the data items. Data Structures provide Efficiency, Reusability, and
Abstraction.
Data Structures Important :
1.Data Structures and Algorithms are two of the key aspects of
Computer Science.
2.Data Structures allow us to organize and store data, whereas
Algorithms allow us to process that data meaningfully.
3.Learning Data Structures and Algorithms will help us become
better Programmers.
4.We will be able to write code that is more effective and reliable.
Module I
Introduction to Data Structure
Concepts of Data Structure
Understanding the Objectives of Data Structures :
1. Correctness: Data Structures are designed to operate correctly
for all kinds of inputs based on the domain of interest.
2. Efficiency: In a real-time state, the efficiency of a data structure
is a key factor in determining the success and failure of the
process.
Understanding some Key Features of Data Structures :
1.Robustness: Generally, all computer programmers aim to produce
software that yields correct output for every possible input, along with
efficient execution on all hardware platforms.
2.Adaptability: Building software applications like Web Browsers, Word
Processors, and Internet Search Engine include huge software systems
that require correct and efficient working or execution for many years.
3. Reusability: It is known that the programmer needs many resources to
build any software, making it a costly enterprise. However, if the software
is developed in a reusable and adaptable way, then it can be applied in
most future applications.
Module I
Introduction to Data Structure
Concepts of Data Structure
Data structures uses:
Storing data : For effective data persistence, data structures are
used
Managing resources and services: Core operating system
resources and services are available through.
Data exchange : Data structures describe information exchanged
across programmers, including TCP/IP packets, organization.
Ordering and sorting :provide efficient sorting methods such as
tags for items and Programmers can handle objects ordered
according to a certain priority with data structures such as
priorities queues.
Searching : Even complex data structures like B-trees are needed
to index objects contained in a database.
Scalability : Big data applications employ the data structures for
the distributed storage locations allocation and management, to
Module I
Introduction to Data Structure
Concepts of Data Structure
CLASSIFICATION OF DATA STRUCTURES :
Module I
Introduction to Data Structure
Concepts of Data Structure
Primitive data type :
Primitive data structures are the fundamental data types which
are supported by a programming language. some basic data types
are integer, character, Boolean pointer, float, double, and real.
Non-primitive data structures :
Non-primitive data structures are that data structures that are
created using primitive data structures as—: as array, linked list,
tree, etc.
Module I
Introduction to Data Structure
Concepts of Data Structure
Linear Data Structures:-
1.Arrays:- A set of things is stored in other memory sites. The same kind
of items are kept together to compute or readily get the location of every
element by index. Fixed or flexible arrays can be used in length.
2.Stacks:- In the linear sequence, a stack stores a group of elements. Last
in, first out (LIFO) or first in, first out (FIFO).
3.Queues:- A queue keeps the collection of objects like a stack, but only
first in, first out.
4.Linked Lists:- A linked list stores a linear order of objects. The link list
includes a data item as well as a reference or link to the next item in the
list in each element or node.
5.Hash Tables:- A hash table, also known as a hash map, contains an
associative array of objects that record the keys. A hash table employs a
hash algorithm to transform an index to a bucket array that contains the
data item you want.
Module I
Introduction to Data Structure
Concepts of Data Structure
Non-linear data structures:-
1.Trees:- A tree keeps an abstract, hierarchical collection of
objects. Each node has a key-value associated with parent nodes
associated with child nodes — or subnodes. There is a root node,
the ancestor of every tree node.
2.Graphs:- A diagram stores a non-linear collection of elements.
The graphs consist of a finite collection of nodes, also known as
vertices and lines, also known as edges, which link them. These
are useful to portray systems like computer networks in the actual
world.
3.Tries:- A trial is also known as a keyword tree and is a data
structure that holds strings in a visual graph like data objects.
Module I
Introduction to Data Structure
Array and Representation
Array and Data Structure :
Arrays are defined as the collection of similar types of data items
stored at contiguous memory locations.
It is one of the simplest data structures where each data element
can be randomly accessed by using its index number
In C programming, they are the derived data types that can store
the primitive type of data such as int, char, double, float, etc.
Representation of an array:
Module I
Introduction to Data Structure
Array and Representation
Memory allocation of an array :
1. 0 (zero-based indexing): The first element of the array will be
arr[0].
2. 1 (one-based indexing): The first element of the array will be
arr[1].
3. n (n - based indexing): The first element of the array can reside
at any random index number
Module I
Introduction to Data Structure
Array and Representation
Arrays can be classified into different types:
One-Dimensional Array: An Array with only one row of data elements is
known as a One-Dimensional Array. It is stored in ascending storage
location.
Two-Dimensional Array/Multidimensional Array: We can define
Multidimensional Array as an Array of Arrays. Multidimensional Arrays are
not bounded to two indices or two dimensions as they can include as
Module I
Introduction to Data Structure
Array and Representation
Array Basic operations :
•Traversal - This operation is used to print the elements of the
array.
•Insertion - It is used to add an element at a particular index.
•Deletion - It is used to delete an element from a particular index.
•Search - It is used to search an element using the given index or
by the value.
•Update - It updates an element at a particular index.
Module I
Introduction to Data Structure
Array and Representation
Advantages of Array:
•Array provides the single name for the group of variables of the
same type. Therefore, it is easy to remember the name of all the
elements of an array.
•Traversing an array is a very simple process; we just need to
increment the base address of the array in order to visit each
element one by one.
•Any element in the array can be directly accessed by using the
index.
Disadvantages of Array:
•Array is homogenous. It means that the elements with similar
data type can be stored in it.
•In array, there is static memory allocation that is size of an array
cannot be altered.
•There will be wastage of memory if we store less number of
Module I
Introduction to Data Structure
Sparse matrix and its representation
What is a matrix?
A matrix can be defined as a two-dimensional array having 'm'
rows and 'n' columns.
A matrix with m rows and n columns is called m × n matrix. It is a
set of numbers that are arranged in the horizontal or vertical lines
of entries.
Module I
Introduction to Data Structure
Sparse matrix and its representation
What is a sparse matrix?
Sparse matrices are those matrices that have the majority of their
elements equal to zero. In other words, the sparse matrix can be
defined as the matrix that has a greater number of zero elements
than the non-zero elements.
Why to use Sparse Matrix instead of simple matrix ?
Storage: There are lesser non-zero elements than zeros and thus
lesser memory can be used to store only those elements.
Computing time: Computing time can be saved by logically
designing a data structure traversing only non-zero elements.
Module I
Introduction to Data Structure
Sparse matrix and its representation
Sparse Matrix Representations can be done in many ways
following are two common representations:
1. Array representation
2. Linked list represent
Method 1: Using Arrays:
2D array is used to represent a sparse matrix in which there are
three rows named as
Row: Index of row, where non-zero element is located
Column: Index of column, where non-zero element is located
Value: Value of the non zero element located at index –
(row,column)
Module I
Introduction to Data Structure
Sparse matrix and its representation
Method 2: Using Linked Lists
In linked list, each node has four fields. These four fields are
defined as:
Row: Index of row, where non-zero element is located
Column: Index of column, where non-zero element is located
Value: Value of the non zero element located at index – (row,
column)
Next node: Address of the next node

The Stack in Data structure and algorithm

  • 1.
    Module I Introduction toData Structure • Computer is an electronic machine which is used for data processing and manipulation. • When programmer collects such type of data for processing, he would required to store all of them in computers main memory.
  • 2.
    Module I Introduction toData Structure What is Data Structure? “It is set of procedures to define ,store ,access and manipulate data” OR “The organized collection of data is called data structure” OR “The logical or mathematical model of a particular organization of data is called data structure “
  • 3.
    Module I Introduction toData Structure Basic Terminologies The following are some fundamental terminologies used whenever the data structures are involved: 1.Data: We can define data as an elementary value or a collection of values. For example, the Employee's name and ID are the data related to the Employee. 2.Data Items: A Single unit of value is known as Data Item. 3.Group Items: Data Items that have subordinate data items are known as Group Items. For example, an employee's name can have a first, middle, and last name. 4.Elementary Items: Data Items that are unable to divide into sub- items are known as Elementary Items. For example, the ID of an Employee. 5.Entity and Attribute: A class of certain objects is represented by an Entity. It consists of different Attributes. Each Attribute symbolizes the specific property of that Entity. For example, Attributes ID Name Gender Job Title Values 1234 Stacey M. Hill Female Software Developer
  • 4.
    Module I Introduction toData Structure Basic Terminologies The term "information" is sometimes utilized for data with given attributes of meaningful or processed data. 1.Field: A single elementary unit of information symbolizing the Attribute of an Entity is known as Field. 2.Record: A collection of different data items are known as a Record. For example, if we talk about the employee entity, then its name, id, address, and job title can be grouped to form the record for the employee. 3.File: A collection of different Records of one entity type is known as a File. For example, if there are 100 employees, there will be 25 records in the related file containing data about each employee.
  • 5.
    Module I Introduction toData Structure Concepts of Data Structure Understanding the Need for Data Structures : As applications are becoming more complex and the amount of data is increasing every day, which may lead to problems with data searching, processing speed, multiple requests handling, and many more. Data Structures support different methods to organize, manage, and store data efficiently. With the help of Data Structures, we can easily traverse the data items. Data Structures provide Efficiency, Reusability, and Abstraction. Data Structures Important : 1.Data Structures and Algorithms are two of the key aspects of Computer Science. 2.Data Structures allow us to organize and store data, whereas Algorithms allow us to process that data meaningfully. 3.Learning Data Structures and Algorithms will help us become better Programmers. 4.We will be able to write code that is more effective and reliable.
  • 6.
    Module I Introduction toData Structure Concepts of Data Structure Understanding the Objectives of Data Structures : 1. Correctness: Data Structures are designed to operate correctly for all kinds of inputs based on the domain of interest. 2. Efficiency: In a real-time state, the efficiency of a data structure is a key factor in determining the success and failure of the process. Understanding some Key Features of Data Structures : 1.Robustness: Generally, all computer programmers aim to produce software that yields correct output for every possible input, along with efficient execution on all hardware platforms. 2.Adaptability: Building software applications like Web Browsers, Word Processors, and Internet Search Engine include huge software systems that require correct and efficient working or execution for many years. 3. Reusability: It is known that the programmer needs many resources to build any software, making it a costly enterprise. However, if the software is developed in a reusable and adaptable way, then it can be applied in most future applications.
  • 7.
    Module I Introduction toData Structure Concepts of Data Structure Data structures uses: Storing data : For effective data persistence, data structures are used Managing resources and services: Core operating system resources and services are available through. Data exchange : Data structures describe information exchanged across programmers, including TCP/IP packets, organization. Ordering and sorting :provide efficient sorting methods such as tags for items and Programmers can handle objects ordered according to a certain priority with data structures such as priorities queues. Searching : Even complex data structures like B-trees are needed to index objects contained in a database. Scalability : Big data applications employ the data structures for the distributed storage locations allocation and management, to
  • 8.
    Module I Introduction toData Structure Concepts of Data Structure CLASSIFICATION OF DATA STRUCTURES :
  • 9.
    Module I Introduction toData Structure Concepts of Data Structure Primitive data type : Primitive data structures are the fundamental data types which are supported by a programming language. some basic data types are integer, character, Boolean pointer, float, double, and real. Non-primitive data structures : Non-primitive data structures are that data structures that are created using primitive data structures as—: as array, linked list, tree, etc.
  • 10.
    Module I Introduction toData Structure Concepts of Data Structure Linear Data Structures:- 1.Arrays:- A set of things is stored in other memory sites. The same kind of items are kept together to compute or readily get the location of every element by index. Fixed or flexible arrays can be used in length. 2.Stacks:- In the linear sequence, a stack stores a group of elements. Last in, first out (LIFO) or first in, first out (FIFO). 3.Queues:- A queue keeps the collection of objects like a stack, but only first in, first out. 4.Linked Lists:- A linked list stores a linear order of objects. The link list includes a data item as well as a reference or link to the next item in the list in each element or node. 5.Hash Tables:- A hash table, also known as a hash map, contains an associative array of objects that record the keys. A hash table employs a hash algorithm to transform an index to a bucket array that contains the data item you want.
  • 11.
    Module I Introduction toData Structure Concepts of Data Structure Non-linear data structures:- 1.Trees:- A tree keeps an abstract, hierarchical collection of objects. Each node has a key-value associated with parent nodes associated with child nodes — or subnodes. There is a root node, the ancestor of every tree node. 2.Graphs:- A diagram stores a non-linear collection of elements. The graphs consist of a finite collection of nodes, also known as vertices and lines, also known as edges, which link them. These are useful to portray systems like computer networks in the actual world. 3.Tries:- A trial is also known as a keyword tree and is a data structure that holds strings in a visual graph like data objects.
  • 12.
    Module I Introduction toData Structure Array and Representation Array and Data Structure : Arrays are defined as the collection of similar types of data items stored at contiguous memory locations. It is one of the simplest data structures where each data element can be randomly accessed by using its index number In C programming, they are the derived data types that can store the primitive type of data such as int, char, double, float, etc. Representation of an array:
  • 13.
    Module I Introduction toData Structure Array and Representation Memory allocation of an array : 1. 0 (zero-based indexing): The first element of the array will be arr[0]. 2. 1 (one-based indexing): The first element of the array will be arr[1]. 3. n (n - based indexing): The first element of the array can reside at any random index number
  • 14.
    Module I Introduction toData Structure Array and Representation Arrays can be classified into different types: One-Dimensional Array: An Array with only one row of data elements is known as a One-Dimensional Array. It is stored in ascending storage location. Two-Dimensional Array/Multidimensional Array: We can define Multidimensional Array as an Array of Arrays. Multidimensional Arrays are not bounded to two indices or two dimensions as they can include as
  • 15.
    Module I Introduction toData Structure Array and Representation Array Basic operations : •Traversal - This operation is used to print the elements of the array. •Insertion - It is used to add an element at a particular index. •Deletion - It is used to delete an element from a particular index. •Search - It is used to search an element using the given index or by the value. •Update - It updates an element at a particular index.
  • 16.
    Module I Introduction toData Structure Array and Representation Advantages of Array: •Array provides the single name for the group of variables of the same type. Therefore, it is easy to remember the name of all the elements of an array. •Traversing an array is a very simple process; we just need to increment the base address of the array in order to visit each element one by one. •Any element in the array can be directly accessed by using the index. Disadvantages of Array: •Array is homogenous. It means that the elements with similar data type can be stored in it. •In array, there is static memory allocation that is size of an array cannot be altered. •There will be wastage of memory if we store less number of
  • 17.
    Module I Introduction toData Structure Sparse matrix and its representation What is a matrix? A matrix can be defined as a two-dimensional array having 'm' rows and 'n' columns. A matrix with m rows and n columns is called m × n matrix. It is a set of numbers that are arranged in the horizontal or vertical lines of entries.
  • 18.
    Module I Introduction toData Structure Sparse matrix and its representation What is a sparse matrix? Sparse matrices are those matrices that have the majority of their elements equal to zero. In other words, the sparse matrix can be defined as the matrix that has a greater number of zero elements than the non-zero elements. Why to use Sparse Matrix instead of simple matrix ? Storage: There are lesser non-zero elements than zeros and thus lesser memory can be used to store only those elements. Computing time: Computing time can be saved by logically designing a data structure traversing only non-zero elements.
  • 19.
    Module I Introduction toData Structure Sparse matrix and its representation Sparse Matrix Representations can be done in many ways following are two common representations: 1. Array representation 2. Linked list represent Method 1: Using Arrays: 2D array is used to represent a sparse matrix in which there are three rows named as Row: Index of row, where non-zero element is located Column: Index of column, where non-zero element is located Value: Value of the non zero element located at index – (row,column)
  • 20.
    Module I Introduction toData Structure Sparse matrix and its representation Method 2: Using Linked Lists In linked list, each node has four fields. These four fields are defined as: Row: Index of row, where non-zero element is located Column: Index of column, where non-zero element is located Value: Value of the non zero element located at index – (row, column) Next node: Address of the next node