SlideShare a Scribd company logo
Linear Data Structures Using
Sequential Organization
Sequential Organization
 Sequential organization allows storing data at a fixed
distance apart.
 If the ith element is stored at location X, then the next
sequential (i+1)th
element is stored at location X+C, where C is
constant.
ARRAYS
 If we intend to store a group of data together in a sequential manner in
computer’s memory, then arrays can be one of the possible data structures.
 An array is a finite ordered collection of homogeneous data elements which
provides direct access (or random access) to any of its elements.
 An array as a data structure is defined as a set of pairs (index, value) such
that with each index a value is associated.
• index — indicates the location of an element in an array.
• value - indicates the actual value of that data element.
• Declaration of an array in ‘C++’:
int A[20];
GENERIC DATA TYPE
 Generic Data type is a data type where the
operations are defined but the types of the
items being manipulated are not
ARRAYS AS AN ADT
 Formally ADT is a collection of domain, operations, and axioms (or rules)
 For defining an array as an ADT, we have to define its very basic operations or
functions that can be performed on it
 The basic operations of arrays are creation of an array, storing an element,
accessing an element, and traversing the array.
 Let us specify ADT Array in which we provide specifications with operations to
be performed.
 ADT ARRAY(Index, Value)
 declare CREATE( ) array
ACCESS (array, index) value
STORE (array, index, value) array
for all Array_A ε array, x Î value, and i, j ε index let
ACCESS (CREATE, i) = error.
ACCESS (STORE (Array_A, i, x), j) = x if EQUAL (i, j)
else ACCESS (Array_A, j)
end
end ARRAY.
MEMORY REPRESENTATION & ADDRESS
CALCULATION
A0
A1
.
.
.
Ai
.
An-1
a i
ai+1
ai+2
:
:
an-1
X(Base)
X+1
X+2
X+(n-1)
Array A
 The address of the ith
element is calculated by the following
formula
• (Base address) + (offset of the ith
element from base address)
• Here, base address is the address of the first element where
array storage starts.
 Arrays support various operations such as traversal, sorting,
searching, insertion, deletion, merging, block movement, etc.
 Insertion of an element into an array
 Deleting an element
 Memory Representation of Two-Dimensional Arrays
 Row-major Representation
 Column-major Representation
Columns
Col1 col2 .... coln
A11 A12 .... A1n
A11 A12 .... A1n
Am1 Am2 .... Amn
: :
:
m*n
Rows R1
R2
Rm
1 2 3 4
5 6 7 8
9 10 11 12
Matrix M =
ROW-MAJOR REPRESENTATION
 In row-major representation, the elements of
Matrix are stored row-wise, i.e., elements of 1st row,
2nd row, 3rd row, and so on till mth
row
(0,0) (0,1) (0,2) (0,3) (1,0) (1,1) (1,2) (1,3) (2,0) (2,1) (2,2) (2,3)
Row1 Row2 Row3
1 2 3 4 5 6 7 8 9 10 11 12
ROW MAJOR ARRANGEMENT
 Address of A[i][j] = base addr + (col_index * total no. of rows +
row_index) element size
Row 0
Row 1
Row m-1
Row 0
Row 1
Row
m-1
Memory Location
Row-major arrangement in memory , in row major representation
COLUMN-MAJOR ARRANGEMENT
 Address of A[i][j] = base addr + (row_index * total no. of columns +
col_index) *element size
col1 col2
Col
n-1
Col
0
Col
1
Col
2
Memory Location
…
Column-major arrangement in memory , in column major representation
(0,0) (1,0) (2,0) (0,1) (1,1) (2,1) (0,2) (1,2) (2,2) (0,3) (1,3) (2,3)
Col 1 Col 2 Col 3 Col 4
1 2 3 4 5 6 7 8 9 10 11 12
Column-Major Representation of 2-D array
N -DIMENSIONAL ARRAYS
U2.pptx Advanced Data Structures and Algorithms
Row-Major representation of 2D array
Three dimensions row-major
arrangement
(i*m2*m3) elements
A[0][m2][m3] A[1][m2][m3] A[i][m2][m3] A[m1-1][m2]
ARRAYS USING TEMPLATE
 The function is defined in similar way replacing int by T as
datatype of member of array
 In all member functions header, Array is replaced by Array
<T> :: now
 Following statements instantiate the template class Array to int
