SlideShare a Scribd company logo
1 of 3
Download to read offline
IOSR Journal of Computer Engineering (IOSR-JCE)
e-ISSN: 2278-0661, p- ISSN: 2278-8727Volume 16, Issue 1, Ver. I (Jan. 2014), PP 20-22
www.iosrjournals.org
www.iosrjournals.org 20 | Page
Alternate Sort
Syed Azher Nadeem Pasha
Lecturer Department of Computer Science Bapuji Institute of Hi-tech Education Davangere - 577004 ,
Karnataka State , India
Abstract: Sorting algorithms are the main concepts of the subject Data Structures and It’s Applications. These
algorithms are designed in arranging the data elements in the sorted order. If the data elements are arranged
in sorted order , then the searching is very easier. Some algorithms are comparison sort and some are non-
comparison sort. The choice of a algorithm is based on the efficiency of the algorithm. I have designed one
algorithm called as Alternate Sort. The main aspect is that different technique of comparisons is involed. I have
presented the algorithm , It’s working and the examples and finally my paper is consisting of the program
listing.
Keywords: Alternate Array Efficiency Exchanges Sort
I. Introduction
The sorting algorithms are used in arranging the data elements in ascending order or descending order.
Many sorting algorithms are existing like Selection sort , Insertion sort , Bubble sort , Quick sort , Shell sort ,
Radix sort etc. The choice of the algorithm depends on the efficiency of the algorithm. The efficiency of the
algorithm depends on the number of comparisons , number of exchanges and the memory requirements for data
storage.
The purpose of presenting my paper is to find the compatibility and different techniques of comparing
the data elements. .
II. Alternate Sort
2.1 Algorithm
K=0 ;
for (i=0 i<=n-1 ; ++i)
begin
for (j=k ; j<n-1 ; j=j+2)
begin
if a[j] > a[j+1]
a[j]<->a[j+1]
end
k=k+1
if (k>1) then
k=0 ;
end
2.1.1 Working of above algorithm
This sort uses two loops . The outer loop controls the number of iterations . The inner loop is used to
compare the data elements.
Step 1:
First time when the inner loop executes : The first two elements are compared . If they are out of order, the
elements will be exchanged. Next the third and fourth elements are compared .If they are out of order the
elements are exchanged. Process is repeated till the end of the list.When we reach the end of the list , if single
element iremains then do not consider it for comparison , leave it as it is.
Step2 :
Second time when the inner loop executes : second and third elements are compared . If they are out of order the
elements will be exchanged. Then fourth and fifth elements are compared . If they are out of order the elements
are exchanged. Repeat the process till the end of the list. If one element remains do not consider it for
comparison .
Alternate Sort
www.iosrjournals.org 21 | Page
Step3 :
The same method as in Step1 is continued
Step 4 :
The same method as in step 2 is continued .
The complete process halts when the outer loop exits.
2.2Examples
Problem Pass1 Pass2 Pass3 Pass4 Pass5 Sorted Array
5 5 4 4 2 2 1
4 4 5 2 4 1 2
3 3 2 5 1 4 3
2 2 3 1 5 3 4
1 1 1 3 3 5 5
Comparisons 2 2 2 2 2
exchanges 2 2 2 2 2
Total comparisons = 10 =5*4/2 n(n-1)/2 where n is number of elements in the array
Total exchanges = 10 = 5*4/2n(n0-1)/2
Problem Pass1 Pass2 Pass3 Pass4 Pass5 Pass6 Sorted
Array
6 6 5 5 3 3 1 1
5 5 6 3 5 1 3 2
4 4 3 6 1 5 2 3
3 3 4 1 6 2 5 4
2 2 1 4 2 6 4 5
1 1 2 2 4 4 6 6
Comparisons 3 2 3 2 3 2
exchanges 3 2 3 2 3 2
Total comparisons = 15=6*5/2=n*(n-1)/2 where n is number of element s in the array
Total exchanges =15=6*5/2=n*(n-1)/2
2.3Program listing :
void main()
{
int i,j,k,n, temp , a[50] ;
clrscr () ;
printf("Enter the number of elements : ");
scanf("%d",&n) ;
printf("Enter array elements : n") ;
for (i=0 ; i<=n-1 ; ++i)
{
scanf("%d",&a[i]) ;
}
k=0 ;
for (i=0 ; i<=n-1 ; ++i)
{
for (j=k ; j<n-1 ; j=j+2 )
{
if (a[j] > a[j+1] )
{
temp = a[j] ;
a[j] = a[j+1] ;
a[j+1] = temp ;
}
}
k=k+1 ;
if (k>1 )
Alternate Sort
www.iosrjournals.org 22 | Page
k= 0 ;
}
printf("The array elements are : n") ;
for (i=0 ; i<=n-1 ; ++i)
{
printf("%dn",a[i]) ;
}
getch() ;
}
III. Efficiency :
The formula for number of comparisons is n*(n-1)/2
The formula for number of exchanges is n*(n-1)/2
The efficiency of the above algorithm is O(n2) w.r.t number of comparisons and also w.r.t number of
exchanges.
IV. Conclusion
The algorithm is simple to implement. It takes constant memory space. The efficiency is same as the
efficiency of Bubble sort. This algorithm is used for relatively small sized arrays.
REFERENCES
[1] Website referring the Sorting algorithm from Wickepedia

