{"id":17354723,"url":"https://github.com/openmohan/datastructures","last_synced_at":"2025-06-10T23:36:20.175Z","repository":{"id":166769851,"uuid":"74817112","full_name":"openmohan/DataStructures","owner":"openmohan","description":null,"archived":false,"fork":false,"pushed_at":"2018-04-11T10:17:32.000Z","size":1730,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-27T13:49:13.080Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","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/openmohan.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":"2016-11-26T09:42:42.000Z","updated_at":"2018-04-11T10:17:33.000Z","dependencies_parsed_at":"2023-07-29T12:47:52.699Z","dependency_job_id":null,"html_url":"https://github.com/openmohan/DataStructures","commit_stats":null,"previous_names":["openmohan/datastructures"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openmohan%2FDataStructures","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openmohan%2FDataStructures/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openmohan%2FDataStructures/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openmohan%2FDataStructures/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/openmohan","download_url":"https://codeload.github.com/openmohan/DataStructures/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openmohan%2FDataStructures/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259171766,"owners_count":22816509,"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":[],"created_at":"2024-10-15T17:37:51.988Z","updated_at":"2025-06-10T23:36:20.140Z","avatar_url":"https://github.com/openmohan.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DataStructures and Algorithms\n\nAlgrithms should be unambiguous (not more than one meaning/step)\n\nAnalysis:\nA Priori Analysis - Theorectical Analysis , Without implementing it , Assuming all factors\n\nA posterior Analysis - Emprical Analysis - Implement and anaysed\n\nComplexity:\nTime : counted by number of key operations\nSpace : counted by max memory space used by program (number of variables static/dynamic used)\n\n\nThree types :\n Best case : Upper bound of algorithms running time -  Ω notation\n Worst case : Lower bound of algorithms running time - O notation\n Average case : average of Best and worst case - θ notation\n\nAysmptotic notations :\nO(1) - constant time - one operations\n\nO(n) - linear time - number operations is same as the input numbers\n\nO(log n) -  basically means time goes up linearly while the n goes up exponentially. So if it takes 1 second to compute 10 elements, it will take 2 seconds to compute 100 elements, 3 seconds to compute 1000 elements, and so on (Divide and conquer may be) - https://i.stack.imgur.com/spHFh.png\n\nO(n log n) -  when we do divide and conquer type of algorithms e.g binary search. Another example is quick sort where each time we divide the array into two parts and each time it takes\nO(N) time to find a pivot element. Hence it  N O(log N)\n\nO(n2) - number of operations increases n*n times with n number of inputs\n\n\nPopular Alogorithm types :\n\nGreedy algorithms : Being greedy to provide optimal solution\nexamples :\nCounting coins\nTravelling Salesman Problem\nPrim's Minimal Spanning Tree Algorithm\nKruskal's Minimal Spanning Tree Algorithm\nDijkstra's Minimal Spanning Tree Algorithm\nGraph - Map Coloring\nGraph - Vertex Cover\nKnapsack Problem\nJob Scheduling Problem\n\nDivide and conquer : Break a problem in to subproblems recursively untill it cannot be further divided and solve the subproblems and merge the solutions together for the solution of original Problem\nexamples :\nMerge Sort\nQuick Sort\nBinary Search\nStrassen's Matrix Multiplication\nClosest pair (points)\n\nDynamic programming - Problem is divided in to subproblems and the result of the subproblems will be remembered for having the optimal solution while solving the original problem .\nexamples :\nFibonacci number series\nKnapsack problem\nTower of Hanoi\nAll pair shortest path by Floyd-Warshall\nShortest path by Dijkstra\nProject scheduling\n\n\nSkipping stack and queue to Graph DS\n\nGraph DS\nVertex is the point\nEdge is the line connecting the points  \nConnected vertices are considered adjacent\nPath is connected edges from one vertex to another\nDegree is the number of vertex connected to the current Vertex\nTypes:\n1.)Undirected graph - two way relationship eg: Jim and jack play basketball , where jim and jack are vertex and play-basketball is edge\n2.) Directed graph - One way relationship eg: Jim drives car ,  car cannot drive jim , where jim and car are vertex and drive is edge\n\nUndirected cyclic  graph : from a  vertex we can traverse and reach the same vertex again -\nUndirected acyclic  graph : from a  vertex we can traverse and cannot reach the same vertex again - by removing few of the edges . It is a tree actually , since all the vertex can reach other .\nIf a edge is removed from Undirected acyclic graph , it will result in two seperate graph or disjoint trees .\nJoining trees form a forest .\n\n\nWays to represent graph :\nAdjacency matrices\nAdjacency lists\nAdjacency sets\n\n\nAdjacency  matrix for undirected graph will be symmetric\nAdjacency  matrix for directed graph will be asymmetric\n\n\nCommon graph problems -\nTopological sort - Computation graphs in neural networks - DAG (directed acyclic graph)   eg: scheduling tasks\nShortest path - fast delivery of anything , packets or networks\nMinimum spanning - Planning transport roads , Planning railway lines\n\nTopological sort = Directed acyclic graph - used for scheduling and neural networks - precedence order - one task after another - A graph can have more than one Topological sort/order\nCalculate in-degree (number of incoming edges on vertex )in DAG - if no vertex has in-degree of 0 , then the graph is cyclic and Topological sort is not possible\nSteps :  \n1.) Start with the 0 in-degree vertex , process it and then mark it as processed , add it to precedencelist and remove from the graph\n2.) Calculate in-degree again - process the vertex with in-degree equals 0 ,and mark it as processed , add it to the precedencelist and  and remove it from graph , repeat\n\n\nShortest Path :\nFinding the shortest path between two nodes - tranportation  -\nEdge weights determine the cost of the path\nTwo algorithms :\nIf all edges of same weight - unweighted shortest path algorithms\nif the edges are of different weight - Dijkstra algorithm\n\nunweighted shortest path algorithm:\nDistance table - three column array - (nodes , distance from source node , preceding node[node encountered before the particular node from the source node] )\nDistance tables\n\nConstructing distance table - get the source node and fill in all the columns (A,0,A) and get the immediate neighbours (adjacent nodes) of the source node and add it to the queue and update the distance table . Now take the node from queue and find the unvisited adjacent nodes and add it queue and update the table . Repeat untill all nodes are visited\nOnce distance table is done , we will make series of lookups on the distance table to find the shortest path . (Backtracking)\neg: For the ultimate destination node look in the distance table and see what is the preceeding node and add it to the stack\n and for the preceeding node look in the  distance table for its preceding node , add it the stack and repeat this step untill the node is the source node\nAdd the number of entries in stack for the cost and use last in first out feature for finding the path\n\n\nDjistras Algorithm :  Finding shortest path for weighted graphs\nEnqueing algorithm is based on the priority by the weight from the source node .\n\nConstructing distance table :\nDistance table - three column array - (nodes , distance from source node , preceding node[node encountered before the particular node from the source node] )\nget the source node and fill in all columns (A,0,A) , (B,infinite,A) ... .  Get the immediate neighbours and distance from source and put it in proirity queue . Get the node with lowest cost and process it (get the neighbours and cost from source, put it in proirity queue and update it in distance table) . Repeat the steps untill the the proirity queue is empty .\nwe will make series of lookups on the distance table to find the shortest path . (Backtracking)\neg: For the ultimate destination node look in the distance table and see what is the preceeding node and add it to the stack\n and for the preceeding node look in the  distance table for its preceding node , add it the stack and repeat this step untill the node is the source node\nAdd the distance column of entries in stack for the cost and use last in first out feature for finding the path\n\n\nMinumum spanning tree - Removing the cyclic edges from the graph make it a tree, and from every node we should be able to access the other nodes (through set of edges) .\nRemoving an edge from spanning tree will result in two seperate trees . If a graph has 6 vertices , then there will 5 edges in minumum spanning tree\nA graph can have more than one spanning tree\nMinumum spanning tree is spanning tree with lowest weight . ie : cost of all edges in the spanning tree\n\nPrims algorithm  - should work only with connected graph\nKruskals algorith  - works even with disconnected graphs\n\nPrims algorithm - Start with any node in the graph , Spanning tree will be different based on the what node we start with\nfind all edges that goes out from the node - all those edges are candidate edges .Choose the lowest cost edge from the candidate edges and Add the edge and mark the vertex as visited.\nNow get all the unvisted edges for all the visted nodes and get the edge with the lowest cost , Repeat those steps untill all nodes are visited\nPrims algorithm find the local optimum mimimal spanning tree , since it is greedy algorithm \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenmohan%2Fdatastructures","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenmohan%2Fdatastructures","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenmohan%2Fdatastructures/lists"}