SlideShare a Scribd company logo
1 of 8
   The selection sort is a combination of searching
    and sorting.
   In selection sort, sorting is done after selecting a
    particular smallest or largest element from an
    array and shifted it to a particular location in an
    array.
   During each pass, the unsorted element with the
    smallest (or largest) value is moved to its proper
    position in the array.
   Let's look at our same table of elements using a
    selection sort for ascending order:
Array     40     50         60         10             30         20

       1-pass   10     50         60         40             30         20
       2-pass 10        20         60         40             30         50

        3-pass 10       20         30             40         60         50

          4-pass 10          20         30         40             60         50

           5-pass 10         20         30             40         50         60
   The number of times the sort passes through the
    array is one less than the number of items in the
    array.
   In the selection sort, the inner loop finds the next
    smallest (or largest) value and the outer loop
    places that value into its proper location.
   Lets watch a video which will give you a basic idea
    of a selection sort.
   Please co-operate.
   Lets look at coding of it in c++:
   #include<iostream>
   using namespace std;
   void selectionsort(int *array,int length)
   {
       int i,j,min,minat,temp;
       for(i=0;i<(length-1);i++)
       {
                  minat=i;
                  min=array[i];
                  for(j=0;j<length;j++)
                  {
                            if(min>array[j])
                            {
                                     minat=j;
                                     min=array[j];
                            }
                  }
       temp=array[i];
       array[i]=array[minat];
       array[minat]=temp;
       }
   }
   void printelements(int *array,int length)
   {
     int i;
     for(i=0;i<length;i++)
            cout<<array[i]<<” “<<;
   }
   int main()
   {
       int array[100],n,i;
       cout<<”enter number of element you wants to enter in an array”;
       cin>>n;
       if(n<0)
       {
                cout<<”enter proper positive element”;
                cin>>n;
       }
       for(i=0;i<n;i++)
       {
                cout<<”enter values in array”;
                cin>>array[i];
       }
       selectionsort(array,n);
       printelement(array,n);
       return 0;
   }
   Any query?
   Any question or any point which you doesn’t get?
Selection sort

More Related Content

What's hot

What's hot (20)

Presentation on the topic selection sort
Presentation on the topic selection sortPresentation on the topic selection sort
Presentation on the topic selection sort
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stack
 
Linear and Binary search
Linear and Binary searchLinear and Binary search
Linear and Binary search
 
Sorting
SortingSorting
Sorting
 
Data Structures - Lecture 8 [Sorting Algorithms]
Data Structures - Lecture 8 [Sorting Algorithms]Data Structures - Lecture 8 [Sorting Algorithms]
Data Structures - Lecture 8 [Sorting Algorithms]
 
Stacks in c++
Stacks in c++Stacks in c++
Stacks in c++
 
Insertion sort
Insertion sortInsertion sort
Insertion sort
 
Data Structures- Part5 recursion
Data Structures- Part5 recursionData Structures- Part5 recursion
Data Structures- Part5 recursion
 
Sorting Techniques
Sorting TechniquesSorting Techniques
Sorting Techniques
 
sparse matrix in data structure
sparse matrix in data structuresparse matrix in data structure
sparse matrix in data structure
 
Queues
QueuesQueues
Queues
 
Recursion - Algorithms and Data Structures
Recursion - Algorithms and Data StructuresRecursion - Algorithms and Data Structures
Recursion - Algorithms and Data Structures
 
Selection sort
Selection sortSelection sort
Selection sort
 
Arrays in python
Arrays in pythonArrays in python
Arrays in python
 
Insertion sort
Insertion sortInsertion sort
Insertion sort
 
Insertion sort algorithm power point presentation
Insertion  sort algorithm power point presentation Insertion  sort algorithm power point presentation
Insertion sort algorithm power point presentation
 
Recursion
RecursionRecursion
Recursion
 
Binary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsBinary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of Algorithms
 
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
 
Set methods in python
Set methods in pythonSet methods in python
Set methods in python
 

Viewers also liked

Viewers also liked (20)

Selection sort
Selection sortSelection sort
Selection sort
 
Selection sort
Selection sortSelection sort
Selection sort
 
3.4 selection sort
3.4 selection sort3.4 selection sort
3.4 selection sort
 
