SlideShare a Scribd company logo
Chapter-3
Linear Data Structure - Arrays
MRS.SOWMYA JYOTHI, SDMCBM, MANGALORE
Reference: Data Structures with C by Seymour Lipschutz,
Schaum’s Outlines Series.
INTRODUCTION
• Data structures are classified as either linear or nonlinear.
• A data structure is said to be linear, if its elements form a sequence.
There are two basic ways of representing linear structures in memory.
1. Using arrays.
2. Using linked lists.
• LINEAR ARRAYS
A linear array is a list of a finite number N of homogeneous data elements (i.e.
data elements of the same type) such that:
a) The elements of the array are referred respectively by an index set consisting
of n consecutive numbers
b) The elements of the array are stored respectively in successive memory
locations.
The number n of elements is called the length or size of the array. If not explicitly
stated, we will assume the index set consists of the integers 1, 2, …. N.
In general, the length or the number of data elements of the array can be
obtained from the index set by the formula
Length=UB – LB + 1
Where UB is the largest index, called the upper bound, and LB is the smallest
index, called the lower bound of the array. (Length= UB when LB=1).
The elements of an array A may be denoted by the subscript notation
A1, A2, A3, ….. An
OR by the bracket notation A[1], A[2], A[3], ….. A[n]
The number K in A[K] is called a subscript or an index and A[K] is called
a subscripted variable.
Example
• Let DATA be a 6-element linear array of integers such that DATA[1]=247
DATA[2]=56 DATA[3]=429 DAT[4]=135 DATA[5]=87 DATA[6]=156.
• We will denote such an array by DATA: 247, 56, 429, 135, 87, 156
Problems:
1) Consider the linear array LA(1:10).
Find the number of elements in an array.
Ans: The number of elements is equal to the length; hence the
formula
Length= UB – LB + 1
Length(LA) = 10 – 1 + 1
= 10
2) Consider the linear array AA(5:50), BB(-5:10) and CC(18). Find
the number of elements in each array.
Ans:
Length= UB – LB + 1
a) Length(AA) = 50 – 5 + 1
= 46
b) Length(BB) = 10 – (-5) + 1
= 16
c) Length(CC) = 18 – 1 + 1
= 18
Abstract Data Types (ADT)
• An abstract data type refers to a set of data values and associated
operations that are specified accurately, independent of
implementation.
• With an ADT, it is possible to know what a data type does, but how it
does is hidden.
• An ADT can further be defined as a data declaration packaged
together with the operations that are meaningful for the data. User
may not have the knowledge of data structure.
ARRAY AS ADT
• An array is a fundamental Abstract Data Type. An array is pre-
defined set which has a sequence of cells where we can store
different types of elements.
• Consider the following example: object (A, N). Here an array A is
created which can store N number of items in it.
• A[i] is an item in the array stored in its ith position.
• REPRESENTATION OF LINEAR ARRAYS IN MEMORY
• Let LA be a linear array in the memory of the computer. The notation
LOC(LA[K])=address of the element LA[K] of the array LA.
• Let LA[10]={5, 6, 12, 4, 15, 45, 87, 1, 9, 13} and Base address be 100.
• The elements of linear array LA are stored in successive
memory locations.
• Computer does not need to keep track of the address of
every element of LA, but it needs the base address Base(LA).
• Using the address of Base(LA), the computer calculates the
address of any element of LA by the following formula:
• LOC(LA[K]) = Base(LA) + w(K – Lower Bound)
Where w is number of words per memory cell for the array LA
Problems:
1) Consider the linear array AA(1:10).
Suppose Base(AA)=100 and w=4 words per memory cell
for AA.
Find the address of LA[5].
Ans:
LOC(AA[K]) = Base(AA) + w(K-LB)
LOC(AA[5]) = 100 + 4 (5-1)
= 100 + 16
= 116
2) Consider the linear array AA(5:50).
Suppose Base(AA)=300 and w=4 words per memory cell for AA.
Find the address of a) AA[15], b) AA[35] and c) AA[55].
LOC(AA[K]) = Base(AA) + w(K-LB)
a) LOC(AA[15]) = 300 + 4 (15-5)
= 300 + 40
= 340
b) LOC(AA[35]) = 300 + 4 (35-5)
= 300 + 120
= 420
c) AA[55] is not an element of AA, since 55 exceeds UB=50.
TRAVERSING A LINEAR ARRAY
• Let LA be the collection of data elements stored in the memory of the
computer. Suppose we want to print the contents of each element of
LA or suppose we want to count the number of elements of LA with
each given property.
• This can be accomplished by traversing A, that is, by accessing and
processing each element of the array exactly once is called
traversing.
• Algorithm 4.1: (Traverse a Linear Array) Here LA is a Linear array with
lower boundary LB and upper boundary 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.
[End of Step 2 loop]
5. Exit.
The alternate algorithm for traversing (using for loop) is:
Algorithm 4.1: (Traverse a Linear Array) This algorithm traverse a linear
array LA with lower bound LB and upper bound UB.
1. Repeat for K=LB to UB
Apply PROCESS to LA[K].
[End of loop]
2. Exit.
Problems:
1) Suppose a 5-element array A contains the values {25, 32, 65, 43, 78}.
Find the values of the given arrays after each loop.
a) Repeat for K = 1 to 4:
Set AB[K + 1] := A[K]
[End of loop]
Ans:
First AB[2] := A[1] sets AB[2]=25, the value of A[1]
Then AB[3] := A[2] sets AB[3]=32, the value of A[2]
Then AB[4] := A[3] sets AB[4]=65, the value of A[3]
Then AB[5] := A[4] sets AB[5]=43, the value of A[4]
Suppose a 5-element array A contains the values {25, 32, 65, 43, 78}.
b) Repeat for K = 4 to 1 by -1:
Set A[K + 1] := A[K]
[End of loop]
Ans:
First A[5] := A[4] sets A[5]=78
Then A[4] := A[3] sets A[4]=43
Then A[3] := A[2] sets A[3]=65
Then A[2] := A[1] sets A[2]=32
INSERTING
• Let LA be a collection of data elements in the memory of the
computer.
• “Inserting” refers to the operation of adding another
element to the collection LA.
• Always Insertion is done at the last.
• Suppose an element is to be inserted in the middle of the
array. Then, half of the elements must be moved downwards
to new locations to accommodate the new element and
keep the order of the other elements.
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. the algorithm inserts an element ITEM into Kth position in LA.
1. [Initialize counter] Set J:=N
2. Repeat Steps 3 and 4 while J>=K
3. [Move Jth element downward] Set LA[J+1]:=LA[J]
4. [Decrease the counter] Set J:=J-1.
[End of Step 2 Loop]
5. [Insert the element] Set LA[K]:=ITEM
6. [Reset N] Set N:=N+1
7. Exit
LA[J+1]:=LA[J]
Set J:=J-1.
5 6
4 5
3 4
J
N is Incremented as an
element is added
DELETING
• Let LA be a collection of data elements in the memory of the
computer.
• “Deleting” refers to the operation of removing one of the
elements from LA.
• Deleting an element at the end of an array presents no
difficulties, but deleting an element somewhere in the
middle of the array would require that each subsequent
element be moved one location upward in order to “fill up”
the array.
• The following algorithm deletes the Kth element from the
linear array LA and assigns it to the variable ITEM.
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. The
algorithm deletes Kth element from LA.
1. Set ITEM:=LA[K]
2. Repeat For J=K to N-1
[Move J+1st element upward] Set LA[J]:=LA[J+1]
[End of Loop]
3. [Reset the number N of elements in LA] Set N:=N-1.
4. Exit
LA[J]:=LA[J+1]
3 2
4 3
5 4
6 5
7 6
N is Decremented as an element is removed
REPRESENTATION OF POLYNOMIALS USING ARRAYS
•Sometimes it may be necessary to evaluate several
polynomial expressions to perform basic arithmetic
operations. The polynomial expressions can be stored
in arrays. All the elements of an array has two values
namely coefficient and exponent.
• Once a polynomial is built, it can be used to perform
any arithmetic operations.
• A single dimensional array is used to represent a
single variable polynomial of degree n. the index can
be considered as exponent and the coefficients can be
stored at that particular location.
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
SPARSE MATRIX
• A matrix with a relatively high proportion of zero entries is called
sparse matrix. Two general types of n-square sparse matrices
which occur in various applications are shown below.
1. The matrix where all the entries above the main diagonal are
zeros, non-zero entries may occur below the main diagonal is
called lower triangular matrix.
2. The matrix where all the entries below the main diagonal are
zeros, non-zero entries may occur above the main diagonal is
called upper triangular matrix.
3. The matrix where non-zero entries occur on the diagonal or on
elements immediately above or below the diagonal, is called
tri-diagonal matrix.
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
Ad

