Changes

Jump to navigation Jump to search
1,173 bytes added ,  23:47, 13 December 2016
no edit summary
Line 63: Line 63:  
</syntaxhighlight>
 
</syntaxhighlight>
    +
'''Binary Sort Algorithm'''
 +
----
   −
'''HeapSort Algorithm'''
+
'''Binary Sort''' (aka half-interval search/logarithmic search) is a search algorithm that finds a target value within a sorted array by comparing the target to the middle element, if unequal, the half of integers where the target cannot lie is unlimited. This process is continued unless target is identified.
 +
 
 +
EX:  1, 7, 27, 33, 45,  57 , 66, 77, 89, 99, 101, 129, 156, 234
 +
  Find: Number 77
 +
      a. Identify the middle value of the sorted array : 66
 +
      b. Eliminate the lower half of the array integers [>66] since the integer we are looking for is 77.
 +
      c. Continue this median allocation and deletion until correct integer in the array is isolated and selected.
 +
 
 +
 
 +
 
 +
'''Example Python Code'''
 +
----
 +
 
 +
 
 +
Python Binary Sort Example 1
 +
 
 +
<syntaxhighlight lang="cpp">
 +
def binarySearch(alist, item):
 +
  first = 0
 +
  last = len(alist)- 1
 +
  found = False
 +
 
 +
  while first <=last and not found:
 +
      midpoint = (first + last)// 2
 +
      if alist[midpoint] == item
 +
        found = True
 +
 
 +
      else:
 +
        if item < alist[midpoint]:
 +
          last = midpoint - 1
 +
        else:
 +
          first = midpoint + 1
 +
 
 +
  return found
 +
 
 +
 
 +
 
 +
 
 +
 
 +
'''Heap Sort Algorithm'''
 
----
 
----
  
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu