SlideShare una empresa de Scribd logo
1 de 44
Linear and Non-Linear

Data structures are classified as either linear or
non-linear.

Linear- if its elements form a sequence.

Non-linear- if its elements do not form a
sequence. Eg: trees, graphs.

One way to representing linear structures in
memory is storing them in sequential memory
locations. Which is called ARRAYS.
Other way is to have a linera relationship between
the elements represented by means of pointer
or links.
This is called LINKED LISTS.
INSERTING

Consider an array DATA. We want to
insert an element at Kth position in
DATA.

First we will have to move down all the
elements starting from K, one by one.

We start moving, starting from the
bottom.
OPERATIONS PERFORMED

Operations performed on a linear structure are:

Traversal.

Search

Insertion

Deletion

Sorting

Merging.
CRITERIA FOR CHOOSING DATA
STRUCTURES
The criteria of choosing a given data structure
depends on the frequency with which one
performs these operations.
ARRAYS

Easy to traverse, search and sort.

So used for permanent storage of data, that is
not changed often.

A LINEAR ARRAY is a list of a finite number n of
homogeneous data elements such that:

The elements of the array are referenced by an
index set consisting of consecutive numbers.

The elements of the array are stored in
consecutive memory locations.
The number n is called length or size of array.
If not otherwise stated we will assume that the
index set consists of integers 1,2,3,4....n.
The length of array can be obtained by formula:
Length= UB-LB +1
Where UB is the largest index.
And LB is the smallest index.

Each programming language has its own way of
declaring the arrays.

But all languages must provide following 3
things:

Name of the array.

Data type

Index set.
REPRESENTATIONS IN MEMORY

As discussed earlier.

Computer does not keep track of each memory
location.

It only keeps track of the first memory location
of the array called BASE(LA).

Other memory locations are calculated by
formula:

LOC(LA[K])= base (LA) + w(k-lowerbound)

w=number of words per memory cell of array.

Things to note:

The time taken to find each memory location is
same.

Means time taken to find any location in an
array is independent of the length of the array.

Any memory location can be located without
traversing other memory locations.
TRAVERSING

Traversing means visiting each element of the
array exactly once.

Eg: if i want to print all the elements of the array.

Or if i want to count the number of elements of
an array, or if i want to print the elements of
array with certain property.

We can name any of this work as PROCESS
ALGORITHM OF TRAVERSING.
INSERTING AND
DELETING IN AN ARRAY

Let A be an array.

INSERTING refers to the operation of
adding another element in array.

DELETING refers to the operation of
removing one element from array.

Inserting at end is easy, given an extra
memory space at the end.

If inserting at the middle of the array,
then on an average we need to move
half of the elements downwards.

Similarly deleting from the end is quite
easy.

But if deleting from middle of array, on
average we will have to move half of the
elements of the array upwards.

Show by drawing a diagram

Let LA be a linear array with N
elements. We want to insert an element
at Kth position.
1. Set J:=N.
2. Repeat steps 3 and 4 till J >=K
3. Set LA[J+1]:= LA[J]
4. Set J:=J-1
5. Set LA[K]:= ITEM.
6. Set N:=N+1
DELETING

After deleting an element from Kth
position we will have to move each
element one position UP.

Let LA be a linear array with N number
of elements
1. Set ITEM:= LA[K].
2. Repeart for J=K to N-1.
3.Set LA[J] := LA[J+1].
4.Set N:= N-1
BUBBLE SORT

Sorting means rearranging the elements
of array so that they are is
increasing/decreasing order.

Show an eg of sorting.

The concept behind bubble sort is that
suppose A is the array. First we
compare A[1] and A[2]. If A[1] is greater
than A[2] then we interchange the
positions of both, else not.

Then we check A[2] and A[3]. If A[2] is
greater than A[3] then we interchange
their positions, else not.

So on till A[n]. this whole series of
comparison is called ONE PASS.

After completion of Pass 1, the largest
element will be at the end.

Means in Pass 1, N-1 comparisons
have been made.

At the end of pass 1, the largest
element in the list is at its place.

Then we repeat same process for Pass
2. but now the number of comparisons
is N-2.

And so on.

In each pass the number of
comparisons will be decreasing.

We will have total N-1 passes.

