Hi is there any books or websites that I can refer to for more practice on recursion for c programming? Seems like those I find is the standard gcd, tower of hanoi and etc. Want to get more practice!
Hi is there any books or websites that I can refer to for more practice on recursion for c programming? Seems like those I find is the standard gcd, tower of hanoi and etc. Want to get more practice!
Binary searches?
If you understand what you're doing, you're not learning anything.
Try to implement quicksort.
Good idea, but I'd try mergesort first, 1) because it is easier, 2) because it is useful to understand how quick- and merge- work comparatively. I think a lot of people who skip straight to quicksort buy into the hype about it, and fail to understand that mergesort is often a stronger general purpose sort.
They are both good for learning recursion.
Last edited by MK27; 10-24-2011 at 09:32 AM.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
I support quicksort over mergesort because I've met Hoare, but I've never met von Neumann!Originally Posted by MK27
Nah, in reality I use whatever sort is readily available in the standard and other libraries, and pick my algorithms more carefully when these don't suffice.
Anyway, a somewhat more ambitious project would be to implement a recursive descent parser, because more than just practicing recursion by translating some recursive algorithm into code, you would need to learn about grammars.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
I suggested quicksort because it's a tougher than GCD or Towers or Hanoi, and -- more importantly to me -- it requires a good understanding of arrays in C, especially when performing the in-place version of the algo. However, merge sort might well be a good way to ease into recursive sorting algorithms.
Fooling around with binary trees is also a good way to get a "feel" for recursion...maybe even be the best way, since one can visualize pretty easily, say, a preorder traversal algorithm in action. Plus, working with trees in C provides some extra practice with pointers and structs.
Make mazes. Then solve mazes. BFS, DFS. Then try solving them without recursion.
Quzah.
Last edited by quzah; 10-24-2011 at 06:35 PM.
Hope is the first step on the road to disappointment.
Well this will help you understand one important aspect of recursion, namely the simple end condition which stops the recursion being infinite
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
I never get tired of that one.
Quzah.
Hope is the first step on the road to disappointment.
Both merge and quicksort will be good for looking at recursion; however, I have the following suggestion:
When writing quicksort, sort with an array; quicksort requires (for best performance) a way to randomly access elements.
When writing merge sort, sort with a linked list; the merge step with a linked list requires no extra storage or hoops to jump through.
You can use quicksort on a linked list and merge sort on an array, but the extra work you'll have to do for them won't help you with learning recursion.
You might also benefit from looking at a functional language like Haskell or OCaml, where recursion is more a fundamental part of programming than it is in C. Not that you should necessarily switch to such a language, but it could help you get a better understanding of recursion.