Algorithm Analysis - Types, Time, & Examples
Algorithm Analysis - Types, Time, & Examples
Havi
List and explain the three types of analysis one can perform on Algorithms
What is time complexity and what does it indicate?
List six sort algorithms
List two search algorithms
3/3
There are three types of analysis that one can perform on algorithms:
Time complexity analysis: This involves analyzing how the running time of an algorithm
increases as the size of the input increases. It measures the amount of time an algorithm takes
to execute as the input size grows, usually in terms of big O notation.
Space complexity analysis: This involves analyzing how much memory an algorithm requires to
execute as the size of the input increases. It measures the amount of memory an algorithm
uses as the input size grows, also typically in terms of big O notation.
Correctness analysis: This involves analyzing whether an algorithm produces the correct output
for all possible inputs.
Time complexity refers to the amount of time an algorithm takes to execute as the size of the
input increases. It is usually measured in terms of the "big O" notation, which describes the
upper bound on the time an algorithm takes to execute. Time complexity is important because it
helps us understand how an algorithm will scale as the input size grows, and allows us to
compare the efficiency of different algorithms.
Bubble sort: This is a simple sorting algorithm that repeatedly steps through the list, compares
adjacent elements and swaps them if they are in the wrong order.
Selection sort: This is another simple sorting algorithm that sorts an array by repeatedly finding
the minimum element from unsorted part and putting it at the beginning.
Insertion sort: This algorithm sorts the array by shifting elements one by one to the right and
inserting the current element in its correct position.
Merge sort: This is a divide-and-conquer algorithm that recursively divides the input list into
smaller sub-lists, sorts them and then merges them to produce a sorted output.
Quick sort: This is another divide-and-conquer algorithm that selects a pivot element and
partitions the array around the pivot, sorting the sub-arrays recursively.
Heap sort: This algorithm sorts an array by first building a binary heap from the input array, and
then repeatedly extracting the maximum element and rebuilding the heap until the array is
sorted.
Linear search: This algorithm searches for a given element in an array by sequentially checking
each element of the array until a match is found or the entire array is searched.
Binary search: This algorithm searches for a given element in a sorted array by repeatedly
dividing the search interval in half and eliminating the half where the element cannot be present.
It is a more efficient algorithm than linear search for large arrays.