Here DATA us ab array with N elements.
1) Repeat steps 2 and 3 for K=1 to N-1.
(for keeping track of number of pass)
2) Set PTR:=1.
3) Repeat while PTR <= N-K(for
number of comparisons)
1) If DATA[PTR] > DATA[PTR-1], then
Interchange DATA[PTR] and
DATA[PTR+1].
1) Set PTR:=PTR+1
4) EXIT.
SEARCHING.

Searching refers to the operation of
finding the location LOC of ITEM in array
DATA, or printing some message that
ITEM does not appear in array.

Successful search: if ITEM is found.

Many different searching algorithms.

Criteria for choosing certain algo is the
way in which info is organized in DATA.

The complexity of searching algo is
measured in terms of number f(n) of
comparison required to find ITEM in
DATA, where DATA contains “n”
elements.
LINEAR SEARCH

Suppose DATA is a linear array with n
elements.

We want to search ITEM in DATA.

First we test whether DATA[1]=ITEM,
then we check whether DATA[2]=ITEM
and so on.

This method which traverses DATA
sequentially to loacate item is called
“linear search” or “sequential search”.

We first insert ITEM to be searched at
DATA[n+1] location, ie, at the last
position of the array.

LOC denotes the location where ITEM
first occurs in DATA.

Means if at the end of algo we get LOC=
n+1, it means the search was
unsuccessful, cause WE have inserted
ITEM at n+1.

The purpose of this initial assignment is
to avoid checking that have we reached
the end of the array or not??
Let DATA be a linear array with N elements
and ITEM is a given item of info. This
algo finds the location LOC of ITEM in
DATA, or sets LOC:=0 if seach is
unsuccessful
ALGO
1.Set DATA[N+1]= item.(insert at end)
2.Set LOC:=1
3.Repeat while DATA[LOC]!= ITEM.(search)
Set LOC:= LOC +1.
1.If LOC= N+1, Then set LOC:=0.
2.Exit.
COMPLEXITY OF LINEAR
SEARCH

Complexity is measured y the number
f(n) of comparisons required to find
ITEM in DATA where DATA contains “n”
elements.

We discuss about AVERAGE CASE and
WORST CASE.

Worst case is if the item doesnot occur
in the array. So in this case algo
requires:

f(n)= n+1 comparisons.

Thus runnign time is proportional to n.
For average case f(n)= (n+1)/2.
BINARY SEARCH

Suppose data in array is sorted in
increasing numerical order.

There is an extremely efficient algo for
this called BINARY SEARCH.

Example of telephone directory.

Suppose following is the array DATA:
DATA[BEG], DATA[BEG+1], DATA[BEG+2],.....,
DATA[END].

Means we have to define a BEG and an END.

During each stage our search is reduced
to a segment of DATA.

The algo compares ITEM with the
middle element DATA[MID] of the
segment, where MID =
int((BEG+END)/2).

INT used because we want an integer
value of MID.

If DATA[MID]= ITEM, then search is
successful, and LOC:=MID.

Otherwise search is narrowed down to a
new segment, which is obtained as:
1. If ITEM< DATA[MID], then ITEM
appears in the left half, so reset END
as:

END= MID-1, and begin search again.
1. If ITEM> DATA[MID], then ITEM
appears in the right half, so reset BEG
as:

BEG= MID+1, and begin search
again.

First we begin with BEG=LB n END=UB.

If the ITEM is found, then it will be found
at the MID.

Let DATA is a sorted array, with lower
bound LB, upper bound UP. ITEM is a
given item of information. The variables
BEG, END and MID are used. Algo finds
location LOC of ITEM in DATA or sets
LOC = NULL.
1. Set BEG=LB, END=UB,
MID=int((BEG+END)/2).
2.Repeat steps 3 and 4 while BEG<=END and
DATA[MID]!=ITEM.
3. If ITEM < DATA[MID], then:

Set END:= MID - 1.

Else

Set BEG= MID + 1.
1. Set MID = int((BEG+END)/2).
1. If DATA[MID] = ITEM, then

Set LOC=MID
Else

Set LOC=NULL.
1.END

When item doesnot appear in DATA, the
algorithm eventually arrives at a position
where BEG=END=MID.
Complexity and
Disadvantages

Complexity is:

f(n)=log 2 n + 1

Limitations of this algo:

Requires array to be sorted.

Which is quite expensive when new
elements are inserted and deleted
frequently.
RECORDS AND RECORD
STRUCTURE