and float respectively. So P is array of ints and Q in array of
floats.
Array <int> P;
Array <float> Q;
 In similar we can also have array of any user defined data type
CONCEPT OF ORDERED LIST
 Ordered list is the most common and frequently used data object
 Def: it is set of elements where set may be empty or it can be written as
collection of elements such as (a1, a2, a3 ………, an)
 Linear elements of an ordered list are related with each other in a particular
order or sequence
 Following are some examples of the ordered list.
• 1, 3,5,7,9,11,13,15
• January, February, March, April, May, June, July, August, September,
• October, November, December
• Red, Blue, Green, Black, Yellow
 There are many basic operations that can be performed on the ordered list as
follows:
 Finding the length of the list
 Traverse the list from left to right or from right to left
 Access the ith element in the list
 Update (Overwrite) the value of the ith position
 Insert an element at the ith location
 Delete an element at the ith position
SINGLE VARIABLE POLYNOMIAL
SINGLE VARIABLE POLYNOMIAL
 Representation Using Arrays
 Array of Structures
 Polynomial Evaluation
 Polynomial Addition
 Multiplication of Two Polynomials
 Polynomial as an ADT, the basic operations
are as follows:
 Creation of a polynomial
 Addition of two polynomials
 Subtraction of two polynomials
 Multiplication of two polynomials
 Polynomial evaluation
POLYNOMIAL BY USING ARRAY
POLYNOMIAL BY USING ARRAY
 STRUCTURE IS BETTER THAN ARRAY
FOR POLYNOMIAL:
 Such representation by an array is both time and space efficient when
polynomial is not a sparse one such as polynomial P(x) of degree 3 where P(x)=
3x3+x2–2x+5.
 But when polynomial is sparse such as in worst case a polynomial as A(x)= x99
+ 78 for degree of n =100, then only two locations out of 101 would be used.
 In such cases it is better to store polynomial as pairs of coefficient and exponent.
We may go for two different arrays for each or a structure having two members
as two arrays for each of coeff. and Exp or an array of structure that consists of
two data members coefficient and exponent.
POLYNOMIAL BY USING STRUCTURE
 Let us go for structure having two data