The selection sort algorithm
The selection sort algorithmThe selection sort algorithm
The selection sort algorithm
 
Selection Sort
Selection SortSelection Sort
Selection Sort
 
Merge sort
Merge sortMerge sort
Merge sort
 
Quick Sort
Quick SortQuick Sort
Quick Sort
 
Linear Search & Binary Search
Linear Search & Binary SearchLinear Search & Binary Search
Linear Search & Binary Search
 
Sorting
SortingSorting
Sorting
 
Algorithm: Quick-Sort
Algorithm: Quick-SortAlgorithm: Quick-Sort
Algorithm: Quick-Sort
 
Selection sort 1
Selection sort 1Selection sort 1
Selection sort 1
 
Sorting (Bubble,Merge,Selection sort)
Sorting (Bubble,Merge,Selection sort)Sorting (Bubble,Merge,Selection sort)
Sorting (Bubble,Merge,Selection sort)
 
Bubblesort Algorithm
Bubblesort AlgorithmBubblesort Algorithm
Bubblesort Algorithm
 
Binary search
Binary searchBinary search
Binary search
 
3.1 bubble sort
3.1 bubble sort3.1 bubble sort
3.1 bubble sort
 
Linear search algorithm
Linear search algorithmLinear search algorithm
Linear search algorithm
 
Bubble sort a best presentation topic
Bubble sort a best presentation topicBubble sort a best presentation topic
Bubble sort a best presentation topic
 
Quicksort
QuicksortQuicksort
Quicksort
 
Insertion sort
Insertion sortInsertion sort
Insertion sort
 
Quick sort
Quick sortQuick sort
Quick sort
 

Similar to Selection sort

Chapter 7.2
Chapter 7.2Chapter 7.2
Chapter 7.2sotlsoc
 
Bubble sort, Selection sort SORTING .pptx
Bubble sort, Selection sort SORTING .pptxBubble sort, Selection sort SORTING .pptx
Bubble sort, Selection sort SORTING .pptxKalpana Mohan
 
Sorting_Algoritm-computee-scienceggn.pdf
Sorting_Algoritm-computee-scienceggn.pdfSorting_Algoritm-computee-scienceggn.pdf
Sorting_Algoritm-computee-scienceggn.pdfMohammed472103
 
An Introduction to Part of C++ STL
An Introduction to Part of C++ STLAn Introduction to Part of C++ STL
An Introduction to Part of C++ STL乐群 陈
 
Bin Sorting And Bubble Sort By Luisito G. Trinidad
Bin Sorting And Bubble Sort By Luisito G. TrinidadBin Sorting And Bubble Sort By Luisito G. Trinidad
Bin Sorting And Bubble Sort By Luisito G. TrinidadLUISITO TRINIDAD
 
Parsing swiftly-Cocoaheads-2015-02-12
Parsing swiftly-Cocoaheads-2015-02-12Parsing swiftly-Cocoaheads-2015-02-12
Parsing swiftly-Cocoaheads-2015-02-12griotspeak
 
Decimal Long Double Double Double. Represents double-precision floating-point...
Decimal Long Double Double Double. Represents double-precision floating-point...Decimal Long Double Double Double. Represents double-precision floating-point...
Decimal Long Double Double Double. Represents double-precision floating-point...Anwar Patel
 
sorting algorithm graphical method
sorting algorithm graphical method sorting algorithm graphical method
sorting algorithm graphical method Shantanu Mishra
 
Unit3 jwfiles
Unit3 jwfilesUnit3 jwfiles
Unit3 jwfilesmrecedu
 
Java AssignmentWrite a program using sortingsorting bubble,sele.pdf
Java AssignmentWrite a program using sortingsorting bubble,sele.pdfJava AssignmentWrite a program using sortingsorting bubble,sele.pdf
Java AssignmentWrite a program using sortingsorting bubble,sele.pdfeyewatchsystems
 
C++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdfC++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdfRahul04August
 
9781439035665 ppt ch09
9781439035665 ppt ch099781439035665 ppt ch09
9781439035665 ppt ch09Terry Yoast
 
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...Sunil Kumar Gunasekaran
 

Similar to Selection sort (20)

