Daa Miniproject 2 This Is The Mini Project For Daa
Daa Miniproject 2 This Is The Mini Project For Daa
A PRELIMENERY REPORT ON
OF
SUBMITTED BY,
Vaibhav Ugale
CERTIFICATE
Vaibhav Ugale
Are bonafide students of this institute and the work has been carried out by them under the
supervision of Prof. Sanjay.P.Pingat and it is approved for the partial fulfillment of the
requirement of Savitribai Phule Pune University, for the award of the degree of Bachelor of
Engineering (Computer Engineering)
Place : Pune
Date:
ACKNOWLEDGEMENT
The present world of competition there is a race of existence in which those are having will to come
forward succeed. Project is like a bridge between theoretical and practical working. With
thiswilling we joined this particular project. First of all, we would like to thank the supreme
powerthe Almighty God who is obviously the one has always guided us to work on the right path
of life.
We sincerely thank Prof. R.H.Borhade sir Head of the Department of Computer Science of Smt
Kashibai Navale college of engineering, for all the facilities provided to us in the pursuitof this
project.
We are indebted to our project guide Prof.Sanjay.P.Pingat, Department of Computer Science of Smt.
Kashibai Navale college of engineering. We feel it’s a pleasure to be indebted to our guide for his
valuable support, advice and encouragement and we think him for his superb and constant guidance
towards this project.
We are deeply grateful to all the staff members of CS department, for supporting us in all aspects.
We acknowledge our deep sense of gratitude to our loving parents for being a constant sourceof
inspiration and motivation.
Mini Project
Title: Implement single-threaded merge sort and multithreaded merge sort.
Problem Statement: Implement merge sort and multithreaded merge sort. Compare time
required by both the algorithms. Also analyse the performance of each algorithm for the best case
and the worst case.
Objectives: To analyse the performance of Single-threaded merge sort and Multithreaded merge
sort algorithm for the best case and the worst case.
Outcome: To analyse and conclude which algorithm works best and takes less time for sorting.
Theory:
• Merge Sort: Merge sort is the sorting technique that follows the divide and conquer
approach. It is one of the most popular and efficient sorting algorithm. It divides the given
list into two equal halves, calls itself for the two halves and then merges the two sorted
halves. We have to define the merge() function to perform the merging. The sub-lists are
divided again and again into halves until the list cannot be divided further. Then we
combine the pair of one element lists into two-element lists, sorting them in the process.
The sorted two-element pairs is merged into the four-element lists, and so on until we get
the sorted list
Fast central processing unit (CPU) speed and large memory capacities are needed for
multithreading. The single processor executes pieces, or threads, of various programs so
fast, it appears the computer is handling multiple requests simultaneously.
• Merge Sort using Multithreading: Merge Sort is a popular sorting technique which
divides an array or list into two halves and then start merging them when sufficient depth
is reached. Time complexity of merge sort is O(nlogn).
Threads are lightweight processes and threads shares with other threads their code section,
data section and OS resources like open files and signals. But, like process, a thread has its
own program counter (PC), a register set, and a stack space.
Conclusion: We can conclude that Single threaded recursive Merge sort is more faster in each
and every case than Multithreaded recursive Merge sort.
Package DAA_Project
super(()->{
}); this.start();
}
// Perform Threaded merge sort public sta琀椀c void
threadedSort(Integer[] array){
7
Downloaded by vaidehi dharmadhikari ([email protected])
lOMoARcPSD|47139209
for(Thread t: threads){
try{
t.join();
} catch(InterruptedExcep琀椀on ignored){}
}
琀椀me = System.currentTimeMillis() - 琀椀me;
(begin+end)/2;
//Typical 2-way merge public sta琀椀c void merge(Integer[] array, int begin, int
= 0;
}else{
temp[k] = array[j];
j+=1;
}
k+=1;
// Add remaining elements to temp array from 昀椀rst half that are le昀琀 over while(i<=mid){
// Add remaining elements to temp array from second half that are le昀琀 over
while(j<=end){ temp[k] =
= temp[k];
9
Downloaded by vaidehi dharmadhikari ([email protected])
lOMoARcPSD|47139209
class Driver{
list[i] = random.nextInt(size+(size-1))-(size-1);
each: list)
System.out.print(each+", ");
System.currentTimeMillis(); Arrays.sort(arr1,
System.currentTimeMillis() - t;
MergeSort.mergeSort(arr2, 0, arr2.length-1); t
= System.currentTimeMillis() - t;
merge_sort(): " + t +
10
"ms");
MergeSort.threadedSort(arr); System.out.print("Output
each: arr)
System.out.print(each+", ");
System.out.print("]\n");
11
Downloaded by vaidehi dharmadhikari ([email protected])