members coefficient and exponent and its
array.
AN ARRAY FOR FREQUENCY COUNT
We can use array to store the number of times a particular
element occurs in any sequence. Such occurrence of
particular element is known as frequency count.
void Frequency_Count ( int Freq[10 ], int A [ 100])
{
int i;
for ( i=0;i<10;i++)
Freq[i]=0;
for ( i=0;i<100;i++)
Freq[A[i] ++;
}
Frequency count of numbers ranging
between 0 to 9
SPARSE MATRIX
In many situations, matrix size is very large but out of
it, most of the elements are zeros (not necessarily
always zeros).
And only a small fraction of the matrix is actually
used. A matrix of such type is called a sparse matrix,
Sparse Logical Matrix
Sparse matrix and its representation
TRANSPOSE OF SPARSE MATRIX
 Simple Transpose
 Fast Transpose
Time complexity of manual technique is O (mn).
SPARSE MATRIX TRANSPOSE
 Time complexity will be O (n . T)
= O (n . mn)
= O (mn2
)
which is worst than the conventional transpose with
time complexity O (mn)
Simple Sparse matrix transpose
FAST SPARSE MATRIX TRANSPOSE
 In worst case, i.e. T= m × n (non-zero elements) the
magnitude becomes O (n +mn) = O (mn) which is the
same as 2-D transpose
 However the constant factor associated with fast
transpose is quite high
 When T is sufficiently small, compared to its maximum of
m . n, fast transpose will work faster
STRING MANIPULATION
 Def: String is sequence of characters. The strings are defined with double quotes.
 The string is stored in the memory with terminating character ‘0’.
 There are various operations that can be performed on the string:
 To find the length of a string (strlen)
 To concatenate two strings (strcat)
 To copy a string (strcpy)
 To reverse a string (strrev)
 String compare (strcmp, strcmpi)
 Palindrome check
 To recognize a sub string. (strstr)
BASICALLY A STRING IS STORED AS A SEQUENCE
OF CHARACTERS IN ONE-DIMENSIONAL
CHARACTER ARRAY SAY A.
CHAR A[10] ="STRING" ;
EACH STRING IS TERMINATED BY A SPECIAL
CHARACTER THAT IS NULL CHARACTER ‘0’.
THIS NULL CHARACTER INDICATES THE END OR
TERMINATION OF EACH STRING.
CHARACTERISTICS OF ARRAY
 An array is a finite ordered collection of homogeneous data
elements.
 In array, successive elements of list are stored at a fixed distance
apart.
 Array is defined as set of pairs-( index and value).
 Array allows random access to any element
 In array, insertion and deletion of elements in between positions
requires data movement.
 Array provides static allocation, which means space allocation
done once during compile time, can not be changed run time.
ADVANTAGE OF ARRAY
DATA STRUCTURE
 Arrays permit efficient random access in constant time 0(1).
 Arrays are most appropriate for storing a fixed amount of data and also for high
frequency of data retrievals as data can be accessed directly.
 Wherever there is a direct mapping between the elements and there positions,
arrays are the most suitable data structures.
 Ordered lists such as polynomials are most efficiently handled using arrays.
 Arrays are useful to form the basis for several more complex data structures,
such as heaps, and hash tables and can be used to represent strings, stacks and
queues.
DISADVANTAGE OF
ARRAY DATA STRUCTURE
 Arrays provide static memory management. Hence
during execution the size can neither be grown nor
shrunk.
 Array is inefficient when often data is to inserted or
deleted as inserting and deleting an element in array
needs a lot of data movement.
 Hence array is inefficient for the applications, which
very often need insert and delete operations in
between.
APPLICATIONS OF ARRAYS
 Although useful in their own right, arrays also form the basis for
several more complex data structures, such as heaps, hash tables
and can be used to represent strings, stacks and queues.
 All these applications benefit from the compactness and direct
access benefits of arrays.
 Two-dimensional data when represented as Matrix and matrix
operations.
Ad

More Related Content

Similar to U2.pptx Advanced Data Structures and Algorithms (20)

@ R reference
@ R reference@ R reference
@ R reference
vickyrolando
 
R command cheatsheet.pdf
R command cheatsheet.pdfR command cheatsheet.pdf
R command cheatsheet.pdf
Ngcnh947953
 
data structure programing language in c.ppt
data structure programing language in c.pptdata structure programing language in c.ppt
data structure programing language in c.ppt
LavkushGupta12
 
unit 2.pptx
unit 2.pptxunit 2.pptx
unit 2.pptx
researchgrad82
 
Short Reference Card for R users.
Short Reference Card for R users.Short Reference Card for R users.
Short Reference Card for R users.
Dr. Volkan OBAN
 
Reference card for R
Reference card for RReference card for R
Reference card for R
Dr. Volkan OBAN
 
Arrays
ArraysArrays
Arrays
Trupti Agrawal
 
Data structures in c#
Data structures in c#Data structures in c#
Data structures in c#
SivaSankar Gorantla
 
Numpy ndarrays.pdf
Numpy ndarrays.pdfNumpy ndarrays.pdf
Numpy ndarrays.pdf
SudhanshiBakre1
 
Chyuuuuuuuuuuryyyyyyyyyyy123456789786341.pptx
Chyuuuuuuuuuuryyyyyyyyyyy123456789786341.pptxChyuuuuuuuuuuryyyyyyyyyyy123456789786341.pptx
Chyuuuuuuuuuuryyyyyyyyyyy123456789786341.pptx
RobertCarreonBula
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
KristinaBorooah
 
Arrays in C++ in Tamil - TNSCERT SYLLABUS PPT
Arrays in C++ in Tamil - TNSCERT SYLLABUS PPT Arrays in C++ in Tamil - TNSCERT SYLLABUS PPT
Arrays in C++ in Tamil - TNSCERT SYLLABUS PPT
LATHA LAKSHMI
 
Various Operations Of Array(Data Structure Algorithm).pptx
Various Operations Of Array(Data Structure Algorithm).pptxVarious Operations Of Array(Data Structure Algorithm).pptx
Various Operations Of Array(Data Structure Algorithm).pptx
atirathpal007
 
cluod.pdf
cluod.pdfcluod.pdf
cluod.pdf
ssuser92d367
 
Svm Presentation
Svm PresentationSvm Presentation
Svm Presentation
shahparin
 
ADVANCED DATA STRUCTURES AND ALGORITHMS.pptx
ADVANCED DATA STRUCTURES AND ALGORITHMS.pptxADVANCED DATA STRUCTURES AND ALGORITHMS.pptx
ADVANCED DATA STRUCTURES AND ALGORITHMS.pptx
brajmohan21nitj
 
Data structure and algorithm list structures
Data structure and algorithm list structuresData structure and algorithm list structures
Data structure and algorithm list structures
gangaresearch21
 
Module 4- Arrays and Strings
Module 4- Arrays and StringsModule 4- Arrays and Strings
Module 4- Arrays and Strings
nikshaikh786
 
DATA STRUCTURE AND ALGORITJM POWERPOINT.ppt
DATA STRUCTURE AND ALGORITJM POWERPOINT.pptDATA STRUCTURE AND ALGORITJM POWERPOINT.ppt
DATA STRUCTURE AND ALGORITJM POWERPOINT.ppt
yarotos643
 
Array Presentation
Array PresentationArray Presentation
Array Presentation
Deep Prajapati Microplacer
 
R command cheatsheet.pdf
R command cheatsheet.pdfR command cheatsheet.pdf
R command cheatsheet.pdf
Ngcnh947953
 
data structure programing language in c.ppt
data structure programing language in c.pptdata structure programing language in c.ppt
data structure programing language in c.ppt
LavkushGupta12
 
Short Reference Card for R users.
Short Reference Card for R users.Short Reference Card for R users.
Short Reference Card for R users.
Dr. Volkan OBAN
 
Chyuuuuuuuuuuryyyyyyyyyyy123456789786341.pptx
Chyuuuuuuuuuuryyyyyyyyyyy123456789786341.pptxChyuuuuuuuuuuryyyyyyyyyyy123456789786341.pptx
Chyuuuuuuuuuuryyyyyyyyyyy123456789786341.pptx
RobertCarreonBula
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
KristinaBorooah
 
Arrays in C++ in Tamil - TNSCERT SYLLABUS PPT
Arrays in C++ in Tamil - TNSCERT SYLLABUS PPT Arrays in C++ in Tamil - TNSCERT SYLLABUS PPT
Arrays in C++ in Tamil - TNSCERT SYLLABUS PPT
LATHA LAKSHMI
 
Various Operations Of Array(Data Structure Algorithm).pptx
Various Operations Of Array(Data Structure Algorithm).pptxVarious Operations Of Array(Data Structure Algorithm).pptx
Various Operations Of Array(Data Structure Algorithm).pptx
atirathpal007
 
Svm Presentation
Svm PresentationSvm Presentation
Svm Presentation
shahparin
 
ADVANCED DATA STRUCTURES AND ALGORITHMS.pptx
ADVANCED DATA STRUCTURES AND ALGORITHMS.pptxADVANCED DATA STRUCTURES AND ALGORITHMS.pptx
ADVANCED DATA STRUCTURES AND ALGORITHMS.pptx
brajmohan21nitj
 
Data structure and algorithm list structures
Data structure and algorithm list structuresData structure and algorithm list structures
Data structure and algorithm list structures
gangaresearch21
 
Module 4- Arrays and Strings
Module 4- Arrays and StringsModule 4- Arrays and Strings
Module 4- Arrays and Strings
nikshaikh786
 
DATA STRUCTURE AND ALGORITJM POWERPOINT.ppt
DATA STRUCTURE AND ALGORITJM POWERPOINT.pptDATA STRUCTURE AND ALGORITJM POWERPOINT.ppt
DATA STRUCTURE AND ALGORITJM POWERPOINT.ppt
yarotos643
 

More from snehalkulkarni78 (9)

U5-DataBase_Management_System_123-S1.pptx
U5-DataBase_Management_System_123-S1.pptxU5-DataBase_Management_System_123-S1.pptx
U5-DataBase_Management_System_123-S1.pptx
snehalkulkarni78
 
Mongo_DB_Introduction_detail_STI_123.ppt
Mongo_DB_Introduction_detail_STI_123.pptMongo_DB_Introduction_detail_STI_123.ppt
Mongo_DB_Introduction_detail_STI_123.ppt
snehalkulkarni78
 
Unit IV-infix to postfix and eval.ppt dsa
Unit IV-infix to postfix and eval.ppt dsaUnit IV-infix to postfix and eval.ppt dsa
Unit IV-infix to postfix and eval.ppt dsa
snehalkulkarni78
 
Unit I Recurrence Relations.pptx Fundamentals
Unit I Recurrence Relations.pptx FundamentalsUnit I Recurrence Relations.pptx Fundamentals
Unit I Recurrence Relations.pptx Fundamentals
snehalkulkarni78
 
Hashing_Unit4.pptx Data Structures and Algos
Hashing_Unit4.pptx Data Structures and AlgosHashing_Unit4.pptx Data Structures and Algos
Hashing_Unit4.pptx Data Structures and Algos
snehalkulkarni78
 
hashing1.pptx Data Structures and Algorithms
hashing1.pptx Data Structures and Algorithmshashing1.pptx Data Structures and Algorithms
hashing1.pptx Data Structures and Algorithms
snehalkulkarni78
 
Unit – III.pptx Data Structures and Algorithms
Unit – III.pptx Data Structures and AlgorithmsUnit – III.pptx Data Structures and Algorithms
Unit – III.pptx Data Structures and Algorithms
snehalkulkarni78
 
IP Addressing.ppt Network layer IP addressing
IP Addressing.ppt  Network layer IP addressingIP Addressing.ppt  Network layer IP addressing
IP Addressing.ppt Network layer IP addressing
snehalkulkarni78
 
addressing.pptx Network layer IP addressing
addressing.pptx Network layer IP addressingaddressing.pptx Network layer IP addressing
addressing.pptx Network layer IP addressing
snehalkulkarni78
 
U5-DataBase_Management_System_123-S1.pptx
U5-DataBase_Management_System_123-S1.pptxU5-DataBase_Management_System_123-S1.pptx
U5-DataBase_Management_System_123-S1.pptx
snehalkulkarni78
 
Mongo_DB_Introduction_detail_STI_123.ppt
Mongo_DB_Introduction_detail_STI_123.pptMongo_DB_Introduction_detail_STI_123.ppt
Mongo_DB_Introduction_detail_STI_123.ppt
snehalkulkarni78
 
Unit IV-infix to postfix and eval.ppt dsa
Unit IV-infix to postfix and eval.ppt dsaUnit IV-infix to postfix and eval.ppt dsa
Unit IV-infix to postfix and eval.ppt dsa
snehalkulkarni78
 
Unit I Recurrence Relations.pptx Fundamentals
Unit I Recurrence Relations.pptx FundamentalsUnit I Recurrence Relations.pptx Fundamentals
Unit I Recurrence Relations.pptx Fundamentals
snehalkulkarni78
 
Hashing_Unit4.pptx Data Structures and Algos
Hashing_Unit4.pptx Data Structures and AlgosHashing_Unit4.pptx Data Structures and Algos
Hashing_Unit4.pptx Data Structures and Algos
snehalkulkarni78
 
hashing1.pptx Data Structures and Algorithms
hashing1.pptx Data Structures and Algorithmshashing1.pptx Data Structures and Algorithms
hashing1.pptx Data Structures and Algorithms
snehalkulkarni78
 
Unit – III.pptx Data Structures and Algorithms
Unit – III.pptx Data Structures and AlgorithmsUnit – III.pptx Data Structures and Algorithms
Unit – III.pptx Data Structures and Algorithms
snehalkulkarni78
 
IP Addressing.ppt Network layer IP addressing
IP Addressing.ppt  Network layer IP addressingIP Addressing.ppt  Network layer IP addressing
IP Addressing.ppt Network layer IP addressing
snehalkulkarni78
 
addressing.pptx Network layer IP addressing
addressing.pptx Network layer IP addressingaddressing.pptx Network layer IP addressing
addressing.pptx Network layer IP addressing
snehalkulkarni78
 
Ad

Recently uploaded (20)

2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18
Celine George
 
APM Midlands Region April 2025 Sacha Hind Circulated.pdf
APM Midlands Region April 2025 Sacha Hind Circulated.pdfAPM Midlands Region April 2025 Sacha Hind Circulated.pdf
APM Midlands Region April 2025 Sacha Hind Circulated.pdf
Association for Project Management
 
dynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south Indiadynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south India
PrachiSontakke5
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
Sugar-Sensing Mechanism in plants....pptx
Sugar-Sensing Mechanism in plants....pptxSugar-Sensing Mechanism in plants....pptx
Sugar-Sensing Mechanism in plants....pptx
Dr. Renu Jangid
 
03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.
MCH
 
Engage Donors Through Powerful Storytelling.pdf
Engage Donors Through Powerful Storytelling.pdfEngage Donors Through Powerful Storytelling.pdf
Engage Donors Through Powerful Storytelling.pdf
TechSoup
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
Herbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptxHerbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptx
RAJU THENGE
 
SPRING FESTIVITIES - UK AND USA -
SPRING FESTIVITIES - UK AND USA            -SPRING FESTIVITIES - UK AND USA            -
SPRING FESTIVITIES - UK AND USA -
Colégio Santa Teresinha
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdfBiophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
PKLI-Institute of Nursing and Allied Health Sciences Lahore , Pakistan.
 
Contact Lens:::: An Overview.pptx.: Optometry
Contact Lens:::: An Overview.pptx.: OptometryContact Lens:::: An Overview.pptx.: Optometry
Contact Lens:::: An Overview.pptx.: Optometry
MushahidRaza8
 
Introduction-to-Communication-and-Media-Studies-1736283331.pdf
Introduction-to-Communication-and-Media-Studies-1736283331.pdfIntroduction-to-Communication-and-Media-Studies-1736283331.pdf
Introduction-to-Communication-and-Media-Studies-1736283331.pdf
james5028
 
Grade 3 - English - Printable Worksheet (PDF Format)
Grade 3 - English - Printable Worksheet  (PDF Format)Grade 3 - English - Printable Worksheet  (PDF Format)
Grade 3 - English - Printable Worksheet (PDF Format)
Sritoma Majumder
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18
Celine George
 
dynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south Indiadynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south India
PrachiSontakke5
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
Sugar-Sensing Mechanism in plants....pptx
Sugar-Sensing Mechanism in plants....pptxSugar-Sensing Mechanism in plants....pptx
Sugar-Sensing Mechanism in plants....pptx
Dr. Renu Jangid
 
03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.
MCH
 
Engage Donors Through Powerful Storytelling.pdf
Engage Donors Through Powerful Storytelling.pdfEngage Donors Through Powerful Storytelling.pdf
Engage Donors Through Powerful Storytelling.pdf
TechSoup
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
Herbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptxHerbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptx
RAJU THENGE
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
Contact Lens:::: An Overview.pptx.: Optometry
Contact Lens:::: An Overview.pptx.: OptometryContact Lens:::: An Overview.pptx.: Optometry
Contact Lens:::: An Overview.pptx.: Optometry
MushahidRaza8
 
Introduction-to-Communication-and-Media-Studies-1736283331.pdf
Introduction-to-Communication-and-Media-Studies-1736283331.pdfIntroduction-to-Communication-and-Media-Studies-1736283331.pdf
Introduction-to-Communication-and-Media-Studies-1736283331.pdf
james5028
 
Grade 3 - English - Printable Worksheet (PDF Format)
Grade 3 - English - Printable Worksheet  (PDF Format)Grade 3 - English - Printable Worksheet  (PDF Format)
Grade 3 - English - Printable Worksheet (PDF Format)
Sritoma Majumder
 
Ad

U2.pptx Advanced Data Structures and Algorithms

  • 1. Linear Data Structures Using Sequential Organization
  • 2. Sequential Organization  Sequential organization allows storing data at a fixed distance apart.  If the ith element is stored at location X, then the next sequential (i+1)th element is stored at location X+C, where C is constant.
  • 3. ARRAYS  If we intend to store a group of data together in a sequential manner in computer’s memory, then arrays can be one of the possible data structures.  An array is a finite ordered collection of homogeneous data elements which provides direct access (or random access) to any of its elements.  An array as a data structure is defined as a set of pairs (index, value) such that with each index a value is associated. • index — indicates the location of an element in an array. • value - indicates the actual value of that data element. • Declaration of an array in ‘C++’: int A[20];
  • 4. GENERIC DATA TYPE  Generic Data type is a data type where the operations are defined but the types of the items being manipulated are not
  • 5. ARRAYS AS AN ADT  Formally ADT is a collection of domain, operations, and axioms (or rules)  For defining an array as an ADT, we have to define its very basic operations or functions that can be performed on it  The basic operations of arrays are creation of an array, storing an element, accessing an element, and traversing the array.  Let us specify ADT Array in which we provide specifications with operations to be performed.  ADT ARRAY(Index, Value)  declare CREATE( ) array ACCESS (array, index) value STORE (array, index, value) array for all Array_A ε array, x Î value, and i, j ε index let ACCESS (CREATE, i) = error. ACCESS (STORE (Array_A, i, x), j) = x if EQUAL (i, j) else ACCESS (Array_A, j) end end ARRAY.
  • 6. MEMORY REPRESENTATION & ADDRESS CALCULATION A0 A1 . . . Ai . An-1 a i ai+1 ai+2 : : an-1 X(Base) X+1 X+2 X+(n-1) Array A  The address of the ith element is calculated by the following formula • (Base address) + (offset of the ith element from base address) • Here, base address is the address of the first element where array storage starts.
  • 7.  Arrays support various operations such as traversal, sorting, searching, insertion, deletion, merging, block movement, etc.  Insertion of an element into an array  Deleting an element  Memory Representation of Two-Dimensional Arrays  Row-major Representation  Column-major Representation
  • 8. Columns Col1 col2 .... coln A11 A12 .... A1n A11 A12 .... A1n Am1 Am2 .... Amn : : : m*n Rows R1 R2 Rm 1 2 3 4 5 6 7 8 9 10 11 12 Matrix M =
  • 9. ROW-MAJOR REPRESENTATION  In row-major representation, the elements of Matrix are stored row-wise, i.e., elements of 1st row, 2nd row, 3rd row, and so on till mth row (0,0) (0,1) (0,2) (0,3) (1,0) (1,1) (1,2) (1,3) (2,0) (2,1) (2,2) (2,3) Row1 Row2 Row3 1 2 3 4 5 6 7 8 9 10 11 12
  • 10. ROW MAJOR ARRANGEMENT  Address of A[i][j] = base addr + (col_index * total no. of rows + row_index) element size Row 0 Row 1 Row m-1 Row 0 Row 1 Row m-1 Memory Location Row-major arrangement in memory , in row major representation
  • 11. COLUMN-MAJOR ARRANGEMENT  Address of A[i][j] = base addr + (row_index * total no. of columns + col_index) *element size col1 col2 Col n-1 Col 0 Col 1 Col 2 Memory Location … Column-major arrangement in memory , in column major representation
  • 12. (0,0) (1,0) (2,0) (0,1) (1,1) (2,1) (0,2) (1,2) (2,2) (0,3) (1,3) (2,3) Col 1 Col 2 Col 3 Col 4 1 2 3 4 5 6 7 8 9 10 11 12 Column-Major Representation of 2-D array
  • 16. Three dimensions row-major arrangement (i*m2*m3) elements A[0][m2][m3] A[1][m2][m3] A[i][m2][m3] A[m1-1][m2]
  • 17. ARRAYS USING TEMPLATE  The function is defined in similar way replacing int by T as datatype of member of array  In all member functions header, Array is replaced by Array <T> :: now  Following statements instantiate the template class Array to int and float respectively. So P is array of ints and Q in array of floats. Array <int> P; Array <float> Q;  In similar we can also have array of any user defined data type
  • 18. CONCEPT OF ORDERED LIST  Ordered list is the most common and frequently used data object  Def: it is set of elements where set may be empty or it can be written as collection of elements such as (a1, a2, a3 ………, an)  Linear elements of an ordered list are related with each other in a particular order or sequence  Following are some examples of the ordered list. • 1, 3,5,7,9,11,13,15 • January, February, March, April, May, June, July, August, September, • October, November, December • Red, Blue, Green, Black, Yellow
  • 19.  There are many basic operations that can be performed on the ordered list as follows:  Finding the length of the list  Traverse the list from left to right or from right to left  Access the ith element in the list  Update (Overwrite) the value of the ith position  Insert an element at the ith location  Delete an element at the ith position
  • 21. SINGLE VARIABLE POLYNOMIAL  Representation Using Arrays  Array of Structures  Polynomial Evaluation  Polynomial Addition  Multiplication of Two Polynomials
  • 22.  Polynomial as an ADT, the basic operations are as follows:  Creation of a polynomial  Addition of two polynomials  Subtraction of two polynomials  Multiplication of two polynomials  Polynomial evaluation
  • 25.  STRUCTURE IS BETTER THAN ARRAY FOR POLYNOMIAL:  Such representation by an array is both time and space efficient when polynomial is not a sparse one such as polynomial P(x) of degree 3 where P(x)= 3x3+x2–2x+5.  But when polynomial is sparse such as in worst case a polynomial as A(x)= x99 + 78 for degree of n =100, then only two locations out of 101 would be used.  In such cases it is better to store polynomial as pairs of coefficient and exponent. We may go for two different arrays for each or a structure having two members as two arrays for each of coeff. and Exp or an array of structure that consists of two data members coefficient and exponent.
  • 26. POLYNOMIAL BY USING STRUCTURE  Let us go for structure having two data members coefficient and exponent and its array.
  • 27. AN ARRAY FOR FREQUENCY COUNT We can use array to store the number of times a particular element occurs in any sequence. Such occurrence of particular element is known as frequency count. void Frequency_Count ( int Freq[10 ], int A [ 100]) { int i; for ( i=0;i<10;i++) Freq[i]=0; for ( i=0;i<100;i++) Freq[A[i] ++; }
  • 28. Frequency count of numbers ranging between 0 to 9
  • 29. SPARSE MATRIX In many situations, matrix size is very large but out of it, most of the elements are zeros (not necessarily always zeros). And only a small fraction of the matrix is actually used. A matrix of such type is called a sparse matrix,
  • 31. Sparse matrix and its representation
  • 32. TRANSPOSE OF SPARSE MATRIX  Simple Transpose  Fast Transpose
  • 33. Time complexity of manual technique is O (mn).
  • 35.  Time complexity will be O (n . T) = O (n . mn) = O (mn2 ) which is worst than the conventional transpose with time complexity O (mn) Simple Sparse matrix transpose
  • 36. FAST SPARSE MATRIX TRANSPOSE  In worst case, i.e. T= m × n (non-zero elements) the magnitude becomes O (n +mn) = O (mn) which is the same as 2-D transpose  However the constant factor associated with fast transpose is quite high  When T is sufficiently small, compared to its maximum of m . n, fast transpose will work faster
  • 37. STRING MANIPULATION  Def: String is sequence of characters. The strings are defined with double quotes.  The string is stored in the memory with terminating character ‘0’.  There are various operations that can be performed on the string:  To find the length of a string (strlen)  To concatenate two strings (strcat)  To copy a string (strcpy)  To reverse a string (strrev)  String compare (strcmp, strcmpi)  Palindrome check  To recognize a sub string. (strstr)
  • 38. BASICALLY A STRING IS STORED AS A SEQUENCE OF CHARACTERS IN ONE-DIMENSIONAL CHARACTER ARRAY SAY A. CHAR A[10] ="STRING" ; EACH STRING IS TERMINATED BY A SPECIAL CHARACTER THAT IS NULL CHARACTER ‘0’. THIS NULL CHARACTER INDICATES THE END OR TERMINATION OF EACH STRING.
  • 39. CHARACTERISTICS OF ARRAY  An array is a finite ordered collection of homogeneous data elements.  In array, successive elements of list are stored at a fixed distance apart.  Array is defined as set of pairs-( index and value).  Array allows random access to any element  In array, insertion and deletion of elements in between positions requires data movement.  Array provides static allocation, which means space allocation done once during compile time, can not be changed run time.
  • 40. ADVANTAGE OF ARRAY DATA STRUCTURE  Arrays permit efficient random access in constant time 0(1).  Arrays are most appropriate for storing a fixed amount of data and also for high frequency of data retrievals as data can be accessed directly.  Wherever there is a direct mapping between the elements and there positions, arrays are the most suitable data structures.  Ordered lists such as polynomials are most efficiently handled using arrays.  Arrays are useful to form the basis for several more complex data structures, such as heaps, and hash tables and can be used to represent strings, stacks and queues.
  • 41. DISADVANTAGE OF ARRAY DATA STRUCTURE  Arrays provide static memory management. Hence during execution the size can neither be grown nor shrunk.  Array is inefficient when often data is to inserted or deleted as inserting and deleting an element in array needs a lot of data movement.  Hence array is inefficient for the applications, which very often need insert and delete operations in between.
  • 42. APPLICATIONS OF ARRAYS  Although useful in their own right, arrays also form the basis for several more complex data structures, such as heaps, hash tables and can be used to represent strings, stacks and queues.  All these applications benefit from the compactness and direct access benefits of arrays.  Two-dimensional data when represented as Matrix and matrix operations.