Python quick search for Algorithm Application Instances and python quick search
This example describes the application of the Python quick search algorithm for your reference.
The specific implementation method is as follows:
Import randomdef partition (list_object, start, end): random_choice = start # random. choice (range (start, end + 1) # Changing start here to random () is more efficient x = list_object [random_choice] I = start j = end while True: while list_object [I] <x and I <end: I + = 1 while list_object [j]> x: j-= 1 if I> = j: break list_object [I], list_object [j] = list_object [j], list_object [I] print list_object # list_object [random_choice] = list_object [j] # list_object [j] = random_choice return jdef quick_sort (list_object, start, end): if start <end: temp = partition (list_object, start, end) quick_sort (list_object, start, temp-1) quick_sort (list_object, temp + 1, end) a_list = [69,65, 90,37, 92,6, 28,54] quick_sort (a_list,) print a_list
The program test environment is Python2.7.6.
The output result is as follows:
[54, 65, 28, 37, 6, 69, 92, 90][6, 37, 28, 54, 65, 69, 92, 90][6, 37, 28, 54, 65, 69, 92, 90][6, 28, 37, 54, 65, 69, 92, 90][6, 28, 37, 54, 65, 69, 90, 92][6, 28, 37, 54, 65, 69, 90, 92]
I hope this article will help you with Python programming.
Comparison of various search algorithms?
Binary: the sequence to be searched must be sorted, that is, an ordered sequence.
Hash: Hash search is fast when location conflicts are well resolved. It mainly refers to the selection of hash functions.
Binary sorting tree: If the fruit tree is relatively balanced, the complexity of this query is log (n), but if it is very biased, for example, if you have always inserted only the left son node (this is the same as the linked list), it is worse.
The specific text description of the quick search algorithm is attached to the java program.
A quick search algorithm is called binary distribution, provided that elements in an ordered array must be searched recursively. First, assume that the target is located in the middle of the array and compared with the middle position, for example, greater, start searching on the left. If the value is smaller than the value, start searching on the right. In this way, the current half can be excluded from each search,