{"id":22352757,"url":"https://github.com/alinpahontu2912/algorithm-design---1","last_synced_at":"2025-03-26T12:14:07.852Z","repository":{"id":207572140,"uuid":"387446491","full_name":"alinpahontu2912/Algorithm-Design---1","owner":"alinpahontu2912","description":"First Homework for the algorithm design course(Greedy + Dynammic Programming)","archived":false,"fork":false,"pushed_at":"2021-07-19T11:52:47.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-31T13:24:13.888Z","etag":null,"topics":["algorithm-challenges","dynamic-programming","greedy-algorithms"],"latest_commit_sha":null,"homepage":"","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/alinpahontu2912.png","metadata":{"files":{"readme":"README","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}},"created_at":"2021-07-19T11:52:26.000Z","updated_at":"2021-07-28T19:44:06.000Z","dependencies_parsed_at":"2023-11-16T14:45:27.785Z","dependency_job_id":null,"html_url":"https://github.com/alinpahontu2912/Algorithm-Design---1","commit_stats":null,"previous_names":["alinpahontu2912/algorithm-design---1"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alinpahontu2912%2FAlgorithm-Design---1","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alinpahontu2912%2FAlgorithm-Design---1/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alinpahontu2912%2FAlgorithm-Design---1/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alinpahontu2912%2FAlgorithm-Design---1/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alinpahontu2912","download_url":"https://codeload.github.com/alinpahontu2912/Algorithm-Design---1/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245650484,"owners_count":20650105,"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":["algorithm-challenges","dynamic-programming","greedy-algorithms"],"created_at":"2024-12-04T12:27:05.729Z","updated_at":"2025-03-26T12:14:07.817Z","avatar_url":"https://github.com/alinpahontu2912.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"-------------------------------------------------------------------------------\nTask 1:------------------------------------------------------------------------\n\n\tTo solve this task, I adopted a greedy strategy. I sort the computers based\non their initial coins gain. Then, I try to maximize the minimum of the \ncomputers list by always upgrading the computers that generate the minimum \namount of coins per hour.\n\tThe worst case complexity of this task: O(B * N)  \n\n\nTask 2:------------------------------------------------------------------------\n\tSolving this task requires dynammic programming concepts. At any given \nmoment, the result depends on the share to be analyzed, the budget and the\nmaximum loss. This means the complexity of solving this problem is O(N*B*L).\n\nTask 3:------------------------------------------------------------------------\n\tTo solve this task, I used a greedy approach. To find the minimum cost to\nachieve the wanted array, the position of the minimum from the list must always\nbe the pivot. This means, after finding the position of the minimum, the \nminimum cost will be calculated only by adjusting the prefix and the suffix of\nthe array so that each of them is descending and ascending resectively. \n\tOne important case is when the minimum is either the first or last element\nof the array. The cheapest way to get the minimum cost is to switch the \nposition of the minimum by one (moving it to either the second position, or\nthe penultimate one, by decreasing the neighbouring element)\n\tThe complexity of this problem is O(N)\n\nTask 4:------------------------------------------------------------------------\n\tTask 4 requires dynamic programming concepts as well. Another observation\nis : The amount of maximum adjustments I can make to a a mountain is two. This\nis why I am using three dp arrays of size  N (where N is the number\nof mountains). I check for every existing mountain, if I can resize it, (by \ndecreasing its size with 0, 1 or 2), while also checking if the height does not\ngo below 0, and then take the cost of the minimum adjustment.\n\tThe complexity of this program is O(N).\n\nBonus Task:---------------------------------------------------------------------\n\tTo solve this task, I frst had to find the reccurence. Because I notice it\nchanges into three distinct reccurences depending on the number I have, I constructed\n3 matrixes that can take me from one state to another. Depending on the remainder \nof the division by three, I can calculate the final result. I am using matrixes to\nimprove efficiency, because a regular dynamic programming approach with a simple\nvector would have been to slow and use up to much memory.\n\tThe complexity of this task: O(logN).\n\nReferences:\nhttps://www.geeksforgeeks.org/minimize-the-cost-to-make-all-the-adjacent-elements-distinct-in-an-array/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falinpahontu2912%2Falgorithm-design---1","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falinpahontu2912%2Falgorithm-design---1","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falinpahontu2912%2Falgorithm-design---1/lists"}