This is an algorithm that belongs to the Divide & Conquer family of algorithms. This algo. lets you divide the set in two, from to & to where . You sort each half, then sort both halves. The pseudocode for this implementation is as follows:
Define the time it takes for an algorithm to sort , given , to be .
Consider . This means that for all for some , then
For a constant value .
Consider . This means that for all for some , then
For a constant value .
Consider . Then is both and .
To analyze our models we need a computer (of course) and a process that lets us obtain insigths about it. Here are some examples:
RAM Model:
Best Case Scenario.- The algo. is already sorted, which makes the time it takes to implement it linear with respect to its size. This means that the time it takes is:
For n the size of the set.
Worst Case Scenario.- The algo. takes a quadratic time with respect to its size. This means:
Once each half is sorted, you need to check at most cases when comparing the first and the second half. Then the total time for this is at most, given for a given measurable :
Also .
Time for worst case is for some . Some graph theory problems are in Polynomial Time.
Cycle: Process that begins and ends at the same point.
Directed graph: Graph that has a given direction in its edges (you can only traverse it one way).
Simple Path: A path in a graph where you pass through every vertex at most once.
Hamiltonian Cycle: Simple path that contains every vertex once.
Euler Tour: Cycle through each edge in a directed graph.
Given a weighted n-graph check how long is the shortest simple path between two vertices (solvable in polynomial time).
Given a weighted n-graph check how long is the longest simple path between two vertices (unsolvable in polynomial time, solution can be checked in polynomial time).
If you can find a Hamiltonian Cycle for the graph, you find a longest symple path. Determining whether a graph contains a Hamiltonian Cycle is NOT solvable in polynomial time.
A problem is if it's solvable in polynomial time. It is if it can be verified to be solvable in polynomial time. You don't know if the solution is in polyomial time. It is (also referred to as ) if the following condition holds:
If a given problem which is NP complete can be solved in polynomial time, then evey problem in NP can ve solved in polynomial time.
So far we know . If then if you can verify a problem in polynomial time you can solve it in polynomial time.
Cormun, Leisenson, Rivest & Stein. Introduction to Algorithms.