SlideShare a Scribd company logo
DATA STRUCTURE – CS3503
A data structure is a special way of organizing
and storing data in a computer so that it can be
used efficiently.
Data structures are the building blocks of any
program or the software.
Data Structures enable the programmers to
handle the data in an efficient way.
Basic Terminology
Data: Data can be defined as an elementary value or
the collection of values.
Example - student's name and his id are the data
about the student.
Group Items: Data items which have subordinate
data items are called Group item.
Example -name of a student can have first name and
the last name.
Record: Record can be defined as the collection of
various data items.
Example, if student is an entity, then name, address,
course and marks can be grouped together to form
the record for the student.
File: A File is a collection of various records of one
type of entity.
Example: If there are 20 students in a class, then
there will be 20 records, and each record contains
the data about a student.
Attribute and Entity: An entity represents the class
of certain objects and it contains various attributes.
Each attribute represents the particular property of
that entity.
Example : Student is an entity
Deptno, name, sub1 are attributes
Field: Field is a single elementary unit of information
representing the attribute of an entity.
Need of Data Structures
Processor speed: If we have a large amount of data, high
speed processing is required. Representing data with a
particular format may remove the unwanted data there
by increase the processing speed.
Data Search: In a large amount of data, if the
representation of data is not proper then finding out a
particular data is a very complex task.
Multiple requests: If thousands of users are searching the
data simultaneously on a web server, if data are not
organized in a format then there are the chances of
failure in server.
Advantages of Data Structures
Efficiency: Efficiency of a program depends
upon the choice of data structures.
Reusability: Data structures are reusable, i.e.
once we have implemented a particular data
structure, we can use it at any other place.
Abstraction: Data structure is specified by the
ADT which provides a level of abstraction. The
client program uses the data structure through
interface only, without getting into the
implementation details.
CLASSIFICATION OF DATA STRUCTURE
Linear Data Structures: A data structure is called
linear if all of its elements are arranged in the linear
order.
In linear data structures, the elements are stored in
non-hierarchical way where each element has the
successors and predecessors except the first and last
element.
.
Types of Linear Data Structures
Static:
Arrays: An array is a collection of similar type of data
items and each data item is called an element of the
array.
It is static because its size should be specified before
using it.
The data type of the element may be any valid data
type like char, int, float or double.
Types of Linear Data Structures
Static:
Linked List: Linked list is a linear data structure
which is used to maintain a list in the memory.
It can be seen as the collection of nodes stored at
non-contiguous memory locations.
Each node of the list contains a pointer to its
adjacent node.
Stack: Stack is a linear list in which insertion and
deletions are allowed only at one end, called top.
It is named as stack because it behaves like a real-
world stack, for example: deck of cards.
Queue: Queue is a linear list in which elements can
be inserted only at one end called rear and deleted
only at the other end called front.
It is an abstract data structure, similar to stack.
Queue is opened at both end therefore it follows
First-In-First-Out (FIFO) methodology for storing
the data items.
Non Linear Data Structures
This data structure does not form a sequence i.e.
each item or element is connected with two or
more other items in a non-linear arrangement.
The data elements are not arranged in sequential
structure.
Types of Non Linear Data Structures
Trees
Graphs
Trees: Trees are multilevel data structures with a
hierarchical relationship among its elements known
as nodes.
The bottommost nodes in the hierarchy are
called leaf node while the topmost node is
called root node. Each node contains pointers to
point adjacent nodes.
Tree data structure is based on the parent-child
relationship among the nodes.
Each node in the tree can have more than one
children except the leaf nodes whereas each node
can have atmost one parent except the root node.
Graphs: Graphs can be defined as the pictorial
representation of the set of elements.
These elements are represented as vertices
and the vertices are connected by the links
known as edges.
A graph is different from tree in the sense that
a graph can have cycle while the tree can not
have the one.
Operations on data structure
1) Traversing: Every data structure contains the set of data
elements. Traversing the data structure means visiting
each element of the data structure in order to perform
some specific operation like searching or sorting.
Example: If we have an array contains a set of numbers.
Each and every element is visited by traversing the
complete array.
2) Insertion: Insertion can be defined as the process of
adding the elements to the data structure at any location.
3) Deletion:The process of removing an element from the
data structure is called Deletion. We can delete an element
from the data structure at any random location.
4) Searching: The process of finding the location of
an element within the data structure is called
Searching.
5) Sorting: The process of arranging the data
structure in a specific order is known as Sorting.
There are many algorithms that can be used to
perform sorting, for example, insertion sort,
selection sort, bubble sort, etc.
6) Merging: When two lists List A and List B of size
M and N respectively, of similar type of elements,
clubbed or joined to produce the third list, List C of
size (M+N), then this process is called merging
Data Structure Introduction- Arrays, Matrix, Linked List
Data Structure Introduction- Arrays, Matrix, Linked List
Data Structure Introduction- Arrays, Matrix, Linked List
Array Length
Consider the following array stored in memory.
Let us find the length of this array
Length = UB-LB+1
= 207 – 200 +1 = 8
So the length is 8 ( number of elements)
Data Structure Introduction- Arrays, Matrix, Linked List
Data Structure Introduction- Arrays, Matrix, Linked List
Data Structure Introduction- Arrays, Matrix, Linked List
Data Structure Introduction- Arrays, Matrix, Linked List
Data Structure Introduction- Arrays, Matrix, Linked List
Linear Arrays
• A linear array is a list of a finite number n of
homogeneous data elements.
• The length of data elements of the array can
be obtained by the following formula:
• Length = UB – LB + 1
• UB is upper bound and LB is the lower bound.
Algorithm 4.1(Traversing a Linear Array)
• Here LA is a linear array with lower bound LB and
upper bond UB. This algorithm traverses LA
applying an operation PROCESS to each element
of LA.
• 1. [Initialize counter] Set K := LB
• 2. Repeat steps 3 and 4 while K ≤ UB
• 3. [Visit element] Apply PROCESS to LA[K]
• 4. [Increase counter] Set K := K + 1
• 5. [End of Step 2 loop]
Algorithm 4.2(Inserting into a Linear Array)
• INSERT(LA, N, K, ITEM)
• Here LA is a linear array with N elements and K
is a positive integer such that K ≤ N. This
algorithm inserts an element ITEM into the
Kth position in LA.
Algorithm 4.2(Inserting into a Linear Array)
• 1. [Initialize counter] Set J := N
• 2. Repeat steps 3 and 4 while J ≥ K
• [Move Jth element downward]
• 3. Set LA[J+1] := LA[J]
• 4.[Decrease counter] Set J := J – 1
• [End of Step 2 loop]
• 5. [Insert element] Set LA[K] := ITEM
• 6. [Reset N] Set N := N + 1
• 7. Exit
Algorithm 4.3(Deleting from a Linear Array)
• DELETE(LA, N, K, ITEM)
• Here LA is a linear array with N elements and K
is a positive integer such that K ≤ N. this
algorithm deletes the Kth element from LA.
Algorithm 4.3(Deleting from a Linear Array)
• 1. Set ITEM := LA[K]
• 2. Repeat steps for J = K to N - 1
• [Move J + 1st element upward]
• Set LA[J] := LA[J + 1]
• [End of Step 2 loop]
• 3. [Reset the number N of elements in LA]
• Set N := N - 1
• 4. Exit
Data Structure Introduction- Arrays, Matrix, Linked List
Multidimensional Arrays
• The arrays whose elements are accessed by
more than one subscript are termed as
multidimensional arrays.
• Two-Dimensional array
A two dimensional m × n array A is a collection of
m.n data elements such that each element is
specified by a pair of integers (such as J, K)
called subscripts, with the property that1 ≤ J ≤
m and 1 ≤ K ≤ m
The element of A with first subscript j and second
subscript k will be denoted by A[J, K]
Representation of Two-Dimensional Arrays in Memory
stored in two different ways:
• Column Major Order
• Row Major Order
Column Major Order
• In the column major order, the
elements are stored column by
column. First column, second column
and so on.
number[3][2] in column major order
would look like:
Row Major Order
• In the row major order, the elements
are stored row by row. First row,
second row and so on.
number[3][2] in row major order
would look like:
Representation of Two-Dimensional Arrays in
Memory
Location of an element in Column Major Order:
The formula is:
LOC (A [J, K]) = Base (A) + w [M (K-1) + (J-1)]
Here
LOC (A [J, K]) : is the location of the element in the
Jth row and Kth column.
Base (A) : is the base address of the array A.
w : is the number of bytes required to
store single element of the array A.
M : is the total number of rows in the array.
J : is the row number of the element.
K : is the column number of the element.
Location of an element in Row Major Order:
The formula is:
LOC (A [J, K]) = Base (A) + w [N (J-1) + (K-1)]
Here
LOC (A [J, K]) : is the location of the element in the
Jth row and Kth column.
Base (A) : is the base address of the array A.
w : is the number of bytes required to store
single element of the array A.
N : is the total number of columns in the
array.
J : is the row number of the element.
K : is the column number of the element.
Data Structure Introduction- Arrays, Matrix, Linked List
find the location of A [3, 2]. The required values are:
Base (A) : 1000
w : 2 (because an integer takes 2 bytes in memory)
M : 3
J : 3
K : 2
Now put these values in the given formula as below:
LOC (A [3, 2]) = 1000 + 2 [3 (2-1) + (3-1)]
= 1000 + 2 [3 (1) + 2]
= 1000 + 2 [3 + 2]
= 1000 + 2 [5]
= 1000 + 10
= 1010
Data Structure Introduction- Arrays, Matrix, Linked List
find the location of A [3, 2]. The required values are:
Base (A) : 1000
w : 2 (because an integer takes 2 bytes in memory)
N : 4
J : 3
K : 2
Now put these values in the given formula as below:
LOC (A [3, 2]) = 1000 + 2 [4 (3-1) + (2-1)]
= 1000 + 2 [4 (2) + 1]
= 1000 + 2 [8 + 1]
= 1000 + 2 [9]
= 1000 + 18
= 1018
Records
A record is a collection of related elements, possibly of different
types, having a single name. Each element in a record is called a
field.
A field is the smallest element of named data that has meaning.
A field has a type and exists in memory. Fields can be assigned type
and exists in memory.
Fields can be assigned values, which in turn be accessed for
selection or manipulation.
A field differs from a variable in that it is part of a record
Two examples of records.
The first example, fraction, has two fields, both of
which are integers. The second example, student,
has three fields made up of three different types.
Array of Records
EXAMPLE 4.17
Suppose a hospital keeps a record of each newborn baby which contains the following
data items: Name, Sex ,Birthday, Father, Mother.
Suppose further that Birthday is a group item with subitems Month, Day and Year, and
Father and Mother are group items, each with subitems Name and Age.
Figure shows how such a record could appear.
The structure of the above record is usually described as follows. (Note that Name appears
three times and Age appears twice in the structure
1 Newborn
2 Name
2 Sex
2 Birthday
3 Month
3 Day
3 Year
2 Father
3 Name
3 Age
2 Mother
3 Name
3 Age
The number to the Left of each identifier is called a level number.
Observe that each group item is followed by subitems, and the level of the
subitems is I more than the level of the group item.
Furthermore, an item is a group item if and only if it is immediately
followed by an item with a greater level number.
Some of the identifiers in a record structure may also refer to arrays of
elements.
In fact, suppose the first line of the above structure is replaced by
I Newborn(20)
This will indicate a file of 20 records. and the usual subscript notation will
be used to distinguish between different records in the file.
That is, we will write Newborn1, Newborn2 Newborn3, or Newborn[1],
Ncwborn[2], Newborn[3],. to denote different records in the file.
EXAMPLE 4.18
A class of student records may be organized as follows:
Student(20)
2 Name
3 Last
3 First
3 Ml (Middle Initial)
2 Test(3)
2 Final
2 Grade
The identifier Student( 20) indicates that there are 20 students. The identifier Test (3) indicates that
there are three tests Per student.
Observe that there are 8 elementary items per Student, since Test is counted 3 times. Altogether,
there are 160 elementary items in the entire Student structure.
Indexing Items in a Record
Suppose we Want to access some data item in a record. In some cases, we cannot simply write the
data name of the item since the same name may appear in different places in the record.
For example Age appears in two places in the record in Example 4.17. Accordingly, in order to specify
a particular item, we may have to qualify the name by using appropriate group item names in the
structure.
This qualification is indicated by using decimal points (periods) to separate group items from
EXAMPLE
(a) Consider the record structure Newborn in Example 4.17. Sex and year need no qualification, since each
refer to a unique item in the structure. On the other hand, suppose we want to refer to the age of the
father.
This can be done by writing Newborn. Father. Age or simply Father.Age
The first reference is said to be fully qualified. Sometimes one adds qualifying identifiers for clarity.
(b) Suppose the first line in the record structure in Example 4.17 is replaced by
I Newborn(20)
That is, Newborn is defined to be a file with 20 records. Then every item automatically becomes a 20-
element array.
Some languages allow the sex of the sixth newborn to be referenced by writing Newborn.Sex(6) or
simply Sex[6].
Analogously, the age of the father of the sixth newborn may be referenced by writing Newborn. Father.
Age[6] or simply Father.Agc(6] -
Ad

Recommended

Datastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
Malikireddy Bramhananda Reddy
 
DATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGEST
Swapnil Mishra
 
DS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and Engineering
RAJASEKHARV8
 
M v bramhananda reddy dsa complete notes
M v bramhananda reddy dsa complete notes
Malikireddy Bramhananda Reddy
 
Data Structures and algoithms Unit - 1.pptx
Data Structures and algoithms Unit - 1.pptx
mexiuro901
 
1.1 ADS data-structure.pdf
1.1 ADS data-structure.pdf
RameshBabuKellamapal
 
chapter-4-data-structure.pdf
chapter-4-data-structure.pdf
study material
 
datastructureppt-190327174340 (1).pptx
datastructureppt-190327174340 (1).pptx
DEEPAK948083
 
8074.pdf
8074.pdf
BAna36
 
cluod.pdf
cluod.pdf
ssuser92d367
 
EC2311 – Data Structures and C Programming
EC2311 – Data Structures and C Programming
Padma Priya
 
DSA - Copy.pptx
DSA - Copy.pptx
BishalChowdhury10
 
DS Module 1.pptx
DS Module 1.pptx
sarala9
 
Data structure ppt
Data structure ppt
Prof. Dr. K. Adisesha
 
8.DATA STRUCTURES UNIT 1 AND 2 CS3301PPT.pptx
8.DATA STRUCTURES UNIT 1 AND 2 CS3301PPT.pptx
venigkrish89
 
General Data structures
General Data structures
Youssef Elsalhawy
 
UNITIII LDS.pdf
UNITIII LDS.pdf
meenamadhuvandhi2
 
DS Module 1.pptx
DS Module 1.pptx
SaralaT3
 
DATA STRUCTURE AND ALGORITHM with linked list
DATA STRUCTURE AND ALGORITHM with linked list
shanmugapriyacsecs
 
arrays
arrays
Enakshi Chanda
 
Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1
blessyboban92
 
Introduction to Data Structures and their importance
Introduction to Data Structures and their importance
Bulbul Agrawal
 
Data structure lecture 1
Data structure lecture 1
Kumar
 
DSA Unit II array.pptx
DSA Unit II array.pptx
sayalishivarkar1
 
Ch 1 intriductions
Ch 1 intriductions
irshad17
 
TSAT Presentation1.pptx
TSAT Presentation1.pptx
Rajitha Reddy Alugati
 
DATA STRUCTURE INTRODUCITON FULL NOTES.pptx
DATA STRUCTURE INTRODUCITON FULL NOTES.pptx
Keerthanakeerthana869629
 
data structure unit -1_170434dd7400.pptx
data structure unit -1_170434dd7400.pptx
coc7987515756
 
Indigo_Airlines_Strategy_Presentation.pptx
Indigo_Airlines_Strategy_Presentation.pptx
mukeshpurohit991
 
lecture12.pdf Introduction to bioinformatics
lecture12.pdf Introduction to bioinformatics
SergeyTsygankov6
 

More Related Content

Similar to Data Structure Introduction- Arrays, Matrix, Linked List (20)

8074.pdf
8074.pdf
BAna36
 
cluod.pdf
cluod.pdf
ssuser92d367
 
EC2311 – Data Structures and C Programming
EC2311 – Data Structures and C Programming
Padma Priya
 
DSA - Copy.pptx
DSA - Copy.pptx
BishalChowdhury10
 
DS Module 1.pptx
DS Module 1.pptx
sarala9
 
Data structure ppt
Data structure ppt
Prof. Dr. K. Adisesha
 
8.DATA STRUCTURES UNIT 1 AND 2 CS3301PPT.pptx
8.DATA STRUCTURES UNIT 1 AND 2 CS3301PPT.pptx
venigkrish89
 
General Data structures
General Data structures
Youssef Elsalhawy
 
UNITIII LDS.pdf
UNITIII LDS.pdf
meenamadhuvandhi2
 
DS Module 1.pptx
DS Module 1.pptx
SaralaT3
 
DATA STRUCTURE AND ALGORITHM with linked list
DATA STRUCTURE AND ALGORITHM with linked list
shanmugapriyacsecs
 
arrays
arrays
Enakshi Chanda
 
Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1
blessyboban92
 
Introduction to Data Structures and their importance
Introduction to Data Structures and their importance
Bulbul Agrawal
 
Data structure lecture 1
Data structure lecture 1
Kumar
 
DSA Unit II array.pptx
DSA Unit II array.pptx
sayalishivarkar1
 
Ch 1 intriductions
Ch 1 intriductions
irshad17
 
TSAT Presentation1.pptx
TSAT Presentation1.pptx
Rajitha Reddy Alugati
 
DATA STRUCTURE INTRODUCITON FULL NOTES.pptx
DATA STRUCTURE INTRODUCITON FULL NOTES.pptx
Keerthanakeerthana869629
 
data structure unit -1_170434dd7400.pptx
data structure unit -1_170434dd7400.pptx
coc7987515756
 
8074.pdf
8074.pdf
BAna36
 
EC2311 – Data Structures and C Programming
EC2311 – Data Structures and C Programming
Padma Priya
 
DS Module 1.pptx
DS Module 1.pptx
sarala9
 
8.DATA STRUCTURES UNIT 1 AND 2 CS3301PPT.pptx
8.DATA STRUCTURES UNIT 1 AND 2 CS3301PPT.pptx
venigkrish89
 
DS Module 1.pptx
DS Module 1.pptx
SaralaT3
 
DATA STRUCTURE AND ALGORITHM with linked list
DATA STRUCTURE AND ALGORITHM with linked list
shanmugapriyacsecs
 
Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1
blessyboban92
 
Introduction to Data Structures and their importance
Introduction to Data Structures and their importance
Bulbul Agrawal
 
Data structure lecture 1
Data structure lecture 1
Kumar
 
Ch 1 intriductions
Ch 1 intriductions
irshad17
 
DATA STRUCTURE INTRODUCITON FULL NOTES.pptx
DATA STRUCTURE INTRODUCITON FULL NOTES.pptx
Keerthanakeerthana869629
 
data structure unit -1_170434dd7400.pptx
data structure unit -1_170434dd7400.pptx
coc7987515756
 

Recently uploaded (20)

Indigo_Airlines_Strategy_Presentation.pptx
Indigo_Airlines_Strategy_Presentation.pptx
mukeshpurohit991
 
lecture12.pdf Introduction to bioinformatics
lecture12.pdf Introduction to bioinformatics
SergeyTsygankov6
 
ppt somu_Jarvis_AI_Assistant_presen.pptx
ppt somu_Jarvis_AI_Assistant_presen.pptx
MohammedumarFarhan
 
PPT1_CB_VII_CS_Ch3_FunctionsandChartsinCalc.ppsx
PPT1_CB_VII_CS_Ch3_FunctionsandChartsinCalc.ppsx
animaroy81
 
美国毕业证范本中华盛顿大学学位证书CWU学生卡购买
美国毕业证范本中华盛顿大学学位证书CWU学生卡购买
Taqyea
 
NVIDIA Triton Inference Server, a game-changing platform for deploying AI mod...
NVIDIA Triton Inference Server, a game-changing platform for deploying AI mod...
Tamanna36
 
Indigo dyeing Presentation (2).pptx as dye
Indigo dyeing Presentation (2).pptx as dye
shreeroop1335
 
Starbucks in the Indian market through its joint venture.
Starbucks in the Indian market through its joint venture.
sales480687
 
Residential Zone 4 for industrial village
Residential Zone 4 for industrial village
MdYasinArafat13
 
624753984-Annex-A3-RPMS-Tool-for-Proficient-Teachers-SY-2024-2025.pdf
624753984-Annex-A3-RPMS-Tool-for-Proficient-Teachers-SY-2024-2025.pdf
CristineGraceAcuyan
 
Predicting Titanic Survival Presentation
Predicting Titanic Survival Presentation
praxyfarhana
 
Shifting Focus on AI: How it Can Make a Positive Difference
Shifting Focus on AI: How it Can Make a Positive Difference
1508 A/S
 
All the DataOps, all the paradigms .
All the DataOps, all the paradigms .
Lars Albertsson
 
@Reset-Password.pptx presentakh;kenvtion
@Reset-Password.pptx presentakh;kenvtion
MarkLariosa1
 
一比一原版(TUC毕业证书)开姆尼茨工业大学毕业证如何办理
一比一原版(TUC毕业证书)开姆尼茨工业大学毕业证如何办理
taqyed
 
最新版美国约翰霍普金斯大学毕业证(JHU毕业证书)原版定制
最新版美国约翰霍普金斯大学毕业证(JHU毕业证书)原版定制
Taqyea
 
Microsoft Power BI - Advanced Certificate for Business Intelligence using Pow...
Microsoft Power BI - Advanced Certificate for Business Intelligence using Pow...
Prasenjit Debnath
 
Mynd company all details what they are doing a
Mynd company all details what they are doing a
AniketKadam40952
 
NASA ESE Study Results v4 05.29.2020.pptx
NASA ESE Study Results v4 05.29.2020.pptx
CiroAlejandroCamacho
 
RESEARCH-FINAL-GROUP-3, about the final .pptx
RESEARCH-FINAL-GROUP-3, about the final .pptx
gwapokoha1
 
Indigo_Airlines_Strategy_Presentation.pptx
Indigo_Airlines_Strategy_Presentation.pptx
mukeshpurohit991
 
lecture12.pdf Introduction to bioinformatics
lecture12.pdf Introduction to bioinformatics
SergeyTsygankov6
 
ppt somu_Jarvis_AI_Assistant_presen.pptx
ppt somu_Jarvis_AI_Assistant_presen.pptx
MohammedumarFarhan
 
PPT1_CB_VII_CS_Ch3_FunctionsandChartsinCalc.ppsx
PPT1_CB_VII_CS_Ch3_FunctionsandChartsinCalc.ppsx
animaroy81
 
美国毕业证范本中华盛顿大学学位证书CWU学生卡购买
美国毕业证范本中华盛顿大学学位证书CWU学生卡购买
Taqyea
 
NVIDIA Triton Inference Server, a game-changing platform for deploying AI mod...
NVIDIA Triton Inference Server, a game-changing platform for deploying AI mod...
Tamanna36
 
Indigo dyeing Presentation (2).pptx as dye
Indigo dyeing Presentation (2).pptx as dye
shreeroop1335
 
Starbucks in the Indian market through its joint venture.
Starbucks in the Indian market through its joint venture.
sales480687
 
Residential Zone 4 for industrial village
Residential Zone 4 for industrial village
MdYasinArafat13
 
624753984-Annex-A3-RPMS-Tool-for-Proficient-Teachers-SY-2024-2025.pdf
624753984-Annex-A3-RPMS-Tool-for-Proficient-Teachers-SY-2024-2025.pdf
CristineGraceAcuyan
 
Predicting Titanic Survival Presentation
Predicting Titanic Survival Presentation
praxyfarhana
 
Shifting Focus on AI: How it Can Make a Positive Difference
Shifting Focus on AI: How it Can Make a Positive Difference
1508 A/S
 
All the DataOps, all the paradigms .
All the DataOps, all the paradigms .
Lars Albertsson
 
@Reset-Password.pptx presentakh;kenvtion
@Reset-Password.pptx presentakh;kenvtion
MarkLariosa1
 
一比一原版(TUC毕业证书)开姆尼茨工业大学毕业证如何办理
一比一原版(TUC毕业证书)开姆尼茨工业大学毕业证如何办理
taqyed
 
最新版美国约翰霍普金斯大学毕业证(JHU毕业证书)原版定制
最新版美国约翰霍普金斯大学毕业证(JHU毕业证书)原版定制
Taqyea
 
Microsoft Power BI - Advanced Certificate for Business Intelligence using Pow...
Microsoft Power BI - Advanced Certificate for Business Intelligence using Pow...
Prasenjit Debnath
 
Mynd company all details what they are doing a
Mynd company all details what they are doing a
AniketKadam40952
 
NASA ESE Study Results v4 05.29.2020.pptx
NASA ESE Study Results v4 05.29.2020.pptx
CiroAlejandroCamacho
 
RESEARCH-FINAL-GROUP-3, about the final .pptx
RESEARCH-FINAL-GROUP-3, about the final .pptx
gwapokoha1
 
Ad

Data Structure Introduction- Arrays, Matrix, Linked List

  • 2. A data structure is a special way of organizing and storing data in a computer so that it can be used efficiently. Data structures are the building blocks of any program or the software. Data Structures enable the programmers to handle the data in an efficient way.
  • 3. Basic Terminology Data: Data can be defined as an elementary value or the collection of values. Example - student's name and his id are the data about the student. Group Items: Data items which have subordinate data items are called Group item. Example -name of a student can have first name and the last name. Record: Record can be defined as the collection of various data items. Example, if student is an entity, then name, address, course and marks can be grouped together to form the record for the student.
  • 4. File: A File is a collection of various records of one type of entity. Example: If there are 20 students in a class, then there will be 20 records, and each record contains the data about a student. Attribute and Entity: An entity represents the class of certain objects and it contains various attributes. Each attribute represents the particular property of that entity. Example : Student is an entity Deptno, name, sub1 are attributes Field: Field is a single elementary unit of information representing the attribute of an entity.
  • 5. Need of Data Structures Processor speed: If we have a large amount of data, high speed processing is required. Representing data with a particular format may remove the unwanted data there by increase the processing speed. Data Search: In a large amount of data, if the representation of data is not proper then finding out a particular data is a very complex task. Multiple requests: If thousands of users are searching the data simultaneously on a web server, if data are not organized in a format then there are the chances of failure in server.
  • 6. Advantages of Data Structures Efficiency: Efficiency of a program depends upon the choice of data structures. Reusability: Data structures are reusable, i.e. once we have implemented a particular data structure, we can use it at any other place. Abstraction: Data structure is specified by the ADT which provides a level of abstraction. The client program uses the data structure through interface only, without getting into the implementation details.
  • 8. Linear Data Structures: A data structure is called linear if all of its elements are arranged in the linear order. In linear data structures, the elements are stored in non-hierarchical way where each element has the successors and predecessors except the first and last element. .
  • 9. Types of Linear Data Structures Static: Arrays: An array is a collection of similar type of data items and each data item is called an element of the array. It is static because its size should be specified before using it. The data type of the element may be any valid data type like char, int, float or double.
  • 10. Types of Linear Data Structures Static: Linked List: Linked list is a linear data structure which is used to maintain a list in the memory. It can be seen as the collection of nodes stored at non-contiguous memory locations. Each node of the list contains a pointer to its adjacent node. Stack: Stack is a linear list in which insertion and deletions are allowed only at one end, called top. It is named as stack because it behaves like a real- world stack, for example: deck of cards.
  • 11. Queue: Queue is a linear list in which elements can be inserted only at one end called rear and deleted only at the other end called front. It is an abstract data structure, similar to stack. Queue is opened at both end therefore it follows First-In-First-Out (FIFO) methodology for storing the data items.
  • 12. Non Linear Data Structures This data structure does not form a sequence i.e. each item or element is connected with two or more other items in a non-linear arrangement. The data elements are not arranged in sequential structure. Types of Non Linear Data Structures Trees Graphs
  • 13. Trees: Trees are multilevel data structures with a hierarchical relationship among its elements known as nodes. The bottommost nodes in the hierarchy are called leaf node while the topmost node is called root node. Each node contains pointers to point adjacent nodes. Tree data structure is based on the parent-child relationship among the nodes. Each node in the tree can have more than one children except the leaf nodes whereas each node can have atmost one parent except the root node.
  • 14. Graphs: Graphs can be defined as the pictorial representation of the set of elements. These elements are represented as vertices and the vertices are connected by the links known as edges. A graph is different from tree in the sense that a graph can have cycle while the tree can not have the one.
  • 15. Operations on data structure 1) Traversing: Every data structure contains the set of data elements. Traversing the data structure means visiting each element of the data structure in order to perform some specific operation like searching or sorting. Example: If we have an array contains a set of numbers. Each and every element is visited by traversing the complete array. 2) Insertion: Insertion can be defined as the process of adding the elements to the data structure at any location. 3) Deletion:The process of removing an element from the data structure is called Deletion. We can delete an element from the data structure at any random location.
  • 16. 4) Searching: The process of finding the location of an element within the data structure is called Searching. 5) Sorting: The process of arranging the data structure in a specific order is known as Sorting. There are many algorithms that can be used to perform sorting, for example, insertion sort, selection sort, bubble sort, etc. 6) Merging: When two lists List A and List B of size M and N respectively, of similar type of elements, clubbed or joined to produce the third list, List C of size (M+N), then this process is called merging
  • 20. Array Length Consider the following array stored in memory. Let us find the length of this array Length = UB-LB+1 = 207 – 200 +1 = 8 So the length is 8 ( number of elements)
  • 26. Linear Arrays • A linear array is a list of a finite number n of homogeneous data elements. • The length of data elements of the array can be obtained by the following formula: • Length = UB – LB + 1 • UB is upper bound and LB is the lower bound.
  • 27. Algorithm 4.1(Traversing a Linear Array) • Here LA is a linear array with lower bound LB and upper bond UB. This algorithm traverses LA applying an operation PROCESS to each element of LA. • 1. [Initialize counter] Set K := LB • 2. Repeat steps 3 and 4 while K ≤ UB • 3. [Visit element] Apply PROCESS to LA[K] • 4. [Increase counter] Set K := K + 1 • 5. [End of Step 2 loop]
  • 28. Algorithm 4.2(Inserting into a Linear Array) • INSERT(LA, N, K, ITEM) • Here LA is a linear array with N elements and K is a positive integer such that K ≤ N. This algorithm inserts an element ITEM into the Kth position in LA.
  • 29. Algorithm 4.2(Inserting into a Linear Array) • 1. [Initialize counter] Set J := N • 2. Repeat steps 3 and 4 while J ≥ K • [Move Jth element downward] • 3. Set LA[J+1] := LA[J] • 4.[Decrease counter] Set J := J – 1 • [End of Step 2 loop] • 5. [Insert element] Set LA[K] := ITEM • 6. [Reset N] Set N := N + 1 • 7. Exit
  • 30. Algorithm 4.3(Deleting from a Linear Array) • DELETE(LA, N, K, ITEM) • Here LA is a linear array with N elements and K is a positive integer such that K ≤ N. this algorithm deletes the Kth element from LA.
  • 31. Algorithm 4.3(Deleting from a Linear Array) • 1. Set ITEM := LA[K] • 2. Repeat steps for J = K to N - 1 • [Move J + 1st element upward] • Set LA[J] := LA[J + 1] • [End of Step 2 loop] • 3. [Reset the number N of elements in LA] • Set N := N - 1 • 4. Exit
  • 33. Multidimensional Arrays • The arrays whose elements are accessed by more than one subscript are termed as multidimensional arrays. • Two-Dimensional array A two dimensional m × n array A is a collection of m.n data elements such that each element is specified by a pair of integers (such as J, K) called subscripts, with the property that1 ≤ J ≤ m and 1 ≤ K ≤ m The element of A with first subscript j and second subscript k will be denoted by A[J, K]
  • 34. Representation of Two-Dimensional Arrays in Memory stored in two different ways: • Column Major Order • Row Major Order
  • 35. Column Major Order • In the column major order, the elements are stored column by column. First column, second column and so on. number[3][2] in column major order would look like:
  • 36. Row Major Order • In the row major order, the elements are stored row by row. First row, second row and so on. number[3][2] in row major order would look like:
  • 38. Location of an element in Column Major Order: The formula is: LOC (A [J, K]) = Base (A) + w [M (K-1) + (J-1)] Here LOC (A [J, K]) : is the location of the element in the Jth row and Kth column. Base (A) : is the base address of the array A. w : is the number of bytes required to store single element of the array A. M : is the total number of rows in the array. J : is the row number of the element. K : is the column number of the element.
  • 39. Location of an element in Row Major Order: The formula is: LOC (A [J, K]) = Base (A) + w [N (J-1) + (K-1)] Here LOC (A [J, K]) : is the location of the element in the Jth row and Kth column. Base (A) : is the base address of the array A. w : is the number of bytes required to store single element of the array A. N : is the total number of columns in the array. J : is the row number of the element. K : is the column number of the element.
  • 41. find the location of A [3, 2]. The required values are: Base (A) : 1000 w : 2 (because an integer takes 2 bytes in memory) M : 3 J : 3 K : 2 Now put these values in the given formula as below: LOC (A [3, 2]) = 1000 + 2 [3 (2-1) + (3-1)] = 1000 + 2 [3 (1) + 2] = 1000 + 2 [3 + 2] = 1000 + 2 [5] = 1000 + 10 = 1010
  • 43. find the location of A [3, 2]. The required values are: Base (A) : 1000 w : 2 (because an integer takes 2 bytes in memory) N : 4 J : 3 K : 2 Now put these values in the given formula as below: LOC (A [3, 2]) = 1000 + 2 [4 (3-1) + (2-1)] = 1000 + 2 [4 (2) + 1] = 1000 + 2 [8 + 1] = 1000 + 2 [9] = 1000 + 18 = 1018
  • 44. Records A record is a collection of related elements, possibly of different types, having a single name. Each element in a record is called a field. A field is the smallest element of named data that has meaning. A field has a type and exists in memory. Fields can be assigned type and exists in memory. Fields can be assigned values, which in turn be accessed for selection or manipulation. A field differs from a variable in that it is part of a record
  • 45. Two examples of records. The first example, fraction, has two fields, both of which are integers. The second example, student, has three fields made up of three different types.
  • 47. EXAMPLE 4.17 Suppose a hospital keeps a record of each newborn baby which contains the following data items: Name, Sex ,Birthday, Father, Mother. Suppose further that Birthday is a group item with subitems Month, Day and Year, and Father and Mother are group items, each with subitems Name and Age. Figure shows how such a record could appear.
  • 48. The structure of the above record is usually described as follows. (Note that Name appears three times and Age appears twice in the structure 1 Newborn 2 Name 2 Sex 2 Birthday 3 Month 3 Day 3 Year 2 Father 3 Name 3 Age 2 Mother 3 Name 3 Age
  • 49. The number to the Left of each identifier is called a level number. Observe that each group item is followed by subitems, and the level of the subitems is I more than the level of the group item. Furthermore, an item is a group item if and only if it is immediately followed by an item with a greater level number. Some of the identifiers in a record structure may also refer to arrays of elements. In fact, suppose the first line of the above structure is replaced by I Newborn(20) This will indicate a file of 20 records. and the usual subscript notation will be used to distinguish between different records in the file. That is, we will write Newborn1, Newborn2 Newborn3, or Newborn[1], Ncwborn[2], Newborn[3],. to denote different records in the file.
  • 50. EXAMPLE 4.18 A class of student records may be organized as follows: Student(20) 2 Name 3 Last 3 First 3 Ml (Middle Initial) 2 Test(3) 2 Final 2 Grade The identifier Student( 20) indicates that there are 20 students. The identifier Test (3) indicates that there are three tests Per student. Observe that there are 8 elementary items per Student, since Test is counted 3 times. Altogether, there are 160 elementary items in the entire Student structure. Indexing Items in a Record Suppose we Want to access some data item in a record. In some cases, we cannot simply write the data name of the item since the same name may appear in different places in the record. For example Age appears in two places in the record in Example 4.17. Accordingly, in order to specify a particular item, we may have to qualify the name by using appropriate group item names in the structure. This qualification is indicated by using decimal points (periods) to separate group items from
  • 51. EXAMPLE (a) Consider the record structure Newborn in Example 4.17. Sex and year need no qualification, since each refer to a unique item in the structure. On the other hand, suppose we want to refer to the age of the father. This can be done by writing Newborn. Father. Age or simply Father.Age The first reference is said to be fully qualified. Sometimes one adds qualifying identifiers for clarity. (b) Suppose the first line in the record structure in Example 4.17 is replaced by I Newborn(20) That is, Newborn is defined to be a file with 20 records. Then every item automatically becomes a 20- element array. Some languages allow the sex of the sixth newborn to be referenced by writing Newborn.Sex(6) or simply Sex[6]. Analogously, the age of the father of the sixth newborn may be referenced by writing Newborn. Father. Age[6] or simply Father.Agc(6] -