Tag: algorithm

  • Insertion Sort

    Insertion Sort algorithm does the following Keeps the sorted numbers from left to right. Compares the left with right and interchanges the number if left is greater than right. Here is code snippet of Insertion Sort in Swift. [code language=”swift”]var inputArr:[Int] = [Int]() // generate random numbers for rIndex in 0..<10 { inputArr.append(((Int(arc4random()) % 100)))…

  • Selection Sort

    Selection Sort algorithm does the same amount of comparison( N*(N-1)/2 ) like bubble sort but the number swaps (N) is reduced drastically. This sort algorithm traverse through all the items, picks the smallest number and swaps it with left most item. Then the step is repeated for the next smallest number until it reaches the…