2. Divide and Conquer

In computer science, divide and conquer is an algorithm design paradigm based on multi-branched recursion. A divide-and-conquer algorithm works by recursively breaking down a problem into two or more sub-problems of the same or related type, until these become simple enough to be solved directly. The solutions to the sub-problems are then combined to give a solution to the original problem [1].

In computer science, binary search, also known as half-interval search or logarithmic search, is a search algorithm that finds the position of a target value within a sorted array. Binary search compares the target value to the middle element of the array. If they are not equal, the half in which the target cannot lie is eliminated and the search continues on the remaining half, again taking the middle element to compare to the target value, and repeating this until the target value is found. If the search ends with the remaining half being empty, the target is not in the array [2].

With time complexity of $ \Theta(\log_{}{n}) $.

Computational Complexity validation

In computer science, the computational complexity or simply complexity of an algorithm is the amount of resources required to run it. Particular focus is given to time and memory requirements. The complexity of a problem is the complexity of the best algorithms that allow solving the problem [3].

Hence, $ \Theta(\log_{2}(n)) = \log_{2}(16) = 4 $

2.2. Quick Sort

Quicksort (sometimes called partition-exchange sort) is an efficient sorting algorithm. Developed by British computer scientist Tony Hoare in 1959 and published in 1961, it is still a commonly used algorithm for sorting [4].

Quicksort is a divide-and-conquer algorithm. It works by selecting a 'pivot' element from the array and partitioning the other elements into two sub-arrays, according to whether they are less than or greater than the pivot. The sub-arrays are then sorted recursively. This can be done in-place, requiring small additional amounts of memory to perform the sorting.

With time complexity of $ \Theta(n \log_{}{n}) $ and $ O(n^2) $, and space complexity of $ \Theta(n) $.

2.3. Merge Sort

In computer science, merge sort (also commonly spelled mergesort) is an efficient, general-purpose, comparison-based sorting algorithm. Most implementations produce a stable sort, which means that the order of equal elements is the same in the input and output. Merge sort is a divide and conquer algorithm that was invented by John von Neumann in 1945 [5].

With time complexity of $ \Theta(n \log_{}{n}) $.

Experiment: compare sorting algorithms

3.4. Convex Hull

In geometry, the convex hull or convex envelope or convex closure of a shape is the smallest convex set that contains it. For a bounded subset of the plane, the convex hull may be visualized as the shape enclosed by a rubber band stretched around the subset [6].

Formally, the convex hull may be defined either as the intersection of all convex sets containing a given subset of a Euclidean space, or equivalently as the set of all convex combinations of points in the subset. Convex hulls of open sets are open, and convex hulls of compact sets are compact. Every convex set is the convex hull of its extreme points.

3.4.1. Convex Hull from Scratch

3.4.2. Convex Hull with scipy.spatial

Reference

[1] Wikipedia - Divide-and-Conquer algorithm.
[2] Wikipedia - Binary search.
[3] Wikipedia - Computational complexity.
[4] Wikipedia - Quicksort.
[5] Wikipedia - Merge sort.
[6] Wikipedia - Convex hull.


« Home