More Related Content

What's hot

Selection sort
Selection sortSelection sort
Selection sortamna izzat
 
Insertion Sort, Quick Sort And Their complexity
Insertion Sort, Quick Sort And Their complexityInsertion Sort, Quick Sort And Their complexity
Insertion Sort, Quick Sort And Their complexityMotaleb Hossen Manik
 
Implementing Merge Sort
Implementing Merge SortImplementing Merge Sort
Implementing Merge Sortsmita gupta
 
Selection Sort with Improved Asymptotic Time Bounds
Selection Sort with Improved Asymptotic Time BoundsSelection Sort with Improved Asymptotic Time Bounds
Selection Sort with Improved Asymptotic Time Boundstheijes
 
SQUARE ROOT SORTING ALGORITHM
SQUARE ROOT SORTING ALGORITHMSQUARE ROOT SORTING ALGORITHM
SQUARE ROOT SORTING ALGORITHMMirOmranudinAbhar
 
366 it elective 4 (analysis of algoritm)
366 it elective 4 (analysis of algoritm)366 it elective 4 (analysis of algoritm)
366 it elective 4 (analysis of algoritm)Neil Soliven
 
Java Tutorial Lab 3
Java Tutorial Lab 3Java Tutorial Lab 3
Java Tutorial Lab 3Berk Soysal
 
Selection sort
Selection sortSelection sort
Selection sortasra khan
 
Array operations
Array operationsArray operations
Array operationsRazzaaa
 
Selection sort
Selection sortSelection sort
Selection sortstella D
 
Selection sort and insertion sort
Selection sort and insertion sortSelection sort and insertion sort
Selection sort and insertion sortMay Ann Mendoza
 
Overview and Implementation of Principal Component Analysis
Overview and Implementation of Principal Component Analysis Overview and Implementation of Principal Component Analysis
Overview and Implementation of Principal Component Analysis Taweh Beysolow II
 
Ap Power Point Chpt8
Ap Power Point Chpt8Ap Power Point Chpt8
Ap Power Point Chpt8dplunkett
 

What's hot (17)

Selection sort
Selection sortSelection sort
Selection sort
 
Insertion Sort, Quick Sort And Their complexity
Insertion Sort, Quick Sort And Their complexityInsertion Sort, Quick Sort And Their complexity
Insertion Sort, Quick Sort And Their complexity
 
Implementing Merge Sort
Implementing Merge SortImplementing Merge Sort
Implementing Merge Sort
 
Merge sort
Merge sortMerge sort
Merge sort
 
Selection Sort with Improved Asymptotic Time Bounds
Selection Sort with Improved Asymptotic Time BoundsSelection Sort with Improved Asymptotic Time Bounds
Selection Sort with Improved Asymptotic Time Bounds
 
Operators in java
Operators in javaOperators in java
Operators in java
 
SQUARE ROOT SORTING ALGORITHM
SQUARE ROOT SORTING ALGORITHMSQUARE ROOT SORTING ALGORITHM
SQUARE ROOT SORTING ALGORITHM
 
Mergesort
MergesortMergesort
Mergesort
 
