Assign 01
Assign 01
Submitted to
Dr. Naveed Anwar Butt
Submitted by
Tooba Khan 22021519-016
Class
BSCS – 6 – C
Course Name
Design and Analysis of Algorithms
Semester
Spring 2025
Deadline
20th February 2025
Counting Iterations in Relation to Input Size n: The loop takes n iterations in the
worst case (where the element is at the last location or cannot be retrieved) when it runs
from i = 0 to i = n-1.
Conclusion
Worst-case complexity: O(n) (element is not present or found at the last position).
Best-case complexity: O(1) (element is found at the first position).
Average-case complexity: O(n) (element is expected to be somewhere in the middle on average).
In conclusion
• The worst-case complexity, which is comparable to Binary Search, is O(log n).
• If the element appears in the first few comparisons, the best-case complexity is O(1).
• O(log n) is the average-case complexity.
In conclusion
• The worst-case complexity, which always necessitates merging, is O(n log n).
• Best-case complexity: O(n log n) (recursive calls are made even if the data has already been
sorted).
• Because of the consistent divide-and-conquer structure, the average-case complexity is O(n log
n).
Merge sort and fast sort performance comparison
When stability is crucial, such as when sorting records with several fields, merge sort is
recommended.
• Because QuickSort is in-place and requires less memory, it is typically faster in practice.
• For big datasets, both algorithms perform better than O(n2) sorting algorithms like Bubble Sort
and Insertion Sort.