diff --git a/01_materials/slides/1_motivation_big_o.ipynb b/01_materials/slides/1_motivation_big_o.ipynb index 565db598..8a8e6a35 100644 --- a/01_materials/slides/1_motivation_big_o.ipynb +++ b/01_materials/slides/1_motivation_big_o.ipynb @@ -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" ] } ], @@ -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" ] } ], @@ -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" ] } ], @@ -580,7 +580,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "dsi_participant", "language": "python", "name": "python3" }, @@ -594,7 +594,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.5" + "version": "3.9.19" } }, "nbformat": 4, diff --git a/01_materials/slides/2_ds_search_sort.ipynb b/01_materials/slides/2_ds_search_sort.ipynb index 43ba3333..5c887895 100644 --- a/01_materials/slides/2_ds_search_sort.ipynb +++ b/01_materials/slides/2_ds_search_sort.ipynb @@ -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" ] }, { @@ -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\")" ] }, { @@ -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" }, @@ -436,7 +586,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.5" + "version": "3.9.19" } }, "nbformat": 4, diff --git a/01_materials/slides/3_recursion.ipynb b/01_materials/slides/3_recursion.ipynb index 125619d3..45300c07 100644 --- a/01_materials/slides/3_recursion.ipynb +++ b/01_materials/slides/3_recursion.ipynb @@ -134,14 +134,16 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "id": "1b65eaad", "metadata": {}, "outputs": [], "source": [ "def countdown(i):\n", " print(i)\n", - " countdown(i - 1)" + " countdown(i - 1)\n", + "\n", + " #countdown(5)" ] }, { @@ -155,17 +157,33 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 27, "id": "1cf5d588", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "5\n", + "4\n", + "3\n", + "2\n", + "1\n", + "0\n" + ] + } + ], "source": [ "def countdown(i):\n", " print(i)\n", " if i <= 0:\n", " return \n", " else:\n", - " countdown(i - 1)" + " countdown(i - 1)\n", + "\n", + "\n", + "countdown(5)" ] }, { @@ -187,16 +205,29 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 32, "id": "b2b9ea9b", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "6" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "def factorial(n):\n", - " if x == 1:\n", + "def factorial(x):\n", + " if x == 1 or x == 0:\n", " return 1\n", " else:\n", - " return x * factorial(x - 1)" + " return x * factorial(x - 1)\n", + "\n", + "factorial(3)" ] }, { @@ -350,7 +381,15 @@ "metadata": {}, "outputs": [], "source": [ - "# Your answer here" + "# Your answer herede\n", + "def recursive_function(some_input):\n", + " recursive_helper(some_inputm, base_values)\n", + "\n", + "def recursive_helper(some_input, additional_information):\n", + " #does the work\n", + " #has a base case\n", + " #has a recursuve case\n", + " recursive_helper(with_update_input, additional_information)" ] }, { @@ -370,10 +409,21 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 35, "id": "b31da01e", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[6]" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# INPUT\n", "lst = [1,2,5,6]\n", @@ -385,14 +435,38 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 44, "id": "bd660dc1", "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "# Your code here\n", + "def find_sums(lst, x):\n", + " result=[]\n", + " find_sum_helper(lst,x,[],result)\n", + "\n", + "def find_sum_helper(lst,x,combinations,result):\n", + " if(len(lst)==0):\n", + " return\n", + " if(x==0):\n", + " result.append(combinations)\n", + " if(x<0):\n", + " return\n", + "\n", + " find_sum_helper(lst[1:],x-lst[0],combinations+[lst[0]], result )\n", + " find_sum_helper(lst[1:], x, combinations, result)\n", + "\n", + " find_sums(lst, x )" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "964be1b0", + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "markdown", "id": "b17e5971-fb5c-48a4-a92e-87a720633a26", @@ -557,16 +631,175 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "24066712", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "lst=[1,2,3,4,5,6]\n", + "\n", + "my_set = set()\n", + "\n", + "for item in lst:\n", + " if item not in my_set:\n", + " my_set.add(item)" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "5d05bc82", + "metadata": {}, + "outputs": [], + "source": [ + "class HashTable():\n", + " def __init__ (self, size=100):\n", + " self.size = size\n", + " self.ht=[]\n", + " for i in range(size):\n", + " self.ht.append([])\n", + " \n", + " def my_hash(self, key):\n", + " index= hash(key)%self.size\n", + " return index\n", + " \n", + " def insert(self, key, value):\n", + " index= self.my_hash(key)\n", + " for pair in self.ht[index]:\n", + " if pair[0]==key:\n", + " return\n", + " self.ht[index].append((key,value))\n", + " \n", + " def remove (self, key):\n", + " index= self.my_hash(key)\n", + " for i in range(len(self.ht[index])):\n", + " if(self.ht.index[i][0]==key):\n", + " self.ht[index].remove(i)\n", + " \n", + " def contains(self, key):\n", + " index= self.my_hash(key)\n", + " for i in range(len(self.ht[index])):\n", + " if(self.ht.index[i][0]==key):\n", + " return True\n", + " return False\n", + " \n", + " def get(self, key):\n", + " index= self.my_hash(key)\n", + " for i in range(len(self.ht[index])):\n", + " if(self.ht.index[i][0]==key):\n", + " return self.ht[index][1]\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "b739b774", + "metadata": {}, + "outputs": [], + "source": [ + "my_ht=HashTable(size=10)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "91a5d28f", + "metadata": {}, + "outputs": [], + "source": [ + "my_ht.insert('dog', 'toby')\n", + "my_ht.insert('dog2', '2toby')\n", + "my_ht.insert('dog3', '3toby')" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "06adda8a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[],\n", + " [],\n", + " [],\n", + " [],\n", + " [],\n", + " [('dog2', '2toby')],\n", + " [],\n", + " [('dog3', '3toby')],\n", + " [('dog', 'toby')],\n", + " []]" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "my_ht.ht" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "36d163f6", + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "'builtin_function_or_method' object is not subscriptable", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[25], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mmy_ht\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcontains\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mdog\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n", + "Cell \u001b[1;32mIn[24], line 28\u001b[0m, in \u001b[0;36mHashTable.contains\u001b[1;34m(self, key)\u001b[0m\n\u001b[0;32m 26\u001b[0m index\u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmy_hash(key)\n\u001b[0;32m 27\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m i \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mrange\u001b[39m(\u001b[38;5;28mlen\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mht[index])):\n\u001b[1;32m---> 28\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m(\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mht\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mindex\u001b[49m\u001b[43m[\u001b[49m\u001b[43mi\u001b[49m\u001b[43m]\u001b[49m[\u001b[38;5;241m0\u001b[39m]\u001b[38;5;241m==\u001b[39mkey):\n\u001b[0;32m 29\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;01mTrue\u001b[39;00m\n\u001b[0;32m 30\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;01mFalse\u001b[39;00m\n", + "\u001b[1;31mTypeError\u001b[0m: 'builtin_function_or_method' object is not subscriptable" + ] + } + ], + "source": [ + "my_ht.contains('dog')" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "c8d4db6c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[],\n", + " [],\n", + " [],\n", + " [],\n", + " [],\n", + " [('dog2', '2toby')],\n", + " [],\n", + " [('dog3', '3toby')],\n", + " [('dog', 'toby')],\n", + " []]" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "my_ht.ht" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "dsi_participant", "language": "python", "name": "python3" }, @@ -580,7 +813,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.5" + "version": "3.9.19" } }, "nbformat": 4, diff --git a/02_activities/assignments/assignment_2.ipynb b/02_activities/assignments/assignment_2.ipynb index 26bb3864..44522524 100644 --- a/02_activities/assignments/assignment_2.ipynb +++ b/02_activities/assignments/assignment_2.ipynb @@ -27,9 +27,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 32, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2\n" + ] + } + ], "source": [ "import hashlib\n", "\n", @@ -37,7 +45,7 @@ " hash_object = hashlib.sha256(input_string.encode())\n", " hash_int = int(hash_object.hexdigest(), 16)\n", " return (hash_int % 3) + 1\n", - "input_string = \"your_first_name_here\"\n", + "input_string = \"Sunbal\"\n", "result = hash_to_range(input_string)\n", "print(result)\n" ] @@ -86,7 +94,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 33, "metadata": {}, "outputs": [], "source": [ @@ -97,7 +105,8 @@ "# self.left = left\n", "# self.right = right\n", "def is_duplicate(root: TreeNode) -> int:\n", - " # TODO" + " #TODO\n", + " pass\n" ] }, { @@ -119,6 +128,8 @@ "\n", " Input: `root = [1, 2, 2, 3, 5, 6, 7]` *What traversal method is this?*\n", "\n", + " **This is Breadth first search traversal order **\n", + "\n", " Output: [[1, 2, 3], [1, 2, 5], [1, 2, 6], [1, 2, 7]]\n", "\n", " ### Example 2\n", @@ -136,18 +147,78 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 34, "metadata": {}, "outputs": [], "source": [ + "#Definition for a binary tree node.\n", + "from typing import List\n", + "\n", "# Definition for a binary tree node.\n", - "# class TreeNode(object):\n", - "# def __init__(self, val = 0, left = None, right = None):\n", - "# self.val = val\n", - "# self.left = left\n", - "# self.right = right\n", + "class TreeNode(object):\n", + " def __init__(self, val=0, left=None, right=None):\n", + " self.val = val\n", + " self.left = left\n", + " self.right = right\n", + "\n", + "\n", "def bt_path(root: TreeNode) -> List[List[int]]:\n", - " # TODO" + " def depth_first_search(node, path, result):\n", + " if not node:\n", + " return\n", + " path.append(node.val)\n", + "\n", + " if not node.left and not node.right:\n", + " result.append(list(path))\n", + " else:\n", + " depth_first_search(node.left, path, result)\n", + " depth_first_search(node.right, path, result)\n", + "\n", + " path.pop() # backtrack after exploring children\n", + "\n", + " result = []\n", + " depth_first_search(root, [], result)\n", + " return result\n", + "\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[10, 9, 8], [10, 7]]\n" + ] + } + ], + "source": [ + "root = TreeNode(10,TreeNode(9,None,TreeNode(8)),TreeNode(7))\n", + "print(bt_path(root))" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[1, 2, 3], [1, 2, 5], [1, 2, 6], [1, 2, 7]]\n" + ] + } + ], + "source": [ + "root = TreeNode(1)\n", + "root.left = TreeNode(2, TreeNode(3), TreeNode(5))\n", + "root.right = TreeNode(2, TreeNode(6), TreeNode(7))\n", + "print(bt_path(root))" ] }, { @@ -188,11 +259,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 37, "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "ename": "IndentationError", + "evalue": "expected an indented block (2767058236.py, line 2)", + "output_type": "error", + "traceback": [ + "\u001b[1;36m Cell \u001b[1;32mIn[37], line 2\u001b[1;36m\u001b[0m\n\u001b[1;33m # TODO\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mIndentationError\u001b[0m\u001b[1;31m:\u001b[0m expected an indented block\n" + ] + } + ], "source": [ "def missing_num(nums: List) -> int:\n", " # TODO" @@ -227,7 +307,7 @@ "metadata": {}, "outputs": [], "source": [ - "# Your answer here" + "# Your answer here\n" ] }, { @@ -396,7 +476,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "dsi_participant", "language": "python", "name": "python3" }, @@ -410,7 +490,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.5" + "version": "3.9.19" } }, "nbformat": 4, diff --git a/02_activities/assignments/assignment_2_Part_3.ipynb b/02_activities/assignments/assignment_2_Part_3.ipynb new file mode 100644 index 00000000..1e2f4807 --- /dev/null +++ b/02_activities/assignments/assignment_2_Part_3.ipynb @@ -0,0 +1,187 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "8de61ba3", + "metadata": {}, + "source": [ + "## Part 3 of Sunbal Cheema's Assignmet 2\n", + "\n", + "**Assignment 1 By Shripad Tak**" + ] + }, + { + "cell_type": "markdown", + "id": "60aacfc1", + "metadata": {}, + "source": [ + "*Paraphrase the problem in your own words.*\n", + "\n", + "In a string of Brackets combinations from '(',')','{','}','['and ']'.\n", + "Evaluate if the string is valid\n", + "1. every bracket closes to corressponding\n", + "2. brackets closed in correct order " + ] + }, + { + "cell_type": "markdown", + "id": "39b9628c", + "metadata": {}, + "source": [ + "\n", + "*Create 1 new example that demonstrates you understand the problem. Trace/walkthrough 1 example that your partner made and explain it.*" + ] + }, + { + "cell_type": "markdown", + "id": "58fb90a4", + "metadata": {}, + "source": [ + "```python\n", + "Input: s = \"([]){}\"\n", + "Output: True\n", + "```\n", + "```python\n", + "Input: s = \"{)(}\"\n", + "Output: False" + ] + }, + { + "cell_type": "markdown", + "id": "a6803749", + "metadata": {}, + "source": [ + "*Copy the solution your partner wrote.*" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "aaa06ef9", + "metadata": {}, + "outputs": [], + "source": [ + "def is_valid_brackets(s: str) -> bool:\n", + " stack = []\n", + " mapping = {')': '(', ']': '[', '}': '{'}\n", + " \n", + " for char in s:\n", + " if char in mapping.values():\n", + " stack.append(char)\n", + " elif char in mapping:\n", + " if not stack or stack[-1] != mapping[char]:\n", + " return False\n", + " stack.pop()\n", + " else:\n", + " return False\n", + " \n", + " return len(stack) == 0\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "3bc95e67", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], + "source": [ + "s = \"{[()]}\"\n", + "result = is_valid_brackets(s)\n", + "print(result)" + ] + }, + { + "cell_type": "markdown", + "id": "517cbe22", + "metadata": {}, + "source": [ + "\n", + "*Explain the problem’s time and space complexity in your own words.*" + ] + }, + { + "cell_type": "markdown", + "id": "9da480d9", + "metadata": {}, + "source": [ + "This function checks whether all brackets in the string s are properly opened and closed in the correct order — i.e., it validates parentheses, square brackets, and curly braces.\n", + "* stack keeps track of the most recent opening brackets\n", + "* mapping defines which opening bracket corresponds to each closing bracket." + ] + }, + { + "cell_type": "markdown", + "id": "a9600cbf", + "metadata": {}, + "source": [ + "*Explain Time and Space complexity in your own words*\n", + "\n", + "Time: O(n) → Each character processed once.\n", + "\n", + "Space: O(n) → Stack can hold all opening brackets in the worst case." + ] + }, + { + "cell_type": "markdown", + "id": "75004047", + "metadata": {}, + "source": [ + "*Critique your partner's solution, including explanation, and if there is anything that should be adjusted.*\n", + "\n", + "Strength: Linear time and space is optimal for this problem.\n", + "The code is readable but can be slightly improved:\n", + "\n", + "The else: return False is technically safe here, but if the input is guaranteed to contain only bracket characters, it is unnecessary.\n", + "\n", + "Adding docstrings or comments explaining the role of the stack and mapping would help someone new read the code faster." + ] + }, + { + "cell_type": "markdown", + "id": "f3c19344", + "metadata": {}, + "source": [ + "### Reflection" + ] + }, + { + "cell_type": "markdown", + "id": "b1d665c7", + "metadata": {}, + "source": [ + "Throughout Assignment 1, I approached the tasks methodically, beginning with a careful reading of the problem statements and understanding the expected outputs. I tested each function using sample inputs to ensure correctness and handle edge cases, which helped identify and correct subtle logical errors early. \n", + "During the presentation and review with my partner, I learned the value of collaboration and peer feedback. Receiving feedback also made me more aware of potential optimizations and the importance of readability in code. Overall, this assignment strengthened both my technical skills and my ability to communicate computational ideas effectively, which will be valuable in future collaborative projects." + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "dsi_participant", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.19" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}