SlideShare a Scribd company logo
Introduction to
Data Structures
and Algorithms
Basic Terminology
• When selecting a data structure to solve a problem, the
following steps must be performed.
1. Analysis of the problem to determine the basic operations
that must be supported. For example, basic operation may
include inserting/deleting/searching a data item from the data
structure.
2. Quantify the resource constraints for each operation.
3. Select the data structure that best meets these requirements.
Elementary Data Structure
Organization
 Data represents a single value or a set of values assigned to
entities. Data item refers a single or group of values with in
the data
 An entity is a thing that has some properties which can take
• values.
 Processed or meaning full data is called information. This is
• used for taking some action.
Classification Of Data Structures
• Data structures are generally categorized into
two classes:
– Primitive data structures.
– non-primitive data structures.
Primitive Data Types
 These are the data structures which are directly supported by
the machine.i.e.Any operation can be performed in these data
items.
 The different primitive data types are
 Integer
 Float
 Double
 Character
 boolean
Non Primitive Data Types
 These Datastructures do not allow any specific instructions to
be performed on the Data items directly.
 The different non primitive data types are
 Arrays
 Structures
 Unions
 Class etc.
7
Linear and Non-linear Data Structures
• Linear Data Structure: Linear data structures can be
constructed as a continuous arrangement of data
elements in the memory. It can be constructed by
using array data type. In the linear Data Structures the
relationship of adjacency is maintained between the
data elements.
• Non-Linear Data Structure: Non-linear data
Structure can be constructed as a collection of
randomly distributed set of data item joined together
by using a special pointer (tag). In non-linear Data
structure the relationship of adjacency is not
maintained between the data items
Array
• An array is a collection of similar data elements.
• These data elements have the same data type.
• The elements of the array are stored in consecutive memory locations
and are referenced by an index (also known as the subscript).
• In C, arrays are declared using the following syntax:
– type name[size];
• For example,
– int marks[10];
• The above statement declares an array marks that contains 10 elements.
• In C, the array index starts from zero.
• This means that the array marks will contain 10 elements in all.
• The first element will be stored in marks[0], second element in
marks[1], so on and so forth.
• Therefore, the last element, that is the 10th element, will be stored in
marks[9].
• In the memory, the array will be stored as shown in Fig.
Linked Lists
• A linked list is a very flexible, dynamic data structure in which elements
(called nodes) form a sequential list.
• In contrast to static arrays, a programmer need not worry about how
many elements will be stored in the linked list.
• This feature enables the programmers to write robust programs which
require less maintenance.
• In a linked list, each node is allocated space as it is added to the list.
• Every node in the list points to the next node in the list. Therefore, in a
linked list, every node contains the following two types of data:
– The value of the node or any other data that corresponds to that node
– A pointer or link to the next node in the list
• The last node in the list contains a NULL pointer to indicate that it is the
end or tail of the list.
• Since the memory for a node is dynamically allocated when it is added to
the list, the total number of nodes that may be added to a list is limited
only by the amount of memory available.
Stack
• A stack is a linear data structure in which insertion and deletion of
elements are done at only one end, which is known as the top of the
stack.
• Stack is called a last-in, first-out (LIFO) structure because the last
element which is added to the stack is the first element which is deleted
from the stack.
• In the computer’s memory, stacks can be implemented using arrays or
linked lists.
• Figure shows the array implementation of a stack.
• Every stack has a variable top associated with it.
• Top is used to store the address of the topmost element of the stack.
• It is this position from where the element will be added or deleted.
• There is another variable MAX, which is used to store the maximum
number of elements that the stack can store.
Stack
• If top = NULL, then it indicates that the stack is empty and if top =
MAX–1, then the stack is full.
• A stack supports three basic operations: push, pop, and peep.
• The push operation adds an element to the top of the stack.
• The pop operation removes the element from the top of the stack.
• And the peep operation returns the value of the topmost element of
the stack (without deleting it).
• However, before inserting an element in the stack, we must check
for overflow conditions.
• An overflow occurs when we try to insert an element into a stack
that is already full.
• Similarly, before deleting an element from the stack, we must check
for underflow conditions.
• An underflow condition occurs when we try to delete an element
from a stack that is already
• empty.
Queues
• A queue is a first-in, first-out (FIFO) data structure in which the element that is
inserted first is the first one to be taken out.
• The elements in a queue are added at one end called the rear and removed from
the other end called the front.
• Like stacks, queues can be implemented by using either arrays or linked lists.
• Every queue has front and rear variables that point to the position from where
deletions and insertions can be done, respectively.
• Consider the queue shown in Fig.
• Here, front = 0 and rear = 5.
• If we want to add one more value to the list, if we want to add another element
with the value 45, then the rear would be incremented by 1 and the value would
be stored at the position pointed by the rear.
• The queue, after the addition, would be as shown in Fig.
• .
Queues
• Here, front = 0 and rear = 6.
• Every time a new element is to be added, we will repeat the
same procedure.
• Now, if we want to delete an element from the queue, then the
value of front will be incremented.
• Deletions are done only from this end of the queue.
• The queue after the deletion will be as shown in Fig
Trees
• A tree is a non-linear data structure which consists of a collection
of nodes arranged in a hierarchical order.
• One of the nodes is designated as the root node, and the remaining
nodes can be partitioned into disjoint sets such that each set is a
sub-tree of the root.
• The simplest form of a tree is a binary tree.
• A binary tree consists of a root node and left and right sub-trees,
where both sub-trees are also binary trees.
• Each node contains a data element, a left pointer which points to
the left sub-tree, and a right pointer which points to the right sub-
tree.
• The root element is the topmost node which is pointed by a ‘root’
pointer.
• If root = NULL then the tree is empty.
Trees
• Figure shows a binary tree, where R is the root node and T1 and T2
are the left and right subtrees of R.
• If T1 is non-empty, then T1 is said to be the left successor of R.
• Likewise, if T2 is non-empty, then it is called the right successor of
R.
Graphs
• A graph is a non-linear data structure which is a collection of
vertices (also called nodes) and edges that connect these vertices.
• A graph is often viewed as a generalization of the tree structure,
where instead of a purely parent-to-child relationship between tree
nodes, any kind of complex relationships between the nodes can
exist.
• In a tree structure, nodes can have any number of children but only
one parent, a graph on the other hand relaxes all such kinds of
restrictions.
• Figure shows a graph with five nodes.
Graphs
• A node in the graph may represent a city and the edges connecting
the nodes can represent roads.
• A graph can also be used to represent a computer network where the
nodes are workstations and the edges are the network connections.
• Graphs have so many applications in computer science and
mathematics that several algorithms have been written to perform
the standard graph operations, such as searching the graph and
finding the shortest path between the nodes of a graph.
• Note that unlike trees, graphs do not have any root node.
• Rather, every node in the graph can be connected with every another
node in the graph.
• When two nodes are connected via an edge, the two nodes are
known as neighbours.
• For example, in Fig, node A has two neighbours: B and D.
Operations
 Traversing
