Skip to content

Commit ff99d27

Browse files
authored
Add files via upload
1 parent f455013 commit ff99d27

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

Diff for: linear_search.ipynb

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 4,
6+
"id": "6cd9ba0b",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"def binary_search(L,x):\n",
11+
" n = len(L)\n",
12+
" for i in range(n):\n",
13+
" if L[i]==x:\n",
14+
" return i\n",
15+
" return -1"
16+
]
17+
},
18+
{
19+
"cell_type": "code",
20+
"execution_count": 5,
21+
"id": "c5d90e91",
22+
"metadata": {},
23+
"outputs": [
24+
{
25+
"name": "stdout",
26+
"output_type": "stream",
27+
"text": [
28+
"6\n"
29+
]
30+
}
31+
],
32+
"source": [
33+
"li = [26,947,49,39,68,0,67,90]\n",
34+
"index = binary_search(li,67)\n",
35+
"print(index)\n"
36+
]
37+
},
38+
{
39+
"cell_type": "code",
40+
"execution_count": null,
41+
"id": "8d9d4e60",
42+
"metadata": {},
43+
"outputs": [],
44+
"source": []
45+
}
46+
],
47+
"metadata": {
48+
"kernelspec": {
49+
"display_name": "Python 3 (ipykernel)",
50+
"language": "python",
51+
"name": "python3"
52+
},
53+
"language_info": {
54+
"codemirror_mode": {
55+
"name": "ipython",
56+
"version": 3
57+
},
58+
"file_extension": ".py",
59+
"mimetype": "text/x-python",
60+
"name": "python",
61+
"nbconvert_exporter": "python",
62+
"pygments_lexer": "ipython3",
63+
"version": "3.9.7"
64+
}
65+
},
66+
"nbformat": 4,
67+
"nbformat_minor": 5
68+
}

0 commit comments

Comments
 (0)