﻿<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD with MathML3 v1.2 20190208//EN" "http://dtd.nlm.nih.gov/publishing/3.0/journalpublishing3.dtd">
<article
    xmlns:mml="http://www.w3.org/1998/Math/MathML"
    xmlns:xlink="http://www.w3.org/1999/xlink" dtd-version="3.0" xml:lang="en" article-type="article">
  <front>
    <journal-meta>
      <journal-id journal-id-type="publisher-id">IJMEBAC</journal-id>
      <journal-title-group>
        <journal-title>International Journal of Mathematical, Engineering, Biological and Applied Computing</journal-title>
      </journal-title-group>
      <issn pub-type="epub"></issn>
      <issn pub-type="ppub"></issn>
      <publisher>
        <publisher-name>Science Publications</publisher-name>
      </publisher>
    </journal-meta>
    <article-meta>
      <article-id pub-id-type="doi">10.31586/ijmebac.2022.285</article-id>
      <article-id pub-id-type="publisher-id">IJMEBAC-285</article-id>
      <article-categories>
        <subj-group subj-group-type="heading">
          <subject>Article</subject>
        </subj-group>
      </article-categories>
      <title-group>
        <article-title>
          A Linear-Time Algorithm to Find the Second Smallest Number
        </article-title>
      </title-group>
      <contrib-group>
<contrib contrib-type="author">
<name>
<surname>Marappan</surname>
<given-names>Raja</given-names>
</name>
</contrib>
<contrib contrib-type="author">
<name>
<surname>Bhaskaran</surname>
<given-names>S.</given-names>
</name>
</contrib>
      </contrib-group>
      <pub-date pub-type="epub">
        <day>01</day>
        <month>05</month>
        <year>2022</year>
      </pub-date>
      <volume>1</volume>
      <issue>1</issue>
      <history>
        <date date-type="received">
          <day>01</day>
          <month>05</month>
          <year>2022</year>
        </date>
        <date date-type="rev-recd">
          <day>01</day>
          <month>05</month>
          <year>2022</year>
        </date>
        <date date-type="accepted">
          <day>01</day>
          <month>05</month>
          <year>2022</year>
        </date>
        <date date-type="pub">
          <day>01</day>
          <month>05</month>
          <year>2022</year>
        </date>
      </history>
      <permissions>
        <copyright-statement>&#xa9; Copyright 2022 by authors and Trend Research Publishing Inc. </copyright-statement>
        <copyright-year>2022</copyright-year>
        <license license-type="open-access" xlink:href="http://creativecommons.org/licenses/by/4.0/">
          <license-p>This work is licensed under the Creative Commons Attribution International License (CC BY). http://creativecommons.org/licenses/by/4.0/</license-p>
        </license>
      </permissions>
      <abstract>
        An algorithm is defined as a finite step-by-step procedure to accomplish a required result. It is also defined as a sequence of computational operations that convert the given input into the required output. In general, in the worst case, an algorithm is said to be optimal if there are no algorithms that perform a less basic number of well-defined operations, in the worst case. This paper presents an optimal algorithm for finding the second smallest among n numbers. The complexity of the proposed algorithm and its advantages are also analyzed in this paper.
      </abstract>
      <kwd-group>
        <kwd-group><kwd>Algorithm</kwd>
