DAA Assignment PDF
DAA Assignment PDF
ALGORITHMS ASSIGNMENT
PANJAB UNIVERSITY SSG-RC
SUBMITTED TO:
MR. GURPINDER SINGH
SUBMITTED BY:
Ankur
BE(IT) 5th SEM
SG-17801
QUICK SORT
In case of quick sort, the array is parted into any ratio. There is no compulsion of
dividing the array of elements into equal parts in quick sort.
The worst case complexity of quick sort is O(n2) as there is need of lot of
comparisons in the worst condition.
Efficiency :
Quick sort is more efficient and works faster than merge sort in case of smaller
array size or datasets.
Sorting method :
The quick sort is internal sorting method where the data is sorted in main memory.
Stability :
Quick sort is unstable in this scenario. But it can be made stable using some
changes in code.
Preferred for :
Quicksort exhibits good cache locality and this makes quicksort faster than merge
sort (in many cases like in virtual memory environment).
MERGE SORT
In the merge sort, the array is parted into just 2 halves (i.e. n/2).
In merge sort, worst case and average case has same complexities O(n log n).
Merge sort can work well on any type of data sets irrespective of its size (either
large or small).
Merge sort is not in place because it requires additional memory space to store
the auxiliary arrays.
Efficiency :
Merge sort is more efficient and works faster than quick sort in case of larger
array size or datasets.
Sorting method :
The merge sort is external sorting method in which the data that is to be sorted
cannot be accommodated in the memory and needed auxiliary memory for
sorting.
Stability :
Merge sort is stable as two elements with equal value appear in the same order in
sorted output as they were in the input unsorted array.
Preferred for :
Quicksort exhibits good cache locality and this makes quicksort faster than merge
sort (in many cases like in virtual memory environment).
BINARY SEARCH
The best case time in binary search, it is for the middle element, i.e.,
O(1).
We can use Dijkstra’s shortest path algorithm for finding all pair shortest paths by
running it for every vertex.
time complexity of this would be O(VE Log V) which can go (V3 Log V) in worst case.
It is greedy algorithm.
Floyd Warshall
Lastly Floyd Warshall works for negative edge but no negative cycle.
Time complexity is O(EV log V) with binary heap and o(E+VlogV)with Fibonacci
heap.
The next node include must be connected with the node we traverse.
It traverse the one node several time in order to get it minimum distance.
Greedy algorithm.
KRUSKAL ALGORITHM
It start to built the mst from minimum weighted vertex in the graph.
The next edge include may or may not be connected but should not form the cycle.
It traverse the edge only once and based on cycle it will either reject it or accept it.
Dynamic algorithm.
BELLMAN FORD
Calculations for node n involves knowledge of link cost to all neighboring node plus
Each node can maintain a set of costs and path for every other node.
Complexity is O(n^3).
Factors 0/1 Knapsack Fractional Knapsack