A “record” is a collection of related data
items.

Each data item is called “attribute”.

Record is a collection of data items, but
it differs from linear array.

Array is collection of homogeneous data,
whereas record is a collection of
“nonhomogeneous” data.

We can see a record as “structure” in C.
Memory
representation:Parallel
Array

Record cannot be stored in linear array,
cause of its nonhomogeneousity.

So languages have build in “record
structures”, like structures in C.

Consider a record of Newbord baby
which consists of following:

name(string)

gender(char)

Birthday

Month

Day

Year

Father

Name

age
Mother
 Name
 age

Now data in each array having same
subscript belongs to same record.

These arrays used to store various
attributes of array are called PARALLEL
ARRAYS.
– Name
– Gender
– Month
– Day
– Year
– Father name
– Father age
– Mother name
– Mother age.

Such a record can be saved in a
structure.

Discuss about structures.

Suppose a programming language doest
not have anything like structure to
represent such kind of record.

In such case we ll have to make 9 arrays
as:
MATRICES AND VECTORS
Anything stored in linear array can be said
as Vector.
Anything stored in 2 dimenssional array
can be said as Matrix.
Show some examples of vector and matrix
arithematic.
SPARCE MATRIX.

Matrix with relatively high proportion of
zero entries are called sparse matrices.
4
3 -5
6 3 2
4 2 12 1
4 5 6 56 3
5 2
2 6
6 7
8 9
TRIANGULAR
MATRIX
TRIDIAGONAL
MATRIX
arrays

Más contenido relacionado

La actualidad más candente

Lecture 3 data structures and algorithms
Lecture 3 data structures and algorithmsLecture 3 data structures and algorithms
Lecture 3 data structures and algorithmsAakash deep Singhal
 
Data structure lecture 3
Data structure lecture 3Data structure lecture 3
Data structure lecture 3Kumar
 
Array operations
Array operationsArray operations
Array operationsZAFAR444
 
Set data structure
Set data structure Set data structure
Set data structure Tech_MX
 
Arrays and structures
Arrays and structuresArrays and structures
Arrays and structuresMohd Arif
 
2nd puc computer science chapter 3 data structures 1
2nd puc computer science chapter 3 data structures 12nd puc computer science chapter 3 data structures 1
2nd puc computer science chapter 3 data structures 1Aahwini Esware gowda
 
Array data structure
Array data structureArray data structure
Array data structuremaamir farooq
 
Data structure and its types
Data structure and its typesData structure and its types
Data structure and its typesNavtar Sidhu Brar
 
Data Structure and Algorithms Arrays
Data Structure and Algorithms ArraysData Structure and Algorithms Arrays
Data Structure and Algorithms ArraysManishPrajapati78
 
Data structure lecture 2
Data structure lecture 2Data structure lecture 2
Data structure lecture 2Kumar
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithmsHoang Nguyen
 
Introduction to Data Structure
Introduction to Data Structure Introduction to Data Structure
Introduction to Data Structure Prof Ansari
 
Unit 1 introduction to data structure
Unit 1   introduction to data structureUnit 1   introduction to data structure
Unit 1 introduction to data structurekalyanineve
 
Data structure using c module 3
Data structure using c module 3Data structure using c module 3
Data structure using c module 3smruti sarangi
 

La actualidad más candente (20)

Lecture 3 data structures and algorithms
Lecture 3 data structures and algorithmsLecture 3 data structures and algorithms
Lecture 3 data structures and algorithms
 
2-D array
2-D array2-D array
2-D array
 
Array ppt
Array pptArray ppt
Array ppt
 
Data structure lecture 3
Data structure lecture 3Data structure lecture 3
Data structure lecture 3
 
Array operations
Array operationsArray operations
Array operations
 
Set data structure
Set data structure Set data structure
Set data structure
 
Arrays and structures
Arrays and structuresArrays and structures
Arrays and structures
 
Lecture 2a arrays
Lecture 2a arraysLecture 2a arrays
Lecture 2a arrays
 
Data structure
Data structureData structure
Data structure
 
2nd puc computer science chapter 3 data structures 1
2nd puc computer science chapter 3 data structures 12nd puc computer science chapter 3 data structures 1
2nd puc computer science chapter 3 data structures 1
 
Data Structures (BE)
Data Structures (BE)Data Structures (BE)
Data Structures (BE)
 
