Difference and advantages between dijkstra & A star

It says A* is faster than using dijkstra and uses best-first-search to speed things up. A* is basically an informed variation of Dijkstra.A* is considered a “best first search” because it greedily chooses which vertex to explore next, according to the value of f(v) [f(v) = h(v) + g(v)] – where h is the heuristic and g is the cost so … Read more

Polynomial time and exponential time

Check this out. Exponential is worse than polynomial. O(n^2) falls into the quadratic category, which is a type of polynomial (the special case of the exponent being equal to 2) and better than exponential. Exponential is much worse than polynomial. Look at how the functions grow k^1000 is exceptionally huge unless k is smaller than something like 1.1. Like, … Read more

Quick Sort Vs Merge Sort

See Quicksort on wikipedia: Typically, quicksort is significantly faster in practice than other Θ(nlogn) algorithms, because its inner loop can be efficiently implemented on most architectures, and in most real-world data, it is possible to make design choices which minimize the probability of requiring quadratic time. Note that the very low memory requirement is a big … Read more

What is stability in sorting algorithms and why is it important?

A sorting algorithm is said to be stable if two objects with equal keys appear in the same order in sorted output as they appear in the input array to be sorted. Some sorting algorithms are stable by nature like Insertion sort, Merge Sort, Bubble Sort, etc. And some sorting algorithms are not, like Heap Sort, Quick … Read more

Time complexity of a Priority Queue in C++

If you have an array of size n and you want to build a heap from all items at once, Floyd’s algorithm can do it with O(n) complexity. See Building a heap. This corresponds to the std::priority_queue constructors that accept a container parameter. If you have an empty priority queue to which you want to add n items, one at a time, … Read more