线性回归 python_Python线性搜索
线性回归 python
Here you will get program for linear search in python.
在这里,您将获得用于python中线性搜索的程序。
Linear search is one of the simplest searching algorithm in which targeted item in sequentially matched with each item in a list. It is worst searching algorithm with worst case time complexity O (n).
线性搜索是最简单的搜索算法之一,其中目标项目与列表中的每个项目顺序匹配。 这是最糟糕的搜索算法,具有最差的时间复杂度O(n)。
Below is its implementation.
以下是其实现。
Also Read: Python Binary Search
另请参阅: Python二进制搜索
Python线性搜索程序 (Program for Python Linear Search)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
items = [5, 7, 10, 12, 15]
print("list of items is", items)
x = int(input("enter item to search:"))
i = flag = 0
while i < len(items):
if items[i] == x:
flag = 1
break
i = i + 1
if flag == 1:
print("item found at position:", i + 1)
else:
print("item not found")
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
items = [ 5 , 7 , 10 , 12 , 15 ]
print ( "list of items is" , items )
x = int ( input ( "enter item to search:" ) )
i = flag = 0
while i < len ( items ) :
if items [ i ] == x :
flag = 1
break
i = i + 1
if flag == 1 :
print ( "item found at position:" , i + 1 )
else :
print ( "item not found" )
|
Output
输出量
list of items is [5, 7, 10, 12, 15] enter item to search:12 item found at position: 4
项目列表为[5、7、10、12、15] 输入要搜索的 项目:在位置:4找到 12个 项目
Comment below if you have any queries regarding python linear search program.
如果您对python线性搜索程序有任何疑问,请在下面评论。
翻译自: https://www.thecrazyprogrammer.com/2017/05/python-linear-search.html
线性回归 python