More Related Content

What's hot (20)

Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]
Muhammad Hammad Waseem
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Muhammad Hammad Waseem
 
Binary Tree Traversal
Binary Tree TraversalBinary Tree Traversal
Binary Tree Traversal
Dhrumil Panchal
 
Queue ppt
Queue pptQueue ppt
Queue ppt
SouravKumar328
 
Linked List
Linked ListLinked List
Linked List
Ashim Lamichhane
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
shameen khan
 
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
Umesh Kumar
 
Binary search
Binary searchBinary search
Binary search
AparnaKumari31
 
Hashing
HashingHashing
Hashing
Amar Jukuntla
 
sparse matrix in data structure
sparse matrix in data structuresparse matrix in data structure
sparse matrix in data structure
MAHALAKSHMI P
 
Relational model
Relational modelRelational model
Relational model
Dabbal Singh Mahara
 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - Notes
Omprakash Chauhan
 
Data Structures (CS8391)
Data Structures (CS8391)Data Structures (CS8391)
Data Structures (CS8391)
Elavarasi K
 
Unit 1 introduction to data structure
Unit 1   introduction to data structureUnit 1   introduction to data structure
Unit 1 introduction to data structure
kalyanineve
 
Heap sort
Heap sortHeap sort
Heap sort
Mohd Arif
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
Poojith Chowdhary
 
Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
Sowmya Jyothi
 
