Bubblesort

Introduction

This challenge requires a basic understanding of arrays and the Serial Search and Bubble Sort algorithms.

Useful Links:

Task 1

Declare an array (size 10) and populate it with 10 random numbers between 1 and 100.

Create a new method called printArray() that outputs the array to screen using a For Loop.

Add a feature so a user can enter a number.

The program will use serial search to check the array and either return the number or output “Number Not Found”

Task 2

Implement the bubble sort algorithm on your array and sort the algorithm into ascending order.

Use your printArray() method to output the sorted array.

Extensions

1) Using either a counter (easy) or a timer (harder) track the number of comparisons / time taken for an unsorted list to become sorted. You should perform this test many times so might want to set up a test method that repeats the sort for: 10 x arrays size 10, 10 x arrays size 20, …. 10 x arrays size 100. You should be able to take an average from each set and plot them out (In Python I recommend Plotly). You could repeat the test for arrays built from a lesser or greater range of numbers.

2) Improve your BubbleSort so that it will sort in ascending or descending.

About CDB 362 Articles
Self-Employed Software Developer, Spark, Property Management, Hobby Forestry, Ex-Teacher, Engineering - Wood, Metal, Electrics & Computers. Outdoors - Walk, Cycle, Kitesurf,

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.