Interactive Approach to Learning of Sorting Algorithms

— Today we live in a society of high technologies, advanced information and communication systems in every field, including education. So, in modern education, teachers make full use of the possibilities of modern Information and Communication Technologies (ICT). In this case, the attitude of the teachers towards the use of computers, to achieve the educational goals, is very important. To have the technologies sustained and significant effect, students in secondary and higher schools need to understand how to use them. The goal of this article is to help of students in secondary and higher schools to acquire enough practical programming skills and to learn the sorting algorithms, i.e. the article considers basic sorting algorithms. We developed and describe here software with name “Visual sorting” that shows visual, the execution of the basic sorting algorithms: Bubble sort; Selection sort; Insertion sort


Introduction
Today we live in a society of high technologies, advanced information and communication systems in every field, including education. In last years the high technologies, radically changed the people's lifestyles, the businesses and the education in secondary and higher schools [1][2][3][4]. As a result from the rapid development of new Information and Communication Technologies (ICT) in education, which enables a two-way connection in real time, the forms of regular, part-time, distance and individual educational are interweaves.
Increasingly, the people have need access to information and if the schools and universities cannot provide it, the people will turn to other institutions. That is why educational institutions should not lag behind technological progress. From this point of view, the education field is becoming in constant consumer of high-tech products.
Today, the access to information is accomplished through computer, using computer networks and software products, which offer many more alternatives than any textbook. Through ICT the students in secondary and higher schools have access to huge number of information sources (electronic libraries, electronic books and magazines, websites of various institutions and people, etc.). This information stream is two-way at any time of the day -from web space to the students (colleagues, teachers, experts, followers, friends and etc.) in secondary and higher schools and vice versa. So, the attitudes of teachers to the use of computers and Internet to achieve the educational goals are very important, if we want to have successful learning, using the full potential of modern ICT.
Only innovations are not enough. Without the right set of skills, the students in secondary and higher schools will not be able to take advantage of the opportunities that they will face in the future. That is why the global companies, such as Microsoft, are committed to both technology innovation, and education and training. To have the technologies sustained and significant effect, the people should learn how to use them, and this educational process should last a lifetime.
The aim of this article is to help of students in secondary and higher schools to acquire in-depth knowledge and enough practical programming skills for Sorting algorithms and .NET framework. To achieve this aim, using C# programing language, we developed software for visual implementation of some basic sorting algorithms. This software shows step by step sorting process and performance of individual sorting algorithm, which can be very useful in learning and understanding sorting algorithms in education of student in secondary and higher schools.
The C# programing language is an object-oriented language, which is used by programmers around the world to develop applications for .NET platform. This language is built-on the base of the C, C++, Visual Basic (VB) and Java programing languages and provides a complete development environment for applications. The C# programming language combines the power of C, the C++ object-orientation, and VB graphical interface [5][6][7][8][9].
In the sections below, we: • Make short descriptions of basic sorting algorithms • Present our software with name "Visual sorting" • Show the run of "Visual sorting" software 2