Array data structure
Array data structureArray data structure
Array data structure
 
Data structure and its types
Data structure and its typesData structure and its types
Data structure and its types
 
Data Structure and Algorithms Arrays
Data Structure and Algorithms ArraysData Structure and Algorithms Arrays
Data Structure and Algorithms Arrays
 
Data structure lecture 2
Data structure lecture 2Data structure lecture 2
Data structure lecture 2
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 
Introduction to Data Structure
Introduction to Data Structure Introduction to Data Structure
Introduction to Data Structure
 
Unit 1 introduction to data structure
Unit 1   introduction to data structureUnit 1   introduction to data structure
Unit 1 introduction to data structure
 
Data structure using c module 3
Data structure using c module 3Data structure using c module 3
Data structure using c module 3
 
Data structures using c
Data structures using cData structures using c
Data structures using c
 

Destacado

Linear Dynamic Analysis and Seismic Evaluation of RC Building
Linear Dynamic Analysis and Seismic Evaluation of RC BuildingLinear Dynamic Analysis and Seismic Evaluation of RC Building
Linear Dynamic Analysis and Seismic Evaluation of RC BuildingQudsia Wahab, EIT
 
1223989 static pushover analysis
1223989 static pushover analysis1223989 static pushover analysis
1223989 static pushover analysismansoor_yakhchalian
 
3.4 pushover analysis
3.4 pushover analysis3.4 pushover analysis
3.4 pushover analysisNASRIN AFROZ
 
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....Shail Nakum
 
Non linear static pushover analysis
Non linear static pushover analysisNon linear static pushover analysis
Non linear static pushover analysisjeyanthi4
 
The Pushover Analysis from basics - Rahul Leslie
The Pushover Analysis from basics - Rahul LeslieThe Pushover Analysis from basics - Rahul Leslie
The Pushover Analysis from basics - Rahul LeslieRahul Leslie
 
English 9 - Linear vs. Non-Linear Text
English 9 - Linear vs. Non-Linear TextEnglish 9 - Linear vs. Non-Linear Text
English 9 - Linear vs. Non-Linear TextJuan Miguel Palero
 

Destacado (8)

Capstone
CapstoneCapstone
Capstone
 
Linear Dynamic Analysis and Seismic Evaluation of RC Building
Linear Dynamic Analysis and Seismic Evaluation of RC BuildingLinear Dynamic Analysis and Seismic Evaluation of RC Building
Linear Dynamic Analysis and Seismic Evaluation of RC Building
 
1223989 static pushover analysis
1223989 static pushover analysis1223989 static pushover analysis
1223989 static pushover analysis
 
3.4 pushover analysis
3.4 pushover analysis3.4 pushover analysis
3.4 pushover analysis
 
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....
 
Non linear static pushover analysis
Non linear static pushover analysisNon linear static pushover analysis
Non linear static pushover analysis
 
The Pushover Analysis from basics - Rahul Leslie
The Pushover Analysis from basics - Rahul LeslieThe Pushover Analysis from basics - Rahul Leslie
The Pushover Analysis from basics - Rahul Leslie
 
English 9 - Linear vs. Non-Linear Text
English 9 - Linear vs. Non-Linear TextEnglish 9 - Linear vs. Non-Linear Text
English 9 - Linear vs. Non-Linear Text
 

Similar a arrays

Data structure using c module 1
Data structure using c module 1Data structure using c module 1
Data structure using c module 1smruti sarangi
 
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada ReddyDatastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada ReddyMalikireddy Bramhananda Reddy
 
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 EngineeringRAJASEKHARV8
 
Ch 1 intriductions
Ch 1 intriductionsCh 1 intriductions
Ch 1 intriductionsirshad17
 
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 structuresmidtushar
 
advanced searching and sorting.pdf
advanced searching and sorting.pdfadvanced searching and sorting.pdf
advanced searching and sorting.pdfharamaya university
 
Data structure &amp; algorithms introduction
Data structure &amp; algorithms introductionData structure &amp; algorithms introduction
Data structure &amp; algorithms introductionSugandh Wafai
 
DATA STRUCTURE CLASS 12 COMPUTER SCIENCE
DATA STRUCTURE CLASS 12 COMPUTER SCIENCEDATA STRUCTURE CLASS 12 COMPUTER SCIENCE
DATA STRUCTURE CLASS 12 COMPUTER SCIENCEDev Chauhan
 
