r/AskComputerScience • • Nov 29 '24

Red-Black Trees. Why can't a 3-node tree fulfill the conditions for RBT?

2 Upvotes

Challenge from instructor in Coursera Algorithms course.

see screenshot: https://imgur.com/a/4SKpX5y

If I color node #2 red, then it appears to me that all 3 conditions are met.

  1. root and leaves are Black
  2. Every Red node has two Black children.
  3. The Black height from any node is well defined and consistent.

I don't know what I am missing.

(in comparison, here is a different slide from his lecture with a RBT https://imgur.com/a/eUJW3S2)


r/AskComputerScience • • Nov 29 '24

A question concerning skiena's algorithm course

2 Upvotes

In lecture 2 (Asymptotic Notation) slide 1 and 2 we are asked to find counter examples to the proposed algorithms for the knapsack problem, but I don't understand the algorithms, there are 3 of them:

1 Put the elements of S in the knapsack in left to right order if they fit, i.e. the first-fit algorithm?

2 Put the elements of S in the knapsack from smallest to largest, i.e. the best-fit algorithm?

3 Put the elements of S in the knapsack from largest to smallest?

What does he mean by "in left to right order"?

Do 2 and 3 mean that we should try to put the elements monotonous until we got the target number?