Recursion And Linkedlist

·

1 min read

Recursion expects us to divide the problem into more small problems and in case of linkedlist one way of dividing the problem is by observing linkedlist as head and rest of linkedlist

ATTITUDE -> first node, which we have to deal with, and the rest of the list, which we don’t and therefore aren’t concerned about.

APROACH ->

  1. If L is minimal, we directly assign a default value. Otherwise . . .
  2. Use a recursive call to produce an answer to Q for the “rest of” list L (the list starting with the second node of L).
  3. Inspect the value in the first node of L.
  4. Use the results of the previous two steps to answer Q for the whole of L