Coder Social home page Coder Social logo

recursion's Introduction

Recursion

Problem 1:

Write a recursive function that prints all the elements of an array of integers in reverse order. (RecursionPracticeQuestions-UG1, problem 2)

Input:
5
69 87 45 21 47
Output:
47 21 45 87 69

Problem 2:

Find the sum of the integers from 1 through n. Use recursion.(RecursionPracticeQuestions-UG1, problem 4)

Input:
4
Output:
10

Basic Mathematical Operations using Recursion

Problem 3:

Write a recursive program to remove all odd integers from an array. You must not use any extra array.

Input:
6
1 54 88 6 55 7
Output:
54 88 6

Problem 4:

Write a recursive program to remove all odd integers from an array. You must not use any extra array or print anything in the function. Just read input, call the recursive function, then print the array in main().

Input:
6
1 54 88 6 55 7
Output:
54 88 6

Problem 5:

Write a recursive solution to print the polynomial series for any input n: 1 + x + x2 + ................. + xn-1
alt text

Input:
5
Output:
1 + x + x^2 + x^3 + x^4

Problem 6:

Write a recursive solution to evaluate the previous polynomial for any given x and n. Like, when x=2 and n=5, we have 1 + x + x2 + ................. + xn-1 = 31

Input:
2 5
Output:
31

Problem 7:

Find the Factorial of a Number using Recursion

Input:
5
Output:
120

Problem 8:

Write a recursive program to print fibonacci series. 1st and 2nd fibonacci numbers are 1, 1.

Input:
6
Output:
1 1 2 3 5 8

Problem 9:

Write a recursive program to compute nth fibonacci number. 1st and 2nd fibonacci numbers are 1, 1.

Input:
6
Output:
8

Problem 10:

Write a recursive program to determine whether a given integer is prime or not.(6.189 IAP 2011: Optional Recursion Exercises MIT OpenCourseWare problem 6)

Input:
19

Output:
prime

Problem 11:

Find GCD or HCF of two numbers

Input:
68 51
Output:
17
alt text

Problem 12:

Write a recursive solution to compute lcm of two integers. use this formula lcm(a,b) = (a x b) / gcd(a,b);

Input:
23 488
Output:
11224

Problem 13:

Write a recursive solution to compute lcm of two integers. You must not use the formula lcm(a,b) = (a x b) / gcd(a,b); find lcm from scratch...

Input:
23 488
Output:
11224

A Venn Diagram showing the least common multiples of combinations of 2, 3, 4, 5 and 7 (6 is skipped as it is 2 × 3, both of which are already represented). For example, a card game which requires its cards to be divided equally among up to 5 players requires at least 60 cards, the number at the intersection of the 2, 3, 4 and 5 sets, but not the 7 set.

alt text

Problem 14:

Find Product of 2 Numbers using Recursion (panding) (6.189 IAP 2011: Optional Recursion Exercises)

Input:
4 4
Output:
16

Problem 15:

Write a recursive solution to find the second maximum number from a given set of integers.(panding)CSC 349: Design and Analyis of Algorithms

Input:
5
5 8 7 9 3
Output:
8

Problem 16:

Write a recursive function to print an array in the following order. [0] [n-1]
[1] [n-2]
.........
.........
[(n-1)/2] [n/2]

Input:
5
1 5 7 8 9
Output:
1 9
5 8
7 7

Problem 17:

Count the number of zeros in an array of integers. Use recursion.(RecursionPracticeQuestions-UG1, problem 6)

Input:
2,4,0,6,0
Output:
2

Problem 18:

Write a function using recursion to print numbers from n to 0.(6.189 IAP 2011: Optional Recursion Exercises MIT OpenCourseWare, problem 3)

Input:
5
Output:
5 4 3 2 1 0

Problem 19:

Write a function using recursion to print numbers from 0 to n (you just need to change one line in the program of problem 1).(6.189 IAP 2011: Optional Recursion Exercises MIT OpenCourseWare, problem 4)

Input:
5
Output:
0 1 2 3 4 5

Problem 20:

Write a recursive solution to find the maximum element from the array.

Input:
6
5 7 4 9 6 2
Output:
9

Problem 21:

