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

PPTX
Data structure by Digvijay
PPTX
Linear and Binary search .pptx
PPTX
Linked List
PDF
PPTX
C Programming: Structure and Union
PPTX
2D Array
PPT
C++ Arrays
Data structure by Digvijay
Linear and Binary search .pptx
Linked List
C Programming: Structure and Union
2D Array
C++ Arrays

What's hot (20)

PPSX
PPTX
queue & its applications
PPT
PDF
Datatypes in python
PPTX
Data Structures - Lecture 9 [Stack & Queue using Linked List]
PPTX
Stack Data Structure
PPTX
Priority Queue in Data Structure
PPTX
Two dimensional arrays
PPTX
Chapter 17 Tuples
PPTX
Recursion
PPTX
Multi ways trees
PPTX
Stack using Linked List
PPTX
Hashing Technique In Data Structures
PPSX
Data Structure (Queue)
PDF
Arrays in python
PPT
Stacks
PPT
PPTX
Pointer in c program
PPTX
Priority queue in DSA
PDF
Singly linked list
queue & its applications
Datatypes in python
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Stack Data Structure
Priority Queue in Data Structure
Two dimensional arrays
Chapter 17 Tuples
Recursion
Multi ways trees
Stack using Linked List
Hashing Technique In Data Structures
Data Structure (Queue)
Arrays in python
Stacks
Pointer in c program
Priority queue in DSA
Singly linked list
Ad

Similar to Array operations (20)

PPT
Array 2
PPTX
9.Sorting & Searching
PPTX
Sorting and hashing concepts
PPTX
Sorting and hashing concepts
PPTX
PPT Lecture 2.2.1 onn c++ data structures
PPTX
sorting-160810203705.pptx
PPTX
PPTX
2. Array in Data Structure
DOCX
Updated Lab3.docx
PPTX
Algorithms and Data Structures for Sorting Numerical Data
PPT
ds 2-Arrays and its types and operations
PPTX
Chapter 2. data structure and algorithm
PPTX
Searching and sorting Techniques in Data structures
PDF
Quick sort,bubble sort,heap sort and merge sort
PDF
DSA Lec 5+6(Search+Sort) (1).pdf
PPT
Data Structures 6
PPTX
Ist year Msc,2nd sem module1
PPTX
Unit 5 dsuc
PPTX
data_structure_Chapter two_computer.pptx
PDF
jn;lm;lkm';m';;lmppt of data structure.pdf
Array 2
9.Sorting & Searching
Sorting and hashing concepts
Sorting and hashing concepts
PPT Lecture 2.2.1 onn c++ data structures
sorting-160810203705.pptx
2. Array in Data Structure
Updated Lab3.docx
Algorithms and Data Structures for Sorting Numerical Data
ds 2-Arrays and its types and operations
Chapter 2. data structure and algorithm
Searching and sorting Techniques in Data structures
Quick sort,bubble sort,heap sort and merge sort
DSA Lec 5+6(Search+Sort) (1).pdf
Data Structures 6
Ist year Msc,2nd sem module1
Unit 5 dsuc
data_structure_Chapter two_computer.pptx
jn;lm;lkm';m';;lmppt of data structure.pdf
Ad

Recently uploaded (20)

PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PPTX
Cell Structure & Organelles in detailed.
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Computing-Curriculum for Schools in Ghana
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
master seminar digital applications in india
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
102 student loan defaulters named and shamed – Is someone you know on the list?
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Cell Structure & Organelles in detailed.
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Computing-Curriculum for Schools in Ghana
human mycosis Human fungal infections are called human mycosis..pptx
Anesthesia in Laparoscopic Surgery in India
Chinmaya Tiranga quiz Grand Finale.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Final Presentation General Medicine 03-08-2024.pptx
Microbial disease of the cardiovascular and lymphatic systems
202450812 BayCHI UCSC-SV 20250812 v17.pptx
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
master seminar digital applications in india
Abdominal Access Techniques with Prof. Dr. R K Mishra
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
VCE English Exam - Section C Student Revision Booklet
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student

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