<kwd>Computational Complexity</kwd>
<kwd>Optimal Algorithm</kwd>
<kwd>Second Smallest</kwd>
<kwd>Searching Smallest</kwd>
</kwd-group>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec1">
<title>Introduction</title><p>An algorithm is defined as an unambiguous procedure that contains a finite set of well-defined operations or steps that requires a finite amount of storage and takes a finite amount of time to complete and it can be executed by a mathematical machine [
<xref ref-type="bibr" rid="R1">1</xref>]. The word &#x26;#x02018;Algorithmic&#x26;#x02019; is defined as a branch of computer science that consists of both designing and analyzing algorithms. The word &#x26;#x0201c;design&#x26;#x0201d; pertains to the description of the algorithm at the abstract level through a pseudo-language. The algorithm&#x26;#x02019;s correctness is that it should solve the given problem in all cases. Next, the &#x26;#x0201c;analysis&#x26;#x0201d; part deals with the performance evaluation of the algorithm, also defined as the complexity analysis. This paper designs an optimal algorithm to find the second smallest among the given <italic>n</italic> numbers [
<xref ref-type="bibr" rid="R2">2</xref>,<xref ref-type="bibr" rid="R3">3</xref>,<xref ref-type="bibr" rid="R4">4</xref>]. The complexity analysis and the advantages of the proposed algorithm are also explored in the next sections. Optimal algorithms should be designed to solve real-world problems either using hard computing or soft computing techniques [
<xref ref-type="bibr" rid="R5">5</xref>,<xref ref-type="bibr" rid="R6">6</xref>,<xref ref-type="bibr" rid="R7">7</xref>,<xref ref-type="bibr" rid="R8">8</xref>,<xref ref-type="bibr" rid="R9">9</xref>,<xref ref-type="bibr" rid="R10">10</xref>,<xref ref-type="bibr" rid="R11">11</xref>,<xref ref-type="bibr" rid="R12">12</xref>,<xref ref-type="bibr" rid="R13">13</xref>,<xref ref-type="bibr" rid="R14">14</xref>,<xref ref-type="bibr" rid="R15">15</xref>,<xref ref-type="bibr" rid="R16">16</xref>,<xref ref-type="bibr" rid="R17">17</xref>,<xref ref-type="bibr" rid="R18">18</xref>,<xref ref-type="bibr" rid="R19">19</xref>,<xref ref-type="bibr" rid="R20">20</xref>,<xref ref-type="bibr" rid="R21">21</xref>,<xref ref-type="bibr" rid="R22">22</xref>,<xref ref-type="bibr" rid="R23">23</xref>,<xref ref-type="bibr" rid="R24">24</xref>,<xref ref-type="bibr" rid="R25">25</xref>,<xref ref-type="bibr" rid="R26">26</xref>,<xref ref-type="bibr" rid="R27">27</xref>,<xref ref-type="bibr" rid="R28">28</xref>,<xref ref-type="bibr" rid="R29">29</xref>].</p>
</sec><sec id="sec2">
<title>Properties or characteristics of an Algorithm</title><p>The following are the important characteristics of every algorithm [
<xref ref-type="bibr" rid="R3">3</xref>].</p>
<p>An algorithm must be precise.</p>
<p>An algorithm must be effective.</p>
<p>An algorithm must have a fixed finite number of instructions.</p>
<p>The execution of an algorithm must always terminate</p>
<p></p>
</sec><sec id="sec3">
<title>Design of an optimal algorithm for finding the second smallest among <i>n</i> numbers</title><p>The optimal algorithm to find the second smallest among <italic>n</italic> numbers is designed to the properties mentioned in section 2 and the resultant optimal algorithm is presented in this section.</p>
<p></p>
<p>Algorithm Find-SecondMin (A[
], <italic>n</italic>)</p>
<p>// A[1:<italic> n</italic>] is an one-dimensional array, that contains <italic>n</italic> elements</p>
<p>// Finding the second smallest among <italic>n</italic> elements with minimum comparisons, O(<italic>n</italic>)</p>
<p>1: <italic>fmin</italic> =A[
<xref ref-type="bibr" rid="R1">1</xref>]; <italic>smin</italic> = A[
<xref ref-type="bibr" rid="R2">2</xref>];</p>
<p>2: if (<italic>smin</italic> &lt; <italic>fmin</italic>) then <italic>fmin</italic> = A[
<xref ref-type="bibr" rid="R2">2</xref>]; <italic>smin</italic> = A[
<xref ref-type="bibr" rid="R1">1</xref>]; </p>
<p>3: for <italic>i </italic>= 3 to <italic>n</italic> do:</p>
<p>4: if (<italic>fmin </italic>= <italic>smin</italic>) then <italic>smin</italic>=A[<italic>i</italic>]; </p>
<p>5: if (A[<italic>i</italic>] &lt; <italic>fmin</italic>) then <italic>smin</italic> = <italic>fmin</italic>; <italic>fmin </italic>= A[<italic>i</italic>];</p>
<p>6: else if ((<italic>fmin</italic> &lt; A[<italic>i</italic>]) &#x26;#x00026;&#x26;#x00026; (A[<italic>i</italic>] &lt; <italic>smin</italic>)) then <italic>smin </italic>= A[<italic>i</italic>];</p>
<p>7: // End of Algorithm</p>
<p></p>
</sec><sec id="sec4">
<title>Asymptotic Analysis of Algorithm Find-SecondMin (A[], <i>n</i>)</title><p>The best, worst, and average-case analysis of the devised algorithm is explained in this section [
<xref ref-type="bibr" rid="R4">4</xref>,<xref ref-type="bibr" rid="R5">5</xref>].</p>
<p><bold>Worst case: </bold>The total count of basic operations, that is, the count of comparisons performed in the worst case is given by </p>
<p><italic>w</italic>(<italic>n</italic>) = 1 + (<italic>n</italic> &#x26;#x02013; 2 + 1)[
] = 1 + 4(<italic>n</italic> &#x26;#x02013; 1) = 1 + 4<italic>n</italic> &#x26;#x02013; 4 = 4<italic>n</italic> &#x26;#x02013; 3 = O(<italic>n</italic>). </p>
<p>For example, <italic>n</italic> =5, and the inputs (80, 30, 35, 34, 32) result in worst-case performance. </p>
<p><bold>Average case:</bold> The total count of basic operations, that is, the count of comparisons performed in the average case is given by </p>
<p><italic>A</italic>(<italic>n</italic>) = 1 + (<italic>n</italic> &#x26;#x02013; 2 + 1) [
] = 1 + 3(<italic>n</italic> &#x26;#x02013; 1) = 1 + 3<italic>n</italic> &#x26;#x02013; 3 = 3<italic> n</italic> &#x26;#x02013; 2 = O(<italic>n</italic>). </p>
<p>For example, <italic>n</italic> =5 and the inputs (10, 20, 30, 40, and 50) result in average-case performance. </p>
<p><bold>Best case:</bold> The total number of basic operations, that is, the number of comparisons performed in the best case is given by </p>
<p><italic>f</italic>(<italic>n</italic>) = 1 + (<italic>n</italic> &#x26;#x02013; 2 + 1) [
] = 1 + 2(<italic>n</italic> &#x26;#x02013; 1 ) = 1 + 2<italic> n</italic> &#x26;#x02013; 2 = 2<italic> n</italic> &#x26;#x02013; 1 = O(<italic>n</italic>). </p>
<p>For example, <italic>n</italic> = 5, and the inputs (10, 8, 5, 3, and 2) result in best-case performance. </p>
</sec><sec id="sec5">
<title>Advantages of Algorithm Find-SecondMin (A[], <i>n</i>)</title><p>The advantages of the proposed algorithm are presented below.</p>
<p>It takes linear time complexity, O(<italic>n</italic>). Sorting and finding the 2<sup>nd</sup> smallest requires O(<italic>n</italic><sup>2</sup>) time complexity, hence it is an optimal algorithm for <italic>n</italic> (&gt;=4) values.</p>
<p>The first smallest element is also computed and stored in the variable <italic>fmin</italic>. Hence applicable in determining the initial solution using the approximation method of Vogel.</p>
<p>If the first smallest, say <italic>x</italic>, appears in more than one location, and if the next smallest, say <italic>y</italic>, is available in the input set, then <italic>fmin</italic> = <italic>x</italic> and <italic>smin</italic> = <italic>y</italic>. If all inputs are the same, then <italic>fmin </italic>= <italic>smin</italic>.</p>
</sec><sec id="sec6">
<title>Conclusions</title><p>In general, in the worst case, an algorithm <italic>x</italic> is said to be optimal if no algorithm computes less number of basic operations. Here we meant all possible available algorithms, including those not yet designed. Hence, the word &#x26;#x0201c;optimal&#x26;#x0201d; doesn&#x26;#x02019;t mean &#x26;#x0201c;the best known&#x26;#x0201d;, it means &#x26;#x0201c;the best possible&#x26;#x0201d;. This paper explained the design of an optimal algorithm for finding the second smallest among n numbers. The computational complexity of the devised algorithm is analyzed for all three cases and its advantages are also discussed.</p>
</sec>
  </body>
  <back>
    <ref-list>
      <title>References</title>
      
<ref id="R1">
<label>[1]</label>
<mixed-citation publication-type="other">Ellis Horowitz; Sartaj Sahni; Sanguthevar Rajasekaran: Fundamentals of Computer Algorithms. Galgotia Publications, 2003.
</mixed-citation>
</ref>
<ref id="R2">
<label>[2]</label>
<mixed-citation publication-type="other">Sara Baase; Allen Van Gelder: Computer Algorithms - Introduction to Design and Analysis. Third Edition, Pearson Educa-tion, 2008.
</mixed-citation>
</ref>
<ref id="R3">
<label>[3]</label>
<mixed-citation publication-type="other">T.H. Cormen; C.E. Leiserson; R.L. Rivest; C. Stein: Introduction to Algorithms. Second Edition, PHI, 2003.
</mixed-citation>
</ref>
<ref id="R4">
<label>[4]</label>
<mixed-citation publication-type="other">Aho; Hopcroft; Ullman: The Design and Analysis of Computer Algorithms. Fourth Impression, Pearson Education, 2009.
</mixed-citation>
</ref>
<ref id="R5">
<label>[5]</label>
<mixed-citation publication-type="other">Bhaskaran, S., Marappan, R. Design and analysis of an efficient machine learning based hybrid recommendation system with enhanced density-based spatial clustering for digital e-learning applications. Complex Intell. Syst. (2021). https://doi.org/10.1007/s40747-021-00509-4
</mixed-citation>
</ref>
<ref id="R6">
<label>[6]</label>
<mixed-citation publication-type="other">Bhaskaran, S.; Marappan, R.; Santhi, B. Design and Analysis of a Cluster-Based Intelligent Hybrid Recommendation System for E-Learning Applications. Mathematics 2021, 9, 197. https://doi.org/10.3390/math9020197
</mixed-citation>
</ref>
<ref id="R7">
<label>[7]</label>
<mixed-citation publication-type="other">Marappan, R., Sethumadhavan, G. Solving Graph Coloring Problem Using Divide and Conquer-Based Turbulent Particle Swarm Optimization. Arab J Sci Eng (2021). https://doi.org/10.1007/s13369-021-06323-x
</mixed-citation>
</ref>
<ref id="R8">
<label>[8]</label>
<mixed-citation publication-type="other">Bhaskaran, S.; Marappan, R.; Santhi, B. Design and Comparative Analysis of New Personalized Recommender Algorithms with Specific Features for Large Scale Datasets. Mathematics 2020, 8, 1106. https://doi.org/10.3390/math8071106
</mixed-citation>
</ref>
<ref id="R9">
<label>[9]</label>
<mixed-citation publication-type="other">Marappan, R.; Sethumadhavan, G. Complexity Analysis and Stochastic Convergence of Some Well-known Evolutionary Operators for Solving Graph Coloring Problem. Mathematics 2020, 8, 303. https://doi.org/10.3390/math8030303
</mixed-citation>
</ref>
<ref id="R10">
<label>[10]</label>
<mixed-citation publication-type="other">N. S. Anand, R. Marappan and G. Sethumadhavan, "Performance Analysis of SAR Image Speckle Filters and its Recent Challenges," 2018 IEEE International Conference on Computational Intelligence and Computing Research (ICCIC), 2018, pp. 1-4, doi: 10.1109/ICCIC.2018.8782425.
</mixed-citation>
</ref>
<ref id="R11">
<label>[11]</label>
<mixed-citation publication-type="other">Marappan, R., Sethumadhavan, G. Solution to Graph Coloring Using Genetic and Tabu Search Procedures. Arab J Sci Eng 43, 525-542 (2018). https://doi.org/10.1007/s13369-017-2686-9
</mixed-citation>
</ref>
<ref id="R12">
<label>[12]</label>
<mixed-citation publication-type="other">R. Marappan and G. Sethumadhavan, "Solving channel allocation problem using new genetic algorithm with clique parti-tioning method," 2016 IEEE International Conference on Computational Intelligence and Computing Research (ICCIC), 2016, pp. 1-4, doi: 10.1109/ICCIC.2016.7919671.
</mixed-citation>
</ref>
<ref id="R13">
<label>[13]</label>
<mixed-citation publication-type="other">R. Marappan and G. Sethumadhavan, "Solution to graph coloring problem using divide and conquer based genetic method," 2016 International Conference on Information Communication and Embedded Systems (ICICES), 2016, pp. 1-5, doi: 10.1109/ICICES.2016.7518911.
</mixed-citation>
</ref>
<ref id="R14">
<label>[14]</label>
<mixed-citation publication-type="other">R. Marappan and G. Sethumadhavan, "Divide and conquer based genetic method for solving channel allocation," 2016 In-ternational Conference on Information Communication and Embedded Systems (ICICES), 2016, pp. 1-5, doi: 10.1109/ICICES.2016.7518914.
</mixed-citation>
</ref>
<ref id="R15">
<label>[15]</label>
<mixed-citation publication-type="other">Raja Marappan, Gopalakrishnan Sethumadhavan: Solving Fixed Channel Allocation using Hybrid Evolutionary Method. MATEC Web of Conferences 57 02015 (2016) DOI: 10.1051/matecconf/20165702015
</mixed-citation>
</ref>
<ref id="R16">
<label>[16]</label>
<mixed-citation publication-type="other">Marappan, R., &#x00026; Sethumadhavan, G. (2015). Solving graph coloring problem for large graphs. Global Journal of Pure and Applied Mathematics, 11(4), 2487-2494.
</mixed-citation>
</ref>
<ref id="R17">
<label>[17]</label>
<mixed-citation publication-type="other">Marappan, R., &#x00026; Sethumadhavan, G. (2015). Solution to Graph Coloring Problem using Evolutionary Optimization through Symmetry-Breaking Approach. International Journal of Applied Engineering Research, 10(10), 26573-26580.
</mixed-citation>
</ref>
<ref id="R18">
<label>[18]</label>
<mixed-citation publication-type="other">Marappan, R., &#x00026; Sethumadhavan, G. (2015). Solution to graph coloring problem using heuristics and recursive backtracking. International Journal of Applied Engineering Research, 10(10), 25939-25944.
</mixed-citation>
</ref>
<ref id="R19">
<label>[19]</label>
<mixed-citation publication-type="other">G. Sethumadhavan and R. Marappan, "A genetic algorithm for graph coloring using single parent conflict gene crossover and mutation with conflict gene removal procedure," 2013 IEEE International Conference on Computational Intelligence and Computing Research, 2013, pp. 1-6, doi: 10.1109/ICCIC.2013.6724190.
</mixed-citation>
</ref>
<ref id="R20">
<label>[20]</label>
<mixed-citation publication-type="other">R. Marappan and G. Sethumadhavan, "A New Genetic Algorithm for Graph Coloring," 2013 Fifth International Conference on Computational Intelligence, Modelling and Simulation, 2013, pp. 49-54, doi: 10.1109/CIMSim.2013.17.
</mixed-citation>
</ref>
<ref id="R21">
<label>[21]</label>
<mixed-citation publication-type="other">Raja Marappan, Gopalakrishnan Sethumadhavan, R.K. Srihari, New approximation algorithms for solving graph coloring problem - An experimental approach, Perspectives in Science, Volume 8, 2016, Pages 384-387, ISSN 2213-0209, https://doi.org/10.1016/j.pisc.2016.04.083.
</mixed-citation>
</ref>
<ref id="R22">
<label>[22]</label>
<mixed-citation publication-type="other">Raja Marappan, Gopalakrishnan Sethumadhavan, U. Harimoorthy, Solving channel allocation problem using new genetic operators - An experimental approach, Perspectives in Science, Volume 8, 2016, Pages 409-411, ISSN 2213-0209, https://doi.org/10.1016/j.pisc.2016.04.091.
</mixed-citation>
</ref>
<ref id="R23">
<label>[23]</label>
<mixed-citation publication-type="other">S. Balakrishnan, Tamilarasi Suresh, Raja Marappan: Analysis of Recent Trends in Solving NP Problems with New Research Directions Using Evolutionary Methods. International Journal of Research Publication and Reviews Vol (2) Issue (8) (2021) Page 1429-1435
</mixed-citation>
</ref>
<ref id="R24">
<label>[24]</label>
<mixed-citation publication-type="other">S. Bhaskaran; Raja Marappan: New Personalized Recommendation System for E-Learning. AshEse Journal of Physical Sci-ence. Vol. 5(5), pp. 063-067, August, 2021 ISSN: 2059-7827 DOI: http://www.ashese.co.uk/ajps-v5-issue-5/new-personalized-recommendation-system-for-e-learning
</mixed-citation>
</ref>
<ref id="R25">
<label>[25]</label>
<mixed-citation publication-type="other">S. Balakrishnan, Tamilarasi Suresh, Raja Marappan. (2021) A New Multi-Objective Evolutionary Approach to Graph Color-ing and Channel Allocation Problems. Journal of Applied Mathematics and Computation, 5(4), 252-263. DOI: http://dx.doi.org/10.26855/jamc.2021.12.003
</mixed-citation>
</ref>
<ref id="R26">
<label>[26]</label>
<mixed-citation publication-type="other">Raja Marappan: A New Multi-Objective Optimization in Solving Graph Coloring and Wireless Networks Channels Alloca-tion Problems. Int. J. Advanced Networking and Applications Volume: 13 Issue: 02 Pages: 4891-4895 (2021)
</mixed-citation>
</ref>
<ref id="R27">
<label>[27]</label>
<mixed-citation publication-type="other">Raja Marappan, S. Bhaskaran, N. Aakaash, S. Mathu Mitha. (2022) Analysis of COVID-19 Prediction Models: Design &#x00026; Analysis of New Machine Learning Approach. Journal of Applied Mathematics and Computation, 6(1), 121-126. DOI: http://dx.doi.org/10.26855/jamc.2022.03.013
</mixed-citation>
</ref>
<ref id="R28">
<label>[28]</label>
<mixed-citation publication-type="other">Raja Marappan, S. Bhaskaran, S. Ashwadh, H. Aathi Raj. (2022) Extraction of Drug Review Polarity Using Sentimental Analysis. Journal of Applied Mathematics and Computation, 6(2), 167-177. DOI: http://dx.doi.org/10.26855/jamc.2022.06.001
</mixed-citation>
</ref>
<ref id="R29">
<label>[29]</label>
<mixed-citation publication-type="other">Marappan, R., &#x00026; Bhaskaran, S. (2022). Analysis of Network Modeling for Real-world Recommender Systems. International Journal of Mathematical, Engineering, Biological and Applied Computing, 1(1), 1-7.
</mixed-citation>
</ref>
    </ref-list>
  </back>
</article>