Creating Bubble sort simulation with JavaScript

Creating Bubble sort simulation with JavaScript

Couple of years ago I interviewed with one of the software companies. Interview went really well. Position required extensive knowledge of Drupal and other basic web technologies such as PHP, JavaSCript and CSS.

I did not encounter any specific technical questions in our 45 minutes talk. But it was quite nice to talk with some smart creative like that interviewer. We exchanged information on what we were working on and what we like about our jobs.

At the end of interview (of course) he gave me an assignment which was to be submitted within 24 hours of reception. Fortunately it was Friday evening, so I had full Saturday to work on it. Problem was like this,

Write a simulation of bubble sort algorithm using PHP.

Looked like an interesting problem and I took a dive into it. There was bonus point to impress the company if I could write this project as a Drupal module, it would be awesome.

Though sounds like good idea to get a job, it was not really possible for me to learn Drupal in a day from scratch.

Finally I wrote it mainly using JavaScript and PHP as backend.

I never figured purpose of using PHP specifically for this project. It was purely possible to write it client side

I submitted solution well within 24 hours of allotted time. But I never got any feedback from them. But it was fun, creative and challenging project to work on. I took an inspiration from Wikipedia Quicksort simulation.

This is a quick screenshot of my simulation project,

Bubble sort simulation

Below is an overview of available options in this version :

  • Ability to input random of numbers to sort

(User is required to provide max cap limit. Algorithm will then generate specific number of elements between 0 and max limit)

  • Specify an animation type - Continuous or step mode
  • Ability to show current index being processed
  • Ability to display min and max numbers once sorting is completed
  • Ability to show swapped numbers
  • Control to sort numbers in ascending or descending order

Default is an ascending order

Here's a demo if you wish to play with it

http://jayeshkawli.com/BubbleSortSimulation/bubbleSortSimulation.html

(I will appreciate if you find any bugs in the implementation. I always take bug reports quite seriously and try to address them as soon as possible)

Code is also hosted on GitHub Here if you want to fiddle with it.