Write a recursive solution to find the minimum element from the array.(RecursionPracticeQuestions-UG1 problem 7)

Input:
6
5 7 4 9 6 2
Output:
2

Problem 22:

Find the recursive solution of binomial coefficients B(n,k) defined by formula (1) satisfy (hackerrank)
B(n, k) = B(n − 1, k − 1) + B(n − 1, k), 1 ≤ k ≤ n − 1.

Input:
B(n, k) = 10,4
Output:
210

Problem 23:

Write a recursive function to reverse a string. Write a recursive function to reverse the words in a string, i.e., ”cat is running” becomes ”running is cat”.(RecursionPracticeQuestions-UG1 problem 10)

Input:
cat is running
Output:
running is cat

Problem 24:

Write a recursive function to reverse a string. Write a recursive function to reverse the digit in a string.

Input:
running
Output:
gninnur

Problem 25:

Write a recursive function to reverse a string. (java)

Input:
ASDFG
Output:
SDFGA

## Problem 26

Print All Permutation Of String Recursion Input:
'a', 'b', 'c'
Output:
abc 1
acb 2
bca 3
bac 4
cab 5
cba 6

alt text

hackerrank

6.189 IAP 2011: Optional Recursion Exercises MIT OpenCourseWare

    1. Write a function that takes in a base and an exp and recursively computes baseexp. You are not allowed to use the ** operator!
  • 3. Write a function using recursion to print numbers from n to 0.

  • 4. Write a function using recursion to print numbers from 0 to n (you just need to change one line in the program of problem 1).

    1. Write a function using recursion that takes in a string and returns a reversed copy of the string. The only string operation you are allowed to use is string concatenation.
  • 6. Write a function using recursion to check if a number n is prime (you have to check whether n is divisible by any number below n).

  • 7. Write a recursive function that takes in one argument n and computes Fn, the nth value of the Fibonacci sequence. Recall that the Fibonacci sequence is defined by the relation Fn = Fn−1 + Fn−2

www.cs.cornell.edu

  • Q2. Outline, but do not implement, a recursive solution for finding the smallest value in an array.

  • Q4. Outline, but do not implement, a recursive solution for generating all subsets of the set {1, 2, . . . , n}.

  • Q5. Write a recursive definition of xn, where n ≥ 0, similar to the recursive definition of the Fibonacci numbers. Hint: How do you compute xn from xn – 1? How does the recursion terminate?

  • Q6. Write a recursive definition of n! = 1 × 2 × . . . × n, similar to the recursive definition of the Fibonacci numbers.

RecursionPracticeQuestions-UG1

  • 4. Find the sum of the integers from 1 through n. Use recursion.
  • 5. Find the product of the integers from 1 through n (this is called the factorial function). If n is zero, return 1. Use recursion.
  • 6. Count the number of zeros in an array of integers. Use recursion.
  • 7. Find the minimum element in an array of integers. Use recursion.
    1. Write a function for mutliply(a, b), where a and b are both positive integers, but you can only use the + or − operators.
  • 9. Find Greatest Common Divisor (GCD) of 2 numbers using recursion.
  • 10. Write a recursive function to reverse a string. Write a recursive function to reverse the words in a string, i.e., ”cat is running” becomes ”running is cat”.
    1. A word is considered elfish if it contains the letters: e, l, and f in it, in any order. For example, we would say that the following words are elfish: whiteleaf, tasteful, unfriendly, and waffles, because they each contain those letters. Write a function that, given a word, tells us if that word is elfish or not. Hard version: Write another function x-ish, that, given two words, returns true if all the letters of the first word are contained in the second.

2_113_Programming Exercise 2016-17

9.2. C Program to Multiply two Matrices using Recursion 9.3. C Program to calculate sum of numbers 1 to N using recursion 9.4. Find Sum of Digits of the Number using Recursive Function in C Programming 9.5. C Program to print Tower of Hanoi using recursion 9.6. Find Factorial of Number Using Recursion

recursive For loop:

void FOR(int i, int n) {
    if(i==n) return; // terminates
    // do whatever needed
    FOR(i+1, n); // go to next step
}

ref·er·ence

recursion's People

Contributors

cmabdullah avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.