├── project2 ├── testdir │ ├── t1.c │ ├── t1.h │ ├── subdir1 │ │ ├── a.c │ │ └── a.h │ ├── subdir5 │ │ ├── a.c │ │ └── a.h │ ├── subdir2 │ │ └── .gitkeep │ ├── subdir4 │ │ └── .gitkeep │ └── subdir3 │ │ └── subsubdir1 │ │ ├── b.c │ │ └── b.h ├── ex.py ├── 4_active_dir.py ├── 5_blockchain.py ├── 1_lru_cache.py ├── explanation.txt └── 2_file_recursion.py ├── .gitattributes ├── project1 ├── P0.zip ├── project1-check.ods ├── Task0.py ├── Task1.py ├── analysis.txt ├── Task2.py ├── Task4.py └── Task3.py ├── project4 ├── map-10.pickle ├── map-40.pickle ├── test.py ├── helpers.py ├── student_code.py └── graph_data.py ├── practice ├── trees │ ├── bst_01.png │ ├── bst-delete-case3.png │ ├── tree-simple-example.png │ ├── binary_tree.py.txt │ ├── binary_tree_diameter.py │ ├── binary_tree_state.py.txt │ └── binary_tree_root_to_node_path.py ├── assets │ ├── two_runners_circular.png │ └── comparison_computational_complexity.png ├── maps_hashing │ ├── count-stair-hops.jpg │ ├── pair_sum_to_target.py │ ├── maps_dict.py │ ├── string_hash_table.py │ └── longest_consecutive_subsequence.py ├── graphs │ ├── longest_common_subsequence.odt │ ├── longest_common_subsequence.py │ ├── graph_bfs_iteration.py │ ├── dijkstra.py │ ├── knapsack.py │ └── connecting_islands.py ├── recursion │ ├── binary_search.py │ ├── recursion3_palindrome.py │ ├── last_index.py │ ├── tower_of_hanoi.py │ ├── recursion1_simple.py │ ├── recursion2_reverse_string.py │ └── recursion4_permutations.py ├── queues │ ├── priority_queue_test01.py │ ├── priority_queue.py │ ├── priority_queue_test02.py │ ├── queue_array.py │ └── queue_linked_list.py ├── kadane_algorithm.py ├── stacks │ ├── balanced_paranthesis.py │ ├── stack3_linked_list.py │ ├── stack2_linked_list.py │ ├── stack1_simple.py │ ├── stack_reverse.py │ └── reversed_polish_notation.py ├── pascals_triangle.py ├── linked_lists │ ├── even-after-odd.py │ ├── 4_reverse_linked_list.ipynb │ └── 5_detecting_loops.ipynb ├── daysBetweenDates.py └── ex1-class-person.py ├── data-structures-algorithms-learning-plan.ods ├── .gitignore ├── mit_license.md ├── project3 ├── 6_problem.py ├── 4_problem.py ├── 1_problem.py ├── 3_problem.py ├── 2_problem.py └── auto_complete.py ├── README.md └── efficiency_big_O.md /project2/testdir/t1.c: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /project2/testdir/t1.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /project2/testdir/subdir1/a.c: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /project2/testdir/subdir1/a.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /project2/testdir/subdir5/a.c: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /project2/testdir/subdir5/a.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /project2/testdir/subdir2/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /project2/testdir/subdir4/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /project2/testdir/subdir3/subsubdir1/b.c: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /project2/testdir/subdir3/subsubdir1/b.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | practice/* linguist-documentation 2 | -------------------------------------------------------------------------------- /project1/P0.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ssi112/data-structures-algorithms/HEAD/project1/P0.zip -------------------------------------------------------------------------------- /project4/map-10.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ssi112/data-structures-algorithms/HEAD/project4/map-10.pickle -------------------------------------------------------------------------------- /project4/map-40.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ssi112/data-structures-algorithms/HEAD/project4/map-40.pickle -------------------------------------------------------------------------------- /practice/trees/bst_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ssi112/data-structures-algorithms/HEAD/practice/trees/bst_01.png -------------------------------------------------------------------------------- /project1/project1-check.ods: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ssi112/data-structures-algorithms/HEAD/project1/project1-check.ods -------------------------------------------------------------------------------- /practice/trees/bst-delete-case3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ssi112/data-structures-algorithms/HEAD/practice/trees/bst-delete-case3.png -------------------------------------------------------------------------------- /practice/trees/tree-simple-example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ssi112/data-structures-algorithms/HEAD/practice/trees/tree-simple-example.png -------------------------------------------------------------------------------- /practice/assets/two_runners_circular.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ssi112/data-structures-algorithms/HEAD/practice/assets/two_runners_circular.png -------------------------------------------------------------------------------- /practice/maps_hashing/count-stair-hops.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ssi112/data-structures-algorithms/HEAD/practice/maps_hashing/count-stair-hops.jpg -------------------------------------------------------------------------------- /data-structures-algorithms-learning-plan.ods: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ssi112/data-structures-algorithms/HEAD/data-structures-algorithms-learning-plan.ods -------------------------------------------------------------------------------- /practice/graphs/longest_common_subsequence.odt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ssi112/data-structures-algorithms/HEAD/practice/graphs/longest_common_subsequence.odt -------------------------------------------------------------------------------- /practice/assets/comparison_computational_complexity.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ssi112/data-structures-algorithms/HEAD/practice/assets/comparison_computational_complexity.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # .gitignore 2 | *.pdf 3 | **/practice/.ipynb_checkpoints 4 | **/practice/graphs/.ipynb_checkpoints 5 | **/practice/maps_hashing/.ipynb_checkpoints 6 | **/practice/queues/__pycache__ 7 | **/practice/linked_lists/.ipynb_checkpoints 8 | #practice/.ipynb_checkpoints/* 9 | #practice/.ipynb_checkpoints 10 | #practice/trees/.ipynb_checkpoints 11 | #practice/maps_hashing/.ipynb_checkpoints 12 | project1/*.zip 13 | project1/*.ods 14 | project1/.~* 15 | project1/__pycache__ 16 | project2/*.zip 17 | project2/__pycache__ 18 | wip 19 | project3/.ipynb_checkpoints 20 | project3/*.zip 21 | project4/__pycache__ 22 | **/project4/.ipynb_checkpoints 23 | project4/__pycache__ 24 | *.ods 25 | -------------------------------------------------------------------------------- /project4/test.py: -------------------------------------------------------------------------------- 1 | from helpers import load_map 2 | 3 | MAP_40_ANSWERS = [ 4 | (5, 34, [5, 16, 37, 12, 34]), 5 | (5, 5, [5]), 6 | (8, 24, [8, 14, 16, 37, 12, 17, 10, 24]) 7 | ] 8 | 9 | def test(shortest_path_function): 10 | map_40 = load_map('map-40.pickle') 11 | correct = 0 12 | for start, goal, answer_path in MAP_40_ANSWERS: 13 | path = shortest_path_function(map_40, start, goal) 14 | if path == answer_path: 15 | correct += 1 16 | else: 17 | print("For start:", start, 18 | " Goal:", goal, 19 | "Your path:", path, 20 | " Correct:", answer_path) 21 | if correct == len(MAP_40_ANSWERS): 22 | print("All tests pass! Congratulations!") 23 | else: 24 | print("You passed", correct, "/", len(MAP_40_ANSWERS), "test cases") 25 | -------------------------------------------------------------------------------- /practice/recursion/binary_search.py: -------------------------------------------------------------------------------- 1 | """ 2 | binary_search.py 3 | 4 | Using recursion 5 | 6 | 𝑇(𝑛)=𝑙𝑜𝑔(𝑛)∗𝑘 7 | 8 | The time complexity of the function is a logarithmic function of the input, 𝑛 9 | Hence, the time complexity of the recursive algorithm for binary search is 𝑙𝑜𝑔(𝑛). 10 | """ 11 | def binary_search(arr, target): 12 | return binary_search_func(arr, 0, len(arr) - 1, target) 13 | 14 | def binary_search_func(arr, start_index, end_index, target): 15 | if start_index > end_index: 16 | return -1 17 | 18 | mid_index = (start_index + end_index)//2 19 | 20 | if arr[mid_index] == target: 21 | return mid_index 22 | elif arr[mid_index] > target: 23 | return binary_search_func(arr, start_index, mid_index - 1, target) 24 | else: 25 | return binary_search_func(arr, mid_index + 1, end_index, target) 26 | 27 | arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 44, 71, 72, 73, 101, 999] 28 | print(binary_search(arr, 71)) 29 | 30 | -------------------------------------------------------------------------------- /practice/recursion/recursion3_palindrome.py: -------------------------------------------------------------------------------- 1 | """ 2 | recursion3_palindrome.py 3 | 4 | A palindrome is a word that is the reverse of itself. 5 | That is it is the same word when read forwards and backwards. 6 | """ 7 | 8 | 9 | def is_palindrome(input): 10 | """ 11 | Return True if input is palindrome, False otherwise. 12 | 13 | Args: 14 | input(str): input to be checked if it is palindrome 15 | """ 16 | if len(input) <= 1: 17 | return True 18 | else: 19 | first_char = input[0] 20 | last_char = input[-1] 21 | 22 | # sub_input is input with first and last char removed 23 | sub_input = input[1:-1] 24 | # print(sub_input) 25 | return (first_char == last_char) and is_palindrome(sub_input) 26 | 27 | print ("Pass" if (is_palindrome("")) else "Fail") 28 | print ("Pass" if (is_palindrome("a")) else "Fail") 29 | print ("Pass" if (is_palindrome("madam")) else "Fail") 30 | print ("Pass" if (is_palindrome("abba")) else "Fail") 31 | print ("Pass" if not (is_palindrome("Udacity")) else "Fail") 32 | -------------------------------------------------------------------------------- /mit_license.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) [2019] [S. S. Isenberg] 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /practice/maps_hashing/pair_sum_to_target.py: -------------------------------------------------------------------------------- 1 | """ 2 | pair_sum_to_target.py 3 | 4 | Problem statement 5 | 6 | Given an input_list and a target, return the indices of pair of integers in the 7 | list that sum to the target. The best solution takes O(n) time. 8 | You can assume that the list does not have any duplicates. 9 | 10 | For e.g. input_list = [1, 5, 9, 7] and target = 8, the answer would be [0, 3] 11 | """ 12 | 13 | def pair_sum_to_zero(in_list, target): 14 | # TODO: Write pair sum to zero function 15 | 16 | first_index = 0 17 | last_index = len(in_list) - 1 18 | 19 | while first_index < last_index: 20 | pair_sum = in_list[first_index] + in_list[last_index] 21 | if pair_sum < target: 22 | first_index += 1 23 | elif pair_sum > target: 24 | last_index -= 1 25 | else: 26 | # below is the actual values 27 | # in_list[first_index], in_list[last_index] 28 | return [first_index, last_index] 29 | return [None, None] 30 | 31 | 32 | input_list = [1, 5, 9, 7] 33 | print(pair_sum_to_zero(input_list, 8)) # [0, 3] 34 | 35 | input_list = [10, 5, 9, 8, 12, 1, 16, 6] 36 | print(pair_sum_to_zero(input_list, 16)) # [0, 7] 37 | 38 | input_list = [0, 1, 2, 3, -4] 39 | print(pair_sum_to_zero(input_list, -4)) # [0, 4] 40 | 41 | input_list = [0, 1, 2, 3, -4, 77, 101, -3, 11, 81] 42 | print(pair_sum_to_zero(input_list, -11)) # [None, None] 43 | 44 | -------------------------------------------------------------------------------- /practice/maps_hashing/maps_dict.py: -------------------------------------------------------------------------------- 1 | """ 2 | maps_dict.py 3 | 4 | In Python, the map concept appears as a built-in data type called a dictionary. 5 | A dictionary contains key-value pairs. 6 | """ 7 | 8 | locations = {'North America': {'USA': ['Mountain View']}} 9 | locations['Asia'] = {'India': ['Bangalore']} 10 | locations['North America']['USA'].append('Atlanta') 11 | locations['Africa'] = {'Egypt': 'Cairo'} 12 | locations['Asia'].update( {'China': ['Shanghai']} ) 13 | locations['North America'].update({'Mexico': ['Mexico City']}) 14 | locations['North America']['Mexico'].append('Guadalajara') 15 | locations['North America']['Mexico'].append('Juárez') 16 | locations['North America']['Mexico'].append('Guadalupe') 17 | locations['North America']['Mexico'].append('Nuevo Laredo') 18 | 19 | # TODO: Print a list of all cities in the USA in alphabetic order. 20 | country_select = "Mexico" 21 | usa_city_list = sorted(locations['North America'][country_select]) 22 | 23 | # print (usa_city_list) 24 | print("="*25) 25 | 26 | for city in usa_city_list: 27 | print (city) 28 | print("="*25) 29 | 30 | import operator 31 | asia_city_list = [] 32 | 33 | # TODO: Print all cities in Asia, in alphabetic order, next to the name of the country 34 | for country, cities in locations['Asia'].items(): 35 | # print(cities, country) 36 | asia_city_list.append(cities[0] + ', ' + country) 37 | 38 | # sort list on multiple attributes 39 | asia_sorted = sorted(asia_city_list, key = operator.itemgetter(1, 2)) 40 | # print(asia_sorted) 41 | 42 | for val in asia_sorted: 43 | print(val) 44 | 45 | # print(locations) 46 | -------------------------------------------------------------------------------- /practice/queues/priority_queue_test01.py: -------------------------------------------------------------------------------- 1 | """ 2 | priority_queue_test01.py 3 | 4 | some tests for priority_queue.py 5 | 6 | TESTING 1, 2, 3 7 | see https://repl.it/@ssi112/PriorityQueue for similar testing 8 | 9 | """ 10 | import sys 11 | from priority_queue import * 12 | 13 | # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### 14 | 15 | pq = PriorityQueue() 16 | 17 | pq.enqueue("John", 2); 18 | pq.enqueue("Jack", 1); 19 | pq.enqueue("Camila", 1); 20 | pq.enqueue("Esteban", 3) 21 | 22 | print() 23 | print("Is queue empty?", pq.isEmpty()) 24 | print("What is the size of queue?", pq.size()) 25 | hpi = pq.front() 26 | print("Highest priority item is {} at priority {}".format( hpi.element, hpi.priority) ) 27 | 28 | print("adding Esperanaza 4...") 29 | pq.enqueue("Esperanaza", 4) 30 | print("\n.....current priority queue.....") 31 | print(pq) 32 | 33 | print() 34 | print("adding Hayleigh 0.05...") 35 | pq.enqueue("Hayleigh", 0.05) 36 | 37 | print() 38 | print("\n.....current priority queue.....") 39 | print(pq) 40 | 41 | print() 42 | print("adding Rachele 9...") 43 | pq.enqueue("Rachele", 9) 44 | print("What is the size of queue?", pq.size()) 45 | print("\n.....current priority queue.....") 46 | print(pq) 47 | 48 | print() 49 | print("adding Robin 7...") 50 | pq.enqueue("Robin", 7) 51 | print("\n.....current priority queue.....") 52 | print(pq) 53 | 54 | print() 55 | print("Removing lowest priority item...") 56 | lowestRemoved = pq.removeLowestPriorityItem() 57 | print(lowestRemoved.element, lowestRemoved.priority) 58 | print("\n.....current priority queue.....") 59 | print(pq) 60 | 61 | -------------------------------------------------------------------------------- /project1/Task0.py: -------------------------------------------------------------------------------- 1 | """ 2 | Read file into texts and calls. 3 | It's ok if you don't understand how to read files. 4 | """ 5 | import csv 6 | texts = list() 7 | calls = list() 8 | 9 | def readTexts(): 10 | with open('texts.csv', 'r') as f: 11 | reader = csv.reader(f, delimiter='\n') 12 | for line in reader: 13 | texts.append(line) 14 | 15 | 16 | def readCalls(): 17 | with open('calls.csv', 'r') as f: 18 | reader = csv.reader(f, delimiter='\n') 19 | for line in reader: 20 | calls.append(line) 21 | 22 | 23 | def main(): 24 | """ 25 | TASK 0: 26 | What is the first record of texts and what is the last record of calls? 27 | Print messages: 28 | "First record of texts, texts at time