동적 ν”„λ‘œκ·Έλž˜λ°Intermediate

0/1 λ°°λ‚­ 문제

μ£Όμ–΄μ§„ λ¬΄κ²Œμ™€ κ°€μΉ˜λ₯Ό κ°€μ§„ μ•„μ΄ν…œμ„ μ„ νƒν•˜μ—¬ 무게 μ œν•œ λ‚΄μ—μ„œ 총 κ°€μΉ˜λ₯Ό μ΅œλŒ€ν™”ν•˜λŠ” 고전적인 동적 ν”„λ‘œκ·Έλž˜λ° λ¬Έμ œμž…λ‹ˆλ‹€. 각 μ•„μ΄ν…œμ€ ν•œ 번만 선택할 수 μžˆμŠ΅λ‹ˆλ‹€(0/1). μžμ› ν• λ‹Ή, 포트폴리였 μ΅œμ ν™”, ν™”λ¬Ό 적재 λ“±μ˜ μ‘μš©μ΄ μžˆμŠ΅λ‹ˆλ‹€.

#dynamic-programming#optimization#combinatorial#np-complete

Complexity Analysis

Time (Average)

O(n Γ— W)

Expected case performance

Space

O(n Γ— W)

Memory requirements

Time (Best)

O(n Γ— W)

Best case performance

Time (Worst)

O(n Γ— W)

Worst case performance

πŸ“š CLRS Reference

Introduction to Algorithmsβ€’Chapter 16β€’Section 16.2

How it works

  • β€’ 0/1 Knapsack: maximize value within capacity limit
  • β€’ Dynamic programming approach
  • β€’ O(n Γ— W) time, O(n Γ— W) space complexity
  • β€’ Each item can be taken once or not at all
  • β€’ Formula: dp[i][w] = max(dp[i-1][w], dp[i-1][w-wt[i]] + val[i])
Step: 1 / 0
500ms
SlowFast
Keyboard Shortcuts
Space Play/Pause← β†’ StepR Reset1-4 Speed

Real-time Statistics

Algorithm Performance Metrics

Progress0%
Comparisons
0
Swaps
0
Array Accesses
0
Steps
1/ 0

Algorithm Visualization

Step 1 of 0

Initialize array to begin

Default
Comparing
Swapped
Sorted

Code Execution

Currently executing
Previously executed

Implementation

0/1 Knapsack Problem - Algorithm Vision