I'm going to go a completely different direction from other recommendations and say Concrete Mathematics by Knuth and Patashnik. They will definitely be able to use skills from analysis and calculus here, but there are so many additional tools in this book that it's very much a worthwhile digression. The marginal notes are great, as well!
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 |
answer
Note: This exercise can be found in Concrete Mathematics: Foundation for Computer Science. I highly recommend it.
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:
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.
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?
I own this book, and it's a favorite of mine.
https://www.amazon.com/Concrete-Mathematics-Foundation-Compu...
Concrete Mathematics: A Foundation for Computer Science would be my suggestion for a book that covers some advanced topics.
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. Ifn
isx + 2^k
(with the biggest possible k), afterx
steps you have2^k
candidates left and the next candidate in the line is the answer. So the answer is2x+1
.Note: This exercise can be found in Concrete Mathematics: Foundation for Computer Science. I highly recommend it.
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.
To work through your problem, you have
a = 7 * (4/11) = 28/11
, andb = 10
.a / b
= (28/11)/10 = 0.25454545...⌊a/b⌋
= 0b ⌊a/b⌋
= 0 * 0 = 0a - b ⌊a/b⌋
= 28/11 - 0 = 28/11This means your answer is 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.
http://www.amazon.com/Concrete-Mathematics-Foundation-Computer-Science/dp/0201558025
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] -
[1] -
[2] -
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...
[2.] http://www.amazon.com/Concrete-Mathematics-Foundation-Comput...