366 it elective 4 (analysis of algoritm)
366 it elective 4 (analysis of algoritm)366 it elective 4 (analysis of algoritm)
366 it elective 4 (analysis of algoritm)
 
Java Tutorial Lab 3
Java Tutorial Lab 3Java Tutorial Lab 3
Java Tutorial Lab 3
 
Selection sort
Selection sortSelection sort
Selection sort
 
Array operations
Array operationsArray operations
Array operations
 
Selection sort
Selection sortSelection sort
Selection sort
 
Selection sort and insertion sort
Selection sort and insertion sortSelection sort and insertion sort
Selection sort and insertion sort
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
Overview and Implementation of Principal Component Analysis
Overview and Implementation of Principal Component Analysis Overview and Implementation of Principal Component Analysis
Overview and Implementation of Principal Component Analysis
 
Ap Power Point Chpt8
Ap Power Point Chpt8Ap Power Point Chpt8
Ap Power Point Chpt8
 

Viewers also liked

A Novel Mechanism for Low Bit-Rate Compression
A Novel Mechanism for Low Bit-Rate CompressionA Novel Mechanism for Low Bit-Rate Compression
A Novel Mechanism for Low Bit-Rate CompressionIOSR Journals
 
Using of intelligent communicational devices in controlling road structural w...
Using of intelligent communicational devices in controlling road structural w...Using of intelligent communicational devices in controlling road structural w...
Using of intelligent communicational devices in controlling road structural w...IOSR Journals
 
Analysis of Impact of Channel Error Rate on Average PSNR in Multimedia Traffic
Analysis of Impact of Channel Error Rate on Average PSNR in Multimedia TrafficAnalysis of Impact of Channel Error Rate on Average PSNR in Multimedia Traffic
Analysis of Impact of Channel Error Rate on Average PSNR in Multimedia TrafficIOSR Journals
 
An Enhanced Biometric System for Personal Authentication
An Enhanced Biometric System for Personal AuthenticationAn Enhanced Biometric System for Personal Authentication
An Enhanced Biometric System for Personal AuthenticationIOSR Journals
 
Pest Control in Agricultural Plantations Using Image Processing
Pest Control in Agricultural Plantations Using Image ProcessingPest Control in Agricultural Plantations Using Image Processing
Pest Control in Agricultural Plantations Using Image ProcessingIOSR Journals
 
APEC and Trade Liberalization
APEC and Trade LiberalizationAPEC and Trade Liberalization
APEC and Trade LiberalizationIOSR Journals
 
Recognition of Numerals Using Neural Network
Recognition of Numerals Using Neural NetworkRecognition of Numerals Using Neural Network
Recognition of Numerals Using Neural NetworkIOSR Journals
 
Enhancement of Specific Power Output of a Gas Turbine Using Filtered Chilled Air
Enhancement of Specific Power Output of a Gas Turbine Using Filtered Chilled AirEnhancement of Specific Power Output of a Gas Turbine Using Filtered Chilled Air
Enhancement of Specific Power Output of a Gas Turbine Using Filtered Chilled AirIOSR Journals
 
Investigation of spatial configuration of Polypropylene and the influence of ...
Investigation of spatial configuration of Polypropylene and the influence of ...Investigation of spatial configuration of Polypropylene and the influence of ...
Investigation of spatial configuration of Polypropylene and the influence of ...IOSR Journals
 
Digital Implementation of Artificial Neural Network for Function Approximatio...
Digital Implementation of Artificial Neural Network for Function Approximatio...Digital Implementation of Artificial Neural Network for Function Approximatio...
Digital Implementation of Artificial Neural Network for Function Approximatio...IOSR Journals
 
Modeling Liquid Terminal Operation and Service System in a Port Using Linier ...
Modeling Liquid Terminal Operation and Service System in a Port Using Linier ...Modeling Liquid Terminal Operation and Service System in a Port Using Linier ...
Modeling Liquid Terminal Operation and Service System in a Port Using Linier ...IOSR Journals
 
A Study to Explore the Effects of Varied Tempo music on Brisk Walking Perform...
A Study to Explore the Effects of Varied Tempo music on Brisk Walking Perform...A Study to Explore the Effects of Varied Tempo music on Brisk Walking Perform...
A Study to Explore the Effects of Varied Tempo music on Brisk Walking Perform...IOSR Journals
 
