Professional Documents
Culture Documents
ALGORITHM
NAME : MUHAMMAD TOQEER
REG NO : BSCS-2020-34
PROBLEM : 01
Empirical Analysis of Algorithms Write a program that
shows you Empirical Analysis of Growth of Two
Algorithms belonging to diverse classes (linear,
logarithmic, quadratic, etc.). Then Process should be
executed which should be an algorithm to solve any
problem such as searching, sorting or any other task on
data structures, Matrix Operations or any other problem
you like to solve. Then for increasing values of n, show
the increase in time (in any unit). NOTE: Size of the data
should be randomly generated. Input values can be
randomly generated. (for some diverse algorithms, this
condition may not apply). No two students can have same
algorithms and same code and same execution and same
Graph (obviously). PLUS: Output of One Algorithm (out
of two) should be Dry run of the algorithm. PLUS: Share
Acknowledgements and References.
ALGORITHMS
01: BUBBLE SORT
ITS TIME COMPLEXITY IS O(n) “ BEST CASE “
BUBBLE SORT :
* Start with an unsorted array of elements.
* Compare each element with its adjacent element.
* If the adjacent element is smaller, swap them.
* Repeat this process for each pair of adjacent
elements, moving from the beginning to the end of
the array.
* After one pass, the largest element will be in its
correct position at the end of the array.
* Repeat steps 2-5 for the remaining unsorted part of
the array until the entire array is sorted.
SELECTION SORT :
—-----------------------------
OUTPUTS:
01)
02):
—-----------------------------------------------------------------
def bubble_sort(arr):
n = len(arr)
for i in range(n):
for j in range(n-i-1):
if arr[j] > arr[j+1]:
arr[j], arr[j+1] = arr[j+1], arr[j]
def selection_sort(arr):
n = len(arr)
for i in range(n):
min_idx = i
for j in range(i+1, n):
if arr[j] < arr[min_idx]:
min_idx = j
arr[i], arr[min_idx] = arr[min_idx], arr[i]
bubble_sort_times.append(bubble_sort_time)
selection_sort_times.append(selection_sort_time)
—-------------------------------------------------------------------
—-------------------------------------------------
Acknowledgements 🙂
TO REVISED THE ALGORITHMS ,
REFERENCE 👍
www.geeksforgeeks.org