/asg/ - Algorithm Study Group

In this thread we discuss our progress reading “Introduction to Algorithms, Fourth Edition”.
We gather every Saturday and Sunday at 12:00 (noon) UTC.

Reading goals for next Saturday:
Chapter 3

I've extended the time we have to finish chapter 3 because I was pretty busy with work this week.
Did you get through all of this week's content? Let us know if you think we are going too fast or too slowly.

Today's discussion questions:
Name a loop invariant property which is not mentioned in the book, and prove that it is loop invariant.
2.1-4 Write pseudocode for linear search, which scans through the array from beginning to end, looking for x . Using a loop invariant, prove that your algorithm is correct. Make sure that your loop invariant fulfils the three necessary properties.

You will gain the most by doing the exercises and problems yourself!
Spoilers are not enabled on this board, so please not post solutions for exercises or problems for sections:
3.1 and beyond

Notable changes from the third edition for this week’s content:
None

Previous thread:

Attached: asg.jpg (1536x1750, 125.64K)

Other urls found in this thread:

youtube.com/watch?v=4YXX5snXGg8
github.com/peteblank/directory2todolist/blob/main/test.go
en.wikipedia.org/wiki/All_horses_are_the_same_color
twitter.com/AnonBabble

>tfw got filtered trying to implement binary tree delete operation

what don't you get about it

Idk I watched some pajeet's youtube video and it confused the fuck outta me.
I probably should read clrs explanation on it.

Can somebody pls post the version with better image quality?

...

How are the new chapters in the 4th edition?

gender friendly

Give me a fucking break man.

daily reminder

Attached: 22e322bb440458cd682f62f144423630.jpg (645x729, 38.46K)

Here youtube.com/watch?v=4YXX5snXGg8

Many thanks, user.

Cool thread, I've been meaning to dig into this book myself.
Any tips for how to catch up so I can stay with these threads? Also I have third edition but I'm assuming the differences are trivial, can anyone confirm/deny?

sup algochads
I bought the 3rd edition around a year ago but got filtered hard by induction

in college they taught us many times, I watched lecture about Mathematics for Computer Science about it yet still I don't get it.

I mean, I understand how it is supposed to work yet it all seems like a bunch of bs.
After the first base case is it really just replacing your formula where every x is x+1 and the solving it, and somehow this proves that it works all along?

So you guys know about algos heh?
K make me an algo that can print my 27mb json line by line
github.com/peteblank/directory2todolist/blob/main/test.go

Show it works for 1. Given it works for n, prove that it works for n + 1.
With these two parts combined, that means working for 1 means it works for 2. Working for 2 means it works for 3. Working for 3 means it works for 4. And on to infinity.

>Given it works for n
why?
why assume it works for n if that is what we're trying to prove

Because you start with this:
Prove it works for 1. Given it works for 1, prove it works for 2. Given it works for 2 prove it works for 3. Given it works for 3 prove it works for 4.
Then you take a step back and notice that all your proofs are the same. Essentially, you just write a function prove(n, n+1) instead of implementing prove(2,3) and prove(3,4), etc.

>After the first base case is it really just replacing your formula where every x is x+1 and the solving it, and somehow this proves that it works all along?
You prove it works for the base case, which is usually 0 or 1; then you take for granted that it works for x and you prove that if it works for x it should work for x+1 too.

That is enough to prove everything because:
>if it works for 0 (base case) then it works for 0+1=1 due to the inductive step;
>if it works for 1 (previous inductive step) then it works for 1+1=2 due to inductive step;
>if it works for 2 (previous inductive step) then it works for 2+1=3 due to inductive step;
>so on and so forth.

It similar to how you can construct every natural number by with a function succ(n)=n+1 and a starting point 0.
>0 is a natural number (starting point)
>1 is a natural number because it is equal to succ(0)
>2 is a natural number because it is equal to succ(succ(0))
>3 is a natural number because it is equal to succ(succ(succ(0)))

Proving the inductive step only is not enough because you don't have a starting point.

after all these years, I think I finally get it, thanks!
I didn't understand how critical the base case is so I was pretty much ignoring it and focusing only on the induction step.
proof(n, n+1) by itself is not enough and left me confused but now I understand that proof(1) and proof(n, n+1) proves 1, 2, 3, ..., n

the preface of the fourth edition tells you what the major changes are.

in addition I am also posting about any significant changes in the material we are reading. for example, next week we are finishing chapter 3:
> Notable changes from the third edition for this week’s content:
> None

>then you take for granted that it works for x and you prove that if it works for x it should work for x+1 too.
this part always confused me as to why are we allowed to assume something that we're trying to prove
But I think that just because we assume doesn't mean it's true, if we fail to prove then our assumption is wrong

You might enjoy this:
en.wikipedia.org/wiki/All_horses_are_the_same_color

Fuck off I already graduated, my advice is pick up a maths book instead.

> if we fail to prove then our assumption is wrong
I don't think that's necessarily accurate in this case, maybe you're thinking about proof by contradiction:
If we try our hardest and cannot find a proof that 'if A is true then B is true', this doesn't tell us much about either statement.
But if we have a proof (1) that 'if A is true then B is true' and another proof (2) that 'B is not true', then we can combine those to obtain a proof (3) that 'A is not true'.