SlideShare a Scribd company logo
1 of 66
Array Index
Insert an element at a particular index in an array
Insert a given element at a specific position in an array.
Input
int arr[5] = {10, 20, 30, 40, 50}
Element = 100 position = 2.
Output
{10, 20, 100, 30, 40, 50}
Algorithm
1. Get the element value which needs to
be inserted.
2. Get the position value.
3. Check whether the position value is valid
or not.
4. If it is valid,
Shift all the elements from the last index
to position index by 1 position to the right.
insert the new element in arr[position]
5. Otherwise,
Invalid Position
Remove a specific element from array
Let's write an algorithm to remove a specific element from the array.
Algorithm
1. Find the given element in the given array
and note the index.
2. If the element found,
Shift all the elements from index + 1 by
1 position to the left.
Reduce the array size by 1.
3. Otherwise, print "Element Not Found"
Visual Representation
Let's take an array of 5 elements.
1, 20, 5, 78, 30.
If we remove element 20 from the array, the execution will be,
Implementation Algorithm:
1. Set index value as -1 initially. i.e. index = -1
2. Get key value from the user which needs to be deleted.
3. Search and store the index of a given key
[index will be -1, if the given key is not present in the array]
4. if index not equal to -1
Shift all the elements from index + 1 by 1 position to the left.
5. else
print "Element Not Found"
Searching an element in an array
Search whether the given key is present or not in the array.
Algorithm
1. Iterate the array using the loop.
2. Check whether the given key present in
the array i.e. arr[i] == key.
3. If yes,
print "Search Found".
4. Else
print "Search Not Found".
Search Found:
Search Not Found:
Implementation of Searching an Element:
Array Index---https://www.log2base2.com/data-structures/array/array-data-
structure.html

More Related Content

Similar to DS1.pptx

Searching, Sorting and Complexity analysis in DS.pdf
Searching, Sorting and Complexity analysis in DS.pdfSearching, Sorting and Complexity analysis in DS.pdf
Searching, Sorting and Complexity analysis in DS.pdf
AkshatMehrotra14
 
IN PYTHONCreate your own list of random integers, do not use r.pdf
IN PYTHONCreate your own list of random integers, do not use r.pdfIN PYTHONCreate your own list of random integers, do not use r.pdf
IN PYTHONCreate your own list of random integers, do not use r.pdf
aggarwalenterprisesf
 

Similar to DS1.pptx (20)

search_sort.ppt
search_sort.pptsearch_sort.ppt
search_sort.ppt
 
ARRAY in python and c with examples .pptx
ARRAY  in python and c with examples .pptxARRAY  in python and c with examples .pptx
ARRAY in python and c with examples .pptx
 
Linear and binary search
Linear and binary searchLinear and binary search
Linear and binary search
 
Searching in DSA that follow a dsa searching.pptx
Searching in DSA that follow a dsa searching.pptxSearching in DSA that follow a dsa searching.pptx
Searching in DSA that follow a dsa searching.pptx
 
Binary Search Algorithm.pptx
Binary Search Algorithm.pptxBinary Search Algorithm.pptx
Binary Search Algorithm.pptx
 
1 class linear and Binary search (3).ppt
1 class linear and Binary search (3).ppt1 class linear and Binary search (3).ppt
1 class linear and Binary search (3).ppt
 
Searching, Sorting and Complexity analysis in DS.pdf
Searching, Sorting and Complexity analysis in DS.pdfSearching, Sorting and Complexity analysis in DS.pdf
Searching, Sorting and Complexity analysis in DS.pdf
 
data structures and algorithms Unit 3
data structures and algorithms Unit 3data structures and algorithms Unit 3
data structures and algorithms Unit 3
 
1 D Arrays in C++
1 D Arrays in C++1 D Arrays in C++
1 D Arrays in C++
 
Searching techniques
Searching techniquesSearching techniques
Searching techniques
 
search_sort Search sortSearch sortSearch sortSearch sort
search_sort Search sortSearch sortSearch sortSearch sortsearch_sort Search sortSearch sortSearch sortSearch sort
search_sort Search sortSearch sortSearch sortSearch sort
 
Arrays in Data
Arrays in DataArrays in Data
Arrays in Data
 
seaching internal 2 ppt.pptx
seaching internal 2 ppt.pptxseaching internal 2 ppt.pptx
seaching internal 2 ppt.pptx
 
Dsa – data structure and algorithms searching
Dsa – data structure and algorithms   searchingDsa – data structure and algorithms   searching
Dsa – data structure and algorithms searching
 
