1

Where can I learn algorithms for programming(java etc) because when ever I search for programs such as permutations,derangements,sortings etc I always find math algorithms.

Example: Counting Derangement

From this, the following relation is derived:

!n = (n - 1) (!(n-1) + !(n-2)).\,
where !n, known as the subfactorial, represents the number of derangements, with the starting values !0 = 1 and !1 = 0.

Notice that this same recurrence formula also works for factorials with different starting values. That is 0! = 1, 1! = 1 and

n! = (n - 1) ((n-1)! + (n-2)!)\,
which is helpful in proving the limit relationship with e below.

Also, the following formulae are known:[4]

!n = n! \sum_{i=0}^n \frac{(-1)^i}{i!},
!n = \left\lfloor\frac{n!}{e}+\frac{1}{2}\right\rfloor , \quad n\geq 1,
!n = \left[ \frac{n!}{e} \right] , \quad n\geq 1

Also another example I find is when I look up sorting in java I see O(n log n) or O(log n) terminology which I don't understand at all. I am not very good at math but at the same time I am very much interested in programming. Please help me in finding a book or a site to understand sorting algorithms required in programming languages

kittu
  • 6,662
  • 21
  • 91
  • 185
  • Programming is many things to even more people. There is finding a finite sequence of steps systematically achieving the desired result for all allowable inputs, describing it, and there is having someone or something execute it. Coding an algorithm in a programming language is a step in having a computer produce results. One idea is to start with a book, [beautiful code](http://shop.oreilly.com/product/9780596510046.do) comes to mind. Then, there are tutorials - hard to imagine getting the knack for coding without practice. – greybeard Nov 22 '14 at 11:28
  • 1
    The "beautiful" series feature nice books, but I would not recommend it as a starting point. – Kraal Nov 22 '14 at 11:40

3 Answers3

6

Algorithms are about mathematics. They are language-agnostic. You can implement algorithms in any language as long as you know its grammar, i.e. its basic datatypes, operators, decision making, etc. Many languages provide libraries implementing known and/or useful algorithms or functionalities (for instance for sorting, encryption, etc.)

That's why searching for "java algorithms" is a bad search string. You should rather search for "java programming basics"

If you want to understand what lies behind (the beauty of) algorithmics, I strongly recommend reading this great book : "Programming Pearls" (2nd edition). The first edition was written in 1983, and it is interesting to understand why the author decided to write a second edition 17 years later.

You can also have a look at online lectures, for instance MIT ones.

Concerning the O(log(n)) part of your question, this is a notation to express the computational complexity of an algorithm (important when you want to understand the performance you can expect from an algorithm, or if you want to communicate the performance of your own algorithms).

For Java you can start with Oracle's tutorials.

Kraal
  • 2,779
  • 1
  • 19
  • 36
3

I took Algorithms I and Algorithms II on Coursera, they are great. There is also a textbook for that course.

Dmitry Leskov
  • 3,233
  • 1
  • 20
  • 17
  • Awesome my friend awesome. I just registered myself on the site and its free to attend the session online. However, Algorithms part I sessions has been finished. Any way to watch the sessions again or do I have wait for the next schedule. – kittu Nov 22 '14 at 11:55
  • @KiritiKomaragiri I am not sure about that particular course, but I enrolled into Principles of Reactive Programming well after it ended and can now watch videos and such. – Dmitry Leskov Nov 24 '14 at 06:06
2

O(n log n) or O(log n) is Big O notation. I linked to the sections where most common cases (like examples you asked for) are explained. There is also excellent answer on stackoverflow

See Algorithm Tutorials on Topcoder for good articles.

The Importance of Algorithms is good tutorial (explains basic algorithms, and gives examples for Big O notation).

Basics of combinatorics covers your problem -derangements.

For books- see Introduction to Algorithms and Algorithms, 4th Edition.

Community
  • 1
  • 1
Bartosz Bilicki
  • 12,599
  • 13
  • 71
  • 113
  • Even I was able to search for Big O notation, but my main problem was in understanding those formulas such sigma, f(n) etc. If you can suggest me a book or something to understand that little math formulas would be great! Thanks for the answer anyway – kittu Nov 22 '14 at 11:49