SlideShare a Scribd company logo
1 of 10
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

Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
Nikhil Sharma
 

What's hot (20)

Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
 
Queue ppt
Queue pptQueue ppt
Queue ppt
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
 
Heap sort
Heap sortHeap sort
Heap sort
 
Sparse matrix and its representation data structure
Sparse matrix and its representation data structureSparse matrix and its representation data structure
Sparse matrix and its representation data structure
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 
Python : Data Types
Python : Data TypesPython : Data Types
Python : Data Types
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
 
trees in data structure
trees in data structure trees in data structure
trees in data structure
 
Searching
SearchingSearching
Searching
 
Python: Modules and Packages
Python: Modules and PackagesPython: Modules and Packages
Python: Modules and Packages
 
Tuple in python
Tuple in pythonTuple in python
Tuple in python
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Python programming : Arrays
Python programming : ArraysPython programming : Arrays
Python programming : Arrays
 
stack & queue
stack & queuestack & queue
stack & queue
 
Quick sort
Quick sortQuick sort
Quick sort
 
Stack
StackStack
Stack
 
Circular link list.ppt
Circular link list.pptCircular link list.ppt
Circular link list.ppt
 
Best,worst,average case .17581556 045
Best,worst,average case .17581556 045Best,worst,average case .17581556 045
Best,worst,average case .17581556 045
 

Similar to Array operations

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
 
jn;lm;lkm';m';;lmppt of data structure.pdf
jn;lm;lkm';m';;lmppt of data structure.pdfjn;lm;lkm';m';;lmppt of data structure.pdf
jn;lm;lkm';m';;lmppt of data structure.pdf
VinayNassa3
 

Similar to Array operations (20)

Array 2
Array 2Array 2
Array 2
 
9.Sorting & Searching
9.Sorting & Searching9.Sorting & Searching
9.Sorting & Searching
 
Sorting and hashing concepts
Sorting and hashing conceptsSorting and hashing concepts
Sorting and hashing concepts
 
Sorting and hashing concepts
Sorting and hashing conceptsSorting and hashing concepts
Sorting and hashing concepts
 
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
 
sorting-160810203705.pptx
sorting-160810203705.pptxsorting-160810203705.pptx
sorting-160810203705.pptx
 
Array
ArrayArray
Array
 
2. Array in Data Structure
2. Array in Data Structure2. Array in Data Structure
2. Array in Data Structure
 
Updated Lab3.docx
Updated Lab3.docxUpdated Lab3.docx
Updated Lab3.docx
 
Searching and sorting Techniques in Data structures
Searching and sorting Techniques in Data structuresSearching and sorting Techniques in Data structures
Searching and sorting Techniques in Data structures
 
DSA Lec 5+6(Search+Sort) (1).pdf
DSA Lec 5+6(Search+Sort) (1).pdfDSA Lec 5+6(Search+Sort) (1).pdf
DSA Lec 5+6(Search+Sort) (1).pdf
 
Data Structures 6
Data Structures 6Data Structures 6
Data Structures 6
 
Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1
 
Unit 5 dsuc
Unit 5 dsucUnit 5 dsuc
Unit 5 dsuc
 
data_structure_Chapter two_computer.pptx
data_structure_Chapter two_computer.pptxdata_structure_Chapter two_computer.pptx
data_structure_Chapter two_computer.pptx
 
Iare ds ppt_3
Iare ds ppt_3Iare ds ppt_3
Iare ds ppt_3
 
jn;lm;lkm';m';;lmppt of data structure.pdf
jn;lm;lkm';m';;lmppt of data structure.pdfjn;lm;lkm';m';;lmppt of data structure.pdf
jn;lm;lkm';m';;lmppt of data structure.pdf
 
introduction to data structures and types
introduction to data structures and typesintroduction to data structures and types
introduction to data structures and types
 
Unit 8 searching and hashing
Unit   8 searching and hashingUnit   8 searching and hashing
Unit 8 searching and hashing
 
Unit 7 sorting
Unit 7   sortingUnit 7   sorting
Unit 7 sorting
 

Recently uploaded

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 

Recently uploaded (20)

Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
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
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 

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