Skip to content

Algorithms definitions and exercises on Python and JavaScript from HackerRank, internet and friends

Notifications You must be signed in to change notification settings

flkt-crnpio/algorithms-exercises

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

algorithms

An algorithm is a set of instructions designed to perform an specific task.

Linear search

Linear search algorithm is a simple and basic search algorithm in which we traverse the array while looking for the number to be searched. Linear: O(n)

Binary search

Search a sorted array by repeatedly dividing the search interval in half. Begin with an interval covering the whole array. If the value of the search key is less than the item in the middle of the interval, narrow the interval to the lower half. Otherwise narrow it to the upper half. Repeatedly check until the value is found or the interval is empty. The idea of binary search is to use the information that the array is sorted and reduce the time complexity to O(Log n).

Jump Search

Jump Search is a searching algorithm for sorted arrays. The basic idea is to check fewer elements (than linear search) by jumping ahead by fixed steps or skipping some elements in place of searching all elements. The time complexity of Jump Search is between Linear Search ( ( O(n) ) and Binary Search ( O (Log n) ).

Binary Search is better than Jump Search, but Jump search has an advantage that we traverse back only once (Binary Search may require up to O(Log n) jumps, consider a situation where the element to be searched is the smallest element or smaller than the smallest). So in a system where binary search is costly, we use Jump Search.

Selection Sort

The selection sort algorithm sorts an array by repeatedly finding the minimum element (considering ascending order) from unsorted part and putting it at the beginning. The algorithm maintains two subarrays in a given array. It has O(n^2) time complexity, making it inefficient on large lists, and generally performs worse than the similar insertion sort.

Bubble Sort

Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in wrong order. Runtime ( O(n^2) )

Insertion Sort

Insertion sort is a simple sorting algorithm where the sorted array is built one item at time with each other sequentially. Runtime ( O(n^2) )

Merge Sort

Merge sort is a divide-and-conquer algorithm based on the idea of breaking down a list into several sub-lists until each sublist consists of a single element and merging those sublists in a manner that results into a sorted list. Runtime O(n log n)


HackerRank problem solving

From friends

About

Algorithms definitions and exercises on Python and JavaScript from HackerRank, internet and friends

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published