Binary tree
Binary treeBinary tree
Binary tree
Rajendran
 
Trigger
TriggerTrigger
Trigger
VForce Infotech
 
linked lists in data structures
linked lists in data structureslinked lists in data structures
linked lists in data structures
DurgaDeviCbit
 
Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]
Muhammad Hammad Waseem
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Muhammad Hammad Waseem
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
shameen khan
 
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
Umesh Kumar
 
sparse matrix in data structure
sparse matrix in data structuresparse matrix in data structure
sparse matrix in data structure
MAHALAKSHMI P
 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - Notes
Omprakash Chauhan
 
Data Structures (CS8391)
Data Structures (CS8391)Data Structures (CS8391)
Data Structures (CS8391)
Elavarasi K
 
Unit 1 introduction to data structure
Unit 1   introduction to data structureUnit 1   introduction to data structure
Unit 1 introduction to data structure
kalyanineve
 
Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
Sowmya Jyothi
 
linked lists in data structures
linked lists in data structureslinked lists in data structures
linked lists in data structures
DurgaDeviCbit
 

Similar to BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI (20)

Lecture 3 data structures and algorithms
Lecture 3 data structures and algorithmsLecture 3 data structures and algorithms
Lecture 3 data structures and algorithms
Aakash deep Singhal
 
2. Array in Data Structure
2. Array in Data Structure2. Array in Data Structure
2. Array in Data Structure
Mandeep Singh
 
DSA.pdf
DSA.pdfDSA.pdf
DSA.pdf
AkashSaha75835
 
Arrays Data Structure
Arrays Data StructureArrays Data Structure
Arrays Data Structure
student
 
Arrays
ArraysArrays
Arrays
DebiPrasadSen
 
Data structure using c module 1
Data structure using c module 1Data structure using c module 1
Data structure using c module 1
smruti sarangi
 
arrays1.ppt python programme arrays insertion
arrays1.ppt python programme arrays insertionarrays1.ppt python programme arrays insertion
arrays1.ppt python programme arrays insertion
bushraashraf639
 
2.DS Array
2.DS Array2.DS Array
2.DS Array
Chandan Singh
 
PPT Lecture 2.2.1 onn c++ data structures
PPT Lecture 2.2.1 onn c++ data structuresPPT Lecture 2.2.1 onn c++ data structures
PPT Lecture 2.2.1 onn c++ data structures
midtushar
 
Data structures (Array 1 dimensional).pptx
Data structures (Array 1 dimensional).pptxData structures (Array 1 dimensional).pptx
Data structures (Array 1 dimensional).pptx
itzsomeone50
 
data structure and algorithm Array.pptx btech 2nd year
data structure and algorithm  Array.pptx btech 2nd yeardata structure and algorithm  Array.pptx btech 2nd year
data structure and algorithm Array.pptx btech 2nd year
palhimanshi999
 
Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1
blessyboban92
 