Searching techniques
Searching techniquesSearching techniques
Searching techniques
 
PPT.pptx Searching and Sorting Techniques
PPT.pptx Searching and Sorting TechniquesPPT.pptx Searching and Sorting Techniques
PPT.pptx Searching and Sorting Techniques
 
Unit iv(dsc++)
Unit iv(dsc++)Unit iv(dsc++)
Unit iv(dsc++)
 
IN PYTHONCreate your own list of random integers, do not use r.pdf
IN PYTHONCreate your own list of random integers, do not use r.pdfIN PYTHONCreate your own list of random integers, do not use r.pdf
IN PYTHONCreate your own list of random integers, do not use r.pdf
 
C++ Arrays different operations .pdf
C++ Arrays different operations .pdfC++ Arrays different operations .pdf
C++ Arrays different operations .pdf
 
Searching and sorting
Searching  and sortingSearching  and sorting
Searching and sorting
 

More from ArifKamal36 (15)

03-arrays-pointers.ppt
03-arrays-pointers.ppt03-arrays-pointers.ppt
03-arrays-pointers.ppt
 
html-lists-tables.ppt
html-lists-tables.ppthtml-lists-tables.ppt
html-lists-tables.ppt
 
HTMLTables.ppt
HTMLTables.pptHTMLTables.ppt
HTMLTables.ppt
 
Basic-HTML.9526794.powerpoint.pptx
Basic-HTML.9526794.powerpoint.pptxBasic-HTML.9526794.powerpoint.pptx
Basic-HTML.9526794.powerpoint.pptx
 
Lecture 1. Data Structure & Algorithm.pptx
Lecture 1. Data Structure & Algorithm.pptxLecture 1. Data Structure & Algorithm.pptx
Lecture 1. Data Structure & Algorithm.pptx
 
topic11LinkedLists.ppt
topic11LinkedLists.ppttopic11LinkedLists.ppt
topic11LinkedLists.ppt
 
3.ppt
3.ppt3.ppt
3.ppt
 
3.ppt
3.ppt3.ppt
3.ppt
 
2.ppt
2.ppt2.ppt
2.ppt
 
1.ppt
1.ppt1.ppt
1.ppt
 
CH5_Linked List.ppt
CH5_Linked List.pptCH5_Linked List.ppt
CH5_Linked List.ppt
 
Games.ppt
Games.pptGames.ppt
Games.ppt
 
IAT334-Lec01-Intro.pptx
IAT334-Lec01-Intro.pptxIAT334-Lec01-Intro.pptx
IAT334-Lec01-Intro.pptx
 
9916167.ppt
9916167.ppt9916167.ppt
9916167.ppt
 
e3-chap-01.ppt
e3-chap-01.ppte3-chap-01.ppt
e3-chap-01.ppt
 

Recently uploaded

Recently uploaded (20)

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 

DS1.pptx

  • 1.
  • 3. Insert an element at a particular index in an array Insert a given element at a specific position in an array. Input int arr[5] = {10, 20, 30, 40, 50} Element = 100 position = 2. Output {10, 20, 100, 30, 40, 50} Algorithm 1. Get the element value which needs to be inserted. 2. Get the position value. 3. Check whether the position value is valid or not. 4. If it is valid, Shift all the elements from the last index to position index by 1 position to the right. insert the new element in arr[position] 5. Otherwise, Invalid Position
  • 4.
  • 5.
  • 6.
  • 7. Remove a specific element from array Let's write an algorithm to remove a specific element from the array. Algorithm 1. Find the given element in the given array and note the index. 2. If the element found, Shift all the elements from index + 1 by 1 position to the left. Reduce the array size by 1. 3. Otherwise, print "Element Not Found"
  • 8. Visual Representation Let's take an array of 5 elements. 1, 20, 5, 78, 30. If we remove element 20 from the array, the execution will be,
  • 9. Implementation Algorithm: 1. Set index value as -1 initially. i.e. index = -1 2. Get key value from the user which needs to be deleted. 3. Search and store the index of a given key [index will be -1, if the given key is not present in the array] 4. if index not equal to -1 Shift all the elements from index + 1 by 1 position to the left. 5. else print "Element Not Found"
  • 10.
  • 11.
  • 12. Searching an element in an array Search whether the given key is present or not in the array. Algorithm 1. Iterate the array using the loop. 2. Check whether the given key present in the array i.e. arr[i] == key. 3. If yes, print "Search Found". 4. Else print "Search Not Found".
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.