Save this video free

Advanced Algorithms (Winter 2026-27) - 03-03 Knapsack DP solution

Sebastian Wild (Lectures) · 32:10 · Watch on YouTube

Part of University of Marburg CS 627. See all 14 lectures and search them

These notes were made with YouTube Collector. Paste any YouTube link and get the same: a summary, chapters and a searchable transcript.

Advanced Algorithms (Winter 2026-27) - 03-03 Knapsack DP solution Watch on YouTube →

Overview

Sebastian Wild explains the standard knapsack dynamic program and why its O(nB) table-filling time is pseudo-polynomial when capacity B can be exponentially large relative to its binary encoding. He then transposes the table to track minimum weight for each exact value, yielding a second pseudo-polynomial approach when total item value is small and foreshadowing how value rounding can support approximation algorithms.

Key takeaways

Chapters

0:00 Knapsack and the Meaning of Pseudo-Polynomial Time
3:30 Capacity-Indexed DP, Item Choices, and Backtracing
11:15 Why the Capacity DP Is Pseudo-Polynomial
14:30 Transpose the Table to Track Exact Values
22:25 Exact-Value DP Examples and Feasibility
26:20 Value-Based Complexity, Approximation, and Broader Context

Keep these chapters and the full searchable transcript in your own library.

Transcript excerpt

0:01 Okay, let's do um, a very short recap. We've been looking at the knapsack problem in the context of this uh, chapter on pseudo-polynomial algorithms, which were algorithms where the running time in a strict sense is exponential, but it is polynomial in a specific parameter of the input, something that we will talk about in more detail in next in the next unit. Uh, namely the largest integer, the largest number that occurs in the input. And where did that discrepancy come from? Well, if you have an input that consists of numbers, you shall use a sensible encoding. And uh, a sensible encoding is a binary code for the numbers, say, uh, giving giving them in in uh, base

0:49 two. And then, a number of size n only takes roughly log n bits, big O of log n bits. By the way, even if you don't know how big the number is, right? There's Elias gamma codes and things like that. So, even if you wanted to specify a number where you don't have to specify up front how many bits it takes, you could still do it in big O of log n bits. You lose a factor two, but not more. Uh, so, we can encode numbers if all we need is this numerical value very concisely, very succinctly. Uh, on the flip side, this means if a problem consists of numbers that can be small written in small things, then taking time proportional to the value of the number is in principle exponential. But we call it pseudo-polynomial

1:36 because it sometimes is closer to tractable. And one example was this knapsack problem. Uh, the formal definition here uh, again was was this one. We have items and different ones. Uh-huh. I don't love the new setup

This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.

In this course

Related notes

Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Sebastian Wild (Lectures).

Want the full transcript?

Save this video in YouTube Collector to get its complete searchable transcript, your own AI summaries, and a library that keeps every video you collect in one place.