SlideShare a Scribd company logo
3
Most read
5
Most read
7
Most read
Lecture 01: DS & Algorithms:2013 
DATA STRUCTURES & 
ALGORITHMS 
Iftikhar Muhammad 
1 
Iftikhar 1
Lecture 01: DS & Algorithms:2013 
Iftikhar 
Arrays Operations 
• Traversal 
• Inserting 
• Deletion 
• Search 
• Sorting 
2
Lecture 01: DS & Algorithms:2013 
Iftikhar 
Traversal 
• Traversing: 
• In traversing operation, each element of an array is accessed 
exactly once for processing. This is called visiting of the array. 
• To compute the sum of values of each element of an array. 
• Display values of each element of an array. 
• Algorithm: 
• 1. Set k=LB 
• 2. Repeat Step 3 and Step 4 while k<=UB 
• 3. Apply PROCESS to LA[K] 
• 4. Set K=K+1 
• 5. [End of Step 2 loop] 
• 6. Exit 
3
Lecture 01: DS & Algorithms:2013 
Iftikhar 
Traversal Algo 
• Find the Number NUM of years during which 
more than 300 automobiles were sold. 
• 1. Set NUM=0 
• 2. Repeat for K=1932 to 1984 
• 3. If AUTO[K]>300, then: Set NUM=NUM +1. 
• 4. [End of Loop] 
• 5. Return 
4
Lecture 01: DS & Algorithms:2013 
Iftikhar 
Inserting 
• In inserting operation , new data items are added or inserted into 
any location of an empty or filled array. 
• In case of empty array, new values are stored in empty locations. 
• In case of filled array , old values are either replaced by new values 
or pushed backward to make room for new values. 
• It is very easy to insert data at the end of array(Why?). 
• Without disturbing the data of other elements of the array. 
5
Lecture 01: DS & Algorithms:2013 
Iftikhar 
Inserting 
• Algorithm- Inserting value at specified location 
1. Set J=N 
2. Repeat Step 3 and Step 4 while J>=K 
3. Set LA[J+1]=LA[J] 
4. Set J=J-1 
5. [End of Step 2 loop] 
6. Set LA[K]=ITEM 
7. Set N=N+1 
8. Exit 
6
Lecture 01: DS & Algorithms:2013 
Iftikhar 
Deletion 
• Deleting item from a specified Location 
• When the data item is removed from a specified location within an 
array, the items from that location up to the end of array are moved 
one location towards the beginning of the array. 
• Algorithm: 
1. Set ITEM=LA[K] 
2. Repeat for J=K to N-1 
3. Set LA[J]=LA[J+1] 
4. [End of loop] 
5. Set N=N-1 
6. Exit 
7
Lecture 01: DS & Algorithms:2013 
Iftikhar 
Search 
• The Process of finding a specific data item and its location in an 
array is called searching. 
• Successful- If found 
• Terminated- If data item found 
• Unsuccessful 
• Searching Operation in data structures is used for data modification 
together with inserting, deleting and updating. 
• For example , when a data item is to be deleted , it is first searched 
and then deleted, if found. 
• The most commonly used search algorithms are as follows. 
• i. Sequential Search 
• Ii. Binary Search 
8
Lecture 01: DS & Algorithms:2013 
Iftikhar 
Search 
• The sequential search is a slow process and is used for only small lists of data. 
• The Method is not recommended for large amount of data because some more 
efficient methods are available for large and complex searches. 
• Algorithm: Linear Search 
1. SET LOC=-1 
2. INPUT N values into array XYZ 
3. INPUT VAL 
4. Repeat Step 5 For I= 1 TO N 
5. IF VAL = XYZ[I] THEN 
6. LOC=1 
7. Print “value found at location”, LOC 
8. Exit 
9. END IF 
10. If LOC=-1 THEN 
11. PRINT ”Value is not Found” 
12. END IF 
13. EXIT 
9
Lecture 01: DS & Algorithms:2013 
Iftikhar 
Search(Binary Search) 
1. Set BEG=LB, END=UB and MID=INT((BEG+ENG)/2 
2. Repeat Steps 3 and 9 while BEB<=ENG and DATA[MID]!=ITEM 
3. If ITEM<DATA[MID],then 
4. Set END=MID-1 
5. Else 
6. Set BEG=MID+1 
7. END IF 
8. Set MID=INT((BEG+END))/2 
9. END OF LOOP 
10. If DATA[MID]=ITEM, then 
11. Set LOC=MID 
12. Else 
13. Set LOC=NULL 
14. END IF 
15. EXIT 
10

More Related Content

What's hot (20)

PPT
Queue Data Structure
Zidny Nafan
 
PDF
Character Array and String
Tasnima Hamid
 
PPTX
Python strings presentation
VedaGayathri1
 
PPTX
Binary Heap Tree, Data Structure
Anand Ingle
 
PPTX
Stacks IN DATA STRUCTURES
Sowmya Jyothi
 
PPTX
single linked list
Sathasivam Rangasamy
 
PPTX
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Muhammad Hammad Waseem
 
PPT
Stack
srihariyenduri
 
PPTX
Sparse matrix
dincyjain
 
PPT
Strings
Mitali Chugh
 
PPTX
Circular link list.ppt
Tirthika Bandi
 
PDF
Files and streams
Pranali Chaudhari
 
PDF
Searching and Sorting Techniques in Data Structure
Balwant Gorad
 
PPTX
Data Structures (CS8391)
Elavarasi K
 
PPTX
Data Structures in Python
Devashish Kumar
 
PPTX
Arrays in c
Jeeva Nanthini
 
PPT
Data Structure and Algorithms
ManishPrajapati78
 
PDF
linked lists in data structures
DurgaDeviCbit
 
PPT
Arrays searching-sorting
Ajharul Abedeen
 
Queue Data Structure
Zidny Nafan
 
Character Array and String
Tasnima Hamid
 
Python strings presentation
VedaGayathri1
 
Binary Heap Tree, Data Structure
Anand Ingle
 
Stacks IN DATA STRUCTURES
Sowmya Jyothi
 
single linked list
Sathasivam Rangasamy
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Muhammad Hammad Waseem
 
Sparse matrix
dincyjain
 
Strings
Mitali Chugh
 
Circular link list.ppt
Tirthika Bandi
 
Files and streams
Pranali Chaudhari
 
Searching and Sorting Techniques in Data Structure
Balwant Gorad
 
Data Structures (CS8391)
Elavarasi K
 
Data Structures in Python
Devashish Kumar
 
Arrays in c
Jeeva Nanthini
 
Data Structure and Algorithms
ManishPrajapati78
 
linked lists in data structures
DurgaDeviCbit
 
Arrays searching-sorting
Ajharul Abedeen
 

Similar to Array operations (20)

PDF
Data Structures
Prof. Dr. K. Adisesha
 
PPTX
Array Operations.pptxdata structure array indsa
ar0454492
 
PPTX
DS1.pptx
ArifKamal36
 
PPTX
datastructure-201021140600.pptx
ZISAN5
 
PPTX
PPT Lecture 2.2.1 onn c++ data structures
midtushar
 
PPT
4.1 sequentioal search
Krish_ver2
 
PDF
Data-Structure-using-C-Rajesh-Pandey.pdf
mohanaprakasht
 
PPT
Lecture#1(Algorithmic Notations).ppt
MuhammadTalhaAwan1
 
PPT
arrays
Enakshi Chanda
 
PDF
Array linear data_structure_2 (1)
eShikshak
 
PPT
arrays1.ppt python programme arrays insertion
bushraashraf639
 
PDF
Lesson 2.1 array
MLG College of Learning, Inc
 
DOCX
Updated Lab3.docx
AleezaAnjum
 
PDF
DS Complete notes for Computer science and Engineering
RAJASEKHARV8
 
PPT
Array 2
Abbott
 
PPTX
DS Module1 (1).pptx
AnuJoseph95
 
PDF
Data Structure & Algorithms - Operations
babuk110
 
PPT
ds 2-Arrays and its types and operations
kavita20193
 
PPTX
Data structure using c module 1
smruti sarangi
 
PPT
Data Structures Types, Arrays, stacks - MLN.ppt
mlnagaraju77
 
Data Structures
Prof. Dr. K. Adisesha
 
Array Operations.pptxdata structure array indsa
ar0454492
 
DS1.pptx
ArifKamal36
 
datastructure-201021140600.pptx
ZISAN5
 
PPT Lecture 2.2.1 onn c++ data structures
midtushar
 
4.1 sequentioal search
Krish_ver2
 
Data-Structure-using-C-Rajesh-Pandey.pdf
mohanaprakasht
 
Lecture#1(Algorithmic Notations).ppt
MuhammadTalhaAwan1
 
Array linear data_structure_2 (1)
eShikshak
 
arrays1.ppt python programme arrays insertion
bushraashraf639
 
Updated Lab3.docx
AleezaAnjum
 
DS Complete notes for Computer science and Engineering
RAJASEKHARV8
 
Array 2
Abbott
 
DS Module1 (1).pptx
AnuJoseph95
 
Data Structure & Algorithms - Operations
babuk110
 
ds 2-Arrays and its types and operations
kavita20193
 
Data structure using c module 1
smruti sarangi
 
Data Structures Types, Arrays, stacks - MLN.ppt
mlnagaraju77
 
Ad

Recently uploaded (20)

PPTX
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PPTX
QUARTER 1 WEEK 2 PLOT, POV AND CONFLICTS
KynaParas
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PDF
Horarios de distribución de agua en julio
pegazohn1978
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PPTX
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PDF
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
QUARTER 1 WEEK 2 PLOT, POV AND CONFLICTS
KynaParas
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
Horarios de distribución de agua en julio
pegazohn1978
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
Dimensions of Societal Planning in Commonism
StefanMz
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
Ad

Array operations

  • 1. Lecture 01: DS & Algorithms:2013 DATA STRUCTURES & ALGORITHMS Iftikhar Muhammad 1 Iftikhar 1
  • 2. Lecture 01: DS & Algorithms:2013 Iftikhar Arrays Operations • Traversal • Inserting • Deletion • Search • Sorting 2
  • 3. Lecture 01: DS & Algorithms:2013 Iftikhar Traversal • Traversing: • In traversing operation, each element of an array is accessed exactly once for processing. This is called visiting of the array. • To compute the sum of values of each element of an array. • Display values of each element of an array. • Algorithm: • 1. Set k=LB • 2. Repeat Step 3 and Step 4 while k<=UB • 3. Apply PROCESS to LA[K] • 4. Set K=K+1 • 5. [End of Step 2 loop] • 6. Exit 3
  • 4. Lecture 01: DS & Algorithms:2013 Iftikhar Traversal Algo • Find the Number NUM of years during which more than 300 automobiles were sold. • 1. Set NUM=0 • 2. Repeat for K=1932 to 1984 • 3. If AUTO[K]>300, then: Set NUM=NUM +1. • 4. [End of Loop] • 5. Return 4
  • 5. Lecture 01: DS & Algorithms:2013 Iftikhar Inserting • In inserting operation , new data items are added or inserted into any location of an empty or filled array. • In case of empty array, new values are stored in empty locations. • In case of filled array , old values are either replaced by new values or pushed backward to make room for new values. • It is very easy to insert data at the end of array(Why?). • Without disturbing the data of other elements of the array. 5
  • 6. Lecture 01: DS & Algorithms:2013 Iftikhar Inserting • Algorithm- Inserting value at specified location 1. Set J=N 2. Repeat Step 3 and Step 4 while J>=K 3. Set LA[J+1]=LA[J] 4. Set J=J-1 5. [End of Step 2 loop] 6. Set LA[K]=ITEM 7. Set N=N+1 8. Exit 6
  • 7. Lecture 01: DS & Algorithms:2013 Iftikhar Deletion • Deleting item from a specified Location • When the data item is removed from a specified location within an array, the items from that location up to the end of array are moved one location towards the beginning of the array. • Algorithm: 1. Set ITEM=LA[K] 2. Repeat for J=K to N-1 3. Set LA[J]=LA[J+1] 4. [End of loop] 5. Set N=N-1 6. Exit 7
  • 8. Lecture 01: DS & Algorithms:2013 Iftikhar Search • The Process of finding a specific data item and its location in an array is called searching. • Successful- If found • Terminated- If data item found • Unsuccessful • Searching Operation in data structures is used for data modification together with inserting, deleting and updating. • For example , when a data item is to be deleted , it is first searched and then deleted, if found. • The most commonly used search algorithms are as follows. • i. Sequential Search • Ii. Binary Search 8
  • 9. Lecture 01: DS & Algorithms:2013 Iftikhar Search • The sequential search is a slow process and is used for only small lists of data. • The Method is not recommended for large amount of data because some more efficient methods are available for large and complex searches. • Algorithm: Linear Search 1. SET LOC=-1 2. INPUT N values into array XYZ 3. INPUT VAL 4. Repeat Step 5 For I= 1 TO N 5. IF VAL = XYZ[I] THEN 6. LOC=1 7. Print “value found at location”, LOC 8. Exit 9. END IF 10. If LOC=-1 THEN 11. PRINT ”Value is not Found” 12. END IF 13. EXIT 9
  • 10. Lecture 01: DS & Algorithms:2013 Iftikhar Search(Binary Search) 1. Set BEG=LB, END=UB and MID=INT((BEG+ENG)/2 2. Repeat Steps 3 and 9 while BEB<=ENG and DATA[MID]!=ITEM 3. If ITEM<DATA[MID],then 4. Set END=MID-1 5. Else 6. Set BEG=MID+1 7. END IF 8. Set MID=INT((BEG+END))/2 9. END OF LOOP 10. If DATA[MID]=ITEM, then 11. Set LOC=MID 12. Else 13. Set LOC=NULL 14. END IF 15. EXIT 10