Line 66: |
Line 66: |
| ---- | | ---- |
| | | |
− | '''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. | + | '''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. In other words, this function will look for an item in an array by dividing the list in half every time it searches. |
| | | |
| EX: 1, 7, 27, 33, 45, 57 , 66, 77, 89, 99, 101, 129, 156, 234 | | EX: 1, 7, 27, 33, 45, 57 , 66, 77, 89, 99, 101, 129, 156, 234 |
Line 89: |
Line 89: |
| | | |
| while first <=last and not found: ### this is a while loop that runs the logarithmic structure of the heap sort until the indicated element is found | | while first <=last and not found: ### this is a while loop that runs the logarithmic structure of the heap sort until the indicated element is found |
− | midpoint = (first + last)// 2 ### this is the logic equation of the python code to run, this finds the midpoint element of the array by adding the first and last integer of that array and diving it by 2 | + | midpoint = (first + last)// 2 ### this is the logic equation of the python code to run, |
| + | ###this finds the midpoint element of the array by adding the first and last integer of that array and diving it by 2 |
| if alist[midpoint] == item ### if the midpoint from the previous equation equates to the indicated integer, then element is found | | if alist[midpoint] == item ### if the midpoint from the previous equation equates to the indicated integer, then element is found |
| found = True | | found = True |
Line 103: |
Line 104: |
| </syntaxhighlight> | | </syntaxhighlight> |
| | | |
| + | Python Binary Sort Example 2 |
| | | |
| + | <syntaxhighlight lang="cpp"> |
| + | |
| + | </syntaxhighlight> |
| | | |
| '''Heap Sort Algorithm''' | | '''Heap Sort Algorithm''' |
Line 114: |
Line 119: |
| | | |
| === Writing Your Own Algorithms === | | === Writing Your Own Algorithms === |
| + | |
| + | |
| + | |
| + | |
| + | Reference: |
| + | ----- |
| + | https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-854j-advanced-algorithms-fall-2005/ |