610758475-Report-DAA-Project-Sorting-Visualizer 7
610758475-Report-DAA-Project-Sorting-Visualizer 7
Major Project II
(CS-805)
REPORT ON
Sorting Visualizer
BACHELOR OF ENGINEERING
(Computer Science & Engineering)
SUBMITTED TO
SUBMITTED BY GUIDED BY
Krishnakant Mishra(0928CS201047) Mrs. Soumya Bajpai
Asst. Professor
Dept. of CSE
IPS COLLEGE OF TECHNOLOGY AND MANAGEMENT, GWALIOR
April 2024
IPS COLLEGE OF TECHNOLOGY & MANAGEMENT,
GWALIOR (M.P.) - 474001
CERTIFICATE
This is to certify that the major project entitled “Sorting Visualizer” which
is submitted by Krishnakant Mishra (0928CS201047), towards partial fulfilment of
the requirements, for the award of the degree of BACHELOR OF TECHNOLOGY
IN COMPUTER SCIENCE ENGINEERING, is a record of student’s own work
carried out by him under my supervision and guidance. The matter contained in this
project has not been submitted for the award of any other degree.
ACKNOWLEDGEMENT
Every project big or small is successful largely due to the effort of a number of
wonderful people who have always given their valuable advice or lent a helping hand.
I sincerely appreciate the inspiration; support and guidance of all those people who have
been instrumental in making this project a success.
I would like to express my deep sense of gratitude to Mrs. Soumya Bajpai, Department
of computer science & engineering, IPS CTM, GWALIOR for his inspirational
guidance and whole hearted cooperation throughout the duration of this work. His
valuable suggestions and help in writing this manuscript are unparalleled, without
which this project report could not have come into its present form.
I would like to express my sincere thanks to Mr. Raju Sharma, Head, Department of
Computer Science Engineering, IPS College of Technology and Management, Gwalior
for continuous support and providing all the facilities needed during my thesis work.
I am highly obliged in taking the opportunity to sincerely thanks to all the staff members
of Computer Science Department for their generous attitude and friendly behavior.
I also place on record my sincere thanks, Dr. Arun Kumar Tyagi, Director, IPS Group
of colleges and Dr. Anurag Garg, Principal, IPS CTM, Gwalior, for providing
infrastructural facilities to work in, without which this work would not have been
possible.
I am very grateful to my parents and my family members who believe in my capabilities
and have always encouraged and supported me in difficult times of my life.
At last but not least, I would like to thank my friends who have helped me one way or
other, for the successful completion of my project- I thesis work.
Date:
ABSTRACT
The main goal of this project was to create a teaching support software with visualization of
the most known sorting algorithms and their variations. The application supports a graphic
visualization of selected algorithms on randomly generated or manually created array, stepby-
step execution possibility, pseudo-code and current state of variables.
This report outlines a study that tested the benefits of animated sorting algorithms for
teaching. To visualize four sorting algorithms, a web-based animation application was
constructed. A visualization of data is implemented as a bar graph, after which a data sorting
and algorithm may be applied. The resulting animation is then performed either automatically
or by the user, who then sets their own pace. This is a research on the computer science
curriculum's approach to learning algorithms. The experiment featured a presentation and a
survey, both of which asked students questions which may illustrate improvements in
algorithm comprehension. These findings and reactions are catalogued in this document and
compared to earlier investigations.
KEYWORDS: sorting algorithm; educational software; react visualizer; selection sort; merge sort;
bubble sort; insertion sort; heap sort.
INDEX
1. INTRODUCTION
2. SYSTEM ANALYSIS
3. RESEARCH METHODOLOGY
4. REQUIREMENT SPECIFICATIONS
5. SYSTEM DESIGN
INTRODUCTION
6. SYSTEM TESTING
UNIT TESTING
INTRODUCTION
The main goal of the project was to create a program which would serve
as a tool for understanding how most known sorting algorithms work.
There was an attempt to make the best possible user experience. The
demonstration software is made in a user-friendly and easy-to-use style.
To gain maximal benefit from learning you can try each sorting algorithm
on your data.
The text of the report describes principles of the most known sorting
algorithms which are demonstrated in the computer program. It might be
used as a source for learning algorithms by students. Also, the program
might be easily used as a demonstration by lecturers and tutors during
classes. Besides, there is programmer documentation and user guide to
the provided software.
The design and structure of the user interface components has remained
unchanged even if the underlying back-end code was refactored midway
through the construction. Each component has its own feature: The
canvas has twelve features; 10 control buttons, and a volume toggle
button. The canvas area is where the four sorting algorithms are
visualized, and that area will be the location where the sorting algorithms'
output is edited in.
The first row of four blue-bordered buttons at the bottom of the canvas
are the selectable algorithms: Selection Sort, Bubble Sort, Insertion Sort,
and Merge/Insertion Sort. This type of visualization is offered to users to
select an algorithm of their choice, and to observe how that algorithm
functions. Before launching the animation, the user will need to select an
algorithm.
The sorting algorithm must be selected before the input data type is
specified. To choose between sorting input data that is already in order or
to reverse and randomize the order, the three gray-bordered buttons on
the left of the bottom row are available.
Sorted order is the default. The sorting algorithm is picked once the input
and sorting method have been selected. Following, the “Start” button in
the next row of buttons is clicked to perform the sort from the beginning
to the end.
The user can click the yellow-orange-bordered “Step” button to watch the
algorithm step-by-step. Once the process is already underway, you can
simply stop it by pressing the “Stop” button.
The colors are modeled on a traffic light with green being the go signal,
red being the stop signal, and yellow being the signal to slow down (or in
this case, yellow-orange means pace yourself). Additionally, each button
also provides visual feedback to the user by changing color as the cursor
hovers over it. The volume toggle button is the final function that is
available on the Web page. The button appears to the left of a speaker
picture on the lower left-hand side of the web page.
You'll only be able to hear the full four octaves in order if the bars are out
of order. The bar's presently being played color will change to green, and
then, when the sound animation is finished, it will change back to blue.
However, because the animation is hungry with memory, the animation
may stop momentarily and then resume. This means that the sound
animation is turned off by default, but the user has the option to toggle it.
You'll get the best results if you use the sound animation with Selection
Sort.
Fig. Main Window of Application
Before the final phase of development, the design was almost completely
functional, where only three objects were used: one to control the canvas
that displayed the animation, another to represent a piece of data, or “bar”
object (blue rectangle with dynamically changing height and position),
and a final one to represent the positions that each bar moved to, or “pos”
objects. Although this incorporated several function calls, some instance
variables and Boolean values were utilized to keep track of the algorithm
picked and when to animation, but this led to a greatly integrated mass of
code that was difficult to maintain.
Several big refactorings later, the code has now taken on the form of a
Model-View-Controller Architecture. Although, because of its functional
character, it possesses a multitude of individualized functions that alter
the instance variables and Boolean values, which means it has a multitude
of functions that directly alter the View and Controller. The major module
in the HTML code between the <script> and </script> tags is known as
the global scope. Everything within the framework is able to access the
aforementioned variables and methods.
The View
There are three items on the view: the sortArea, the bar, and the position.
These objects operate within the container defined by the <script> and
</script> tags in the .html file. This function's space is sometimes
referred to as the "main" function, the first function invoked in a
program.
Fig. View and explanation of the application
It is the sortArea that keeps the bars up to date using a timer, while at the
same time generating the bar graph. As a result, whenever "Step" is
invoked, the bar values are updated depending on the steps array
(discussed later). In the sortArea, after every second iteration of the timer,
the rectangles will be redrawn with varied heights that represent the new
values.
The bars change sixty times per second, so when the “Step” button is
selected, the change is instantaneous. In the sortArea, the bar object
represents each piece of data. The statement encompasses all of the
aspects of color, value, location, height, and sound. While having a
distinct array named bars for the current bars in the bar graph helps
preserve attributes such as the total number of bars (total value)
independent of other characteristics, it is simple to update any or all of
the attributes by iterating over the array as necessary.
The region on the canvas that is updated when the SortArea event fires is
an x-y pixel coordinate grid. This item was made to make arranging the
bars a little bit simpler (1-32). Thus, if I wanted to move a bar, I would
supply merely the number of the bar's location.
In order for the bar to move, it will first determine the exact coordinates
and then go to that location. Another way to say this is to say that,
position one is defined by the two-dimensional coordinate pair (9, 135),
which is the bottom left-hand corner of the bar. As long as each bar has a
rectangular object that is associated with it, as well as a top left-hand
corner point that defines the rectangle's height, the bar must be relocated
to its right location.
CHAPTER 2 SYSTEM
ANALAYSIS
THE MODEL
The model is made up of one item, known as the sorter. This object
houses the algorithm's code divided into methods. Start method
centralizes on an integer constant and uses it to order the algorithm's
possible algorithms. This object is directly controlled by the four sorting
algorithms shown on the user interface as "Selection Sort, Bubble Sort,
Insertion Sort, and Merge/Insertion Sort." The sort algorithm method is
invoked as the user selects a sorting technique and clicks on one of the
sort algorithm buttons.
Then, when the algorithm sorts the data, a trace is created. The steps
array, which contains all the movements in the animation, is a two
dimensional integer array that is available to methods on the web user
interface. A typical back-end code interface is implemented using the
steps array. The “Start,” “Stop,” and “Step” buttons function as
controllers for which sub-array will be displayed on the canvas, after the
computational back-end has completed the tracing.
If this loads before the user has selected "Start" or "Step", then this
represents a user action. When you click the “Step” button, the next step
on the canvas loads and animates. An animated sequence of a single bar
moving across the others is produced because the timer continually
redraws the bars. There's no “Start” button, only a “Step” button that is
set to go off on a timer. Using a two-dimensional array gives you the
option to view the sorting algorithm's stages within the View.
The process of adding an algorithm is similar to writing down the trace of
the new algorithm, which is then saved in the same location. To complete
the algorithm's walkthrough, the View will cycle through the data and
update the bars in the bar graph to show how the algorithm calculated the
steps it took. It's important to note that if the algorithm generated a
change in the position of a piece of data, the steps are merely recorded.
Let's give an example: When sorting the pieces of data using Selection
Sort, each piece of data is moved to its final and accurate location after
one step, whilst the others require numerous steps to get at their final
positions. While this sorting method appears to do the most effort
compared to other sorting methods, it finishes sorting the most slowly.
As a result, the visualization doesn't provide the correct visual impression
of the data comparisons, which is one of the most important aspects of
sorting algorithms. Two-dimensional arrays do demand more memory
than a one-dimensional array. The size of the array is based on the
number of steps that are required to sort the data.
We may assess the algorithm's space needs by examining how long it
takes. In Computer Science, using Big-Oh analysis is the standard way
for determining how long something will take. The notation consists of a
capital letter O, which represents the worst-case performance of the
algorithm in question, followed by a constraint in parentheses that
describes the worst-case performance of the algorithm.
STRUCTURE OVERVIEW
Program source codes are structured into packages:
Each package contains certain classes, which are grouped by the purpose
of use. Next subsections contain some general descriptions of the classes
from packages. More detailed descriptions of the class functions are
located directly in the source codes.
A Root Package
The root package contains only one class. It is MainUI.java. This class
serves as the main class which starts the application. Although JavaFX
provides the possibility of using XML-based language for creating a user
interface, here it is not used. The MainUI class defines main user
interface elements and does the instantiating of controllers.
All these three packages work with data and data structures, although a
bit differently. Constants package has only an eponymous class. This
class contains final static variables that are used as default values in the
program. Data package contains classes which serve as definitions for
data objects. BindingData class instance holds binding data for the
buttons from the control panel. Results class defines object that is used
for transferring results from the input dialog. Enum package contains one
definition of the enum class. Algorithm enum defines list of algorithms
that are visualized in the program. For example, a list with algorithm
names in the main window is generated from this enum.
Controllers package
NodeControllers package
We shall talk about them next. Before moving on, we describe node
managers generally. These objects are responsive for creation a visual
representation from the given data.
Also, they may create some additional graphic items, e.g. buckets for the
Bucket Sort. Node managers define animations for the certain types of
nodes and define their own metric system for certain type of nodes. The
first is DynamicNodes class. DynamicNodes object manages visual nodes
whose height depends on their value. Then, there is FixedNodes class.
This node manager class defines a manager that controls nodes of fixed
size. Finally, there is Tree node manager. Tree represents manager that
creates and controls a visual binary heap and corresponding visual array.
(a) Dynamic-size nodes (b) Fixed-size nodes (c) Tree nodes
UI package
Utilities package
Algorithms package
And the last, but not the least significant, package called Algorithms. It
contains classes that actually do animating of the algorithms. Each class
that creates animations is supposed to extend Sorting class and implement
the AbstractAlgorithm interface. List of class definitions here
corresponds to the list of algorithms in the Algorithm enum.
Resources
Apart from the source code packages, project has a resource folder inside.
This folder contains images that are used in the program: icons, button
images. Also, it includes CSS files that are used for the styling of the
main window (style.css) and of the input dialog (dialog.css). In the
resource folder exists a subfolder that stores files with descriptions of the
algorithms. File names here correspond to the long names from the
Algorithm enum without spaces. Such name conventions help the reader
tool to find the right description.
CHAPTER 3
RESEARCH
METHODOLOGY
This section contains a description of the research methodologies
followed during the implementation of the project. The project was
implemented with a mixture of both Waterfall and Agile methodologies
often referred to as Hybrid Development methodology. Brief descriptions
of the methodologies are given below.
WATERFALL METHODOLOGY
The waterfall model is the first modern approach to the (SDLC) software
development life cycle model. The model describes the project
development in multiple sequential phases. Each phase track progress of
the project from multiple dimensions and the result of each phase act as
input for the next phase.
system and software design. In this phase, there are two types of
design development High-Level Design (HLD) and Low-Level
Design (LLD). HLD describes the properties of every module
such as description, name, outline, functionality, relationship,
identification of database table, and complete architecture diagram
along with technical details. And LLD is more of a description of
the functional logic of the modules, database table with the
properties like type and size, complete interface details, handling
errors, and input/output for every module.
• Implementation: In the third phase, the coding of the application
begins according to the specification of the system design. The
system is built using the chosen programming of language/s. The
tasks are divided into multiple smaller units which are assigned to
the developers. Along the way, the unit or the modules are
integrated into larger functional components of the system as
described in the previous phases. This is normally the
longestrunning phase-out of all the phases in the waterfall model.
• Testing: Testing is the fourth phase of the waterfall model. Once,
the system is ready, it is deployed or hosted in a testing
environment. The testing of the system is carried out to verify
functional and non-functional requirements are met which is set by
the customer during the requirement analysis phase. During the
testing, the possible bugs and defects are tracked and reported
back to the developers, and fixed. The system is tested multiple
times and the process continues until the application is stable,
bugfree as much as possible, and covers all the business
requirements.
• Deployment: In this phase, the application is deployed or
packaged for installation to the environment where the end-users
can start using it. The system is monitored for any possible
deployment issues.
• Maintenance: After the deployment or release of the system, the
end-users will start using it. During this phase, three major
activities are performed Bug fixing, upgrade, and enhancement.
Feedbacks are taken from the end user's experience and any bugs
that are tracked will be fixed. It ensures the system is consistently
performing as per the specification.
The flow chart below describes the logic of the application. It begins with
opening the application, then the user can see customizable settings in the
application UI. They can be changed, or the default setting can be used in
which case it will generate the steps of sorting for the default sorting
algorithm. To visualize the sorting process, all navigation buttons except
the “reset” button can be pressed or the “start” button for automatic
visualization. The reset button will generate the random array again. After
the visualization is complete, the process can be repeated, or the
application can be closed.
SYSTEM REQUIREMENTS
Since Java is cross-platform, you may use the application within the most
popular PC operating systems where Java is supported. Here are given
minimal system requirements for several operating systems.
Requirements:
Next opportunity is to run it through the command line. For Windows and
macOS it is done the same way. Type the command from below and add
the right path before the file name.
ja va −j a r So r ti ng−V i s u a l i z a t i o n . j a r
Just after running the application, the main window (Figure 12) shows up
and the application is ready to use.
CHAPTER 5
SYSTEM DESIGN
INTRODUCTION
HTML, CSS
CSS stands for Cascade Style Sheets. It is a tool used to add presentation
styles such as colors, layout, animations, and fonts to the web pages. It
allows the web pages to adapt to the different screen sizes across various
devices. CSS is independent of HTML thus it can also be used with any
XML-based markup language. CSS uses a selector to target the HTML
element and add styling to them. The CSS properties can be placed inside
the tag inside the tag of HTML file or it can be separated into a different
file with “.css” extension. Figure 7 below shows a basic HTML file with
CSS for styling.
The codes are written in a file with a “.ts” extension, any valid
JavaScript code is also TypeScript code, but TypeScript’s type
checking will point out errors that might cause possible type
mismatch and help minimize run time errors. The main aim of
TypeScript for building a JavaScript application is to avoid a
potential syntactical error that may cause runtime errors earlier
during the development phase. TypeScript also helps bring a
proper structure and documentation to the codebase and
scalability to the whole project. TypeScript is developed and
maintained by Microsoft.
SYSTEM TESTING
UNIT TESTING
In order to perform an experiment to evaluate my animation tool, we
recruited coworkers to act as test subjects and survey respondents. To that
end, the plan was to expose her Computer Science Data Structures class
to the tool and get them to take part in a survey comprising questions that
gave the students the ability to write down what they observed and learnt,
even if it was little. Despite the class size being of twenty-one students,
only thirteen were present; fortunately, all of the students who had
completed the survey were there. The set-up here was ideal since it
addressed the audience for whom we were designing this course: a group
of college students who were taking their first course in computer science
and who needed assistance with algorithms.
Results
Start by arranging the data, and then pick the visualization algorithm to
use. Algorithm buttons provide sorting of data as it arrives on the
interface. Asking to specify the ordering of elements takes precedence
because when the algorithm has completed running the initialization
process, the interface is now showing a new ordering, while the code has
already completed running the initialization with the prior data set. There
was considerable confusion caused by the way the ordering buttons and
algorithm buttons were shown in the UI after the surveys were
completed.
When beginning the sorting process, the student noted that she was
having problems starting because she believed that she was hitting the
buttons in the wrong order. This then led to her failing to execute the
animation.
Overall, our animation tool did not aid with the understanding of sorting
algorithms. Among those who answered question 3, which questioned if
their knowledge of a particular algorithm changed after using the tool, 5
of the 13 students (38%) stated that they had in some way altered their
previous knowledge of the algorithm. Many thought the tool was a good
concept, while the other 7 did not find it useful at all. It was said that one
student stated a false positive about the instrument (whom I did not
include in the 5 that said it was helpful).
Fig. View after the array is sorted
Feedback
This is consistent with our prior research, which revealed that there was
no substantial difference in learning the content. What we do agree with
totally is the attitude that holds there is a great need to investigate and
produce animated presentations to enhance education in the classroom.
Overall, we are not concerned that a large rework to a different language
will be required soon because JavaScript is still one of the most popular
web languages.
We all know about my laundry list of upcoming projects, but there is one
elephant in the room that still has to be addressed: resolving the memory
difficulties. Following this, we would implement Merge/Insertion Sort,
which takes into account the Merge Sort. Then, we would start up Quick
Sort so as to finish the job because the code is ready to be integrated.
Finally, we would make the online tool available to the public, with the
feature we want most, which is to make it available to the public.
This might be tough as well. The application that created the animation
tool knows that it's available locally, but because of concurrency, it can
serve numerous requests to the web site by separate users. As we try to
figure out how to make the code as efficient as possible, we'd need to
spend some time thinking about how to make it work with numerous
people using it. This would be excellent, as it would enable a form of
comparison study.
REFERENCES
For the successful completion of this project, we referred to multiple
sources for gathering information and data.
These sources include various research papers, related internet sites and
books.