Chapter 7.2
Chapter 7.2Chapter 7.2
Chapter 7.2
 
Bubble sort, Selection sort SORTING .pptx
Bubble sort, Selection sort SORTING .pptxBubble sort, Selection sort SORTING .pptx
Bubble sort, Selection sort SORTING .pptx
 
Sorting_Algoritm-computee-scienceggn.pdf
Sorting_Algoritm-computee-scienceggn.pdfSorting_Algoritm-computee-scienceggn.pdf
Sorting_Algoritm-computee-scienceggn.pdf
 
sorting and its types
sorting and its typessorting and its types
sorting and its types
 
An Introduction to Part of C++ STL
An Introduction to Part of C++ STLAn Introduction to Part of C++ STL
An Introduction to Part of C++ STL
 
Bin Sorting And Bubble Sort By Luisito G. Trinidad
Bin Sorting And Bubble Sort By Luisito G. TrinidadBin Sorting And Bubble Sort By Luisito G. Trinidad
Bin Sorting And Bubble Sort By Luisito G. Trinidad
 
Parsing swiftly-Cocoaheads-2015-02-12
Parsing swiftly-Cocoaheads-2015-02-12Parsing swiftly-Cocoaheads-2015-02-12
Parsing swiftly-Cocoaheads-2015-02-12
 
Decimal Long Double Double Double. Represents double-precision floating-point...
Decimal Long Double Double Double. Represents double-precision floating-point...Decimal Long Double Double Double. Represents double-precision floating-point...
Decimal Long Double Double Double. Represents double-precision floating-point...
 
sorting algorithm graphical method
sorting algorithm graphical method sorting algorithm graphical method
sorting algorithm graphical method
 
C Language Unit-3
C Language Unit-3C Language Unit-3
C Language Unit-3
 
Unit3 jwfiles
Unit3 jwfilesUnit3 jwfiles
Unit3 jwfiles
 
Lecture 7 arrays
Lecture   7 arraysLecture   7 arrays
Lecture 7 arrays
 
07 Arrays
07 Arrays07 Arrays
07 Arrays
 
Arrays
ArraysArrays
Arrays
 
9 Arrays
9 Arrays9 Arrays
9 Arrays
 
Java AssignmentWrite a program using sortingsorting bubble,sele.pdf
Java AssignmentWrite a program using sortingsorting bubble,sele.pdfJava AssignmentWrite a program using sortingsorting bubble,sele.pdf
Java AssignmentWrite a program using sortingsorting bubble,sele.pdf
 
C++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdfC++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdf
 
Huraira_waris_Assgnment_4.docx
Huraira_waris_Assgnment_4.docxHuraira_waris_Assgnment_4.docx
Huraira_waris_Assgnment_4.docx
 
9781439035665 ppt ch09
9781439035665 ppt ch099781439035665 ppt ch09
9781439035665 ppt ch09
 
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
 

More from Jay Patel

Unit 3(rdbms)
Unit 3(rdbms)Unit 3(rdbms)
Unit 3(rdbms)Jay Patel
 
Unit 3(rdbms)
Unit 3(rdbms)Unit 3(rdbms)
Unit 3(rdbms)Jay Patel
 
Assignment 2(web)
Assignment 2(web)Assignment 2(web)
Assignment 2(web)Jay Patel
 
Assignment 2(web)
Assignment 2(web)Assignment 2(web)
Assignment 2(web)Jay Patel
 
Assignment 1(web)
Assignment 1(web)Assignment 1(web)
Assignment 1(web)Jay Patel
 
I assignmnt(oops)
I assignmnt(oops)I assignmnt(oops)
I assignmnt(oops)Jay Patel
 
Inline function(oops)
Inline function(oops)Inline function(oops)
Inline function(oops)Jay Patel
 
1 unit (oops)
1 unit (oops)1 unit (oops)
1 unit (oops)Jay Patel
 
Anchored data type
Anchored data typeAnchored data type
Anchored data typeJay Patel
 
Mutlimedia authoring tools
Mutlimedia authoring toolsMutlimedia authoring tools
Mutlimedia authoring toolsJay Patel
 
Multimedia software tools
Multimedia software toolsMultimedia software tools
Multimedia software toolsJay Patel
 
