{"id":25171769,"url":"https://github.com/basemax/0-1knapsackrecursivec","last_synced_at":"2025-04-03T21:24:28.022Z","repository":{"id":65256812,"uuid":"588922489","full_name":"BaseMax/0-1KnapsackRecursiveC","owner":"BaseMax","description":"This is an implementation of the 0-1 knapsack problem in C using a recursive approach. The problem consists of a set of items, each with a weight and a value, and a knapsack with a maximum weight capacity. The goal is to determine the subset of items that maximizes the total value of the knapsack without exceeding its weight capacity.","archived":false,"fork":false,"pushed_at":"2023-01-14T22:38:37.000Z","size":23,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-28T17:08:04.352Z","etag":null,"topics":["c","knapsack","knapsack-01","knapsack-problem","knapsack-problem-recursive","knapsack-recursive","knapsack-solution","knapsack-solver","knapsack0-1","knapsack01"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BaseMax.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2023-01-14T13:45:00.000Z","updated_at":"2023-01-15T01:57:05.000Z","dependencies_parsed_at":"2023-01-15T23:45:50.770Z","dependency_job_id":null,"html_url":"https://github.com/BaseMax/0-1KnapsackRecursiveC","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BaseMax%2F0-1KnapsackRecursiveC","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BaseMax%2F0-1KnapsackRecursiveC/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BaseMax%2F0-1KnapsackRecursiveC/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BaseMax%2F0-1KnapsackRecursiveC/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BaseMax","download_url":"https://codeload.github.com/BaseMax/0-1KnapsackRecursiveC/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247080366,"owners_count":20880252,"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":["c","knapsack","knapsack-01","knapsack-problem","knapsack-problem-recursive","knapsack-recursive","knapsack-solution","knapsack-solver","knapsack0-1","knapsack01"],"created_at":"2025-02-09T09:22:00.330Z","updated_at":"2025-04-03T21:24:27.996Z","avatar_url":"https://github.com/BaseMax.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 0-1 Knapsack Problem in C (Recursive)\n\nThis is an implementation of the 0-1 knapsack problem in C using a recursive approach. The problem consists of a set of items, each with a weight and a value, and a knapsack with a maximum weight capacity. The goal is to determine the subset of items that maximizes the total value of the knapsack without exceeding its weight capacity.\n\n## How to use\n\nTo use this implementation, include the `knapsack_recursive.c` file in your project and call the `knapSackRecursive()` function with the following parameters:\n\n- `W`: the maximum weight capacity of the knapsack\n- `wt[]`: an array of weights for each item\n- `val[]`: an array of values for each item\n- `n`: the number of items\n\nThe function will return the maximum value that can be put in the knapsack without exceeding its weight capacity.\n\n```c\n#include \"knapsack_recursive.c\"\n\nint main()\n{\n    int W = 50;\n    int wt[] = {10, 20, 30};\n    int val[] = {60, 100, 120};\n    int n = sizeof(wt)/sizeof(wt[0]);\n    printf(\"%d\", knapSackRecursive(W, wt, val, n));\n    return 0;\n}\n```\n\n### Time and Space Complexity\n\nThe time complexity of this implementation is `O(2^n)` where `n` is the number of items, W is the knapsack capacity. The space complexity is `O(n)` for the recursive call stack.\n\n### Note\n\nThis is a naive implementation of the problem, it will have exponential time complexity and will not be efficient for large inputs. Consider using dynamic programming techniques such as Memoization or Tabulation to improve the performance.\n\nI hope this implementation helps you solve the 0-1 knapsack problem in your project. If you have any questions or suggestions, feel free to reach out.\n\nCopyright (c) 2022, Max Base\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbasemax%2F0-1knapsackrecursivec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbasemax%2F0-1knapsackrecursivec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbasemax%2F0-1knapsackrecursivec/lists"}