{"id":21239570,"url":"https://github.com/ahmedabougabal/pythondatastructuresalgorithms","last_synced_at":"2025-03-15T03:41:30.045Z","repository":{"id":260912861,"uuid":"882444194","full_name":"ahmedabougabal/PythonDataStructuresAlgorithms","owner":"ahmedabougabal","description":"Let's go DeepDiving 🤿","archived":false,"fork":false,"pushed_at":"2025-01-17T12:59:12.000Z","size":1203,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-17T14:05:54.911Z","etag":null,"topics":["binary-search-tree","breadth-first-search","depth-first-search","dequeue","heapq","heapsort-algorithm","max-heap-priority-queue","python3","stack"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ahmedabougabal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-02T19:43:14.000Z","updated_at":"2025-01-17T12:59:14.000Z","dependencies_parsed_at":"2025-01-17T13:56:54.753Z","dependency_job_id":"d39de560-49ff-4e02-b839-e6c078b8de6e","html_url":"https://github.com/ahmedabougabal/PythonDataStructuresAlgorithms","commit_stats":null,"previous_names":["ahmedabougabal/pythondatastructuresalgorithms"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmedabougabal%2FPythonDataStructuresAlgorithms","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmedabougabal%2FPythonDataStructuresAlgorithms/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmedabougabal%2FPythonDataStructuresAlgorithms/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmedabougabal%2FPythonDataStructuresAlgorithms/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ahmedabougabal","download_url":"https://codeload.github.com/ahmedabougabal/PythonDataStructuresAlgorithms/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243680975,"owners_count":20330155,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["binary-search-tree","breadth-first-search","depth-first-search","dequeue","heapq","heapsort-algorithm","max-heap-priority-queue","python3","stack"],"created_at":"2024-11-21T00:44:09.625Z","updated_at":"2025-03-15T03:41:30.032Z","avatar_url":"https://github.com/ahmedabougabal.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!-- @format --\u003e\n\n# PythonDataStructuresAlgorithms\n\n**_I will document some of my DataStructures taken notes here, Stay Tuned..._**\n\n[![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome)\n[![Project Status](https://img.shields.io/badge/status-Still%20in%20Progress-yellow)](https://github.com/yourusername/mernStackMilestoneProject_ITI)\n\n\u003c!-- ![Binary Tree](https://img.shields.io/badge/Data%20Structure-Binary%20Tree-blue)\n![Linked List](https://img.shields.io/badge/Data%20Structure-Linked%20List-brightgreen) --\u003e\n\n![Profile Views](https://komarev.com/ghpvc/?username=ahmedabougabal\u0026color=brightgreen)\n\n# checkout the DSA MindMaps i just added :)\n\n**_Mind map 1_**\n![image](https://github.com/user-attachments/assets/b7297d5c-543b-42d7-8cb6-27ea21777e52)\n\n**_Mind map 2_**\n![image](https://github.com/user-attachments/assets/914f4463-0475-4b0d-bada-890ee8a81edc)\n\n# Trees\n\n- trees are used to store information.\n- tree is usually upside down.\n- each circle is called a node or a vertex.\n- link between 2 nodes is an edge.\n\n![image](https://github.com/user-attachments/assets/52695b9b-7247-4b18-a50b-0f12cf44c5b0)\n\n- from the above tree, we deduce the following. . .\n- the edge is the distance (connection) between 2 nodes, node 5 has no edge with node 4\n- [Tree with n nodes has n - 1 edges](https://www.cs.purdue.edu/homes/spa/courses/sa12/mod8.pdf)\n- the tree has 4 levels, levels (0,1,2,3)\n- Node(1) has 2 children: 2 and 3\n- The parent of Node(7) is node(2)\n- Nodes {5, 9} are siblings (brothers)\n- height (specific to each node) represents the number of edges on the longest downward path between a node(vertex) and a leaf.\n- Tree of N levels has N-1 heights, since that the tree above has 4 levels, then the height is 4-1 = 3 edges\n- the height of the node 1 (root) is 3 (start from the root to the longest path downward to the farest leaf)\n- node 7 has a height = 0\n- Node's Depth : the number of edges from the node to the root node.\n  **_Difference between Depth and Height_**\n  - depth is specific about 2 nodes (root node and the current node only)\n  - height is going down from the node to the leaves. (height is about my current node and any other node (leaf) i can reach - longest path)\n- there is only 1 path between any 2 nodes. (you are now at the root node and you wanted to go to the node 4, then there is only 1 way (simple tree)\n- in a tree where every node has only 1 single parent, then there is only 1 path from a node to another.\n\n**Sub Trees**\n\n- recursive nature where each tree has a subtree and each subtree has another subtree.\n- Problem solving tip: we deduce that when we want to get the elements of a tree, we will do this recursively.\n\n# Binary Trees\n\n- a tree where each node at least has at most 2 children (left and right nodes).\n- a leaf node is a node with no children.\n\n**this is a simple tree (a node has many children)**\n![image](https://github.com/user-attachments/assets/896209b1-7bba-4d07-bdcd-c1a92d3d5433)\n\n**this is a binary tree (each node has at most 2 children)**\n![image](https://github.com/user-attachments/assets/61f26fc1-cb60-4e11-9841-9947f31100fe)\n\n-- A linked List is a special case of a binary tree.\n\n---\n# binary tree traversal 1\n\ntraversal is a way of walking through an elements of a data structure.\n\nwe need to create an expression tree (leaves are operands and others are operators)\n\ncan draw this tree : (2+3)\\*4\n\n# types of traversal\n\n- LVR (left, visit, right) --\u003e in order traversal\n\u003cbr /\u003e\nhow to know the printed nodes visually ?\n\u003cbr /\u003e\n\nproject down each node and read from left to right, this is how the binary tree is represented visually as shown.\n\n\n![image](https://github.com/user-attachments/assets/8b68607a-96a2-425a-b7f7-d9367194e1f5)\n\n---\n\n- LRV (left, right, visit) --\u003e post order traversal\n\n --\u003e left first, then right first , then printing the nodes \n\n how to deduce the printed nodes visually ? \n \njust in 2 steps : \n\n**step 1**\nfor every node , if it doesnot have a right , then project it down, what if it does have a right node? --\u003e wait for it \n\n**step 2**\n\nfor the nodes that have a right node , project it down after its right node.\n\nnote that, when projecting the nodes in step 2 , we go from bottom to up level by level.\n\n![image](https://github.com/user-attachments/assets/80d4a03b-e2d0-4145-be93-954e771f2893)\n\n---\n\n- VLR (visit, left, right) --\u003e preorder traversal\n\n how to deduce the printed nodes visually ? \n\nwill be the opposite of the post order traversal (2 steps)\n\n**step 1**\nfor every node , if it doesnot have a left, then project it down, what if it does have a left node? --\u003e wait for it \n\n**step 2**\nthen we project the nodes that have a left node before its left subtrees \n\n\n- note that, when projecting the nodes in step 2 , we go from bottom to up level by level.\n\n\n![image](https://github.com/user-attachments/assets/83789541-068c-4e8d-b1b2-738d01c9af96)\n\n\n\n\n---\n# BFS Tree Structure explanation for the 'whatTasteIsItLike.py' question :\n\n**initial state**\n\n\n                        food_items\n                            │\n                ┌───────────┴───────────┐\n              fruits               vegetables\n\nQueue Box: ['fruits', 'vegetables']\n\u003cbr /\u003e\nCurrent: []\n\u003cbr /\u003e\nProcessed: []\n\n---\n\n**step 1**\n\n                        food_items\n                            │\n                ┌───────────┴───────────┐\n              fruits ←             vegetables\n\nQueue Box: ['vegetables', 'tropical', 'temperate']\n\u003cbr /\u003e\nCurrent: 'fruits'\n\u003cbr /\u003e\nProcessed: ['fruits']\n\n---\n\n**step 2**\n\n                        food_items\n                            │\n                ┌───────────┴───────────┐\n              fruits               vegetables ←\n                │                     │\n        ┌───────┴───────┐      ┌─────┴─────┐\n    tropical        temperate  leafy      root\n\nQueue Box: ['tropical', 'temperate', 'leafy', 'root']\n\u003cbr /\u003e\nCurrent: 'vegetables'\n\u003cbr /\u003e\nProcessed: ['fruits', 'vegetables']\n\n---\n\n**step 3**\n\n                        food_items\n                            │\n                ┌───────────┴───────────┐\n              fruits               vegetables\n                │                     │\n        ┌───────┴───────┐      ┌─────┴─────┐\n    tropical ←      temperate  leafy      root\n        │\n    ┌───┴───┐\n\nmango pineapple\n\nQueue Box: ['temperate', 'leafy', 'root', 'mango', 'pineapple']\n\u003cbr /\u003e\nCurrent: 'tropical'\n\u003cbr /\u003e\nProcessed: ['fruits', 'vegetables', 'tropical']\n\n---\n\n**and so on...**\n\nLogic :\n\nWhen processing 'apple':\n\u003cbr /\u003e\nQueue Box: ['pear', 'spinach', 'kale', 'carrot', 'beet']\n\u003cbr /\u003e\nCurrent: 'apple' (red found!) , since apple is a dict instance and has 'color' in one of its keys... \n\u003cbr /\u003e\nProcessed: [..., 'apple']\n\u003cbr /\u003e\nResult: [\"The apple is sweet.\"]\n\n\u003cbr /\u003e\nWhen processing 'beet':\n\u003cbr /\u003e\nQueue Box: []\n\u003cbr /\u003e\nCurrent: 'beet' (red found!) , since beet is a dict instance and has 'color' in one of its keys... \n\u003cbr /\u003e\nProcessed: [..., 'apple', ..., 'beet']\n\u003cbr /\u003e\nResult: [\"The apple is sweet.\", \"The beet is earthy.\"]\n\n---\n\nThe key movements:\n\nItem moves from Queue Box → Current Box\n\u003cbr /\u003e\nAfter processing:\n\u003cbr /\u003e\nItem moves to Processed Box\n\u003cbr /\u003e\nIf it has children, they're added to Queue Box\n\u003cbr /\u003e\nIf it's red, it adds to Result\n---\nfurther explanation : \n\nSo when we say \"red found!\", we mean:\n\n- val is a dictionary (passed isinstance check)\n\u003cbr /\u003e\n\n- val has a 'color' key (passed 'color' in val check)\n\u003cbr /\u003e\n\n- val['color'] equals 'red' (passed color comparison)\n\n\u003cbr /\u003e\n\n- This is different from nodes like 'fruits' or 'temperate' which:\n\n-- Are dictionaries but don't have a 'color' key\n\u003cbr /\u003e\n-- Have nested dictionaries instead of direct properties\n\n\n\n\n\n\n\n---\n\n\u003cdiv align=\"center\" style=\"background-color: #f9f9f9; padding: 15px; border-radius: 10px; border: 1px solid #e1e4e8;\"\u003e\n  \u003ch3\u003e⚠️ Heads Up!\u003c/h3\u003e\n  \u003cp\u003e\u003cstrong\u003eThis ReadMe is under constant updates.\u003c/strong\u003e\u003c/p\u003e\n  \u003cp\u003eStay tuned for new notes as I progress. . . 📚💡\u003c/p\u003e\n\u003c/div\u003e\n\n---\n\n# Acknowledgments\n\n\u003e Thanks to Dr.Moustafa Saad, Nidal Fikri\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahmedabougabal%2Fpythondatastructuresalgorithms","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahmedabougabal%2Fpythondatastructuresalgorithms","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahmedabougabal%2Fpythondatastructuresalgorithms/lists"}