Distortion Analysis of Differential Amplifier
Distortion Analysis of Differential AmplifierDistortion Analysis of Differential Amplifier
Distortion Analysis of Differential AmplifierIOSR Journals
 
Comparison of Neural Network Training Functions for Hematoma Classification i...
Comparison of Neural Network Training Functions for Hematoma Classification i...Comparison of Neural Network Training Functions for Hematoma Classification i...
Comparison of Neural Network Training Functions for Hematoma Classification i...IOSR Journals
 
The Effect of Relationship Quality on Customer Advocacy: The Mediating Role o...
The Effect of Relationship Quality on Customer Advocacy: The Mediating Role o...The Effect of Relationship Quality on Customer Advocacy: The Mediating Role o...
The Effect of Relationship Quality on Customer Advocacy: The Mediating Role o...IOSR Journals
 
An Empirical Study on relationship among Quality of work life and its factors
An Empirical Study on relationship among Quality of work life and its factorsAn Empirical Study on relationship among Quality of work life and its factors
An Empirical Study on relationship among Quality of work life and its factorsIOSR Journals
 
Developing Organic Processed Food Entrepreneurial Intention: Study On Women F...
Developing Organic Processed Food Entrepreneurial Intention: Study On Women F...Developing Organic Processed Food Entrepreneurial Intention: Study On Women F...
Developing Organic Processed Food Entrepreneurial Intention: Study On Women F...IOSR Journals
 
Web Mining for an Academic Portal: The case of Al-Imam Muhammad Ibn Saud Isla...
Web Mining for an Academic Portal: The case of Al-Imam Muhammad Ibn Saud Isla...Web Mining for an Academic Portal: The case of Al-Imam Muhammad Ibn Saud Isla...
Web Mining for an Academic Portal: The case of Al-Imam Muhammad Ibn Saud Isla...IOSR Journals
 
Nigerian Women Entrepreneurs: Challenges, Incentives and Achievements Indicators
Nigerian Women Entrepreneurs: Challenges, Incentives and Achievements IndicatorsNigerian Women Entrepreneurs: Challenges, Incentives and Achievements Indicators
Nigerian Women Entrepreneurs: Challenges, Incentives and Achievements IndicatorsIOSR Journals
 
X-Ray Line Profile Analysis of Chemically Deposited Nanostructured PBS Films
X-Ray Line Profile Analysis of Chemically Deposited Nanostructured PBS FilmsX-Ray Line Profile Analysis of Chemically Deposited Nanostructured PBS Films
X-Ray Line Profile Analysis of Chemically Deposited Nanostructured PBS FilmsIOSR Journals
 

Viewers also liked (20)

A Novel Mechanism for Low Bit-Rate Compression
A Novel Mechanism for Low Bit-Rate CompressionA Novel Mechanism for Low Bit-Rate Compression
A Novel Mechanism for Low Bit-Rate Compression
 
Using of intelligent communicational devices in controlling road structural w...
Using of intelligent communicational devices in controlling road structural w...Using of intelligent communicational devices in controlling road structural w...
Using of intelligent communicational devices in controlling road structural w...
 
Analysis of Impact of Channel Error Rate on Average PSNR in Multimedia Traffic
Analysis of Impact of Channel Error Rate on Average PSNR in Multimedia TrafficAnalysis of Impact of Channel Error Rate on Average PSNR in Multimedia Traffic
Analysis of Impact of Channel Error Rate on Average PSNR in Multimedia Traffic
 
An Enhanced Biometric System for Personal Authentication
An Enhanced Biometric System for Personal AuthenticationAn Enhanced Biometric System for Personal Authentication
An Enhanced Biometric System for Personal Authentication
 
Pest Control in Agricultural Plantations Using Image Processing
Pest Control in Agricultural Plantations Using Image ProcessingPest Control in Agricultural Plantations Using Image Processing
Pest Control in Agricultural Plantations Using Image Processing
 
APEC and Trade Liberalization
APEC and Trade LiberalizationAPEC and Trade Liberalization
APEC and Trade Liberalization
 
Recognition of Numerals Using Neural Network
Recognition of Numerals Using Neural NetworkRecognition of Numerals Using Neural Network
Recognition of Numerals Using Neural Network
 