CSE225_LEC3 (1).pptx
CSE225_LEC3 (1).pptxCSE225_LEC3 (1).pptx
CSE225_LEC3 (1).pptx
MamunurRasidAsif
 
cluod.pdf
cluod.pdfcluod.pdf
cluod.pdf
ssuser92d367
 
data structure unit -1_170434dd7400.pptx
data structure unit -1_170434dd7400.pptxdata structure unit -1_170434dd7400.pptx
data structure unit -1_170434dd7400.pptx
coc7987515756
 
Arrays.pptx
Arrays.pptxArrays.pptx
Arrays.pptx
Koteswari Kasireddy
 
Arrays in C.pptx
Arrays in C.pptxArrays in C.pptx
Arrays in C.pptx
HarsimranKaur362773
 
DATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGESTDATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGEST
Swapnil Mishra
 
Unit ii data structure-converted
Unit  ii data structure-convertedUnit  ii data structure-converted
Unit ii data structure-converted
Shri Shankaracharya College, Bhilai,Junwani
 
DS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and EngineeringDS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and Engineering
RAJASEKHARV8
 
Lecture 3 data structures and algorithms
Lecture 3 data structures and algorithmsLecture 3 data structures and algorithms
Lecture 3 data structures and algorithms
Aakash deep Singhal
 
2. Array in Data Structure
2. Array in Data Structure2. Array in Data Structure
2. Array in Data Structure
Mandeep Singh
 
Arrays Data Structure
Arrays Data StructureArrays Data Structure
Arrays Data Structure
student
 
Data structure using c module 1
Data structure using c module 1Data structure using c module 1
Data structure using c module 1
smruti sarangi
 
arrays1.ppt python programme arrays insertion
arrays1.ppt python programme arrays insertionarrays1.ppt python programme arrays insertion
arrays1.ppt python programme arrays insertion
bushraashraf639
 
PPT Lecture 2.2.1 onn c++ data structures
PPT Lecture 2.2.1 onn c++ data structuresPPT Lecture 2.2.1 onn c++ data structures
PPT Lecture 2.2.1 onn c++ data structures
midtushar
 
Data structures (Array 1 dimensional).pptx
Data structures (Array 1 dimensional).pptxData structures (Array 1 dimensional).pptx
Data structures (Array 1 dimensional).pptx
itzsomeone50
 
data structure and algorithm Array.pptx btech 2nd year
data structure and algorithm  Array.pptx btech 2nd yeardata structure and algorithm  Array.pptx btech 2nd year
data structure and algorithm Array.pptx btech 2nd year
palhimanshi999
 
Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1
blessyboban92
 
data structure unit -1_170434dd7400.pptx
data structure unit -1_170434dd7400.pptxdata structure unit -1_170434dd7400.pptx
data structure unit -1_170434dd7400.pptx
coc7987515756
 
DATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGESTDATA 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 EngineeringDS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and Engineering
RAJASEKHARV8
 
Ad

More from Sowmya Jyothi (20)

Functions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothiFunctions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothi
Sowmya Jyothi
 
Strings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothiStrings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothi
Sowmya Jyothi
 
Arrays in c unit iii chapter 1 mrs.sowmya jyothi
Arrays in c unit iii chapter 1 mrs.sowmya jyothiArrays in c unit iii chapter 1 mrs.sowmya jyothi
Arrays in c unit iii chapter 1 mrs.sowmya jyothi
Sowmya Jyothi
 
Bca data structures linked list mrs.sowmya jyothi
Bca data structures linked list mrs.sowmya jyothiBca data structures linked list mrs.sowmya jyothi
Bca data structures linked list mrs.sowmya jyothi
Sowmya Jyothi
 
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHIBCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
Sowmya Jyothi
 
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHIBCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI
Sowmya Jyothi
 
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHIBCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
Sowmya Jyothi
 
HARDWARE AND PC MAINTENANCE -THE COMPLETE PC-MRS SOWMYA JYOTHI REFERENCE-MIKE...
HARDWARE AND PC MAINTENANCE -THE COMPLETE PC-MRS SOWMYA JYOTHI REFERENCE-MIKE...HARDWARE AND PC MAINTENANCE -THE COMPLETE PC-MRS SOWMYA JYOTHI REFERENCE-MIKE...
HARDWARE AND PC MAINTENANCE -THE COMPLETE PC-MRS SOWMYA JYOTHI REFERENCE-MIKE...
Sowmya Jyothi
 
