# Concrete Mathematics: A Foundation for Computer Science (2nd Edition)

All Stack Overflow 18
This Month Stack Overflow 1

Concrete Mathematics: A Foundation for Computer Science would be my suggestion for a book that covers some advanced topics.

My program works for inputs 2, 4, 8, 16, 32, 64 and so on as ans in all these is 1.

This is a good observation. Actually the answer is just a small step from here.

You have `n` candidates, and you select 1 each time. If `n` is `x + 2^k` (with the biggest possible k), after `x` steps you have `2^k` candidates left and the next candidate in the line is the answer. So the answer is `2x+1`.

``````1 2 3 4 5 6 7
^   ^   ^ |
removed  |
``````

Note: This exercise can be found in Concrete Mathematics: Foundation for Computer Science. I highly recommend it.

Or concrete, as suggested by Knuth, Graham, and Patashnik in their book, "Concrete Mathematics: A Foundation for Computer Science".

https://www.amazon.com/Concrete-Mathematics-Foundation-Compu...

Have a look here: "Is it possible to do modulo of a fraction" on math.stackexchange.com.

One natural way to define the modular function is

a (mod b) = a − b ⌊a / b⌋

where ⌊⋅⌋ denotes the floor function. This is the approach used in the influential book Concrete Mathematics by Graham, Knuth, Patashnik.

This will give you 1/2(mod3)=1/2.

To work through your problem, you have `a = 7 * (4/11) = 28/11`, and `b = 10`.

`a / b` = (28/11)/10 = 0.25454545...

`⌊a/b⌋` = 0

`b ⌊a/b⌋` = 0 * 0 = 0

`a - b ⌊a/b⌋` = 28/11 - 0 = 28/11

Wolfram Alpha agrees with me and gives `28/11` as the exact result. Google also agrees, but gives it as a decimal, 2.54545454.....

A fraction is an exact answer and not a decimal.

I suggest books with good tutorials throughout if you're unable to partake in a maths course. For computer science-related maths Don Knuth's Concrete Mathematics is meant to be very good.

Obviously nothing can replace a good teacher, but good tutorials can come pretty damn close. You really get to learn the subject in the tutorials I think.

There is a good book, that I think would help you to get more out of computer science research papers and dissertations. It's called "Concrete Mathematics: A foundation for Computer Science", and it's available on Amazon:

http://www.amazon.com/Concrete-Mathematics-Foundation-Computer-Science/dp/0201558025/ref=sr_1_1?s=books&ie=UTF8&qid=1341081763&sr=1-1&keywords=math+computer+science

I think this would help because it will all be relevant, and its consolidated which will help expedite the learning process.

Even if you don't have any money, just Google it and take a look at the index to get an idea of what areas you might want to learn.

And here's one more interesting book.

CLRS is quite 'academic' and requires good understanding of mathematics. It's a great book, but not a good one for beginners, imo. It will be difficult as self study for first timers. You can start with Datastructures and Algorithm Analysis in C by M. A. Weiss[0]. One more alternative is The Algorithm Design Manual by S. Skiena[1]. It's also good and focuses more on algorithm, implementation (as opposed to math-y stuff of CLRS). If I were you, I would get both the books and read alternatively. Don't miss out on exercises, they are very important.

I also suggest you to join this Coursera course, Algorithms: Design and Analysis by Tim Roughgarden[2]. Currently the course is open, so you can sign up for classes. The course is offered in two parts[3], complete both of them.

Once you are comfortable with basic concepts start solving questions/puzzles online on sites like SPOJ[4], UVa[5], (YC-funded) HackerRank[6]. You could try TopCoder[7] also, but the questions are bit difficult. Hope this helps.

PS - You should study math, because it is important in Algorithms Analysis. You could try reading required parts of Concrete Mathematics by Knuth[8] or as you come across new concepts, Google and understand them.

[0] -

Has anyone read both this and Knuth's Concrete Mathematics? http://www.amazon.com/Concrete-Mathematics-Foundation-Comput... How do they compare with each other?
This is always a good topic with numerous HN submissions and comments:

Just from a search, there are some great results:

1. Mathematics for Computer Science - HN Submissions: http://www.amazon.com/Mathematics-Content-Methods-Meaning-Do...