You are on page 1of 3

CSC508 : DATA STRUCTURES

LAB ASSIGNMENT 2 (SORTING)

NAME : MUHAMMAD HARITH IKHWAN BIN ROSMAEINI

Insertion Sorting
SIZE 10 100 1000 10 000 100 000
EXP 1 0ms 0ms 4ms 27ms 1447ms
EXP 2 0ms 0ms 4ms 25ms 1192ms
EXP 3 0ms 0ms 4ms 26ms 1176ms
EXP 4 0ms 0ms 4ms 31ms 1172ms
EXP 5 0ms 0ms 5ms 23ms 1304ms
EXP 6 0ms 0ms 3ms 25ms 1086ms
EXP 7 0ms 0ms 4ms 24ms 1132ms
EXP 8 0ms 0ms 6ms 22ms 1089ms
EXP 9 0ms 0ms 3ms 26ms 1184ms
EXP 10 0ms 0ms 4ms 27ms 1153ms
AVERAGE 0ms 0ms 4.1ms 25.6ms 1193.5ms

Merge Sorting
SIZE 10 100 1000 10 000 100 000
EXP 1 0ms 0ms 1ms 3ms 24ms
EXP 2 0ms 0ms 1ms 4ms 24ms
EXP 3 0ms 0ms 1ms 5ms 23ms
EXP 4 0ms 0ms 1ms 4ms 24ms
EXP 5 0ms 0ms 0ms 3ms 25ms
EXP 6 0ms 1ms 1ms 6ms 27ms
EXP 7 0ms 0ms 1ms 5ms 23ms
EXP 8 0ms 0ms 1ms 3ms 24ms
EXP 9 0ms 0ms 1ms 3ms 24ms
EXP 10 0ms 0ms 0ms 4ms 25ms
AVERAGE 0ms 0.1ms 0.8ms 4ms 24.3ms
Heap Sorting
SIZE 10 100 1000 10 000 100 000
EXP 1 0ms 0ms 1ms 3ms 20ms
EXP 2 0ms 0ms 0ms 5ms 20ms
EXP 3 0ms 0ms 0ms 3ms 18ms
EXP 4 0ms 0ms 1ms 3ms 20ms
EXP 5 0ms 0ms 1ms 2ms 21ms
EXP 6 0ms 0ms 1ms 2ms 19ms
EXP 7 0ms 0ms 1ms 3ms 23ms
EXP 8 0ms 0ms 0ms 4ms 20ms
EXP 9 0ms 0ms 1ms 2ms 18ms
EXP 10 0ms 0ms 0ms 4ms 21ms
AVERAGE 0ms 0ms 0.6ms 3.1ms 20ms

Selection Sorting
SIZE 10 100 1000 10 000 100 000
EXP 1 0ms 0ms 3ms 70ms 6367ms
EXP 2 0ms 0ms 4ms 66ms 5843ms
EXP 3 0ms 0ms 4ms 73ms 5883ms
EXP 4 0ms 0ms 3ms 72ms 5890ms
EXP 5 0ms 0ms 5ms 71ms 5798ms
EXP 6 0ms 0ms 3ms 76ms 5715ms
EXP 7 0ms 0ms 4ms 71ms 5715ms
EXP 8 0ms 0ms 4ms 72ms 5890ms
EXP 9 0ms 0ms 6ms 75ms 5907ms
EXP 10 0ms 0ms 5ms 77ms 5980ms
AVERAGE 0ms 0ms 4.1ms 72.3ms 5898.8ms
Report based on above test
Introduction:
In the context of data structures, sorting algorithms are used to organize data in a structured
and easily accessible manner. They allow us to rearrange the elements of a data structure,
such as an array or a linked list, based on a specific sorting order.
For this test will be using size 10,100,1000,10000,100000 to test the time it take to sort
the random number.
Results:

1. Insertion Sort have a very good record to the smaller number but as the array got to
(100000 number) it take a long time to sort those number compare to heap and
merge.

2. Merge Sort can be considered as one of the best sorting method as it stay
consistent as the size of the array get bigger . the time it took for it to sort the
number will stay consistent and short compare to insertion and selection but it
cannot beat heap sorting method.

3. Heap Sort will be the best method to use when sorting numbers in an array as the
time it took to sort any numbers as the size of the array got bigger is the shortest
compare to other method as example when sorting (100000numbers) the average
time it took is 20ms which is the shortest.

4. Selection sort will be the longest for the time it took to sort number as the array
size got bigger with an average of 5898.8ms for sorting 100000 numbers

Conclusion :
In summary, if you have a small dataset or need a simple implementation, Insertion Sort
might be suitable. For larger datasets or when efficiency is crucial, Merge Sort or Heap Sort
are better choices. Selection Sort is generally not recommended for larger datasets due to
its poor performance compared to the other algorithms.

You might also like