Unit II chapter 4 Loops in C
Unit II chapter 4 Loops in CUnit II chapter 4 Loops in C
Unit II chapter 4 Loops in C
Sowmya Jyothi
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
Sowmya Jyothi
 
Unit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cUnit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in c
Sowmya Jyothi
 
Overview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya JyothiOverview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya Jyothi
Sowmya Jyothi
 
NETWORK AND DATABASE CONCEPTS UNIT 1 CHAPTER 2 MRS.SOWMYA JYOTHI
NETWORK AND DATABASE CONCEPTS UNIT 1 CHAPTER 2 MRS.SOWMYA JYOTHINETWORK AND DATABASE CONCEPTS UNIT 1 CHAPTER 2 MRS.SOWMYA JYOTHI
NETWORK AND DATABASE CONCEPTS UNIT 1 CHAPTER 2 MRS.SOWMYA JYOTHI
Sowmya Jyothi
 
Introduction to computers MRS. SOWMYA JYOTHI
Introduction to computers MRS. SOWMYA JYOTHIIntroduction to computers MRS. SOWMYA JYOTHI
Introduction to computers MRS. SOWMYA JYOTHI
Sowmya Jyothi
 
Introduction to graphics
Introduction to graphicsIntroduction to graphics
Introduction to graphics
Sowmya Jyothi
 
Inter Process Communication PPT
Inter Process Communication PPTInter Process Communication PPT
Inter Process Communication PPT
Sowmya Jyothi
 
Internal representation of file chapter 4 Sowmya Jyothi
Internal representation of file chapter 4 Sowmya JyothiInternal representation of file chapter 4 Sowmya Jyothi
Internal representation of file chapter 4 Sowmya Jyothi
Sowmya Jyothi
 
Buffer cache unix ppt Mrs.Sowmya Jyothi
Buffer cache unix ppt Mrs.Sowmya JyothiBuffer cache unix ppt Mrs.Sowmya Jyothi
Buffer cache unix ppt Mrs.Sowmya Jyothi
Sowmya Jyothi
 
Introduction to the Kernel Chapter 2 Mrs.Sowmya Jyothi
Introduction to the Kernel  Chapter 2 Mrs.Sowmya JyothiIntroduction to the Kernel  Chapter 2 Mrs.Sowmya Jyothi
Introduction to the Kernel Chapter 2 Mrs.Sowmya Jyothi
Sowmya Jyothi
 
Introduction to Unix operating system Chapter 1-PPT Mrs.Sowmya Jyothi
Introduction to Unix operating system Chapter 1-PPT Mrs.Sowmya JyothiIntroduction to Unix operating system Chapter 1-PPT Mrs.Sowmya Jyothi
Introduction to Unix operating system Chapter 1-PPT Mrs.Sowmya Jyothi
Sowmya Jyothi
 
Functions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothiFunctions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothi
Sowmya Jyothi
 
Strings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothiStrings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothi
Sowmya Jyothi
 
Arrays in c unit iii chapter 1 mrs.sowmya jyothi
Arrays in c unit iii chapter 1 mrs.sowmya jyothiArrays in c unit iii chapter 1 mrs.sowmya jyothi
Arrays in c unit iii chapter 1 mrs.sowmya jyothi
Sowmya Jyothi
 
Bca data structures linked list mrs.sowmya jyothi
Bca data structures linked list mrs.sowmya jyothiBca data structures linked list mrs.sowmya jyothi
Bca data structures linked list mrs.sowmya jyothi
Sowmya Jyothi
 
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHIBCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
Sowmya Jyothi
 
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHIBCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI
Sowmya Jyothi
 
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHIBCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
Sowmya Jyothi
 
HARDWARE AND PC MAINTENANCE -THE COMPLETE PC-MRS SOWMYA JYOTHI REFERENCE-MIKE...
HARDWARE AND PC MAINTENANCE -THE COMPLETE PC-MRS SOWMYA JYOTHI REFERENCE-MIKE...HARDWARE AND PC MAINTENANCE -THE COMPLETE PC-MRS SOWMYA JYOTHI REFERENCE-MIKE...
HARDWARE AND PC MAINTENANCE -THE COMPLETE PC-MRS SOWMYA JYOTHI REFERENCE-MIKE...
Sowmya Jyothi
 