Enhancement of Specific Power Output of a Gas Turbine Using Filtered Chilled Air
Enhancement of Specific Power Output of a Gas Turbine Using Filtered Chilled AirEnhancement of Specific Power Output of a Gas Turbine Using Filtered Chilled Air
Enhancement of Specific Power Output of a Gas Turbine Using Filtered Chilled Air
 
Investigation of spatial configuration of Polypropylene and the influence of ...
Investigation of spatial configuration of Polypropylene and the influence of ...Investigation of spatial configuration of Polypropylene and the influence of ...
Investigation of spatial configuration of Polypropylene and the influence of ...
 
Digital Implementation of Artificial Neural Network for Function Approximatio...
Digital Implementation of Artificial Neural Network for Function Approximatio...Digital Implementation of Artificial Neural Network for Function Approximatio...
Digital Implementation of Artificial Neural Network for Function Approximatio...
 
Modeling Liquid Terminal Operation and Service System in a Port Using Linier ...
Modeling Liquid Terminal Operation and Service System in a Port Using Linier ...Modeling Liquid Terminal Operation and Service System in a Port Using Linier ...
Modeling Liquid Terminal Operation and Service System in a Port Using Linier ...
 
A Study to Explore the Effects of Varied Tempo music on Brisk Walking Perform...
A Study to Explore the Effects of Varied Tempo music on Brisk Walking Perform...A Study to Explore the Effects of Varied Tempo music on Brisk Walking Perform...
A Study to Explore the Effects of Varied Tempo music on Brisk Walking Perform...
 
Distortion Analysis of Differential Amplifier
Distortion Analysis of Differential AmplifierDistortion Analysis of Differential Amplifier
Distortion Analysis of Differential Amplifier
 
Comparison of Neural Network Training Functions for Hematoma Classification i...
Comparison of Neural Network Training Functions for Hematoma Classification i...Comparison of Neural Network Training Functions for Hematoma Classification i...
Comparison of Neural Network Training Functions for Hematoma Classification i...
 
The Effect of Relationship Quality on Customer Advocacy: The Mediating Role o...
The Effect of Relationship Quality on Customer Advocacy: The Mediating Role o...The Effect of Relationship Quality on Customer Advocacy: The Mediating Role o...
The Effect of Relationship Quality on Customer Advocacy: The Mediating Role o...
 
An Empirical Study on relationship among Quality of work life and its factors
An Empirical Study on relationship among Quality of work life and its factorsAn Empirical Study on relationship among Quality of work life and its factors
An Empirical Study on relationship among Quality of work life and its factors
 
Developing Organic Processed Food Entrepreneurial Intention: Study On Women F...
Developing Organic Processed Food Entrepreneurial Intention: Study On Women F...Developing Organic Processed Food Entrepreneurial Intention: Study On Women F...
Developing Organic Processed Food Entrepreneurial Intention: Study On Women F...
 
Web Mining for an Academic Portal: The case of Al-Imam Muhammad Ibn Saud Isla...
Web Mining for an Academic Portal: The case of Al-Imam Muhammad Ibn Saud Isla...Web Mining for an Academic Portal: The case of Al-Imam Muhammad Ibn Saud Isla...
Web Mining for an Academic Portal: The case of Al-Imam Muhammad Ibn Saud Isla...
 
Nigerian Women Entrepreneurs: Challenges, Incentives and Achievements Indicators
Nigerian Women Entrepreneurs: Challenges, Incentives and Achievements IndicatorsNigerian Women Entrepreneurs: Challenges, Incentives and Achievements Indicators
Nigerian Women Entrepreneurs: Challenges, Incentives and Achievements Indicators
 
X-Ray Line Profile Analysis of Chemically Deposited Nanostructured PBS Films
X-Ray Line Profile Analysis of Chemically Deposited Nanostructured PBS FilmsX-Ray Line Profile Analysis of Chemically Deposited Nanostructured PBS Films
X-Ray Line Profile Analysis of Chemically Deposited Nanostructured PBS Films
 

Similar to Alternate Sort

Similar to Alternate Sort (20)

my docoment
my docomentmy docoment
my docoment
 
Ijcse13 05-01-048
Ijcse13 05-01-048Ijcse13 05-01-048
Ijcse13 05-01-048
 
