Skip to content

Commit 7d407ea

Browse files
committed
[mikhail.baranov] Add Lecture notebooks
1 parent 9c59670 commit 7d407ea

File tree

2 files changed

+1137
-29
lines changed

2 files changed

+1137
-29
lines changed

lecture_5/Algorythms.ipynb

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414
},
1515
{
1616
"cell_type": "code",
17-
"execution_count": null,
18-
"metadata": {
19-
"collapsed": true
20-
},
17+
"execution_count": 1,
18+
"metadata": {},
2119
"outputs": [],
2220
"source": [
2321
"class prefix_tree:\n",
@@ -26,21 +24,45 @@
2624
" self.root = [{}]\n",
2725
" \n",
2826
" def add(self, string):\n",
27+
" if self.check(string):\n",
28+
" return\n",
29+
" wrk_dict = self.root\n",
30+
" for i in string:\n",
31+
" if i in wrk_dict[0]:\n",
32+
" wrk_dict = wrk_dict[0][i]\n",
33+
" else:\n",
34+
" wrk_dict[0][i] = [{}]\n",
35+
" wrk_dict = wrk_dict[0][i]\n",
36+
" wrk_dict.append(True)\n",
2937
" #TODO добавить строку\n",
3038
" \n",
3139
" def check(self, string):\n",
40+
" wrk_dict = self.root\n",
41+
" for i in string:\n",
42+
" if i in wrk_dict[0]:\n",
43+
" wrk_dict = wrk_dict[0][i]\n",
44+
" else:\n",
45+
" return False\n",
46+
" if len(wrk_dict) != 1:\n",
47+
" return True\n",
48+
" return False\n",
3249
" #TODO проверить наличие строки\n",
3350
" \n",
3451
" def check_part(self, string):\n",
52+
" wrk_dict = self.root\n",
53+
" for i in string:\n",
54+
" if i in wrk_dict[0]:\n",
55+
" wrk_dict = wrk_dict[0][i]\n",
56+
" else:\n",
57+
" return False\n",
58+
" return True\n",
3559
" #TODO проверить наличие строки как префикса"
3660
]
3761
},
3862
{
3963
"cell_type": "code",
40-
"execution_count": null,
41-
"metadata": {
42-
"collapsed": true
43-
},
64+
"execution_count": 2,
65+
"metadata": {},
4466
"outputs": [],
4567
"source": [
4668
"pr_tree = prefix_tree()\n",
@@ -56,7 +78,7 @@
5678
"metadata": {
5779
"anaconda-cloud": {},
5880
"kernelspec": {
59-
"display_name": "Python [default]",
81+
"display_name": "Python 3",
6082
"language": "python",
6183
"name": "python3"
6284
},
@@ -70,7 +92,7 @@
7092
"name": "python",
7193
"nbconvert_exporter": "python",
7294
"pygments_lexer": "ipython3",
73-
"version": "3.5.2"
95+
"version": "3.6.5"
7496
}
7597
},
7698
"nbformat": 4,

0 commit comments

Comments
 (0)