Unit II chapter 4 Loops in C
Unit II chapter 4 Loops in CUnit II chapter 4 Loops in C
Unit II chapter 4 Loops in C
Sowmya Jyothi
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
Sowmya Jyothi
 
Unit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cUnit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in c
Sowmya Jyothi
 
Overview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya JyothiOverview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya Jyothi
Sowmya Jyothi
 
NETWORK AND DATABASE CONCEPTS UNIT 1 CHAPTER 2 MRS.SOWMYA JYOTHI
NETWORK AND DATABASE CONCEPTS UNIT 1 CHAPTER 2 MRS.SOWMYA JYOTHINETWORK AND DATABASE CONCEPTS UNIT 1 CHAPTER 2 MRS.SOWMYA JYOTHI
NETWORK AND DATABASE CONCEPTS UNIT 1 CHAPTER 2 MRS.SOWMYA JYOTHI
Sowmya Jyothi
 
Introduction to computers MRS. SOWMYA JYOTHI
Introduction to computers MRS. SOWMYA JYOTHIIntroduction to computers MRS. SOWMYA JYOTHI
Introduction to computers MRS. SOWMYA JYOTHI
Sowmya Jyothi
 
Introduction to graphics
Introduction to graphicsIntroduction to graphics
Introduction to graphics
Sowmya Jyothi
 
Inter Process Communication PPT
Inter Process Communication PPTInter Process Communication PPT
Inter Process Communication PPT
Sowmya Jyothi
 
Internal representation of file chapter 4 Sowmya Jyothi
Internal representation of file chapter 4 Sowmya JyothiInternal representation of file chapter 4 Sowmya Jyothi
Internal representation of file chapter 4 Sowmya Jyothi
Sowmya Jyothi
 
Buffer cache unix ppt Mrs.Sowmya Jyothi
Buffer cache unix ppt Mrs.Sowmya JyothiBuffer cache unix ppt Mrs.Sowmya Jyothi
Buffer cache unix ppt Mrs.Sowmya Jyothi
Sowmya Jyothi
 
Introduction to the Kernel Chapter 2 Mrs.Sowmya Jyothi
Introduction to the Kernel  Chapter 2 Mrs.Sowmya JyothiIntroduction to the Kernel  Chapter 2 Mrs.Sowmya Jyothi
Introduction to the Kernel Chapter 2 Mrs.Sowmya Jyothi
Sowmya Jyothi
 
Introduction to Unix operating system Chapter 1-PPT Mrs.Sowmya Jyothi
Introduction to Unix operating system Chapter 1-PPT Mrs.Sowmya JyothiIntroduction to Unix operating system Chapter 1-PPT Mrs.Sowmya Jyothi
Introduction to Unix operating system Chapter 1-PPT Mrs.Sowmya Jyothi
Sowmya Jyothi
 
Ad

Recently uploaded (20)

U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
Module 1: Foundations of Research
Module 1: Foundations of ResearchModule 1: Foundations of Research
Module 1: Foundations of Research
drroxannekemp
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and GuestsLDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDM & Mia eStudios
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
Search Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo SlidesSearch Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo Slides
Celine George
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
Botany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic ExcellenceBotany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic Excellence
online college homework help
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Association for Project Management
 
Drugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdfDrugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdf
crewot855
 
2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx
mansk2
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...
parmarjuli1412
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)
jemille6
 
Cultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptxCultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptx
UmeshTimilsina1
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
Module 1: Foundations of Research
Module 1: Foundations of ResearchModule 1: Foundations of Research
Module 1: Foundations of Research
drroxannekemp
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and GuestsLDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDM & Mia eStudios
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
Search Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo SlidesSearch Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo Slides
Celine George
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
Botany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic ExcellenceBotany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic Excellence
online college homework help
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Association for Project Management
 
Drugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdfDrugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdf
crewot855
 
2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx
mansk2
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...
parmarjuli1412
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)
jemille6
 
Cultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptxCultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptx
UmeshTimilsina1
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 

BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI

  • 1. Chapter-3 Linear Data Structure - Arrays MRS.SOWMYA JYOTHI, SDMCBM, MANGALORE Reference: Data Structures with C by Seymour Lipschutz, Schaum’s Outlines Series.
  • 2. INTRODUCTION • Data structures are classified as either linear or nonlinear. • A data structure is said to be linear, if its elements form a sequence. There are two basic ways of representing linear structures in memory. 1. Using arrays. 2. Using linked lists.
  • 3. • LINEAR ARRAYS A linear array is a list of a finite number N of homogeneous data elements (i.e. data elements of the same type) such that: a) The elements of the array are referred respectively by an index set consisting of n consecutive numbers b) The elements of the array are stored respectively in successive memory locations. The number n of elements is called the length or size of the array. If not explicitly stated, we will assume the index set consists of the integers 1, 2, …. N. In general, the length or the number of data elements of the array can be obtained from the index set by the formula Length=UB – LB + 1 Where UB is the largest index, called the upper bound, and LB is the smallest index, called the lower bound of the array. (Length= UB when LB=1).
  • 4. The elements of an array A may be denoted by the subscript notation A1, A2, A3, ….. An OR by the bracket notation A[1], A[2], A[3], ….. A[n] The number K in A[K] is called a subscript or an index and A[K] is called a subscripted variable.
  • 5. Example • Let DATA be a 6-element linear array of integers such that DATA[1]=247 DATA[2]=56 DATA[3]=429 DAT[4]=135 DATA[5]=87 DATA[6]=156. • We will denote such an array by DATA: 247, 56, 429, 135, 87, 156
  • 6. Problems: 1) Consider the linear array LA(1:10). Find the number of elements in an array. Ans: The number of elements is equal to the length; hence the formula Length= UB – LB + 1 Length(LA) = 10 – 1 + 1 = 10
  • 7. 2) Consider the linear array AA(5:50), BB(-5:10) and CC(18). Find the number of elements in each array. Ans: Length= UB – LB + 1 a) Length(AA) = 50 – 5 + 1 = 46 b) Length(BB) = 10 – (-5) + 1 = 16 c) Length(CC) = 18 – 1 + 1 = 18
  • 8. Abstract Data Types (ADT) • An abstract data type refers to a set of data values and associated operations that are specified accurately, independent of implementation. • With an ADT, it is possible to know what a data type does, but how it does is hidden. • An ADT can further be defined as a data declaration packaged together with the operations that are meaningful for the data. User may not have the knowledge of data structure.
  • 9. ARRAY AS ADT • An array is a fundamental Abstract Data Type. An array is pre- defined set which has a sequence of cells where we can store different types of elements. • Consider the following example: object (A, N). Here an array A is created which can store N number of items in it. • A[i] is an item in the array stored in its ith position.
  • 10. • REPRESENTATION OF LINEAR ARRAYS IN MEMORY • Let LA be a linear array in the memory of the computer. The notation LOC(LA[K])=address of the element LA[K] of the array LA. • Let LA[10]={5, 6, 12, 4, 15, 45, 87, 1, 9, 13} and Base address be 100.
  • 11. • The elements of linear array LA are stored in successive memory locations. • Computer does not need to keep track of the address of every element of LA, but it needs the base address Base(LA). • Using the address of Base(LA), the computer calculates the address of any element of LA by the following formula: • LOC(LA[K]) = Base(LA) + w(K – Lower Bound) Where w is number of words per memory cell for the array LA
  • 12. Problems: 1) Consider the linear array AA(1:10). Suppose Base(AA)=100 and w=4 words per memory cell for AA. Find the address of LA[5]. Ans: LOC(AA[K]) = Base(AA) + w(K-LB) LOC(AA[5]) = 100 + 4 (5-1) = 100 + 16 = 116
  • 13. 2) Consider the linear array AA(5:50). Suppose Base(AA)=300 and w=4 words per memory cell for AA. Find the address of a) AA[15], b) AA[35] and c) AA[55]. LOC(AA[K]) = Base(AA) + w(K-LB) a) LOC(AA[15]) = 300 + 4 (15-5) = 300 + 40 = 340 b) LOC(AA[35]) = 300 + 4 (35-5) = 300 + 120 = 420 c) AA[55] is not an element of AA, since 55 exceeds UB=50.
  • 14. TRAVERSING A LINEAR ARRAY • Let LA be the collection of data elements stored in the memory of the computer. Suppose we want to print the contents of each element of LA or suppose we want to count the number of elements of LA with each given property. • This can be accomplished by traversing A, that is, by accessing and processing each element of the array exactly once is called traversing.
  • 15. • Algorithm 4.1: (Traverse a Linear Array) Here LA is a Linear array with lower boundary LB and upper boundary 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. [End of Step 2 loop] 5. Exit.
  • 16. The alternate algorithm for traversing (using for loop) is: Algorithm 4.1: (Traverse a Linear Array) This algorithm traverse a linear array LA with lower bound LB and upper bound UB. 1. Repeat for K=LB to UB Apply PROCESS to LA[K]. [End of loop] 2. Exit.
  • 17. Problems: 1) Suppose a 5-element array A contains the values {25, 32, 65, 43, 78}. Find the values of the given arrays after each loop. a) Repeat for K = 1 to 4: Set AB[K + 1] := A[K] [End of loop] Ans: First AB[2] := A[1] sets AB[2]=25, the value of A[1] Then AB[3] := A[2] sets AB[3]=32, the value of A[2] Then AB[4] := A[3] sets AB[4]=65, the value of A[3] Then AB[5] := A[4] sets AB[5]=43, the value of A[4]
  • 18. Suppose a 5-element array A contains the values {25, 32, 65, 43, 78}. b) Repeat for K = 4 to 1 by -1: Set A[K + 1] := A[K] [End of loop] Ans: First A[5] := A[4] sets A[5]=78 Then A[4] := A[3] sets A[4]=43 Then A[3] := A[2] sets A[3]=65 Then A[2] := A[1] sets A[2]=32
  • 19. INSERTING • Let LA be a collection of data elements in the memory of the computer. • “Inserting” refers to the operation of adding another element to the collection LA. • Always Insertion is done at the last. • Suppose an element is to be inserted in the middle of the array. Then, half of the elements must be moved downwards to new locations to accommodate the new element and keep the order of the other elements.
  • 20. 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. the algorithm inserts an element ITEM into Kth position in LA. 1. [Initialize counter] Set J:=N 2. Repeat Steps 3 and 4 while J>=K 3. [Move Jth element downward] Set LA[J+1]:=LA[J] 4. [Decrease the counter] Set J:=J-1. [End of Step 2 Loop] 5. [Insert the element] Set LA[K]:=ITEM 6. [Reset N] Set N:=N+1 7. Exit
  • 21. LA[J+1]:=LA[J] Set J:=J-1. 5 6 4 5 3 4 J N is Incremented as an element is added
  • 22. DELETING • Let LA be a collection of data elements in the memory of the computer. • “Deleting” refers to the operation of removing one of the elements from LA. • Deleting an element at the end of an array presents no difficulties, but deleting an element somewhere in the middle of the array would require that each subsequent element be moved one location upward in order to “fill up” the array. • The following algorithm deletes the Kth element from the linear array LA and assigns it to the variable ITEM.
  • 23. 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. The algorithm deletes Kth element from LA. 1. Set ITEM:=LA[K] 2. Repeat For J=K to N-1 [Move J+1st element upward] Set LA[J]:=LA[J+1] [End of Loop] 3. [Reset the number N of elements in LA] Set N:=N-1. 4. Exit
  • 24. LA[J]:=LA[J+1] 3 2 4 3 5 4 6 5 7 6 N is Decremented as an element is removed
  • 25. REPRESENTATION OF POLYNOMIALS USING ARRAYS •Sometimes it may be necessary to evaluate several polynomial expressions to perform basic arithmetic operations. The polynomial expressions can be stored in arrays. All the elements of an array has two values namely coefficient and exponent. • Once a polynomial is built, it can be used to perform any arithmetic operations. • A single dimensional array is used to represent a single variable polynomial of degree n. the index can be considered as exponent and the coefficients can be stored at that particular location.
  • 28. SPARSE MATRIX • A matrix with a relatively high proportion of zero entries is called sparse matrix. Two general types of n-square sparse matrices which occur in various applications are shown below. 1. The matrix where all the entries above the main diagonal are zeros, non-zero entries may occur below the main diagonal is called lower triangular matrix. 2. The matrix where all the entries below the main diagonal are zeros, non-zero entries may occur above the main diagonal is called upper triangular matrix. 3. The matrix where non-zero entries occur on the diagonal or on elements immediately above or below the diagonal, is called tri-diagonal matrix.
  翻译: