Interview Questions

  • View all interview questions
  • blank
  • Implement bubble sort
    Implementing bubble sort is used as an example of a slightly harder problem that one should solve to be prepared for the App Academy bootcamp. The source link is listed below, but the statement was:
    I often use "implement bubble sort" (in a beginner-friendly language like Ruby or Python) as an example of one of the harder problems I had to do in order to get in to App Academy.
    We'll go ahead and implement bubble sort in JavaScript and Python below. Bubble sort is actually a very slow algorithm that one should never attempt to seriously use, but the algorithm is simple enough to implement which is why this question might be asked.

    Sources

    http://www.patheos.com/blogs/hallq/2014/06/so-youre-thinking-of-applying-to-app-academy

    Algorithm




    You need to be a premium member to see the rest of this question and code.

    Become a Premium Member

    With our large collection of challengs, tutorials, and solutions, we make it easy for you to become a better coder, prepare for interviews, and learn new skills from more experienced coders.

    “If you're able to solve Medium Coderbyte problems and have a good understanding of web development basics [...] then you are probably ready for admissions at the top schools.” ― Huntly Mayo-Malasky
    • 200+ Coding Challenges
    • Mock Interview Questions
    • 500,000+ Code Solutions
    • Algorithm Tutorials
    • Interview Prep Courses
    mrdaniel published this on 11/24/15 | javascript, bootcamp, array, sorting, App Academy
    Comments
  • +
  • 1
  • -
  • swap(array,i,j) {
    let temp = array[i]
    array[i] = array[j]
    array[j]=temp 
    }
    function bubbleSort(array) {
        let swaps = 0;
        for (let i=0; i<array.length - 1; i++) {
            if (array[i] > array[i + 1]) {
                swap(array, i, i + 1);
                swaps++;
            }
        }
    
        if (swaps > 0) {
            return bubbleSort(array);
        }
        return array;
    };
    bubbleSort([5,2,3,4,8,7,10]) 
  • +
  • 0
  • -
  • Solution via C#:
    
            static void BubbleSort(ref int[] array)
            {
                for (int i = array.Length - 1; i > 0; i--)
                {
                    for (int j = 0; j < i; j++)
                    {
                        if (array[j] > array[j + 1])
                        {
                            Swap(array, j, j + 1);
                        }
                    }
                }
            }
    
            public static void Main(string[] args)
            {
                    int[] array = { 8, 7, 6, 5, 3, 5, 1, 0 };
                    BubbleSort(ref array);
                    string str = string.Join(",", array);
                    Console.WriteLine(str);
            }
    
    
    Login to submit a comment