This repository has been archived by the owner on Oct 23, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4282 from codingCapricorn/master
Merged by aniket965
- Loading branch information
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
def Ordered_binary_Search(olist, item): | ||
|
||
if len(olist) == 0: | ||
return False | ||
else: | ||
midpoint = len(olist) // 2 | ||
if olist[midpoint] == item: | ||
return True | ||
else: | ||
if item < olist[midpoint]: | ||
return binarySearch(olist[:midpoint], item) | ||
else: | ||
return binarySearch(olist[midpoint+1:], item) | ||
|
||
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 | ||
|
||
print(Ordered_binary_Search([0, 1, 3, 8, 14, 18, 19, 34, 52], 3)) | ||
print(Ordered_binary_Search([0, 1, 3, 8, 14, 18, 19, 34, 52], 17)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
def selectionSort(nlist): | ||
for fillslot in range(len(nlist)-1,0,-1): | ||
maxpos=0 | ||
for location in range(1,fillslot+1): | ||
if nlist[location]>nlist[maxpos]: | ||
maxpos = location | ||
|
||
temp = nlist[fillslot] | ||
nlist[fillslot] = nlist[maxpos] | ||
nlist[maxpos] = temp | ||
|
||
nlist = [14,46,43,27,57,41,45,21,70] | ||
selectionSort(nlist) | ||
print(nlist) |