├── .devcontainer ├── Dockerfile ├── devcontainer.json └── startup.sh ├── .github ├── CODEOWNERS ├── ISSUE_TEMPLATE.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ └── main.yml ├── .gitignore ├── .vscode └── settings.json ├── CONTRIBUTING.md ├── Finished ├── DataStructures │ ├── Dictionary │ │ └── dictionary_finished.py │ ├── LinkedList │ │ └── linklist_finished.py │ ├── Queues │ │ └── queue_finished.py │ └── Stacks │ │ └── stack_finished.py ├── Introduction │ └── gcd_finished.py ├── PracticalExamples │ ├── Filter_finished.py │ ├── ValueCounter_finished.py │ ├── balancing_finished.py │ └── findmax_finished.py ├── Recursion │ ├── countdown_finished.py │ └── recursion_finished.py ├── Searching │ ├── issorted_finished.py │ ├── ordered_finished.py │ └── unordered_finished.py └── Sorting │ ├── BubbleSort │ └── bubble_finished.py │ ├── MergeSort │ └── mergesort_finished.py │ └── Quicksort │ └── quicksort_finished.py ├── LICENSE ├── NOTICE ├── README.md ├── Start ├── DataStructures │ ├── Dictionary │ │ └── dictionary_start.py │ ├── LinkedList │ │ └── linklist_start.py │ ├── Queues │ │ └── queue_start.py │ └── Stacks │ │ └── stack_start.py ├── Introduction │ └── gcd_start.py ├── PracticalExamples │ ├── Filter_start.py │ ├── ValueCounter_start.py │ ├── balancing_start.py │ └── findmax_start.py ├── Recursion │ ├── countdown_start.py │ └── recursion_start.py ├── Searching │ ├── issorted_start.py │ ├── ordered_start.py │ └── unordered_start.py └── Sorting │ ├── BubbleSort │ └── bubble_start.py │ ├── MergeSort │ └── mergesort_start.py │ └── QuickSort │ └── quicksort_start.py └── requirements.txt /.devcontainer/Dockerfile: -------------------------------------------------------------------------------- 1 | # See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.233.0/containers/python-3/.devcontainer/base.Dockerfile 2 | 3 | # [Choice] Python version (use -bullseye variants on local arm64/Apple Silicon): 3, 3.10, 3.9, 3.8, 3.7, 3.6, 3-bullseye, 3.10-bullseye, 3.9-bullseye, 3.8-bullseye, 3.7-bullseye, 3.6-bullseye, 3-buster, 3.10-buster, 3.9-buster, 3.8-buster, 3.7-buster, 3.6-buster 4 | ARG VARIANT="3.10" 5 | FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT} 6 | 7 | # [Choice] Node.js version: none, lts/*, 16, 14, 12, 10 8 | ARG NODE_VERSION="none" 9 | RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi 10 | 11 | # [Optional] If your pip requirements rarely change, uncomment this section to add them to the image. 12 | # COPY requirements.txt /tmp/pip-tmp/ 13 | # RUN pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \ 14 | # && rm -rf /tmp/pip-tmp 15 | 16 | # [Optional] Uncomment this section to install additional OS packages. 17 | # RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ 18 | # && apt-get -y install --no-install-recommends 19 | 20 | # [Optional] Uncomment this line to install global node packages. 21 | # RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g " 2>&1 22 | -------------------------------------------------------------------------------- /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Python 3", 3 | "build": { 4 | "dockerfile": "Dockerfile", 5 | "context": "..", 6 | "args": { 7 | "VARIANT": "3.10", // Set Python version here 8 | "NODE_VERSION": "lts/*" 9 | } 10 | }, 11 | "settings": { 12 | "python.defaultInterpreterPath": "/usr/local/bin/python", 13 | "python.linting.enabled": true, 14 | "python.linting.pylintEnabled": true, 15 | "python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8", 16 | "python.formatting.blackPath": "/usr/local/py-utils/bin/black", 17 | "python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf", 18 | "python.linting.banditPath": "/usr/local/py-utils/bin/bandit", 19 | "python.linting.flake8Path": "/usr/local/py-utils/bin/flake8", 20 | "python.linting.mypyPath": "/usr/local/py-utils/bin/mypy", 21 | "python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle", 22 | "python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle", 23 | "python.linting.pylintPath": "/usr/local/py-utils/bin/pylint", 24 | "python.linting.pylintArgs": ["--disable=C0111"] 25 | }, 26 | "extensions": [ 27 | "ms-python.python", 28 | "ms-python.vscode-pylance" 29 | ], 30 | "remoteUser": "vscode", 31 | "onCreateCommand": "echo PS1='\"$ \"' >> ~/.bashrc", //Set Terminal Prompt to $ 32 | "postCreateCommand": "sh .devcontainer/startup.sh" 33 | } 34 | -------------------------------------------------------------------------------- /.devcontainer/startup.sh: -------------------------------------------------------------------------------- 1 | if [ -f requirements.txt ]; then 2 | pip install --user -r requirements.txt 3 | fi -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Codeowners for these exercise files: 2 | # * (asterisk) denotes "all files and folders" 3 | # Example: * @producer @instructor 4 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 7 | 8 | ## Issue Overview 9 | 10 | 11 | ## Describe your environment 12 | 13 | 14 | ## Steps to Reproduce 15 | 16 | 1. 17 | 2. 18 | 3. 19 | 4. 20 | 21 | ## Expected Behavior 22 | 23 | 24 | ## Current Behavior 25 | 26 | 27 | ## Possible Solution 28 | 29 | 30 | ## Screenshots / Video 31 | 32 | 33 | ## Related Issues 34 | 35 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: Copy To Branches 2 | on: 3 | workflow_dispatch: 4 | jobs: 5 | copy-to-branches: 6 | runs-on: ubuntu-latest 7 | steps: 8 | - uses: actions/checkout@v2 9 | with: 10 | fetch-depth: 0 11 | - name: Copy To Branches Action 12 | uses: planetoftheweb/copy-to-branches@v1.2 13 | env: 14 | key: main 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Apple 2 | *.DS_Store 3 | 4 | # Built application files 5 | *.apk 6 | *.ap_ 7 | 8 | # Files for the Dalvik VM 9 | *.dex 10 | 11 | # Java class files 12 | *.class 13 | 14 | # Generated files 15 | bin/ 16 | gen/ 17 | 18 | # Gradle files 19 | .gradle/ 20 | build/ 21 | 22 | # Local configuration file (sdk path, etc) 23 | local.properties 24 | 25 | # Proguard folder generated by Eclipse 26 | proguard/ 27 | 28 | # Log Files 29 | *.log 30 | 31 | # Android Studio Navigation editor temp files 32 | .navigation/ 33 | 34 | # Android Studio captures folder 35 | captures/ 36 | 37 | # Google Doc files 38 | *.gsheet 39 | *.gslides 40 | *.gdoc 41 | 42 | # MS Office files 43 | *.xls_ 44 | *.doc_ 45 | *.ppt_ 46 | 47 | # PDF files 48 | *.pdf 49 | 50 | # ZIP files 51 | *.zip 52 | 53 | # VISUAL STUDIO FILES 54 | 55 | # User-specific files 56 | *.suo 57 | *.user 58 | *.userosscache 59 | *.sln.docstates 60 | 61 | # User-specific files (MonoDevelop/Xamarin Studio) 62 | *.userprefs 63 | 64 | # Build results 65 | [Dd]ebug/ 66 | [Dd]ebugPublic/ 67 | [Rr]elease/ 68 | [Rr]eleases/ 69 | x64/ 70 | x86/ 71 | bld/ 72 | [Bb]in/ 73 | [Oo]bj/ 74 | [Ll]og/ 75 | __pycache__/ 76 | 77 | # Visual Studio 2015 cache/options directory 78 | .vs/ 79 | # Uncomment if you have tasks that create the project's static files in wwwroot 80 | #wwwroot/ 81 | 82 | # MSTest test Results 83 | [Tt]est[Rr]esult*/ 84 | [Bb]uild[Ll]og.* 85 | 86 | # NUNIT 87 | *.VisualState.xml 88 | TestResult.xml 89 | 90 | # Build Results of an ATL Project 91 | [Dd]ebugPS/ 92 | [Rr]eleasePS/ 93 | dlldata.c 94 | 95 | # DNX 96 | project.lock.json 97 | artifacts/ 98 | 99 | *_i.c 100 | *_p.c 101 | *_i.h 102 | *.ilk 103 | *.meta 104 | *.obj 105 | *.pch 106 | *.pdb 107 | *.pgc 108 | *.pgd 109 | *.rsp 110 | *.sbr 111 | *.tlb 112 | *.tli 113 | *.tlh 114 | *.tmp 115 | *.tmp_proj 116 | *.log 117 | *.vspscc 118 | *.vssscc 119 | .builds 120 | *.pidb 121 | *.svclog 122 | *.scc 123 | 124 | # Chutzpah Test files 125 | _Chutzpah* 126 | 127 | # Visual C++ cache files 128 | ipch/ 129 | *.aps 130 | *.ncb 131 | *.opendb 132 | *.opensdf 133 | *.sdf 134 | *.cachefile 135 | *.VC.db 136 | *.VC.VC.opendb 137 | 138 | # Visual Studio profiler 139 | *.psess 140 | *.vsp 141 | *.vspx 142 | *.sap 143 | 144 | # TFS 2012 Local Workspace 145 | $tf/ 146 | 147 | # Guidance Automation Toolkit 148 | *.gpState 149 | 150 | # ReSharper is a .NET coding add-in 151 | _ReSharper*/ 152 | *.[Rr]e[Ss]harper 153 | *.DotSettings.user 154 | 155 | # JustCode is a .NET coding add-in 156 | .JustCode 157 | 158 | # TeamCity is a build add-in 159 | _TeamCity* 160 | 161 | # DotCover is a Code Coverage Tool 162 | *.dotCover 163 | 164 | # NCrunch 165 | _NCrunch_* 166 | .*crunch*.local.xml 167 | nCrunchTemp_* 168 | 169 | # MightyMoose 170 | *.mm.* 171 | AutoTest.Net/ 172 | 173 | # Web workbench (sass) 174 | .sass-cache/ 175 | 176 | # Installshield output folder 177 | [Ee]xpress/ 178 | 179 | # DocProject is a documentation generator add-in 180 | DocProject/buildhelp/ 181 | DocProject/Help/*.HxT 182 | DocProject/Help/*.HxC 183 | DocProject/Help/*.hhc 184 | DocProject/Help/*.hhk 185 | DocProject/Help/*.hhp 186 | DocProject/Help/Html2 187 | DocProject/Help/html 188 | 189 | # Click-Once directory 190 | publish/ 191 | 192 | # Publish Web Output 193 | *.[Pp]ublish.xml 194 | *.azurePubxml 195 | # TODO: Comment the next line if you want to checkin your web deploy settings 196 | # but database connection strings (with potential passwords) will be unencrypted 197 | *.pubxml 198 | *.publishproj 199 | 200 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 201 | # checkin your Azure Web App publish settings, but sensitive information contained 202 | # in these scripts will be unencrypted 203 | PublishScripts/ 204 | 205 | # NuGet Packages 206 | *.nupkg 207 | # The packages folder can be ignored because of Package Restore 208 | **/packages/* 209 | # except build/, which is used as an MSBuild target. 210 | !**/packages/build/ 211 | # Uncomment if necessary however generally it will be regenerated when needed 212 | #!**/packages/repositories.config 213 | # NuGet v3's project.json files produces more ignoreable files 214 | *.nuget.props 215 | *.nuget.targets 216 | 217 | # Microsoft Azure Build Output 218 | csx/ 219 | *.build.csdef 220 | 221 | # Microsoft Azure Emulator 222 | ecf/ 223 | rcf/ 224 | 225 | # Windows Store app package directories and files 226 | AppPackages/ 227 | BundleArtifacts/ 228 | Package.StoreAssociation.xml 229 | _pkginfo.txt 230 | 231 | # Visual Studio cache files 232 | # files ending in .cache can be ignored 233 | *.[Cc]ache 234 | # but keep track of directories ending in .cache 235 | !*.[Cc]ache/ 236 | 237 | # Others 238 | ClientBin/ 239 | ~$* 240 | *~ 241 | *.dbmdl 242 | *.dbproj.schemaview 243 | *.pfx 244 | *.publishsettings 245 | node_modules/ 246 | orleans.codegen.cs 247 | 248 | # Since there are multiple workflows, uncomment next line to ignore bower_components 249 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 250 | #bower_components/ 251 | 252 | # RIA/Silverlight projects 253 | Generated_Code/ 254 | 255 | # Backup & report files from converting an old project file 256 | # to a newer Visual Studio version. Backup files are not needed, 257 | # because we have git ;-) 258 | _UpgradeReport_Files/ 259 | Backup*/ 260 | UpgradeLog*.XML 261 | UpgradeLog*.htm 262 | 263 | # SQL Server files 264 | *.mdf 265 | *.ldf 266 | 267 | # Business Intelligence projects 268 | *.rdl.data 269 | *.bim.layout 270 | *.bim_*.settings 271 | 272 | # Microsoft Fakes 273 | FakesAssemblies/ 274 | 275 | # GhostDoc plugin setting file 276 | *.GhostDoc.xml 277 | 278 | # Node.js Tools for Visual Studio 279 | .ntvs_analysis.dat 280 | 281 | # Visual Studio 6 build log 282 | *.plg 283 | 284 | # Visual Studio 6 workspace options file 285 | *.opt 286 | 287 | # Visual Studio LightSwitch build output 288 | **/*.HTMLClient/GeneratedArtifacts 289 | **/*.DesktopClient/GeneratedArtifacts 290 | **/*.DesktopClient/ModelManifest.xml 291 | **/*.Server/GeneratedArtifacts 292 | **/*.Server/ModelManifest.xml 293 | _Pvt_Extensions 294 | 295 | # Paket dependency manager 296 | .paket/paket.exe 297 | paket-files/ 298 | 299 | # FAKE - F# Make 300 | .fake/ 301 | 302 | # JetBrains Rider 303 | .idea/ 304 | *.sln.iml 305 | 306 | # VS Code folder 307 | .vscode/ 308 | 309 | # Databricks file 310 | *.pyi 311 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.bracketPairColorization.enabled": true, 3 | "editor.cursorBlinking": "solid", 4 | "editor.fontFamily": "ui-monospace, Menlo, Monaco, 'Cascadia Mono', 'Segoe UI Mono', 'Roboto Mono', 'Oxygen Mono', 'Ubuntu Monospace', 'Source Code Pro', 'Fira Mono', 'Droid Sans Mono', 'Courier New', monospace", 5 | "editor.fontLigatures": false, 6 | "editor.fontSize": 22, 7 | "editor.formatOnPaste": true, 8 | "editor.formatOnSave": true, 9 | "editor.lineNumbers": "on", 10 | "editor.matchBrackets": "always", 11 | "editor.minimap.enabled": false, 12 | "editor.smoothScrolling": true, 13 | "editor.tabSize": 2, 14 | "editor.useTabStops": true, 15 | "emmet.triggerExpansionOnTab": true, 16 | "explorer.openEditors.visible": 0, 17 | "files.autoSave": "afterDelay", 18 | "screencastMode.onlyKeyboardShortcuts": true, 19 | "terminal.integrated.fontSize": 18, 20 | "workbench.activityBar.visible": true, 21 | "workbench.colorTheme": "Visual Studio Dark", 22 | "workbench.fontAliasing": "antialiased", 23 | "workbench.statusBar.visible": true 24 | } 25 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | 2 | Contribution Agreement 3 | ====================== 4 | 5 | This repository does not accept pull requests (PRs). All pull requests will be closed. 6 | 7 | However, if any contributions (through pull requests, issues, feedback or otherwise) are provided, as a contributor, you represent that the code you submit is your original work or that of your employer (in which case you represent you have the right to bind your employer). By submitting code (or otherwise providing feedback), you (and, if applicable, your employer) are licensing the submitted code (and/or feedback) to LinkedIn and the open source community subject to the BSD 2-Clause license. 8 | -------------------------------------------------------------------------------- /Finished/DataStructures/Dictionary/dictionary_finished.py: -------------------------------------------------------------------------------- 1 | # Example file for Programming Foundations: Algorithms by Joe Marini 2 | # demonstrate dictionary usage 3 | 4 | 5 | # create a dictionary all at once 6 | items1 = dict({"key1": 1, "key2": 2, "key3": "three"}) 7 | print(items1) 8 | 9 | 10 | # create a dictionary progressively 11 | items2 = {} 12 | items2["key1"] = 1 13 | items2["key2"] = 2 14 | items2["key3"] = 3 15 | print(items2) 16 | 17 | # try to access a nonexistent key 18 | # print(items1["key6"]) 19 | 20 | # replace an item 21 | items2["key2"] = "two" 22 | print(items2) 23 | 24 | # iterate the keys and values in the dictionary 25 | for key, value in items2.items(): 26 | print("key: ", key, " value: ", value) 27 | -------------------------------------------------------------------------------- /Finished/DataStructures/LinkedList/linklist_finished.py: -------------------------------------------------------------------------------- 1 | # Example file for Programming Foundations: Algorithms by Joe Marini 2 | # Linked list example 3 | 4 | 5 | # the Node class 6 | class Node(object): 7 | def __init__(self, val): 8 | self.val = val 9 | self.next = None 10 | 11 | def get_data(self): 12 | return self.val 13 | 14 | def set_data(self, val): 15 | self.val = val 16 | 17 | def get_next(self): 18 | return self.next 19 | 20 | def set_next(self, next): 21 | self.next = next 22 | 23 | 24 | # the LinkedList class 25 | class LinkedList(object): 26 | def __init__(self, head=None): 27 | self.head = head 28 | self.count = 0 29 | 30 | def get_count(self): 31 | return self.count 32 | 33 | def insert(self, data): 34 | new_node = Node(data) 35 | new_node.set_next(self.head) 36 | self.head = new_node 37 | self.count += 1 38 | 39 | def find(self, val): 40 | item = self.head 41 | while (item != None): 42 | if item.get_data() == val: 43 | return item 44 | else: 45 | item = item.get_next() 46 | return None 47 | 48 | def deleteAt(self, idx): 49 | if idx > self.count: 50 | return 51 | if self.head == None: 52 | return 53 | else: 54 | tempIdx = 0 55 | node = self.head 56 | while tempIdx < idx-1: 57 | node = node.get_next() 58 | tempIdx += 1 59 | node.set_next(node.get_next().get_next()) 60 | self.count -= 1 61 | 62 | def dump_list(self): 63 | tempnode = self.head 64 | while (tempnode != None): 65 | print("Node: ", tempnode.get_data()) 66 | tempnode = tempnode.get_next() 67 | 68 | 69 | # create a linked list and insert some items 70 | itemlist = LinkedList() 71 | itemlist.insert(38) 72 | itemlist.insert(49) 73 | itemlist.insert(13) 74 | itemlist.insert(15) 75 | 76 | itemlist.dump_list() 77 | 78 | # exercise the list 79 | print("Item count: ", itemlist.get_count()) 80 | print("Finding item: ", itemlist.find(13)) 81 | print("Finding item: ", itemlist.find(78)) 82 | 83 | # delete an item 84 | itemlist.deleteAt(3) 85 | print("Item count: ", itemlist.get_count()) 86 | print("Finding item: ", itemlist.find(38)) 87 | itemlist.dump_list() 88 | -------------------------------------------------------------------------------- /Finished/DataStructures/Queues/queue_finished.py: -------------------------------------------------------------------------------- 1 | # Example file for Programming Foundations: Algorithms by Joe Marini 2 | # try out the Python queue functions 3 | from collections import deque 4 | 5 | # create a new empty deque object that will function as a queue 6 | queue = deque() 7 | 8 | # add some items to the queue 9 | queue.append(1) 10 | queue.append(2) 11 | queue.append(3) 12 | queue.append(4) 13 | 14 | # print the queue contents 15 | print(queue) 16 | 17 | # pop an item off the front of the queue 18 | x = queue.popleft() 19 | print(x) 20 | print(queue) 21 | -------------------------------------------------------------------------------- /Finished/DataStructures/Stacks/stack_finished.py: -------------------------------------------------------------------------------- 1 | # Example file for Programming Foundations: Algorithms by Joe Marini 2 | # try out the Python stack functions 3 | 4 | # create a new empty stack 5 | stack = [] 6 | 7 | # push items onto the stack 8 | stack.append(1) 9 | stack.append(2) 10 | stack.append(3) 11 | stack.append(4) 12 | 13 | # print the stack contents 14 | print(stack) 15 | 16 | # pop an item off the stack 17 | x = stack.pop() 18 | print(x) 19 | print(stack) 20 | -------------------------------------------------------------------------------- /Finished/Introduction/gcd_finished.py: -------------------------------------------------------------------------------- 1 | # Example file for Programming Foundations: Algorithms by Joe Marini 2 | # Find the greatest common denominator of two numbers 3 | # using Euclid's algorithm 4 | 5 | 6 | def gcd(a, b): 7 | while (b != 0): 8 | t = a # set aside the value of a 9 | a = b # set a equal to b 10 | b = t % b # divide t (which is a) by b 11 | 12 | return a 13 | 14 | 15 | # try out the function with a few examples 16 | print(gcd(60, 96)) # should be 12 17 | print(gcd(20, 8)) # should be 4 18 | -------------------------------------------------------------------------------- /Finished/PracticalExamples/Filter_finished.py: -------------------------------------------------------------------------------- 1 | # Example file for Programming Foundations: Algorithms by Joe Marini 2 | # use a set to count unique items 3 | 4 | 5 | # define a set of items that we want to reduce duplicates 6 | items = ["apple", "pear", "orange", "banana", "apple", 7 | "orange", "apple", "pear", "banana", "orange", 8 | "apple", "kiwi", "pear", "apple", "orange"] 9 | 10 | # create a set to perform a filter 11 | unique_items = set() 12 | 13 | # loop over each item and add to the set 14 | for item in items: 15 | unique_items.add(item) 16 | print(unique_items) 17 | 18 | # Count the unique letters in a sentence 19 | sentence = "The quick brown fox jumps over the lazy dog." 20 | unique_items = {c for c in sentence.lower() if c.isalnum()} 21 | print(unique_items) 22 | -------------------------------------------------------------------------------- /Finished/PracticalExamples/ValueCounter_finished.py: -------------------------------------------------------------------------------- 1 | # Example file for Programming Foundations: Algorithms by Joe Marini 2 | # using a hashtable to count individual items 3 | 4 | 5 | # define a set of items that we want to count 6 | items = ["apple", "pear", "orange", "banana", "apple", 7 | "orange", "apple", "pear", "banana", "orange", 8 | "apple", "kiwi", "pear", "apple", "orange"] 9 | 10 | # create a hashtable object to hold the items and counts 11 | counter = dict() 12 | 13 | # iterate over each item and increment the count for each one 14 | for item in items: 15 | if item in counter.keys(): 16 | counter[item] += 1 17 | else: 18 | counter[item] = 1 19 | 20 | # print the results 21 | print(counter) 22 | -------------------------------------------------------------------------------- /Finished/PracticalExamples/balancing_finished.py: -------------------------------------------------------------------------------- 1 | # Example file for Programming Foundations: Algorithms by Joe Marini 2 | # Use a stack to see if a programming statement is balanced 3 | 4 | 5 | def is_balanced(thestr): 6 | statement_stack = [] 7 | for c in thestr: 8 | if c in ['(','{','[']: 9 | statement_stack.append(c) 10 | 11 | if c in [')','}',']']: 12 | if len(statement_stack) == 0: 13 | return False 14 | 15 | test = statement_stack.pop() 16 | if test == ')' and c != '(': 17 | return False 18 | if test == '}' and c != '{': 19 | return False 20 | if test == ']' and c != '[': 21 | return False 22 | 23 | if len(statement_stack) > 0: 24 | return False 25 | 26 | return True 27 | 28 | test_statements = [ 29 | "print('Hello World!')", 30 | "a(x[i]) == b(x[i])", 31 | "{c for c in a(x)}", 32 | "Hello!)", 33 | "(This is not [balanced)", 34 | "{{{[[(())]}}", 35 | "(", 36 | "}" 37 | ] 38 | 39 | for statement in test_statements: 40 | print(f'{statement} balanced: {is_balanced(statement)}') 41 | -------------------------------------------------------------------------------- /Finished/PracticalExamples/findmax_finished.py: -------------------------------------------------------------------------------- 1 | # Example file for Programming Foundations: Algorithms by Joe Marini 2 | # use a recursive algorithm to find a maximum value 3 | 4 | 5 | # declare a list of values to operate on 6 | items = [6, 20, 8, 19, 56, 23, 87, 41, 49, 53] 7 | 8 | def find_max(items): 9 | # breaking condition: last item in list? return it 10 | if len(items) == 1: 11 | return items[0] 12 | 13 | # otherwise get the first item and call function 14 | # again to operate on the rest of the list 15 | val1 = items[0] 16 | val2 = find_max(items[1:]) 17 | 18 | # perform the comparison when we're down to just two 19 | if val1 > val2: 20 | return val1 21 | else: 22 | return val2 23 | 24 | 25 | # test the function 26 | print(find_max(items)) 27 | -------------------------------------------------------------------------------- /Finished/Recursion/countdown_finished.py: -------------------------------------------------------------------------------- 1 | # Example file for Programming Foundations: Algorithms by Joe Marini 2 | # use recursion to implement a countdown counter 3 | 4 | 5 | def countdown(x): 6 | if x == 0: 7 | print("Done!") 8 | return 9 | else: 10 | print(x, "...") 11 | countdown(x-1) 12 | 13 | 14 | countdown(5) 15 | -------------------------------------------------------------------------------- /Finished/Recursion/recursion_finished.py: -------------------------------------------------------------------------------- 1 | # Example file for Programming Foundations: Algorithms by Joe Marini 2 | # Using recursion to implement power and factorial functions 3 | 4 | 5 | # 2^4 = 2*2*2*2 = 16 6 | def power(num, pwr): 7 | # breaking condition: if we reach zero, return 1 8 | if pwr == 0: 9 | return 1 10 | else: 11 | return num * power(num, pwr-1) 12 | 13 | 14 | # 5! = 5*4*3*2*1 15 | # Special case: 0! is 1, because... math 16 | def factorial(num): 17 | if (num == 0): 18 | return 1 19 | else: 20 | return num * factorial(num-1) 21 | 22 | 23 | print(f"5 to the power of 3 is {power(5, 3)}") 24 | print(f"2 to the power of 4 is {power(2, 4)}") 25 | print(f"4! is {factorial(4)}") 26 | print(f"0! is {factorial(0)}") 27 | -------------------------------------------------------------------------------- /Finished/Searching/issorted_finished.py: -------------------------------------------------------------------------------- 1 | # Example file for Programming Foundations: Algorithms by Joe Marini 2 | # determine if a list is sorted 3 | 4 | 5 | items1 = [6, 8, 19, 20, 23, 41, 49, 53, 56, 87] 6 | items2 = [6, 20, 8, 19, 56, 23, 87, 41, 49, 53] 7 | 8 | def is_sorted(itemlist): 9 | # using the all function 10 | return all(itemlist[i] <= itemlist[i+1] for i in range(len(itemlist)-1)) 11 | 12 | # using the brute force method 13 | # for i in range(0, len(itemlist)-1): 14 | # if (itemlist[i] > itemlist[i+1]): 15 | # return False 16 | # return True 17 | 18 | print(is_sorted(items1)) 19 | print(is_sorted(items2)) 20 | 21 | -------------------------------------------------------------------------------- /Finished/Searching/ordered_finished.py: -------------------------------------------------------------------------------- 1 | # Example file for Programming Foundations: Algorithms by Joe Marini 2 | # searching for an item in an ordered list 3 | # this technique uses a binary search 4 | 5 | 6 | items = [6, 8, 19, 20, 23, 41, 49, 53, 56, 87] 7 | 8 | def binarysearch(item, itemlist): 9 | # get the list size 10 | listsize = len(itemlist) - 1 11 | # start at the two ends of the list 12 | lowerIdx = 0 13 | upperIdx = listsize 14 | 15 | while lowerIdx <= upperIdx: 16 | # calculate the middle point 17 | midPt = (lowerIdx + upperIdx) // 2 18 | 19 | # if item is found, return the index 20 | if itemlist[midPt] == item: 21 | return midPt 22 | # otherwise get the next midpoint 23 | if item > itemlist[midPt]: 24 | lowerIdx = midPt + 1 25 | else: 26 | upperIdx = midPt - 1 27 | 28 | if lowerIdx > upperIdx: 29 | return None 30 | 31 | 32 | print(binarysearch(23, items)) 33 | print(binarysearch(87, items)) 34 | print(binarysearch(21, items)) 35 | -------------------------------------------------------------------------------- /Finished/Searching/unordered_finished.py: -------------------------------------------------------------------------------- 1 | # Example file for Programming Foundations: Algorithms by Joe Marini 2 | # searching for an item in an unordered list 3 | # sometimes called a Linear search 4 | 5 | # declare a list of values to operate on 6 | items = [6, 20, 8, 19, 56, 23, 87, 41, 49, 53] 7 | 8 | def find_item(item, itemlist): 9 | for i in range(0, len(itemlist)): 10 | if item == itemlist[i]: 11 | return i 12 | 13 | return None 14 | 15 | 16 | print(find_item(87, items)) 17 | print(find_item(250, items)) 18 | -------------------------------------------------------------------------------- /Finished/Sorting/BubbleSort/bubble_finished.py: -------------------------------------------------------------------------------- 1 | # Example file for Programming Foundations: Algorithms by Joe Marini 2 | # Bubble sort algorithm 3 | 4 | 5 | def bubbleSort(dataset): 6 | # start with the array length and decrement each time 7 | for i in range(len(dataset)-1, 0, -1): 8 | # examine each item pair 9 | for j in range(i): 10 | # swap items if needed 11 | if dataset[j] > dataset[j+1]: 12 | temp = dataset[j] 13 | dataset[j] = dataset[j+1] 14 | dataset[j+1] = temp 15 | 16 | print("Current state: ", dataset) 17 | 18 | 19 | list1 = [6, 20, 8, 19, 56, 23, 87, 41, 49, 53] 20 | print("Starting state: ", list1) 21 | bubbleSort(list1) 22 | print("Final state: ", list1) 23 | -------------------------------------------------------------------------------- /Finished/Sorting/MergeSort/mergesort_finished.py: -------------------------------------------------------------------------------- 1 | # Example file for Programming Foundations: Algorithms by Joe Marini 2 | # Implement a merge sort with recursion 3 | 4 | 5 | items = [6, 20, 8, 19, 56, 23, 87, 41, 49, 53] 6 | 7 | def mergesort(dataset): 8 | if len(dataset) > 1: 9 | mid = len(dataset) // 2 10 | leftarr = dataset[:mid] 11 | rightarr = dataset[mid:] 12 | 13 | # recursively break down the arrays 14 | mergesort(leftarr) 15 | mergesort(rightarr) 16 | 17 | # now perform the merging 18 | i=0 # index into the left array 19 | j=0 # index into the right array 20 | k=0 # index into merged array 21 | 22 | # while both arrays have content 23 | while i < len(leftarr) and j < len(rightarr): 24 | if leftarr[i] < rightarr[j]: 25 | dataset[k] = leftarr[i] 26 | i += 1 27 | else: 28 | dataset[k] = rightarr[j] 29 | j += 1 30 | k += 1 31 | 32 | # if the left array still has values, add them 33 | while i < len(leftarr): 34 | dataset[k] = leftarr[i] 35 | i += 1 36 | k += 1 37 | 38 | # if the right array still has values, add them 39 | while j < len(rightarr): 40 | dataset[k] = rightarr[j] 41 | j += 1 42 | k += 1 43 | 44 | 45 | # test the merge sort with data 46 | print(items) 47 | mergesort(items) 48 | print(items) 49 | -------------------------------------------------------------------------------- /Finished/Sorting/Quicksort/quicksort_finished.py: -------------------------------------------------------------------------------- 1 | # Example file for Programming Foundations: Algorithms by Joe Marini 2 | # Implement a quicksort 3 | 4 | 5 | items = [20, 6, 8, 53, 56, 23, 87, 41, 49, 19] 6 | 7 | 8 | def quickSort(dataset, first, last): 9 | if first < last: 10 | # calculate the split point 11 | pivotIdx = partition(dataset, first, last) 12 | 13 | # now sort the two partitions 14 | quickSort(dataset, first, pivotIdx-1) 15 | quickSort(dataset, pivotIdx+1, last) 16 | 17 | 18 | def partition(datavalues, first, last): 19 | # choose the first item as the pivot value 20 | pivotvalue = datavalues[first] 21 | # establish the upper and lower indexes 22 | lower = first + 1 23 | upper = last 24 | 25 | # start searching for the crossing point 26 | done = False 27 | while not done: 28 | # advance the lower index 29 | while lower <= upper and datavalues[lower] <= pivotvalue: 30 | lower += 1 31 | 32 | # advance the upper index 33 | while datavalues[upper] >= pivotvalue and upper >= lower: 34 | upper -= 1 35 | 36 | # if the two indexes cross, we have found the split point 37 | if upper < lower: 38 | done = True 39 | else: 40 | # exchange the two values 41 | temp = datavalues[lower] 42 | datavalues[lower] = datavalues[upper] 43 | datavalues[upper] = temp 44 | 45 | # when the split point is found, exchange the pivot value 46 | temp = datavalues[first] 47 | datavalues[first] = datavalues[upper] 48 | datavalues[upper] = temp 49 | 50 | # return the split point index 51 | return upper 52 | 53 | 54 | # test the merge sort with data 55 | print(items) 56 | quickSort(items, 0, len(items)-1) 57 | print(items) 58 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | LinkedIn Learning Exercise Files License Agreement 2 | ================================================== 3 | 4 | This License Agreement (the "Agreement") is a binding legal agreement 5 | between you (as an individual or entity, as applicable) and LinkedIn 6 | Corporation (“LinkedIn”). By downloading or using the LinkedIn Learning 7 | exercise files in this repository (“Licensed Materials”), you agree to 8 | be bound by the terms of this Agreement. If you do not agree to these 9 | terms, do not download or use the Licensed Materials. 10 | 11 | 1. License. 12 | - a. Subject to the terms of this Agreement, LinkedIn hereby grants LinkedIn 13 | members during their LinkedIn Learning subscription a non-exclusive, 14 | non-transferable copyright license, for internal use only, to 1) make a 15 | reasonable number of copies of the Licensed Materials, and 2) make 16 | derivative works of the Licensed Materials for the sole purpose of 17 | practicing skills taught in LinkedIn Learning courses. 18 | - b. Distribution. Unless otherwise noted in the Licensed Materials, subject 19 | to the terms of this Agreement, LinkedIn hereby grants LinkedIn members 20 | with a LinkedIn Learning subscription a non-exclusive, non-transferable 21 | copyright license to distribute the Licensed Materials, except the 22 | Licensed Materials may not be included in any product or service (or 23 | otherwise used) to instruct or educate others. 24 | 25 | 2. Restrictions and Intellectual Property. 26 | - a. You may not to use, modify, copy, make derivative works of, publish, 27 | distribute, rent, lease, sell, sublicense, assign or otherwise transfer the 28 | Licensed Materials, except as expressly set forth above in Section 1. 29 | - b. Linkedin (and its licensors) retains its intellectual property rights 30 | in the Licensed Materials. Except as expressly set forth in Section 1, 31 | LinkedIn grants no licenses. 32 | - c. You indemnify LinkedIn and its licensors and affiliates for i) any 33 | alleged infringement or misappropriation of any intellectual property rights 34 | of any third party based on modifications you make to the Licensed Materials, 35 | ii) any claims arising from your use or distribution of all or part of the 36 | Licensed Materials and iii) a breach of this Agreement. You will defend, hold 37 | harmless, and indemnify LinkedIn and its affiliates (and our and their 38 | respective employees, shareholders, and directors) from any claim or action 39 | brought by a third party, including all damages, liabilities, costs and 40 | expenses, including reasonable attorneys’ fees, to the extent resulting from, 41 | alleged to have resulted from, or in connection with: (a) your breach of your 42 | obligations herein; or (b) your use or distribution of any Licensed Materials. 43 | 44 | 3. Open source. This code may include open source software, which may be 45 | subject to other license terms as provided in the files. 46 | 47 | 4. Warranty Disclaimer. LINKEDIN PROVIDES THE LICENSED MATERIALS ON AN “AS IS” 48 | AND “AS AVAILABLE” BASIS. LINKEDIN MAKES NO REPRESENTATION OR WARRANTY, 49 | WHETHER EXPRESS OR IMPLIED, ABOUT THE LICENSED MATERIALS, INCLUDING ANY 50 | REPRESENTATION THAT THE LICENSED MATERIALS WILL BE FREE OF ERRORS, BUGS OR 51 | INTERRUPTIONS, OR THAT THE LICENSED MATERIALS ARE ACCURATE, COMPLETE OR 52 | OTHERWISE VALID. TO THE FULLEST EXTENT PERMITTED BY LAW, LINKEDIN AND ITS 53 | AFFILIATES DISCLAIM ANY IMPLIED OR STATUTORY WARRANTY OR CONDITION, INCLUDING 54 | ANY IMPLIED WARRANTY OR CONDITION OF MERCHANTABILITY OR FITNESS FOR A 55 | PARTICULAR PURPOSE, AVAILABILITY, SECURITY, TITLE AND/OR NON-INFRINGEMENT. 56 | YOUR USE OF THE LICENSED MATERIALS IS AT YOUR OWN DISCRETION AND RISK, AND 57 | YOU WILL BE SOLELY RESPONSIBLE FOR ANY DAMAGE THAT RESULTS FROM USE OF THE 58 | LICENSED MATERIALS TO YOUR COMPUTER SYSTEM OR LOSS OF DATA. NO ADVICE OR 59 | INFORMATION, WHETHER ORAL OR WRITTEN, OBTAINED BY YOU FROM US OR THROUGH OR 60 | FROM THE LICENSED MATERIALS WILL CREATE ANY WARRANTY OR CONDITION NOT 61 | EXPRESSLY STATED IN THESE TERMS. 62 | 63 | 5. Limitation of Liability. LINKEDIN SHALL NOT BE LIABLE FOR ANY INDIRECT, 64 | INCIDENTAL, SPECIAL, PUNITIVE, CONSEQUENTIAL OR EXEMPLARY DAMAGES, INCLUDING 65 | BUT NOT LIMITED TO, DAMAGES FOR LOSS OF PROFITS, GOODWILL, USE, DATA OR OTHER 66 | INTANGIBLE LOSSES . IN NO EVENT WILL LINKEDIN'S AGGREGATE LIABILITY TO YOU 67 | EXCEED $100. THIS LIMITATION OF LIABILITY SHALL: 68 | - i. APPLY REGARDLESS OF WHETHER (A) YOU BASE YOUR CLAIM ON CONTRACT, TORT, 69 | STATUTE, OR ANY OTHER LEGAL THEORY, (B) WE KNEW OR SHOULD HAVE KNOWN ABOUT 70 | THE POSSIBILITY OF SUCH DAMAGES, OR (C) THE LIMITED REMEDIES PROVIDED IN THIS 71 | SECTION FAIL OF THEIR ESSENTIAL PURPOSE; AND 72 | - ii. NOT APPLY TO ANY DAMAGE THAT LINKEDIN MAY CAUSE YOU INTENTIONALLY OR 73 | KNOWINGLY IN VIOLATION OF THESE TERMS OR APPLICABLE LAW, OR AS OTHERWISE 74 | MANDATED BY APPLICABLE LAW THAT CANNOT BE DISCLAIMED IN THESE TERMS. 75 | 76 | 6. Termination. This Agreement automatically terminates upon your breach of 77 | this Agreement or termination of your LinkedIn Learning subscription. On 78 | termination, all licenses granted under this Agreement will terminate 79 | immediately and you will delete the Licensed Materials. Sections 2-7 of this 80 | Agreement survive any termination of this Agreement. LinkedIn may discontinue 81 | the availability of some or all of the Licensed Materials at any time for any 82 | reason. 83 | 84 | 7. Miscellaneous. This Agreement will be governed by and construed in 85 | accordance with the laws of the State of California without regard to conflict 86 | of laws principles. The exclusive forum for any disputes arising out of or 87 | relating to this Agreement shall be an appropriate federal or state court 88 | sitting in the County of Santa Clara, State of California. If LinkedIn does 89 | not act to enforce a breach of this Agreement, that does not mean that 90 | LinkedIn has waived its right to enforce this Agreement. The Agreement does 91 | not create a partnership, agency relationship, or joint venture between the 92 | parties. Neither party has the power or authority to bind the other or to 93 | create any obligation or responsibility on behalf of the other. You may not, 94 | without LinkedIn’s prior written consent, assign or delegate any rights or 95 | obligations under these terms, including in connection with a change of 96 | control. Any purported assignment and delegation shall be ineffective. The 97 | Agreement shall bind and inure to the benefit of the parties, their respective 98 | successors and permitted assigns. If any provision of the Agreement is 99 | unenforceable, that provision will be modified to render it enforceable to the 100 | extent possible to give effect to the parties’ intentions and the remaining 101 | provisions will not be affected. This Agreement is the only agreement between 102 | you and LinkedIn regarding the Licensed Materials, and supersedes all prior 103 | agreements relating to the Licensed Materials. 104 | 105 | Last Updated: March 2019 106 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2024 LinkedIn Corporation 2 | All Rights Reserved. 3 | 4 | Licensed under the LinkedIn Learning Exercise File License (the "License"). 5 | See LICENSE in the project root for license information. 6 | 7 | ATTRIBUTIONS: 8 | 9 | requests 10 | https://github.com/psf/requests/ 11 | License: Apache 2.0 12 | http://www.apache.org/licenses/ 13 | 14 | Please note, this project may automatically load third party code from external 15 | repositories (for example, NPM modules, Composer packages, or other dependencies). 16 | If so, such third party code may be subject to other license terms than as set 17 | forth above. In addition, such third party code may also depend on and load 18 | multiple tiers of dependencies. Please review the applicable licenses of the 19 | additional dependencies. 20 | 21 | 22 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 23 | 24 | Apache License 25 | Version 2.0, January 2004 26 | http://www.apache.org/licenses/ 27 | 28 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 29 | 30 | 1. Definitions. 31 | 32 | ""License"" shall mean the terms and conditions for use, reproduction, 33 | and distribution as defined by Sections 1 through 9 of this document. 34 | 35 | ""Licensor"" shall mean the copyright owner or entity authorized by 36 | the copyright owner that is granting the License. 37 | 38 | ""Legal Entity"" shall mean the union of the acting entity and all 39 | other entities that control, are controlled by, or are under common 40 | control with that entity. For the purposes of this definition, 41 | ""control"" means (i) the power, direct or indirect, to cause the 42 | direction or management of such entity, whether by contract or 43 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 44 | outstanding shares, or (iii) beneficial ownership of such entity. 45 | 46 | ""You"" (or ""Your"") shall mean an individual or Legal Entity 47 | exercising permissions granted by this License. 48 | 49 | ""Source"" form shall mean the preferred form for making modifications, 50 | including but not limited to software source code, documentation 51 | source, and configuration files. 52 | 53 | ""Object"" form shall mean any form resulting from mechanical 54 | transformation or translation of a Source form, including but 55 | not limited to compiled object code, generated documentation, 56 | and conversions to other media types. 57 | 58 | ""Work"" shall mean the work of authorship, whether in Source or 59 | Object form, made available under the License, as indicated by a 60 | copyright notice that is included in or attached to the work 61 | (an example is provided in the Appendix below). 62 | 63 | ""Derivative Works"" shall mean any work, whether in Source or Object 64 | form, that is based on (or derived from) the Work and for which the 65 | editorial revisions, annotations, elaborations, or other modifications 66 | represent, as a whole, an original work of authorship. For the purposes 67 | of this License, Derivative Works shall not include works that remain 68 | separable from, or merely link (or bind by name) to the interfaces of, 69 | the Work and Derivative Works thereof. 70 | 71 | ""Contribution"" shall mean any work of authorship, including 72 | the original version of the Work and any modifications or additions 73 | to that Work or Derivative Works thereof, that is intentionally 74 | submitted to Licensor for inclusion in the Work by the copyright owner 75 | or by an individual or Legal Entity authorized to submit on behalf of 76 | the copyright owner. For the purposes of this definition, ""submitted"" 77 | means any form of electronic, verbal, or written communication sent 78 | to the Licensor or its representatives, including but not limited to 79 | communication on electronic mailing lists, source code control systems, 80 | and issue tracking systems that are managed by, or on behalf of, the 81 | Licensor for the purpose of discussing and improving the Work, but 82 | excluding communication that is conspicuously marked or otherwise 83 | designated in writing by the copyright owner as ""Not a Contribution."" 84 | 85 | ""Contributor"" shall mean Licensor and any individual or Legal Entity 86 | on behalf of whom a Contribution has been received by Licensor and 87 | subsequently incorporated within the Work. 88 | 89 | 2. Grant of Copyright License. Subject to the terms and conditions of 90 | this License, each Contributor hereby grants to You a perpetual, 91 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 92 | copyright license to reproduce, prepare Derivative Works of, 93 | publicly display, publicly perform, sublicense, and distribute the 94 | Work and such Derivative Works in Source or Object form. 95 | 96 | 3. Grant of Patent License. Subject to the terms and conditions of 97 | this License, each Contributor hereby grants to You a perpetual, 98 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 99 | (except as stated in this section) patent license to make, have made, 100 | use, offer to sell, sell, import, and otherwise transfer the Work, 101 | where such license applies only to those patent claims licensable 102 | by such Contributor that are necessarily infringed by their 103 | Contribution(s) alone or by combination of their Contribution(s) 104 | with the Work to which such Contribution(s) was submitted. If You 105 | institute patent litigation against any entity (including a 106 | cross-claim or counterclaim in a lawsuit) alleging that the Work 107 | or a Contribution incorporated within the Work constitutes direct 108 | or contributory patent infringement, then any patent licenses 109 | granted to You under this License for that Work shall terminate 110 | as of the date such litigation is filed. 111 | 112 | 4. Redistribution. You may reproduce and distribute copies of the 113 | Work or Derivative Works thereof in any medium, with or without 114 | modifications, and in Source or Object form, provided that You 115 | meet the following conditions: 116 | 117 | (a) You must give any other recipients of the Work or 118 | Derivative Works a copy of this License; and 119 | 120 | (b) You must cause any modified files to carry prominent notices 121 | stating that You changed the files; and 122 | 123 | (c) You must retain, in the Source form of any Derivative Works 124 | that You distribute, all copyright, patent, trademark, and 125 | attribution notices from the Source form of the Work, 126 | excluding those notices that do not pertain to any part of 127 | the Derivative Works; and 128 | 129 | (d) If the Work includes a ""NOTICE"" text file as part of its 130 | distribution, then any Derivative Works that You distribute must 131 | include a readable copy of the attribution notices contained 132 | within such NOTICE file, excluding those notices that do not 133 | pertain to any part of the Derivative Works, in at least one 134 | of the following places: within a NOTICE text file distributed 135 | as part of the Derivative Works; within the Source form or 136 | documentation, if provided along with the Derivative Works; or, 137 | within a display generated by the Derivative Works, if and 138 | wherever such third-party notices normally appear. The contents 139 | of the NOTICE file are for informational purposes only and 140 | do not modify the License. You may add Your own attribution 141 | notices within Derivative Works that You distribute, alongside 142 | or as an addendum to the NOTICE text from the Work, provided 143 | that such additional attribution notices cannot be construed 144 | as modifying the License. 145 | 146 | You may add Your own copyright statement to Your modifications and 147 | may provide additional or different license terms and conditions 148 | for use, reproduction, or distribution of Your modifications, or 149 | for any such Derivative Works as a whole, provided Your use, 150 | reproduction, and distribution of the Work otherwise complies with 151 | the conditions stated in this License. 152 | 153 | 5. Submission of Contributions. Unless You explicitly state otherwise, 154 | any Contribution intentionally submitted for inclusion in the Work 155 | by You to the Licensor shall be under the terms and conditions of 156 | this License, without any additional terms or conditions. 157 | Notwithstanding the above, nothing herein shall supersede or modify 158 | the terms of any separate license agreement you may have executed 159 | with Licensor regarding such Contributions. 160 | 161 | 6. Trademarks. This License does not grant permission to use the trade 162 | names, trademarks, service marks, or product names of the Licensor, 163 | except as required for reasonable and customary use in describing the 164 | origin of the Work and reproducing the content of the NOTICE file. 165 | 166 | 7. Disclaimer of Warranty. Unless required by applicable law or 167 | agreed to in writing, Licensor provides the Work (and each 168 | Contributor provides its Contributions) on an ""AS IS"" BASIS, 169 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 170 | implied, including, without limitation, any warranties or conditions 171 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 172 | PARTICULAR PURPOSE. You are solely responsible for determining the 173 | appropriateness of using or redistributing the Work and assume any 174 | risks associated with Your exercise of permissions under this License. 175 | 176 | 8. Limitation of Liability. In no event and under no legal theory, 177 | whether in tort (including negligence), contract, or otherwise, 178 | unless required by applicable law (such as deliberate and grossly 179 | negligent acts) or agreed to in writing, shall any Contributor be 180 | liable to You for damages, including any direct, indirect, special, 181 | incidental, or consequential damages of any character arising as a 182 | result of this License or out of the use or inability to use the 183 | Work (including but not limited to damages for loss of goodwill, 184 | work stoppage, computer failure or malfunction, or any and all 185 | other commercial damages or losses), even if such Contributor 186 | has been advised of the possibility of such damages. 187 | 188 | 9. Accepting Warranty or Additional Liability. While redistributing 189 | the Work or Derivative Works thereof, You may choose to offer, 190 | and charge a fee for, acceptance of support, warranty, indemnity, 191 | or other liability obligations and/or rights consistent with this 192 | License. However, in accepting such obligations, You may act only 193 | on Your own behalf and on Your sole responsibility, not on behalf 194 | of any other Contributor, and only if You agree to indemnify, 195 | defend, and hold each Contributor harmless for any liability 196 | incurred by, or claims asserted against, such Contributor by reason 197 | of your accepting any such warranty or additional liability. 198 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Programming Foundations: Algorithms 2 | This is the repository for the LinkedIn Learning course `Programming Foundations: Algorithms`. The full course is available from [LinkedIn Learning][lil-course-url]. 3 | 4 | ![lil-thumbnail-url] 5 | 6 | Algorithms are the universal building blocks of programming. They power the software you use every day, whether it's a spreadsheet, a social network, or a driving assistant. Algorithms offer a way to think about programming challenges in plain English, before they are translated into a specific language like C# or JavaScript. In this course, author and developer Joe Marini explains some of the most popular and useful algorithms for searching and sorting information, working with techniques like recursion, and understanding common data structures. He also discusses the performance implications of different algorithms and how to evaluate the performance of a given algorithm. Each algorithm is shown in practice in Python, but the lessons can be applied to any programming language. The course is also set up with GitHub Codespaces, so you can follow along with the examples without installing anything on your computer. 7 | 8 | ## Installing 9 | 1. To use these exercise files, you must have the following installed: 10 | - Python 3.10 11 | - A text editor like Visual Studio Code 12 | 2. You can also work online directly using a Github Codespace. 13 | 3. To work locally, clone this repository into your local machine using the terminal (Mac), CMD (Windows), or a GUI tool like SourceTree. 14 | 15 | ## Instructor 16 | Joe Marini has been building software professionally for some of the biggest and best known companies in Silicon Valley for more than 30 years. 17 | 18 | Check out my other courses on [LinkedIn Learning](https://www.linkedin.com/learning/instructors/joe-marini). 19 | 20 | [0]: # (Replace these placeholder URLs with actual course URLs) 21 | 22 | [lil-course-url]: https://www.linkedin.com/learning/programming-foundations-algorithms-22973142 23 | [lil-thumbnail-url]: https://media.licdn.com/dms/image/D560DAQHrmMscOqmJOw/learning-public-crop_675_1200/0/1704914636714?e=2147483647&v=beta&t=lAZIHBE0CL3z8aDZe5PyilO8B9TQKrYjVQC5aypnJJs 24 | 25 | -------------------------------------------------------------------------------- /Start/DataStructures/Dictionary/dictionary_start.py: -------------------------------------------------------------------------------- 1 | # Example file for Programming Foundations: Algorithms by Joe Marini 2 | # demonstrate dictionary usage 3 | 4 | 5 | # TODO: create a dictionary all at once 6 | 7 | 8 | # TODO: create a dictionary progressively 9 | 10 | 11 | # TODO: replace an item 12 | 13 | 14 | # TODO: try to access a nonexistent key 15 | 16 | 17 | # TODO: iterate the keys and values in the dictionary 18 | -------------------------------------------------------------------------------- /Start/DataStructures/LinkedList/linklist_start.py: -------------------------------------------------------------------------------- 1 | # Example file for Programming Foundations: Algorithms by Joe Marini 2 | # Linked list example 3 | 4 | 5 | # the Node class 6 | class Node(object): 7 | def __init__(self, val): 8 | self.val = val 9 | self.next = None 10 | 11 | def get_data(self): 12 | return self.val 13 | 14 | def set_data(self, val): 15 | self.val = val 16 | 17 | def get_next(self): 18 | return self.next 19 | 20 | def set_next(self, nxt): 21 | self.next = nxt 22 | 23 | 24 | # the LinkedList class 25 | class LinkedList(object): 26 | def __init__(self, head=None): 27 | self.head = head 28 | self.count = 0 29 | 30 | def get_count(self): 31 | return self.count 32 | 33 | def insert(self, data): 34 | # TODO: insert a new node 35 | new_node = Node(data) 36 | 37 | def find(self, val): 38 | # TODO: find the first item with a given value 39 | item = self.head 40 | 41 | return None 42 | 43 | def deleteAt(self, idx): 44 | # TODO: delete an item at given index 45 | if idx > self.count-1: 46 | return 47 | 48 | def dump_list(self): 49 | tempnode = self.head 50 | while (tempnode != None): 51 | print("Node: ", tempnode.get_data()) 52 | tempnode = tempnode.get_next() 53 | 54 | 55 | # create a linked list and insert some items 56 | itemlist = LinkedList() 57 | itemlist.insert(38) 58 | itemlist.insert(49) 59 | itemlist.insert(13) 60 | itemlist.insert(15) 61 | itemlist.dump_list() 62 | 63 | # exercise the list 64 | print("Item count: ", itemlist.get_count()) 65 | print("Finding item: ", itemlist.find(13)) 66 | print("Finding item: ", itemlist.find(78)) 67 | 68 | # delete an item 69 | # print("Item count: ", itemlist.get_count()) 70 | # itemlist.deleteAt(3) 71 | # print("Item count: ", itemlist.get_count()) 72 | # print("Finding item: ", itemlist.find(38)) 73 | # itemlist.dump_list() 74 | -------------------------------------------------------------------------------- /Start/DataStructures/Queues/queue_start.py: -------------------------------------------------------------------------------- 1 | # Example file for Programming Foundations: Algorithms by Joe Marini 2 | # try out the Python queue functions 3 | 4 | 5 | # TODO: create a new empty deque object that will function as a queue 6 | 7 | 8 | # TODO: add some items to the queue 9 | 10 | 11 | # TODO: print the queue contents 12 | 13 | 14 | # TODO: pop an item off the front of the queue 15 | -------------------------------------------------------------------------------- /Start/DataStructures/Stacks/stack_start.py: -------------------------------------------------------------------------------- 1 | # Example file for Programming Foundations: Algorithms by Joe Marini 2 | # try out the Python stack functions 3 | 4 | # TODO: create a new empty stack 5 | 6 | 7 | # TODO: push items onto the stack 8 | 9 | 10 | # TODO: print the stack contents 11 | 12 | 13 | # TODO: pop an item off the stack 14 | -------------------------------------------------------------------------------- /Start/Introduction/gcd_start.py: -------------------------------------------------------------------------------- 1 | # Example file for Programming Foundations: Algorithms by Joe Marini 2 | # Find the greatest common denominator of two numbers 3 | # using Euclid's algorithm 4 | 5 | 6 | def gcd(a, b): 7 | pass 8 | 9 | 10 | # try out the function with a few examples 11 | print(gcd(60, 96)) # should be 12 12 | print(gcd(20, 8)) # should be 4 13 | -------------------------------------------------------------------------------- /Start/PracticalExamples/Filter_start.py: -------------------------------------------------------------------------------- 1 | # Example file for Programming Foundations: Algorithms by Joe Marini 2 | # use a set to count unique items 3 | 4 | 5 | # define a set of items that we want to reduce duplicates 6 | items = ["apple", "pear", "orange", "banana", "apple", 7 | "orange", "apple", "pear", "banana", "orange", 8 | "apple", "kiwi", "pear", "apple", "orange"] 9 | 10 | # TODO: create a set to perform a filter 11 | 12 | 13 | # TODO: loop over each item and add to the set 14 | 15 | 16 | # TODO: Count the unique letters in a sentence 17 | sentence = "The quick brown fox jumps over the lazy dog." 18 | -------------------------------------------------------------------------------- /Start/PracticalExamples/ValueCounter_start.py: -------------------------------------------------------------------------------- 1 | # Example file for Programming Foundations: Algorithms by Joe Marini 2 | # using a hashtable to count individual items 3 | 4 | 5 | # define a set of items that we want to count 6 | items = ["apple", "pear", "orange", "banana", "apple", 7 | "orange", "apple", "pear", "banana", "orange", 8 | "apple", "kiwi", "pear", "apple", "orange"] 9 | 10 | # TODO: create a hashtable object to hold the items and counts 11 | counter = None 12 | 13 | # TODO: iterate over each item and increment the count for each one 14 | 15 | 16 | # print the results 17 | print(counter) 18 | -------------------------------------------------------------------------------- /Start/PracticalExamples/balancing_start.py: -------------------------------------------------------------------------------- 1 | # Example file for Programming Foundations: Algorithms by Joe Marini 2 | # Use a stack to see if a programming statement is balanced 3 | 4 | 5 | def is_balanced(thestr): 6 | # TODO: Your code goes here 7 | 8 | return True 9 | 10 | test_statements = [ 11 | "print('Hello World!')", 12 | "a(x[i]) == b(x[i])", 13 | "{c for c in a(x)}", 14 | "Hello!)", 15 | "(This is not [balanced)", 16 | "{{{[[(())]}}", 17 | "(", 18 | "}" 19 | ] 20 | 21 | for statement in test_statements: 22 | print(f'{statement} balanced: {is_balanced(statement)}') 23 | -------------------------------------------------------------------------------- /Start/PracticalExamples/findmax_start.py: -------------------------------------------------------------------------------- 1 | # Example file for Programming Foundations: Algorithms by Joe Marini 2 | # use a recursive algorithm to find a maximum value 3 | 4 | 5 | # declare a list of values to operate on 6 | items = [6, 20, 8, 19, 56, 23, 87, 41, 49, 53] 7 | 8 | def find_max(items): 9 | pass 10 | # TODO: breaking condition: last item in list? return it 11 | 12 | 13 | # TODO: otherwise get the first item and call function 14 | # again to operate on the rest of the list 15 | 16 | 17 | # TODO: perform the comparison when we're down to just two 18 | 19 | 20 | 21 | # test the function 22 | print(find_max(items)) 23 | -------------------------------------------------------------------------------- /Start/Recursion/countdown_start.py: -------------------------------------------------------------------------------- 1 | # Example file for Programming Foundations: Algorithms by Joe Marini 2 | # use recursion to implement a countdown counter 3 | 4 | 5 | def countdown(x): 6 | return 7 | 8 | 9 | countdown(5) 10 | -------------------------------------------------------------------------------- /Start/Recursion/recursion_start.py: -------------------------------------------------------------------------------- 1 | # Example file for Programming Foundations: Algorithms by Joe Marini 2 | # Using recursion to implement power and factorial functions 3 | 4 | # 2^4 = 2*2*2*2 = 16 5 | def power(num, pwr): 6 | pass 7 | 8 | # 5! = 5*4*3*2*1 9 | # Special case: 0! is 1, because... math 10 | def factorial(num): 11 | pass 12 | 13 | 14 | print(f"5 to the power of 3 is {power(5, 3)}") 15 | print(f"2 to the power of 4 is {power(2, 4)}") 16 | print(f"4! is {factorial(4)}") 17 | print(f"0! is {factorial(0)}") 18 | -------------------------------------------------------------------------------- /Start/Searching/issorted_start.py: -------------------------------------------------------------------------------- 1 | # Example file for Programming Foundations: Algorithms by Joe Marini 2 | # determine if a list is sorted 3 | 4 | 5 | items1 = [6, 8, 19, 20, 23, 41, 49, 53, 56, 87] 6 | items2 = [6, 20, 8, 19, 56, 23, 87, 41, 49, 53] 7 | 8 | def is_sorted(itemlist): 9 | # TODO: using the brute force method 10 | 11 | return True 12 | 13 | print(is_sorted(items1)) 14 | print(is_sorted(items2)) 15 | 16 | -------------------------------------------------------------------------------- /Start/Searching/ordered_start.py: -------------------------------------------------------------------------------- 1 | # Example file for Programming Foundations: Algorithms by Joe Marini 2 | # searching for an item in an ordered list 3 | # this technique uses a binary search 4 | 5 | 6 | items = [6, 8, 19, 20, 23, 41, 49, 53, 56, 87] 7 | 8 | def binarysearch(item, itemlist): 9 | # get the list size 10 | listsize = len(itemlist) - 1 11 | # start at the two ends of the list 12 | lowerIdx = 0 13 | upperIdx = listsize 14 | 15 | while lowerIdx <= upperIdx: 16 | pass 17 | # TODO: calculate the middle point 18 | 19 | # TODO: if item is found, return the index 20 | 21 | # TODO: otherwise get the next midpoint 22 | 23 | if lowerIdx > upperIdx: 24 | return None 25 | 26 | 27 | print(binarysearch(23, items)) 28 | print(binarysearch(87, items)) 29 | print(binarysearch(21, items)) 30 | -------------------------------------------------------------------------------- /Start/Searching/unordered_start.py: -------------------------------------------------------------------------------- 1 | # Example file for Programming Foundations: Algorithms by Joe Marini 2 | # searching for an item in an unordered list 3 | # sometimes called a Linear search 4 | 5 | # declare a list of values to operate on 6 | items = [6, 20, 8, 19, 56, 23, 87, 41, 49, 53] 7 | 8 | def find_item(item, itemlist): 9 | pass 10 | 11 | 12 | print(find_item(87, items)) 13 | print(find_item(250, items)) 14 | -------------------------------------------------------------------------------- /Start/Sorting/BubbleSort/bubble_start.py: -------------------------------------------------------------------------------- 1 | # Example file for Programming Foundations: Algorithms by Joe Marini 2 | # Bubble sort algorithm 3 | 4 | 5 | def bubbleSort(dataset): 6 | # TODO: start with the array length and decrement each time 7 | 8 | print("Current state: ", dataset) 9 | 10 | 11 | list1 = [6, 20, 8, 19, 56, 23, 87, 41, 49, 53] 12 | print("Start: ", list1) 13 | bubbleSort(list1) 14 | print("Result: ", list1) 15 | -------------------------------------------------------------------------------- /Start/Sorting/MergeSort/mergesort_start.py: -------------------------------------------------------------------------------- 1 | # Example file for Programming Foundations: Algorithms by Joe Marini 2 | # Implement a merge sort with recursion 3 | 4 | 5 | items = [6, 20, 8, 19, 56, 23, 87, 41, 49, 53] 6 | 7 | def mergesort(dataset): 8 | if len(dataset) > 1: 9 | mid = len(dataset) // 2 10 | leftarr = dataset[:mid] 11 | rightarr = dataset[mid:] 12 | 13 | # TODO: recursively break down the arrays 14 | 15 | 16 | # TODO: now perform the merging 17 | i=0 # index into the left array 18 | j=0 # index into the right array 19 | k=0 # index into merged array 20 | 21 | # TODO: while both arrays have content 22 | 23 | 24 | # TODO: if the left array still has values, add them 25 | 26 | 27 | # TODO: if the right array still has values, add them 28 | 29 | 30 | 31 | # test the merge sort with data 32 | print(items) 33 | mergesort(items) 34 | print(items) 35 | -------------------------------------------------------------------------------- /Start/Sorting/QuickSort/quicksort_start.py: -------------------------------------------------------------------------------- 1 | # Example file for Programming Foundations: Algorithms by Joe Marini 2 | # Implement a quicksort 3 | 4 | 5 | items = [20, 6, 8, 53, 56, 23, 87, 41, 49, 19] 6 | 7 | 8 | def quickSort(dataset, first, last): 9 | if first < last: 10 | # calculate the split point 11 | pivotIdx = partition(dataset, first, last) 12 | 13 | # now sort the two partitions 14 | quickSort(dataset, first, pivotIdx-1) 15 | quickSort(dataset, pivotIdx+1, last) 16 | 17 | 18 | def partition(datavalues, first, last): 19 | # TODO: choose the first item as the pivot value 20 | 21 | # TODO: establish the upper and lower indexes 22 | 23 | # start searching for the crossing point 24 | done = False 25 | while not done: 26 | # TODO: advance the lower index 27 | 28 | # TODO: advance the upper index 29 | 30 | # TODO: if the two indexes cross, we have found the split point 31 | pass 32 | 33 | # TODO: when the split point is found, exchange the pivot value 34 | 35 | # TODO: return the split point index 36 | 37 | 38 | # test the merge sort with data 39 | print(items) 40 | quickSort(items, 0, len(items)-1) 41 | print(items) 42 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | requests>=2.28 2 | --------------------------------------------------------------------------------