Material and Method
Often, when we work with large dataset (the data are from one type), it is necessary to introduce some rules that make it easier to process them. The ordering of the elements could give us a significantly more efficient search algorithm, compared to the case where the data is not sorted.
The sorting is a process of rearranging (permuting appropriately) the dataset elements in a particular order [7]. The sorting is a major activity with a wide range of applications: dictionaries, telephone directories, indexes, and anywhere where is required fast searching of different objects. Depending from the type of the sorted data, the sorting process can be done in a variety of ways.
There are different classifications of the sorting algorithms. Probably the most popular classification is according of data location. Based on this criterion, we can find two types sorting: internally (data is in RAM's computer and often is possible direct access to any element of the dataset) and externally (the data is in external memory (flash drive, Hard Disk Drive and etc.) and often, we access them strictly sequential, starting from the first element). According to the operations, performed over the elements, we have sorting by comparison (usually by using the operators <, > and =) and sorting by transformation (using arithmetic operations, without direct comparison of pairs of elements). Other important classifications are based on certain properties of the sorting algorithms. Example, persistent and unsustainable. We call one method a persistent method, when in sorting process the relative order of elements with equal values remains unchanged. The persistent methods are preferred, when the dataset elements are already sorted, according to other criterion.
Main requirement to sorting algorithms is minimum costs of additional memory. Also, important requirement is the minimum number of comparisons and exchanges in sorting process. Usually, the sorting process is done by a simple exchange of the locations of two elements in array [7].
The sorting algorithms, those are included in developed by us and described here software "Visual sorting", are as following: Bubble sort, Selection sort, Insertion sort and Merge sort.

Bubble sort
Bubble sort has a worst-case and average complexity of О(n 2 ), where n is the number of elements being sorted. It is recommended for small values of n.
Let a0, a1, ..., an-1 to be a sequence that we want sort in increasing order. The algorithm is as follows: 1. Let the variable right = n-1. 2. For the sequence a0, a1, ..., aright we compare sequentially each two adjacent elements ai and ai+1. If ai > ai+1, we exchange them and keep the exchange position i in variable k. If ai <= ai+1, we don't change the locations of elements. The process continues until the end of the sequence. If, in this process, after the exchange of i and i + 1 elements has not been done other exchanges, therefore the elements k+1, k+2, ..., n-1 are sorted in correct order. 3. right = k. 4. If right > 0, we go to Step 2 and Step 3. 5. If right = 0, the sequence is sorted.

Selection sort
Selection sort has O (n 2 ) complexity. The main idea of this method is following: we find the smallest (biggest) element, put it in the beginning of the array, and excluding it from consideration. We repeat these steps for all elements from the sequence that we want to sort [10].

Merge sort
In the basis of this sorting algorithm is the "Divide and Conquer" method, i.e. the algorithm divide the input sequence into two parts, sort each of them in increasing/decreasing order and then combine (merges) the obtained sub sequences. The Merge sort algorithm is one of the most effective sorting algorithms. This algorithm has O(n log n) time complexity.
The source code for the sorting algorithms in C++ and Pascal programming languages are presented in Appendix.

2.5
The "Visual Sorting" software In this article we show developed by us software with name "Visual Sorting". The aim of this software is to make visual representation of performers (step by step) of described above sorting algorithms. We can run our software as desktop application, i.e. we do not need to make installation, just copy and paste the folder with software files on our computer. To develop the "Visual Sorting" software we use C# 2010 Express Edition and MS Visual Studio 2010 Express Edition with Framework 2.0. As we said above, the software contains realizations of described in previous sections sorting algorithms: • Bubble sort -has O(n 2 ) complexity • Selection sort -has O(n 2 ) complexity • Insertion sort -has O(n 2 ) complexity • Merge sort -has O(n log n) complexity For each of these sorting algorithms, our software allows interactive tracking of performance (step by step). For each step of the performance of the chosen algorithm, the array elements that are under consideration are colored in appropriate colors and the software shows message for the action being performed at the respective step from the algorithm execution.

3
Results and Discussion 3.1 Main form of the "Visual Sorting" software Figure 1 show the main form of the "Visual Sorting" software. From main form we can select the number of elements (the maximum number is limited to twenty elements) that need to be sorted. If we enter a number large than twenty elements, the software will display a warning message for too many elements. Once we entering the number of elements, the radio buttons "Generate elements" and "Manual input" are enabled. The button "Generate elements" automatically generates array with the specified number of elements, and the button "Manual Input" allow us to enter sequentially elements (manual generate an array), using the field "Element No." and pressing the "Enter" key. Once the array is generated (automatically or manually), the software displayed it in the "Sorting Results" panel as follow: After that the "Sorting algorithm" list is enabled. This list allows us to choose the sorting algorithm that want to monitor. Once we choose a sorting algorithm, the buttons "Sort", "C ++ Source", and "Pascal Source" are enabled.
To start the sorting process, we need to press the "Sort" button, which will performs the first sorting step, will displays the result in the "Sorting Results" panel, and below the "Sort" button will displays the message "Perform the Steps", button "Continue" and button "Stop" (see Figure 2). The "Continue" button sequentially performs and visualizes the individual steps of the sorting process, and with the "Stop" button the sorting process may be interrupted. The result of the implementation of the chosen algorithm can be deleted by pressing the "Clear" button, which is located under the "Sort" button. Figure 3 shows the obtained result using Bubble sort and array with six elements (automatically generated). The software marks with white color the elements of initial array, with red color the elements that are compared in the current step, and with blue color already sorted elements (see Figure 3). Also, for each of the steps, the software describes the current action (whether or not the relevant elements are exchanged). The next figure (see Figure 4) shows the implementation of Merge sort algorithm.

3.2
The form "Source code" Developed software "Visual Sorting" can shows C++ or Pascal source code for any of the described in previous section algorithms. The buttons "C ++ Source code" and "Pascal Source code" (Main form), open a form that contain C++ (see Figure 5) or Pascal (see Figure 6) source code for the chosen algorithm.  Using this form, the students can study the source code in C++ and Pascal programming languages, for each of the algorithms that are included in developed software.

Conclusion
In conclusion we can say that the use of the visual and event-oriented programming in the Computer science courses is excellent choice and they give us perfect results. For successful implementation of training courses that use the full potential of modern technology, very important are both the mindset and attitude of the lecturers to these technologies, and their use in the learning process, to achieve the educational goals [11][12][13][14][15][16][17][18][19].
In this article we considered the sorting algorithms that are included in the developed by us software with name "Visual sorting". Also, we presented our software to interactive tracking of the progressive execution of sorting algorithms.