Tuesday, June 4, 2019

The Basic Sorting Algorithms Computer Science Essay

The Basic Sorting algorithmic programs Computer Science EssayIn the following scientific report, the sh arary take algorithms exit be discussed and examined. Timing every last(predicate)ow for be do on the various screen out algorithms and experiments will be done to see which of the different variety algorithms are the most high-octane. Assumptions will be made on which sorting algorithm is the most efficient and therefore compare the results to see if the overcompensate assumption were made.We will discuss the reasons why each sorting algorithm is efficient and under which conditions are efficient. A brief explanation of each sorting algorithm will be given to get the basic intellect what its all about. Then a brief conclusion will be done to round of the scientific reportBubble sort is probably one of the most popular and simple sorting algorithm. It is often utilize as a programming exercise for beginners because it is relatively easy to grasp and understand. The p roblem though is that its not very efficient, therefore bubble sort completely gets used one time in a blue moon. There are more efficient sorting algorithms used in real application and that will be discussed in a later stage.It basically cardinal steps that happen in bubble sort, which areIt compares each pair of adjacent elements from the start of the array and, if they are not in the proficient value, they get swappedIf at least one swap has occurred the you repeat step one until no egresss gets swappedHeres a chartical example how Bubble Sort works.Bubble sort http//www.algolist.net/Al We going to sort an array 5, 1, 12, -5, and 16 using bubble sort.Selection sort full like bubble sort is one of the simplest of the sorting algorithms and it works very well with small files.The concept of this algorithm is quite simple. The array is said to be divided in two kick downstairss, a sorted part and an unsorted part. At the beginning the sorted part is empty while the unso rted part is the whole array. At every step the method/algorithm finds the smallest element in the unsorted part of the array and the ads it to the end of the sorted part of the array. When the unsorted part becomes empty the algorithm stops.Insertion Sort just like bubble and Selection is one of the most basic and most common sorting algorithms around. This sorting algorithm is more efficient than the other to because it has fewer comparisons than the other two, but this will be discussed in more detail later on. cipher about how you sort a deck of cards. You start from the beginning and work through the deck and as you find cards that arent in the right order you remove them and place it in the right order, and you do the this until all the cards are in the right position and your deck is sorted This is the main idea behind Insertion sort.The MethodInsertion sorts breaks up the array in two parts, sorted and unsorted. At the start the sorted part of the array only contains one ele ment. Each step the algorithms hang ons, it expands the sorted part of the array by one and then places the first element of the unsorted region and places it in the right place in the sorted area. This will carry on till the whole array will be a sorted array.The illustration on the right hand side shows step by step how insertion sort works.Shell sortShell sort algorithm is one of the first sorting algorithms out there and was invented by D.L Shell in 19593. It is quite effective and easy to comprehend. The sorting algorithm follows two standard procedures1. It arranges the data into a two dimensional array2. The columns of the array will then be sorted at once the procedure has been concluded, the resultant data rate is placed into another(prenominal) two dimensional array, but with less columns. The columns are then sorted and the in a higher place procedure is repeated until a single sorted column is unexhausted 3.MERGESORTThe unite sort algorithm uses divide and conquer approach. The algorithm firstly divides the data sequence into two halves, sorts the two halves and then combines them together to form a sorted set of data sequences. 4Figure 0-4 http//www.inf.fh-flensburg.de/lang/algorithmen/sortieren/merge/mergen.htmIn the above figure it illustrates the basic merge sort process. It starts by dividing the unsorted data sequence a into to unsorted data sequences b and c. The data sequences b and c are then sorted with recursive calls to form b and c. Once the two halves are sorted, they are combined to form a sorted data sequence namely a 4.Quick sortQuick sort is the high-speed sorting algorithm when it comes to large elements in an array. Quick sort has to make use of recursion, because of the way quick sort, sorts the elements.The way quicksort works is that there are tierce pointers, namely a left, right and pin tumbler pointer, the turn pointer is the most important one. The Left pivot will point to the most left element in the array and the right to the most right element in the list. For the pivot any number can be chosen, but its normal approach pattern to make the first element your pivot.The stepsPivot and left pointer points to the 1st element in the list and right to the last elementThe pivot pointer will now compare the object that its pointing at with the one that the right pivot is pointing at.If the right pointer objects are little than the pivot then the two objects swap, it is important to note that the pivot will always point to one number, so if that number moves so does the pivot, the right and left pivot stays in its respectable place.If the right pointer object is not smaller that pivot, the right pivot will just move left until a smaller one is foundOnce the pivot swaps with the right pivot , the pivot and the right pointer will point to the same object, therefore the right pivot will not move anymore now the left pointer will move one rightThe left pointer and the pivot will now compare, and i t the left pointer object is bigger than the pivot object then it will swap, and the pivot will now join the left pointer. This will then let the right pointer move one leftThis will carry on until all three pointers point to the same object, this gist that the object is in its perfect position, to the left of this object no number will be bigger than it and to the left no number would be smaller.Once it found the first object in its perfect place, it will then move to the left hand side of that objectIt will follow all the above steps with the left side.Ones the left side is all sorted it will then go to right side of our first perfect number and sort the right hand side with the same procedure(To see a Illustrative example see Appendix A)Sorting AlgorithmsFigure -Sorting AlgorithmFigure 1 above shows us the relationship of time (ms) and the number of objects the sorting algorithm has to sort. There are 5 sorting algorithms mea indisputabled in this experiment namely Bubble sort, Insertion Sort, Selection Sort, Double Insertion and Double Selection sort. As can be find from the graph above s that all quin sorting algorithms has the same trend but some just increases more than the other and sometimes by quite a substantial amount. First thing noticeable is that if we sort little objects, lets say less than 2000 objects, then it does not matter what algorithm we use all of them are at about the 0ms mark. Only when we get to about the 10000 objects mark, then only the sorting algorithms really shows who the best is.As we can see from the graph is that Bubble Sort is the least sorting Algorithm and is basically just used to explain the sorting procedure to new comers to the programming language. Bubble excerption and Double selection are very similar when it comes to efficiency. The most efficient sorting algorithm by far is the Insertion Sorts. As can be seen by figure 1 Double insertion is the most efficient and it all works on how the sorting algorithm sor ts the array which is discussed in the defraud portion of this report.Experimental ProceduresWhat was needed to run the experimentThe apparatuses needed for his experiment where a Computer, Visual studio C, and a user that has been tutored for Sorting algorithmsHow experiment was executedCode where write for each sorting algorithm in a method in a specific program. A new measure class was created, to have something to time how fast or slow the different sorting algorithms gets sorted. Then the method for each 5 sorting algorithms gets executed and run five times to get an average, to eliminate errors that might have been caused. After all the data has been recorded, a graph was plotted1. This graph was then evaluatedProblems that machinateThe main problem that happened was, each time the programme ran the results werent always constant. And if the programme was not a dedicated programme (i.e. the only programme running at the time) then the values went haywire. This problem was f ixed by forcing the visual studio to run a garbage collector and collect all the garbage, to make sure that when programme runs all the processing power is used for the programme so the times will be more accurate.ConclusionIn this report five different sorting algorithms where discussed. Each one was investigated and briefly explained how they work, and why each one is efficient in their own right. As the experiment when on it was noticed that some sorting algorithms are less efficient than others and that had all to do with how each sorting algorithm works.When figure-1 was examined, it was concluded that Bubble sort was the least efficient of the different sorting algorithms and that Double insertion Sort was the most efficient of all the sorting algorithms.From this we can conclude that Bubble sort is best used just to explain or introduce the sorting algorithm to a new student. As soon as you want to have an efficient sorting algorithm the Double will be the best because less t ime will be spent to sort the objects in the arrayReferenceshttp//wiki.answershttp//www.c.happycodings.com/Sorting_Searching/code17.htmlhttp//stackoverflow.com/questions/832765/whats-a-bubble-sorthttp//www.inf.fh-flensburg.de/lang/algorithmen/sortieren/shell/shellen.htmhttp//www.inf.fh-flensburg.de/lang/algorithmen/sortieren/merge/mergen.htmhttp//www.algolist.net/Algorithms/Sorting/Bubble_sorthttp//www.algolist.net/Algorithms/Sorting/Selection_sorthttp//www.algolist.net/Algorithms/Sorting/Insertion_sort

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.