0.
2
Plot of data from Bubble Sort, Quick Sort Set 1, and Quick Sort Set 2
Qui
c
k
Sor
t
1
Qui
ck
Sor
t
2
Bubbl
eSor
t
0.
18
Execut
i
ont
i
me(
seconds)
0.
16
0.
14
0.
12
0.
1
0.
08
0.
06
0.
04
0.
02
0
0
1
2
3
4
5
6
Setnumber(
16)
Figure 1: Graph for question 6
Answer to question 7:
The execution for Bubble sort is noticeably very low compared to the two instances of
QuickSort, which are markedly higher. Interestingly, the QuickSort1 seems to start with a much
higher execution time than QuickSort2. I believe this can be attributed to the fact that the first
sets may not be cached or loaded in memory when the program first runs, whereas the remaining
sets are. At any rate, the graph indicates that QuickSort1 started with a higher execution time,
implying it did more work at the beginning. Overall, however, it seems QuickSort2 had a higher
execution time. This actually makes sense when we consider that all of the elements in
QuickSort2 are already sorted and we start with the first element. This actually would make more
work for the algorithm. QuickSort generally has a complexity of nlogn with a worst-case
complexity n^2 because it is recursive. When sorting an already sorted list, the program has to
unnecessarily cycle through loops several times, which is only made worse by starting with the
first element which is the smallest. Thus, it spends unnecessary time attempting to find a value
that needs to be sorted, and presumably its complexity meets the worst case scenario of n^2 (or
so the graph indicates). Interestingly, the Bubble sort also has a complexity of n^2, though it still
seems to require less execution time than either QuickSort, and almost appears linear in nature.
Plot of Data From Bubble Sort Lab
of 1
Report
Tell us what’s wrong with it:
Thanks, got it!
We will moderate it soon!
Struggling with your assignment and deadlines?
Let EduBirdie's experts assist you 24/7! Simply submit a form and tell us what you need help with.