Sorting pnk
Sorting pnkSorting pnk
Sorting pnk
 
Data Structure (MC501)
Data Structure (MC501)Data Structure (MC501)
Data Structure (MC501)
 
Sorting
SortingSorting
Sorting
 
IRJET- A Survey on Different Searching Algorithms
IRJET- A Survey on Different Searching AlgorithmsIRJET- A Survey on Different Searching Algorithms
IRJET- A Survey on Different Searching Algorithms
 
Daa chapter5
Daa chapter5Daa chapter5
Daa chapter5
 
14-sorting.ppt
14-sorting.ppt14-sorting.ppt
14-sorting.ppt
 
14-sorting (3).ppt
14-sorting (3).ppt14-sorting (3).ppt
14-sorting (3).ppt
 
14-sorting.ppt
14-sorting.ppt14-sorting.ppt
14-sorting.ppt
 
14-sorting.ppt
14-sorting.ppt14-sorting.ppt
14-sorting.ppt
 
DS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptxDS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptx
 
Data Structures_ Sorting & Searching
Data Structures_ Sorting & SearchingData Structures_ Sorting & Searching
Data Structures_ Sorting & Searching
 
Ada notes
Ada notesAda notes
Ada notes
 
DAA-Divide and Conquer methodology, DAA 2024
DAA-Divide and Conquer methodology, DAA 2024DAA-Divide and Conquer methodology, DAA 2024
DAA-Divide and Conquer methodology, DAA 2024
 
Data structure using c module 3
Data structure using c module 3Data structure using c module 3
Data structure using c module 3
 
Module 2_ Divide and Conquer Approach.pptx
Module 2_ Divide and Conquer Approach.pptxModule 2_ Divide and Conquer Approach.pptx
Module 2_ Divide and Conquer Approach.pptx
 
Sorting
SortingSorting
Sorting
 
Average sort
Average sortAverage sort
Average sort
 
MODULE 5-Searching and-sorting
MODULE 5-Searching and-sortingMODULE 5-Searching and-sorting
MODULE 5-Searching and-sorting
 

More from IOSR Journals (20)

A011140104
A011140104A011140104
A011140104
 
M0111397100
M0111397100M0111397100
M0111397100
 
L011138596
L011138596L011138596
L011138596
 
K011138084
K011138084K011138084
K011138084
 
J011137479
J011137479J011137479
J011137479
 
I011136673
I011136673I011136673
I011136673
 
G011134454
G011134454G011134454
G011134454
 
H011135565
H011135565H011135565
H011135565
 
F011134043
F011134043F011134043
F011134043
 
E011133639
E011133639E011133639
E011133639
 
D011132635
D011132635D011132635
D011132635
 
C011131925
C011131925C011131925
C011131925
 
B011130918
B011130918B011130918
B011130918
 
A011130108
A011130108A011130108
A011130108
 
I011125160
I011125160I011125160
I011125160
 
H011124050
H011124050H011124050
H011124050
 
G011123539
G011123539G011123539
G011123539
 
F011123134
F011123134F011123134
F011123134
 
E011122530
E011122530E011122530
E011122530
 
D011121524
D011121524D011121524
D011121524
 

Recently uploaded

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
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
 
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
 
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
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
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
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
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
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 

Recently uploaded (20)

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
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
 
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
 
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
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
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
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
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
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 

