Pages

Thursday, May 22, 2025

What is recursion? in C++

 Recursion:

A function that repeatedly calls itself.


CODE:

#include<iostream>

using namespace std;

// recursive function -> recursion..

void func() {
cout << "function call...work\n";

func(); // calls itself 

}


int main() {
func();

return 0;

}


OUTPUT:-

function call..work


function call..work


function call..work


function call..work


function call..work

...

.

..

infinite times, until a base case is declared(Smallest problem, where solution is known)..

No comments:

Post a Comment

3917. Count Indices With Opposite Parity (Brute Force) O(n2) + Optimized Solution O(n) + tips LEETCODE WEEKLY 500

  class Solution {     public int [] countOppositeParity ( int [] nums ) {          // approach 1 - checks every pair         int n = n...