Tovisit or process each data exactly once in the data structure
 Searching
Tosearch for a particular value in the data structure for the given key value
 Inserting
Toadd a new value to the data structure
 Deleting
Toremove a value from the data structure
 Sorting
Toarrange the values in the data structure in a particular order.
 Merging
Tojoin two same type of data structure values
19
Abstract Data Type
• An abstract data type, sometimes abbreviated
ADT, is a logical description of how we view
the data and the operations that are allowed
without regard to how they will be
implemented.
• By providing this level of abstraction, we are
creating an encapsulation around the data. The
idea is that by encapsulating the details of the
implementation, we are hiding them from the
user‘s view. This is called information hiding.
Advantage of using ADTs
• In the real world, programs evolve as a result of new
requirements or constraints, so a modification to a program
commonly requires a change in one or more of its data
structures.
• For example, if you want to add a new field to a student’s
record to keep track of more information about each
student, then it will be better to replace an array with a
linked structure to improve the program’s efficiency.
• In such a scenario, rewriting every procedure that uses the
changed structure is not desirable.
• Therefore, a better alternative is to separate the use of a
data structure from the details of its implementation.
• This is the principle underlying the use of abstract data
types.

More Related Content

PPTX
ds bridge.pptx
PPT
Unit 1.ppt
PPT
Fundamentals of data structure syallabus
PPT
DS.ppt Datatastructures notes presentation
PPT
lecture 02.2.ppt
PDF
INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS
PDF
INTRODUCTION TO DATA STRUCTURES AND ALGORITHM
PPTX
Unit 2 linear data structures
ds bridge.pptx
Unit 1.ppt
Fundamentals of data structure syallabus
DS.ppt Datatastructures notes presentation
lecture 02.2.ppt
INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS
INTRODUCTION TO DATA STRUCTURES AND ALGORITHM
Unit 2 linear data structures

