Category Archives: Recursion

Posts that are related to Recursion.

Recaman’s sequence

Given an integer n. Print first n elements of Recaman’s sequence. Examples: Input : n = 6 Output : 0, 1, 3, 6, 2, 7 Input : n = 17 Output : 0, 1, 3, 6, 2, 7, 13, 20, 12, 21, 11, 22, 10, 23, 9, 24, 8 It is basically a function with… Read More »

Recursive Bubble Sort

Background : Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in wrong order.


What is Recursion? The process in which a function calls itself directly or indirectly is called recursion and the corresponding function is called as recursive function. Using recursive algorithm, certain problems can be solved quite easily. Examples of such problems are Towers of Hanoi (TOH), Inorder/Preorder/Postorder Tree Traversals, DFS of Graph, etc. What is base… Read More »

Program for Chocolate and Wrapper Puzzle

Given following three values, the task is to find the total number of maximum chocolates you can eat. money : Money you have to buy chocolates price : Price of a chocolate wrap : Number of wrappers to be returned for getting one extra chocolate. It may be assumed that all given values are positive… Read More »

String with additive sequence

Given a string, the task is to find whether it contains an additive sequence or not. A string contains an additive sequence if its digits can make a sequence of numbers in which every number is addition of previous two numbers. A valid string should contain at least three digit to make one additive sequence.… Read More »