Python search, sorting algorithms summary

First, the binary search (binary search)

Material Preparation: array arr, find an element x, the index number l, mid intermediate index

Method Function: len ()

Function name: binarySearch (arr, l, r, x)

Analyzing index and core algorithms: mid = int (l + (r - 1) / 2)

 

Algorithm performs the steps of:

First, the definition of an array

arr = [2,3,4,5,6,7]

x = 4

 

Second, the binary search function body

Text idea: the function body has four parameters, namely the array, the index number, the maximum array index, find elements.

 

 

Released three original articles · won praise 0 · Views 110

Guess you like

Origin blog.csdn.net/qq_42232026/article/details/104236548