Dmytronoks Algorithms-Cs50
Dmytronoks Algorithms-Cs50
Algorithm is a step-by-step set of instructions for completing a task. Big-O notation is a simplified analysis of an algorithm’s efficiency. It
attempts to answer two questions:
Search Algorithms Q1: how much memory is needed?
Q2: how much time does it take to complete?
Linear Search : Iterate across Worst case O(n): the target element
the array from left to right, is the last element of the array or it
Recursion
searching for a specified doesn’t exist at all. Best case Ω(1):
element. the target element is the first A recursive function is one that, as part of its execution, invokes
element of the array. itself.
Binary Search: Divide and Worst case O(log n) : the target Every recursive function has two cases that could apply, given any
conquer, reducing the search element will be found at the end of input:
area by half each time, trying the last division or it won’t be found - The base case → terminate the recursive process
to find a target number. First, at all. Best case Ω(1): the target - The recursive case → the recursion occurs
Merge Sort: Sort The best and the worst cases are the same:
smaller arrays and n log n.
then merge them in
sorted order.