Lecture6 text
Lecture6   textLecture6   text
Lecture6 textJay Patel
 
Lecture6 text
Lecture6   textLecture6   text
Lecture6 textJay Patel
 
Hypertext and hypermedia
Hypertext and hypermediaHypertext and hypermedia
Hypertext and hypermediaJay Patel
 
Multimedia software tools
Multimedia software toolsMultimedia software tools
Multimedia software toolsJay Patel
 

More from Jay Patel (20)

Unit 3(rdbms)
Unit 3(rdbms)Unit 3(rdbms)
Unit 3(rdbms)
 
Unit 3(rdbms)
Unit 3(rdbms)Unit 3(rdbms)
Unit 3(rdbms)
 
Assignment 2(web)
Assignment 2(web)Assignment 2(web)
Assignment 2(web)
 
Quiz(web)
Quiz(web)Quiz(web)
Quiz(web)
 
Assignment 2(web)
Assignment 2(web)Assignment 2(web)
Assignment 2(web)
 
Assignment 1(web)
Assignment 1(web)Assignment 1(web)
Assignment 1(web)
 
I assignmnt(oops)
I assignmnt(oops)I assignmnt(oops)
I assignmnt(oops)
 
Inline function(oops)
Inline function(oops)Inline function(oops)
Inline function(oops)
 
1 unit (oops)
1 unit (oops)1 unit (oops)
1 unit (oops)
 
Unit1
Unit1Unit1
Unit1
 
Cursor
CursorCursor
Cursor
 
Anchored data type
Anchored data typeAnchored data type
Anchored data type
 
Mutlimedia authoring tools
Mutlimedia authoring toolsMutlimedia authoring tools
Mutlimedia authoring tools
 
Multimedia software tools
Multimedia software toolsMultimedia software tools
Multimedia software tools
 
Lecture6 text
Lecture6   textLecture6   text
Lecture6 text
 
Sound
SoundSound
Sound
 
Lecture6 text
Lecture6   textLecture6   text
Lecture6 text
 
Images
ImagesImages
Images
 
Hypertext and hypermedia
Hypertext and hypermediaHypertext and hypermedia
Hypertext and hypermedia
 
Multimedia software tools
Multimedia software toolsMultimedia software tools
Multimedia software tools
 

Recently uploaded

Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 

Recently uploaded (20)

Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 

Selection sort

  • 1.
  • 2. The selection sort is a combination of searching and sorting.  In selection sort, sorting is done after selecting a particular smallest or largest element from an array and shifted it to a particular location in an array.  During each pass, the unsorted element with the smallest (or largest) value is moved to its proper position in the array.  Let's look at our same table of elements using a selection sort for ascending order:
  • 3. Array 40 50 60 10 30 20 1-pass 10 50 60 40 30 20 2-pass 10 20 60 40 30 50 3-pass 10 20 30 40 60 50 4-pass 10 20 30 40 60 50 5-pass 10 20 30 40 50 60  The number of times the sort passes through the array is one less than the number of items in the array.  In the selection sort, the inner loop finds the next smallest (or largest) value and the outer loop places that value into its proper location.  Lets watch a video which will give you a basic idea of a selection sort.  Please co-operate.
  • 4. Lets look at coding of it in c++:  #include<iostream>  using namespace std;  void selectionsort(int *array,int length)  {  int i,j,min,minat,temp;  for(i=0;i<(length-1);i++)  {  minat=i;  min=array[i];  for(j=0;j<length;j++)  {  if(min>array[j])  {  minat=j;  min=array[j];  }  }  temp=array[i];  array[i]=array[minat];  array[minat]=temp;  }  }
  • 5. void printelements(int *array,int length)  {  int i;  for(i=0;i<length;i++)  cout<<array[i]<<” “<<;  }
  • 6. int main()  {  int array[100],n,i;  cout<<”enter number of element you wants to enter in an array”;  cin>>n;  if(n<0)  {  cout<<”enter proper positive element”;  cin>>n;  }  for(i=0;i<n;i++)  {  cout<<”enter values in array”;  cin>>array[i];  }  selectionsort(array,n);  printelement(array,n);  return 0;  }
  • 7. Any query?  Any question or any point which you doesn’t get?