Similar to 1.Introduction to Data Structures and Algorithms.pptx (20)

PPTX
DATA STRUCTURES AND LINKED LISTS IN C.pptx
PPTX
DATA STRUCTURES AND LINKED LISTS IN C.pptx
PPTX
ALGORITHM ANALYSIS AND LISTS ABSTACTS DT
PPTX
DS Module 1.pptx
PPTX
unit 1.pptx
PPTX
DS Module 1.pptx
PPTX
Chapter 1 _edited.pptx.software engineering
PPTX
RPT_03_A_Linked List presentation for FE
PPTX
DS Module1 (1).pptx
PDF
ds-lecture-4-171012041008 (1).pdf
PPT
Data Structures 3
PPTX
DATA STRUCTURE AND COMPUTER ALGORITHMS LECTURE 2
PPTX
Linked list (1).pptx
PDF
Data Structure Lecture 3 Linked Lists.pdf
PPTX
project on data structures and algorithm
PPTX
linked list in data structure
PDF
DS Module 03.pdf
PPTX
mbit_Unit-2_Linked List.pptx
PPTX
Data Structures (CS8391)
PPTX
Arrays and linked lists
DATA STRUCTURES AND LINKED LISTS IN C.pptx
DATA STRUCTURES AND LINKED LISTS IN C.pptx
ALGORITHM ANALYSIS AND LISTS ABSTACTS DT
DS Module 1.pptx
unit 1.pptx
DS Module 1.pptx
Chapter 1 _edited.pptx.software engineering
RPT_03_A_Linked List presentation for FE
DS Module1 (1).pptx
ds-lecture-4-171012041008 (1).pdf
Data Structures 3
DATA STRUCTURE AND COMPUTER ALGORITHMS LECTURE 2
Linked list (1).pptx
Data Structure Lecture 3 Linked Lists.pdf
project on data structures and algorithm
linked list in data structure
DS Module 03.pdf
mbit_Unit-2_Linked List.pptx
Data Structures (CS8391)
Arrays and linked lists
Ad

Recently uploaded (20)

PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
cuic standard and advanced reporting.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Empathic Computing: Creating Shared Understanding
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPT
Teaching material agriculture food technology
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
Spectroscopy.pptx food analysis technology
PDF
MIND Revenue Release Quarter 2 2025 Press Release
Building Integrated photovoltaic BIPV_UPV.pdf
cuic standard and advanced reporting.pdf
MYSQL Presentation for SQL database connectivity
The Rise and Fall of 3GPP – Time for a Sabbatical?
Empathic Computing: Creating Shared Understanding
Diabetes mellitus diagnosis method based random forest with bat algorithm
sap open course for s4hana steps from ECC to s4
Per capita expenditure prediction using model stacking based on satellite ima...
Teaching material agriculture food technology
Review of recent advances in non-invasive hemoglobin estimation
Mobile App Security Testing_ A Comprehensive Guide.pdf
Understanding_Digital_Forensics_Presentation.pptx
Network Security Unit 5.pdf for BCA BBA.
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Encapsulation_ Review paper, used for researhc scholars
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Programs and apps: productivity, graphics, security and other tools
Spectroscopy.pptx food analysis technology
MIND Revenue Release Quarter 2 2025 Press Release
Ad

