LINEAR SEARCH
Linear Search
Linear Search adalah teknik pencarian dimana program akan mencari anggota dari suatu search space satu persatu sampai value yang dicari ditemukan.
konsep dari linear search ini bisa mencari dari depan maupun dari belakang.
berikut contoh linear search untuk pengurutan dari awal :
search = 2
myList = [1,2,3,4,5,6]
position = 0
last = len(myList)- 1
found = False
while position <= last and not found:
if myList[position] == search:
found = True
else:
position = position + 1
if found:
print ("found the search number")
print (position)
else:
print ("Did not find the search number")
Contoh linear search untuk pengurutan dari belakang :
search = 7
myList = [1,2,3,4,5,6]
position = len(myList)-1
last = 0
found = False
iterasi = 1
while position >= last and not found:
if myList[position] == search:
found = True
else:
position = position - 1
iterasi += 1
if found:
print ("found the search number")
print (iterasi)
else:
print ("Did not find the search number")
print(iterasi)
Di post oleh :
1. FITRI ANISA (170411100014)
2. DHEA OKY SYAFITRI (170411100006)
Komentar
Posting Komentar