Skip to main content

Sorting Algorithms & Data Structures

Project description

cs-algorithms

Goal

The main goal is to familiarize with common Algorithms and Data Structures. Folowing an added benefit is that this code will be accessible and re-useable.

Linkedin

Currently Implemented

Numbers:

Fibonacci Sequence

The Fibonacci numbers are the numbers in the following integer sequence.

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144,... 

In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation

Fn = Fn-1 + Fn-2

with seed values

F0 = 0 and F1 = 1.

Sorting Algorithms:

Is Sorted

Check if a given array is sorted (works for ascending and descending order).

Bubble Sort (Original)

Repeatedly swapps adjacent elements if they are in wrong order. (uses two nested for loops)

Wikipedia

GeeksforGeeks

Bubble Sort (Optimized)

Repeatedly swapping the adjacent elements if they are in wrong order (stops when array is sorted).

Wikipedia

GeeksforGeeks

Selection Sort

Repeatedly finding the minimum element (considering ascending order) from unsorted part and putting it at the beginning.

Wikipedia

GeeksforGeeks

Insertion Sort

The array is virtually split into a sorted and an unsorted part. Values from the unsorted part are picked and placed at the correct position in the sorted part.

Wikipedia

GeeksforGeeks

Merge Sort

It divides the input array into two halves, calls itself for the two halves, and then merges the two sorted halves.

Wikipedia

GeeksforGeeks

Quick Sort

It picks an element as pivot and partitions the given array around the picked pivot.

Wikipedia

GeeksforGeeks

Search Algorithms:

Linear Search

Start from the leftmost element of arr[] and one by one compare x with each element of arr[] If x matches with an element, return the index. If x doesn’t match with any of elements, return -1.

Wikipedia

GeeksforGeeks

Binary Search (Iterative)

Search a sorted array by repeatedly dividing the search interval in half. Begin wiht an intreval covering the whole array. If the value of the search key is less than the item in the middle of the interval, narrow the intreval to the lower half. Otherwise narrow it to the upper half. Repaetadly check until the value is found or the interval is empty.

Wikipedia

GeeksforGeeks

Binary Search (Recursive)

See Binary Search (Iterative).

Wikipedia

GeeksforGeeks

Jump Search

The basic idea is to check fewer elements by jumping ahead fixed steps or skipping some elements in place of searching all elements.

Wikipedia

GeeksforGeeks

Interpolation Search

The Interpolation Search is an improvement over the Binary Search for instance, where the values in a sorted array are uniformly distributed. Binary Search always goes to the middle elemnt to check. On the other hand, Interpolation Search may go to different positions according to the value of the key being searched.

Wikipedia

GeeksforGeeks

Exponential Search

The idea is to start with subarray size 1, compare its element with the key value, then try size 2, then try size 4 and so on until the last element of subarray is not greater. Once we find an index i, we know that the element must be present between i/2 and i.

Wikipedia

GeeksforGeeks

Fibonacci Search

The idea is to find the smallest Fibonacci number that is greater than or equal to the length of the given array. Let the found Fibonacci number be fib. We can use the (m-2)'th Fibonacci number as the index. Let (m-2)'th Fibonacci number be i, we compare arr[i] with the key value. If the key value is same, we return i. Else if the key value is greater, we recur for subarray after i, else we recur for the subarray before i.

Wikipedia

GeeksforGeeks

Data Structures:

Queue

Stack

Binary Tree

Binary Search Tree

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cs-algorithms-0.0.4.tar.gz (8.1 kB view hashes)

Uploaded Source

Built Distribution

cs_algorithms-0.0.4-py3-none-any.whl (9.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page