1.Introduction to Data Structures and Algorithms.pptx

  • 2. Basic Terminology • When selecting a data structure to solve a problem, the following steps must be performed. 1. Analysis of the problem to determine the basic operations that must be supported. For example, basic operation may include inserting/deleting/searching a data item from the data structure. 2. Quantify the resource constraints for each operation. 3. Select the data structure that best meets these requirements.
  • 3. Elementary Data Structure Organization  Data represents a single value or a set of values assigned to entities. Data item refers a single or group of values with in the data  An entity is a thing that has some properties which can take • values.  Processed or meaning full data is called information. This is • used for taking some action.
  • 4. Classification Of Data Structures • Data structures are generally categorized into two classes: – Primitive data structures. – non-primitive data structures.
  • 5. Primitive Data Types  These are the data structures which are directly supported by the machine.i.e.Any operation can be performed in these data items.  The different primitive data types are  Integer  Float  Double  Character  boolean
  • 6. Non Primitive Data Types  These Datastructures do not allow any specific instructions to be performed on the Data items directly.  The different non primitive data types are  Arrays  Structures  Unions  Class etc.
  • 7. 7 Linear and Non-linear Data Structures • Linear Data Structure: Linear data structures can be constructed as a continuous arrangement of data elements in the memory. It can be constructed by using array data type. In the linear Data Structures the relationship of adjacency is maintained between the data elements. • Non-Linear Data Structure: Non-linear data Structure can be constructed as a collection of randomly distributed set of data item joined together by using a special pointer (tag). In non-linear Data structure the relationship of adjacency is not maintained between the data items
  • 8. Array • An array is a collection of similar data elements. • These data elements have the same data type. • The elements of the array are stored in consecutive memory locations and are referenced by an index (also known as the subscript). • In C, arrays are declared using the following syntax: – type name[size]; • For example, – int marks[10]; • The above statement declares an array marks that contains 10 elements. • In C, the array index starts from zero. • This means that the array marks will contain 10 elements in all. • The first element will be stored in marks[0], second element in marks[1], so on and so forth. • Therefore, the last element, that is the 10th element, will be stored in marks[9]. • In the memory, the array will be stored as shown in Fig.
  • 9. Linked Lists • A linked list is a very flexible, dynamic data structure in which elements (called nodes) form a sequential list. • In contrast to static arrays, a programmer need not worry about how many elements will be stored in the linked list. • This feature enables the programmers to write robust programs which require less maintenance. • In a linked list, each node is allocated space as it is added to the list. • Every node in the list points to the next node in the list. Therefore, in a linked list, every node contains the following two types of data: – The value of the node or any other data that corresponds to that node – A pointer or link to the next node in the list • The last node in the list contains a NULL pointer to indicate that it is the end or tail of the list. • Since the memory for a node is dynamically allocated when it is added to the list, the total number of nodes that may be added to a list is limited only by the amount of memory available.
  • 10. Stack • A stack is a linear data structure in which insertion and deletion of elements are done at only one end, which is known as the top of the stack. • Stack is called a last-in, first-out (LIFO) structure because the last element which is added to the stack is the first element which is deleted from the stack. • In the computer’s memory, stacks can be implemented using arrays or linked lists. • Figure shows the array implementation of a stack. • Every stack has a variable top associated with it. • Top is used to store the address of the topmost element of the stack. • It is this position from where the element will be added or deleted. • There is another variable MAX, which is used to store the maximum number of elements that the stack can store.
  • 11. Stack • If top = NULL, then it indicates that the stack is empty and if top = MAX–1, then the stack is full. • A stack supports three basic operations: push, pop, and peep. • The push operation adds an element to the top of the stack. • The pop operation removes the element from the top of the stack. • And the peep operation returns the value of the topmost element of the stack (without deleting it). • However, before inserting an element in the stack, we must check for overflow conditions. • An overflow occurs when we try to insert an element into a stack that is already full. • Similarly, before deleting an element from the stack, we must check for underflow conditions. • An underflow condition occurs when we try to delete an element from a stack that is already • empty.
  • 12. Queues • A queue is a first-in, first-out (FIFO) data structure in which the element that is inserted first is the first one to be taken out. • The elements in a queue are added at one end called the rear and removed from the other end called the front. • Like stacks, queues can be implemented by using either arrays or linked lists. • Every queue has front and rear variables that point to the position from where deletions and insertions can be done, respectively. • Consider the queue shown in Fig. • Here, front = 0 and rear = 5. • If we want to add one more value to the list, if we want to add another element with the value 45, then the rear would be incremented by 1 and the value would be stored at the position pointed by the rear. • The queue, after the addition, would be as shown in Fig. • .
  • 13. Queues • Here, front = 0 and rear = 6. • Every time a new element is to be added, we will repeat the same procedure. • Now, if we want to delete an element from the queue, then the value of front will be incremented. • Deletions are done only from this end of the queue. • The queue after the deletion will be as shown in Fig
  • 14. Trees • A tree is a non-linear data structure which consists of a collection of nodes arranged in a hierarchical order. • One of the nodes is designated as the root node, and the remaining nodes can be partitioned into disjoint sets such that each set is a sub-tree of the root. • The simplest form of a tree is a binary tree. • A binary tree consists of a root node and left and right sub-trees, where both sub-trees are also binary trees. • Each node contains a data element, a left pointer which points to the left sub-tree, and a right pointer which points to the right sub- tree. • The root element is the topmost node which is pointed by a ‘root’ pointer. • If root = NULL then the tree is empty.
  • 15. Trees • Figure shows a binary tree, where R is the root node and T1 and T2 are the left and right subtrees of R. • If T1 is non-empty, then T1 is said to be the left successor of R. • Likewise, if T2 is non-empty, then it is called the right successor of R.
  • 16. Graphs • A graph is a non-linear data structure which is a collection of vertices (also called nodes) and edges that connect these vertices. • A graph is often viewed as a generalization of the tree structure, where instead of a purely parent-to-child relationship between tree nodes, any kind of complex relationships between the nodes can exist. • In a tree structure, nodes can have any number of children but only one parent, a graph on the other hand relaxes all such kinds of restrictions. • Figure shows a graph with five nodes.
  • 17. Graphs • A node in the graph may represent a city and the edges connecting the nodes can represent roads. • A graph can also be used to represent a computer network where the nodes are workstations and the edges are the network connections. • Graphs have so many applications in computer science and mathematics that several algorithms have been written to perform the standard graph operations, such as searching the graph and finding the shortest path between the nodes of a graph. • Note that unlike trees, graphs do not have any root node. • Rather, every node in the graph can be connected with every another node in the graph. • When two nodes are connected via an edge, the two nodes are known as neighbours. • For example, in Fig, node A has two neighbours: B and D.
  • 18. Operations  Traversing Tovisit or process each data exactly once in the data structure  Searching Tosearch for a particular value in the data structure for the given key value  Inserting Toadd a new value to the data structure  Deleting Toremove a value from the data structure  Sorting Toarrange the values in the data structure in a particular order.  Merging Tojoin two same type of data structure values
  • 19. 19 Abstract Data Type • An abstract data type, sometimes abbreviated ADT, is a logical description of how we view the data and the operations that are allowed without regard to how they will be implemented. • By providing this level of abstraction, we are creating an encapsulation around the data. The idea is that by encapsulating the details of the implementation, we are hiding them from the user‘s view. This is called information hiding.
  • 20. Advantage of using ADTs • In the real world, programs evolve as a result of new requirements or constraints, so a modification to a program commonly requires a change in one or more of its data structures. • For example, if you want to add a new field to a student’s record to keep track of more information about each student, then it will be better to replace an array with a linked structure to improve the program’s efficiency. • In such a scenario, rewriting every procedure that uses the changed structure is not desirable. • Therefore, a better alternative is to separate the use of a data structure from the details of its implementation. • This is the principle underlying the use of abstract data types.