Alternate Sort

  • 1. IOSR Journal of Computer Engineering (IOSR-JCE) e-ISSN: 2278-0661, p- ISSN: 2278-8727Volume 16, Issue 1, Ver. I (Jan. 2014), PP 20-22 www.iosrjournals.org www.iosrjournals.org 20 | Page Alternate Sort Syed Azher Nadeem Pasha Lecturer Department of Computer Science Bapuji Institute of Hi-tech Education Davangere - 577004 , Karnataka State , India Abstract: Sorting algorithms are the main concepts of the subject Data Structures and It’s Applications. These algorithms are designed in arranging the data elements in the sorted order. If the data elements are arranged in sorted order , then the searching is very easier. Some algorithms are comparison sort and some are non- comparison sort. The choice of a algorithm is based on the efficiency of the algorithm. I have designed one algorithm called as Alternate Sort. The main aspect is that different technique of comparisons is involed. I have presented the algorithm , It’s working and the examples and finally my paper is consisting of the program listing. Keywords: Alternate Array Efficiency Exchanges Sort I. Introduction The sorting algorithms are used in arranging the data elements in ascending order or descending order. Many sorting algorithms are existing like Selection sort , Insertion sort , Bubble sort , Quick sort , Shell sort , Radix sort etc. The choice of the algorithm depends on the efficiency of the algorithm. The efficiency of the algorithm depends on the number of comparisons , number of exchanges and the memory requirements for data storage. The purpose of presenting my paper is to find the compatibility and different techniques of comparing the data elements. . II. Alternate Sort 2.1 Algorithm K=0 ; for (i=0 i<=n-1 ; ++i) begin for (j=k ; j<n-1 ; j=j+2) begin if a[j] > a[j+1] a[j]<->a[j+1] end k=k+1 if (k>1) then k=0 ; end 2.1.1 Working of above algorithm This sort uses two loops . The outer loop controls the number of iterations . The inner loop is used to compare the data elements. Step 1: First time when the inner loop executes : The first two elements are compared . If they are out of order, the elements will be exchanged. Next the third and fourth elements are compared .If they are out of order the elements are exchanged. Process is repeated till the end of the list.When we reach the end of the list , if single element iremains then do not consider it for comparison , leave it as it is. Step2 : Second time when the inner loop executes : second and third elements are compared . If they are out of order the elements will be exchanged. Then fourth and fifth elements are compared . If they are out of order the elements are exchanged. Repeat the process till the end of the list. If one element remains do not consider it for comparison .
  • 2. Alternate Sort www.iosrjournals.org 21 | Page Step3 : The same method as in Step1 is continued Step 4 : The same method as in step 2 is continued . The complete process halts when the outer loop exits. 2.2Examples Problem Pass1 Pass2 Pass3 Pass4 Pass5 Sorted Array 5 5 4 4 2 2 1 4 4 5 2 4 1 2 3 3 2 5 1 4 3 2 2 3 1 5 3 4 1 1 1 3 3 5 5 Comparisons 2 2 2 2 2 exchanges 2 2 2 2 2 Total comparisons = 10 =5*4/2 n(n-1)/2 where n is number of elements in the array Total exchanges = 10 = 5*4/2n(n0-1)/2 Problem Pass1 Pass2 Pass3 Pass4 Pass5 Pass6 Sorted Array 6 6 5 5 3 3 1 1 5 5 6 3 5 1 3 2 4 4 3 6 1 5 2 3 3 3 4 1 6 2 5 4 2 2 1 4 2 6 4 5 1 1 2 2 4 4 6 6 Comparisons 3 2 3 2 3 2 exchanges 3 2 3 2 3 2 Total comparisons = 15=6*5/2=n*(n-1)/2 where n is number of element s in the array Total exchanges =15=6*5/2=n*(n-1)/2 2.3Program listing : void main() { int i,j,k,n, temp , a[50] ; clrscr () ; printf("Enter the number of elements : "); scanf("%d",&n) ; printf("Enter array elements : n") ; for (i=0 ; i<=n-1 ; ++i) { scanf("%d",&a[i]) ; } k=0 ; for (i=0 ; i<=n-1 ; ++i) { for (j=k ; j<n-1 ; j=j+2 ) { if (a[j] > a[j+1] ) { temp = a[j] ; a[j] = a[j+1] ; a[j+1] = temp ; } } k=k+1 ; if (k>1 )
  • 3. Alternate Sort www.iosrjournals.org 22 | Page k= 0 ; } printf("The array elements are : n") ; for (i=0 ; i<=n-1 ; ++i) { printf("%dn",a[i]) ; } getch() ; } III. Efficiency : The formula for number of comparisons is n*(n-1)/2 The formula for number of exchanges is n*(n-1)/2 The efficiency of the above algorithm is O(n2) w.r.t number of comparisons and also w.r.t number of exchanges. IV. Conclusion The algorithm is simple to implement. It takes constant memory space. The efficiency is same as the efficiency of Bubble sort. This algorithm is used for relatively small sized arrays. REFERENCES [1] Website referring the Sorting algorithm from Wickepedia