Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions 01_materials/slides/1_motivation_big_o.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"List Addition: 0.000406 seconds\n",
"Vectorized Addition: 0.000333 seconds"
"List Addition: 0.002644 seconds\n",
"Vectorized Addition: 0.000074 seconds\n"
]
}
],
Expand Down Expand Up @@ -207,8 +207,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"List Search: 0.000064 seconds\n",
"Set Search: 0.000001 seconds"
"List Search: 0.000188 seconds\n",
"Set Search: 0.000002 seconds\n"
]
}
],
Expand Down Expand Up @@ -296,8 +296,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Selection sort: 1.421455 seconds\n",
"Tim sort: 0.001110 seconds"
"Selection sort: 7.851763 seconds\n",
"Tim sort: 0.001970 seconds\n"
]
}
],
Expand Down Expand Up @@ -580,7 +580,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "dsi_participant",
"language": "python",
"name": "python3"
},
Expand All @@ -594,7 +594,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
"version": "3.9.19"
}
},
"nbformat": 4,
Expand Down
172 changes: 161 additions & 11 deletions 01_materials/slides/2_ds_search_sort.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,141 @@
},
{
"cell_type": "code",
"execution_count": 1,
"id": "fd88bcec",
"execution_count": null,
"id": "820d6b0b",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "180055b9",
"metadata": {},
"source": [
"Abstratc Data Types\n",
"\n",
"Sets : unique elements, \n",
"Lists : order elements\n",
"\n",
"Map "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "81a338e6",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"b\n"
]
}
],
"source": [
"my_map={ \"sunbal\": 'b',\n",
" \"s\": 'a',\n",
" \"n\": 'n'\n",
"} \n",
"my_map\n",
"#lookup value by key\n",
"print(my_map[\"sunbal\"]) # Output: 'b'\n",
"#insert or update key-value pair\n",
"my_map[\"sunbal\"] = 'c' # Update existing key\n",
"my_map[\"new_key\"] = 'd' # Insert new key-value pair\n",
"print(my_map)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "70bc0021",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"my_iterable = iter([1, 2, 3, 4, 5])\n",
"next(my_iterable) # Output: 1\n",
"next(my_iterable) # Output: 2"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "40fe41a5",
"metadata": {},
"outputs": [],
"source": [
"# absract data types \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "21fac096",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1\n"
]
}
],
"source": [
"my_list=[1,2,3,{1,2,4},[4,5]]#access element by index\n",
"print(my_list[0]) # Output: 'apple'\n",
"#insert element at the end\n",
"my_list.append(6) # List becomes [1, 2, 3, {1, 2, 4}, [4, 5], 6]\n"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "fd88bcec",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# INPUT\n",
"lst = [2,2,5,6]\n",
"# OUTPUT\n",
"2"
"\n",
"def get_h_index(lst):\n",
" for i in range(len(lst),-1,-1):\n",
" num_cit=0\n",
" for cit in lst:\n",
" if cit >= i :\n",
" num_cit+=1\n",
" if num_cit==i:\n",
" return i\n",
" return 0\n",
"\n",
"get_h_index(lst)\n",
"\n",
"# OUTPUT 2\n"
]
},
{
Expand Down Expand Up @@ -283,22 +409,44 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 18,
"id": "92fbc341",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"4231697768083451161"
"3824059175998547445"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"hash(\"UofT\")"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "67e0a1d1",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3824059175998547445"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "display_data"
"output_type": "execute_result"
}
],
"source": [
"hash(\"DS 4 Life\")"
"hash(\"UofT\")"
]
},
{
Expand Down Expand Up @@ -417,12 +565,14 @@
"id": "5a1e40b7",
"metadata": {},
"outputs": [],
"source": []
"source": [
"#Sets , Lists"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "dsi_participant",
"language": "python",
"name": "python3"
},
Expand All @@ -436,7 +586,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
"version": "3.9.19"
}
},
"nbformat": 4,
Expand Down
Loading