Data structures arrays
Data structures   arraysData structures   arrays
Data structures arraysmaamir farooq
 
DATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGESTDATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGESTSwapnil Mishra
 
data structures and algorithms Unit 3
data structures and algorithms Unit 3data structures and algorithms Unit 3
data structures and algorithms Unit 3infanciaj
 
DSA UNIT II ARRAY AND LIST - notes
DSA UNIT II ARRAY AND LIST - notesDSA UNIT II ARRAY AND LIST - notes
DSA UNIT II ARRAY AND LIST - notesswathirajstar
 
linked list (c#)
 linked list (c#) linked list (c#)
linked list (c#)swajahatr
 

Similar a arrays (20)

Data structure using c module 1
Data structure using c module 1Data structure using c module 1
Data structure using c module 1
 
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada ReddyDatastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
 
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
 
lect 2-DS ALGO(online).pdf
lect 2-DS  ALGO(online).pdflect 2-DS  ALGO(online).pdf
lect 2-DS ALGO(online).pdf
 
Ch 1 intriductions
Ch 1 intriductionsCh 1 intriductions
Ch 1 intriductions
 
arrays in c
arrays in carrays in c
arrays in c
 
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
 
Data Structure
Data StructureData Structure
Data Structure
 
advanced searching and sorting.pdf
advanced searching and sorting.pdfadvanced searching and sorting.pdf
advanced searching and sorting.pdf
 
Chap10
Chap10Chap10
Chap10
 
cluod.pdf
cluod.pdfcluod.pdf
cluod.pdf
 
Data structure &amp; algorithms introduction
Data structure &amp; algorithms introductionData structure &amp; algorithms introduction
Data structure &amp; algorithms introduction
 
DATA STRUCTURE CLASS 12 COMPUTER SCIENCE
DATA STRUCTURE CLASS 12 COMPUTER SCIENCEDATA STRUCTURE CLASS 12 COMPUTER SCIENCE
DATA STRUCTURE CLASS 12 COMPUTER SCIENCE
 
General Data structures
General Data structuresGeneral Data structures
General Data structures
 
Data structures arrays
Data structures   arraysData structures   arrays
Data structures arrays
 
DATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGESTDATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGEST
 
data structures and algorithms Unit 3
data structures and algorithms Unit 3data structures and algorithms Unit 3
data structures and algorithms Unit 3
 
DSA UNIT II ARRAY AND LIST - notes
DSA UNIT II ARRAY AND LIST - notesDSA UNIT II ARRAY AND LIST - notes
DSA UNIT II ARRAY AND LIST - notes
 
linked list (c#)
 linked list (c#) linked list (c#)
linked list (c#)
 
Arrays in C.pptx
Arrays in C.pptxArrays in C.pptx
Arrays in C.pptx
 

Último

Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 

Último (20)

Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 

arrays

  • 1. Linear and Non-Linear  Data structures are classified as either linear or non-linear.  Linear- if its elements form a sequence.  Non-linear- if its elements do not form a sequence. Eg: trees, graphs.  One way to representing linear structures in memory is storing them in sequential memory locations. Which is called ARRAYS.
  • 2. Other way is to have a linera relationship between the elements represented by means of pointer or links. This is called LINKED LISTS.
  • 3. INSERTING  Consider an array DATA. We want to insert an element at Kth position in DATA.  First we will have to move down all the elements starting from K, one by one.  We start moving, starting from the bottom.
  • 4. OPERATIONS PERFORMED  Operations performed on a linear structure are:  Traversal.  Search  Insertion  Deletion  Sorting  Merging.
  • 5. CRITERIA FOR CHOOSING DATA STRUCTURES The criteria of choosing a given data structure depends on the frequency with which one performs these operations.
  • 6. ARRAYS  Easy to traverse, search and sort.  So used for permanent storage of data, that is not changed often.  A LINEAR ARRAY is a list of a finite number n of homogeneous data elements such that:  The elements of the array are referenced by an index set consisting of consecutive numbers.  The elements of the array are stored in consecutive memory locations.
  • 7. The number n is called length or size of array. If not otherwise stated we will assume that the index set consists of integers 1,2,3,4....n. The length of array can be obtained by formula: Length= UB-LB +1 Where UB is the largest index. And LB is the smallest index.
  • 8.  Each programming language has its own way of declaring the arrays.  But all languages must provide following 3 things:  Name of the array.  Data type  Index set.
  • 9. REPRESENTATIONS IN MEMORY  As discussed earlier.  Computer does not keep track of each memory location.  It only keeps track of the first memory location of the array called BASE(LA).  Other memory locations are calculated by formula:  LOC(LA[K])= base (LA) + w(k-lowerbound)  w=number of words per memory cell of array.
  • 10.  Things to note:  The time taken to find each memory location is same.  Means time taken to find any location in an array is independent of the length of the array.  Any memory location can be located without traversing other memory locations.
  • 11. TRAVERSING  Traversing means visiting each element of the array exactly once.  Eg: if i want to print all the elements of the array.  Or if i want to count the number of elements of an array, or if i want to print the elements of array with certain property.  We can name any of this work as PROCESS
  • 13. INSERTING AND DELETING IN AN ARRAY  Let A be an array.  INSERTING refers to the operation of adding another element in array.  DELETING refers to the operation of removing one element from array.  Inserting at end is easy, given an extra memory space at the end.  If inserting at the middle of the array, then on an average we need to move half of the elements downwards.
  • 14.  Similarly deleting from the end is quite easy.  But if deleting from middle of array, on average we will have to move half of the elements of the array upwards.  Show by drawing a diagram
  • 15.  Let LA be a linear array with N elements. We want to insert an element at Kth position. 1. Set J:=N. 2. Repeat steps 3 and 4 till J >=K 3. Set LA[J+1]:= LA[J] 4. Set J:=J-1 5. Set LA[K]:= ITEM. 6. Set N:=N+1
  • 16. DELETING  After deleting an element from Kth position we will have to move each element one position UP.  Let LA be a linear array with N number of elements 1. Set ITEM:= LA[K]. 2. Repeart for J=K to N-1. 3.Set LA[J] := LA[J+1]. 4.Set N:= N-1
  • 17. BUBBLE SORT  Sorting means rearranging the elements of array so that they are is increasing/decreasing order.  Show an eg of sorting.  The concept behind bubble sort is that suppose A is the array. First we compare A[1] and A[2]. If A[1] is greater than A[2] then we interchange the positions of both, else not.
  • 18.  Then we check A[2] and A[3]. If A[2] is greater than A[3] then we interchange their positions, else not.  So on till A[n]. this whole series of comparison is called ONE PASS.  After completion of Pass 1, the largest element will be at the end.  Means in Pass 1, N-1 comparisons have been made.
  • 19.  At the end of pass 1, the largest element in the list is at its place.  Then we repeat same process for Pass 2. but now the number of comparisons is N-2.  And so on.  In each pass the number of comparisons will be decreasing.  We will have total N-1 passes.
  • 20.  Here DATA us ab array with N elements. 1) Repeat steps 2 and 3 for K=1 to N-1. (for keeping track of number of pass) 2) Set PTR:=1. 3) Repeat while PTR <= N-K(for number of comparisons) 1) If DATA[PTR] > DATA[PTR-1], then Interchange DATA[PTR] and DATA[PTR+1]. 1) Set PTR:=PTR+1 4) EXIT.
  • 21. SEARCHING.  Searching refers to the operation of finding the location LOC of ITEM in array DATA, or printing some message that ITEM does not appear in array.  Successful search: if ITEM is found.  Many different searching algorithms.  Criteria for choosing certain algo is the way in which info is organized in DATA.
  • 22.  The complexity of searching algo is measured in terms of number f(n) of comparison required to find ITEM in DATA, where DATA contains “n” elements.
  • 23. LINEAR SEARCH  Suppose DATA is a linear array with n elements.  We want to search ITEM in DATA.  First we test whether DATA[1]=ITEM, then we check whether DATA[2]=ITEM and so on.  This method which traverses DATA sequentially to loacate item is called “linear search” or “sequential search”.
  • 24.  We first insert ITEM to be searched at DATA[n+1] location, ie, at the last position of the array.  LOC denotes the location where ITEM first occurs in DATA.  Means if at the end of algo we get LOC= n+1, it means the search was unsuccessful, cause WE have inserted ITEM at n+1.
  • 25.  The purpose of this initial assignment is to avoid checking that have we reached the end of the array or not?? Let DATA be a linear array with N elements and ITEM is a given item of info. This algo finds the location LOC of ITEM in DATA, or sets LOC:=0 if seach is unsuccessful
  • 26. ALGO 1.Set DATA[N+1]= item.(insert at end) 2.Set LOC:=1 3.Repeat while DATA[LOC]!= ITEM.(search) Set LOC:= LOC +1. 1.If LOC= N+1, Then set LOC:=0. 2.Exit.
  • 27. COMPLEXITY OF LINEAR SEARCH  Complexity is measured y the number f(n) of comparisons required to find ITEM in DATA where DATA contains “n” elements.  We discuss about AVERAGE CASE and WORST CASE.  Worst case is if the item doesnot occur in the array. So in this case algo requires:  f(n)= n+1 comparisons.  Thus runnign time is proportional to n.
  • 28. For average case f(n)= (n+1)/2.
  • 29. BINARY SEARCH  Suppose data in array is sorted in increasing numerical order.  There is an extremely efficient algo for this called BINARY SEARCH.  Example of telephone directory.  Suppose following is the array DATA: DATA[BEG], DATA[BEG+1], DATA[BEG+2],....., DATA[END].  Means we have to define a BEG and an END.
  • 30.  During each stage our search is reduced to a segment of DATA.  The algo compares ITEM with the middle element DATA[MID] of the segment, where MID = int((BEG+END)/2).  INT used because we want an integer value of MID.  If DATA[MID]= ITEM, then search is successful, and LOC:=MID.
  • 31.  Otherwise search is narrowed down to a new segment, which is obtained as: 1. If ITEM< DATA[MID], then ITEM appears in the left half, so reset END as:  END= MID-1, and begin search again. 1. If ITEM> DATA[MID], then ITEM appears in the right half, so reset BEG as:  BEG= MID+1, and begin search again.  First we begin with BEG=LB n END=UB.
  • 32.  If the ITEM is found, then it will be found at the MID.  Let DATA is a sorted array, with lower bound LB, upper bound UP. ITEM is a given item of information. The variables BEG, END and MID are used. Algo finds location LOC of ITEM in DATA or sets LOC = NULL.
  • 33. 1. Set BEG=LB, END=UB, MID=int((BEG+END)/2). 2.Repeat steps 3 and 4 while BEG<=END and DATA[MID]!=ITEM. 3. If ITEM < DATA[MID], then:  Set END:= MID - 1.  Else  Set BEG= MID + 1. 1. Set MID = int((BEG+END)/2).
  • 34. 1. If DATA[MID] = ITEM, then  Set LOC=MID Else  Set LOC=NULL. 1.END  When item doesnot appear in DATA, the algorithm eventually arrives at a position where BEG=END=MID.
  • 35. Complexity and Disadvantages  Complexity is:  f(n)=log 2 n + 1  Limitations of this algo:  Requires array to be sorted.  Which is quite expensive when new elements are inserted and deleted frequently.
  • 36. RECORDS AND RECORD STRUCTURE  A “record” is a collection of related data items.  Each data item is called “attribute”.  Record is a collection of data items, but it differs from linear array.  Array is collection of homogeneous data, whereas record is a collection of “nonhomogeneous” data.  We can see a record as “structure” in C.
  • 37. Memory representation:Parallel Array  Record cannot be stored in linear array, cause of its nonhomogeneousity.  So languages have build in “record structures”, like structures in C.  Consider a record of Newbord baby which consists of following:
  • 39.  Now data in each array having same subscript belongs to same record.  These arrays used to store various attributes of array are called PARALLEL ARRAYS.
  • 40. – Name – Gender – Month – Day – Year – Father name – Father age – Mother name – Mother age.
  • 41.  Such a record can be saved in a structure.  Discuss about structures.  Suppose a programming language doest not have anything like structure to represent such kind of record.  In such case we ll have to make 9 arrays as:
  • 42. MATRICES AND VECTORS Anything stored in linear array can be said as Vector. Anything stored in 2 dimenssional array can be said as Matrix. Show some examples of vector and matrix arithematic.
  • 43. SPARCE MATRIX.  Matrix with relatively high proportion of zero entries are called sparse matrices. 4 3 -5 6 3 2 4 2 12 1 4 5 6 56 3 5 2 2 6 6 7 8 9 TRIANGULAR MATRIX TRIDIAGONAL MATRIX