Forums Register Login

Recursion Problem

+Pie Number of slices to send: Send
Hello there,
I need some suggestion or help. I have completed my BSc in CS. Still looking around for Job. But the biggest challenge I am facing is recursion. I can do simple recursion with no problem but when it comes recursion with while or for loop, I get completely lost. Two of my interview I faced with tracing recursion problem. I was able to answer all problems on time but I was so disappoint with recursion problem. I need some suggestion what to do or which direction can help me to get more comfortable with recursion problems.

Thanks.
+Pie Number of slices to send: Send
Hi Hasan,
Recursion and the loops are 2 different things,you can use both one for some repititive work though.if you are not stable in parsing the recursion based problems it simply means you have avoid to use it or say you didn't practice it a lot.
the first thing i will recommend you to have a look at the →description of recursion by Wikipedia.
you can search about →*recursion vs nested loops* in the ranch forum.
I would not call like recursion is slower or takes much memory as it depends on the algorithm and the actual context.but personally i avoid using it if i can achieve it with loop,not every time though as sometime recursion let us to solve the problems in a efficient way along with rendering the readability to the code.
try to find the problems based on recursion on ranch(search) or ask for it to the google and practice and practice a lot.their are some classical problems which are solved using recursion like terms in a fibonacci sequence,evaluating factorial...etc,you can find all this on google.

Hope it helps!

Kind Regards,
Praveen.
+Pie Number of slices to send: Send
If you want to discuss possible solutions, perhaps you could give us an example where you need to use "recursion with a while or for loop"? On first looking at your post I'm not exactly sure what that means, but an example, I find, tends to clarify things. It's often hard to think abstractly about things which you have no experience of, and that's when talking about concrete examples can be helpful.
+Pie Number of slices to send: Send
Thanks Praveen and Paul. Sorry praveen you understand me wrong. I certainly understand the different between Recursion and Nested Loop. After all it is not possible to finish degree in CS without knowing the main difference between them. But Paul, I appreciate your answer too as you asked me to specify what kind of problem I face little hard. As an example :



I believe I have to practice more on these kind of problem. But any kind of direction from you guys can boost my skill may be.

Thanks
(1 cow) 1
+Pie Number of slices to send: Send
So you are struggling with these kind of code...
IMO the cause for it is the style of your coding.you are not following the principles of Object Oriented Principles(java is Object oriented... based).although java is OOPS based it doesn't means it's going to stop you from coding in a procedural style.
look in your code-
the indent style,
how many things does the permute Helper is doing.in fact your method has some redundant code in it for the swapping part.
may be these things are puzzling your mind and making it hard for you to parse the logic...
permuteHelper is doing:
1.)printing the array.
2.)swapping.
3.)calculating the different permutation of an array.
Try this may be it can help:
we can refactor it,see the code below
1.) #printHelper

2.) #swapHelper.

3.)#arrayPermutations

4.) #main

method names can be more better and may be,it can be refactored more better if tried but i just meant
to let you understand the effect of it.
i am still learning these things(i have not enough experience with java or any programming language).
but plenty of members like *junilu* always recommend to avoid the procedural style if you are dealing
with object oriented paradigm,if you didn't then you will get habitual of it.and IMO procedural way of
coding jumbles the code and thus puzzling the ones mind during parsing it.the principles of the object
oriented paradigm helps to get rid of the same problems.

practice with keeping the principles(of OOPs) in mind then you will of course gain the comfortable level.

HIH

Kind regards,
Praveen.
1
+Pie Number of slices to send: Send
I think their can be one more method:

#print


modified#printHelper
+Pie Number of slices to send: Send
Thanks Praveen for your help. I will try this later today.
Ruth Stout was famous for gardening naked. Just like this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 540 times.
Similar Threads
re: Things which help you get an interview (?)
Job and Full Time MCA?
Need a boost..
Should I lookout for a job
What are your long term career strategies?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 08:15:35.