Hash table runtime complexity (insert, search and delete)

Hash tables are O(1) average and amortized case complexity, however it suffers from O(n) worst case time complexity. [And I think this is where your confusion is] Hash tables suffer from O(n) worst time complexity due to two reasons: If too many elements were hashed into the same key: looking inside this key may take O(n) time. Once a hash table has passed its load balance – it has … Read more

How to calculate time complexity of backtracking algorithm?

In short: Hamiltonian cycle : O(N!) in the worst case WordBreak and StringSegment : O(2^N) NQueens : O(N!) Note: For WordBreak there is an O(N^2) dynamic programming solution. More details: In Hamiltonian cycle, in each recursive call one of the remaining vertices is selected in the worst case. In each recursive call the branch factor decreases by 1. Recursion … Read more

Calculate distance between two latitude-longitude points? (Haversine formula)

This link might be helpful to you, as it details the use of the Haversine formula to calculate the distance. Excerpt: This script [in Javascript] calculates great-circle distances between the two points – that is, the shortest distance over the earth’s surface – using the ‘Haversine’ formula.