Algorithms Recursion Kia Ha Or Ye Kese Kam Karta Ha:
Slam dusto! kese hain ap sab log mujhe umeed ha ap sab log kharyat say hon gay or market say acha munafa kar rahy hon gay. Aj main algorithm direct recursion bar bar karon ga or bata on ga kay algorithm direct recursion kia ha. Chaly agaz karty hain. Agar ek function apne function body mein baar baar khud ko call karta hai toh use algorithm direct recursive kaha jaata hai. Is definition ko behtar samajhne ke liye direct recursive program ki structure dekhein. Is program mein aapke paas fun naam ka ek method hai jo apne function body mein phir se khud ko call karta hai. Isliye aap keh sakte hain ki ye direct recursive hai.
Algorithect Recursion Recursion jisme function:
Recursion jisme function ek aur function ke through khud ko call karta hai, use indirect recursion kehte hain. Ab, indirect recursive program ki structure dekhein. int fun1(int z){int fun2(int y) {fun2(z-1) fun1(y-2)}
Example:
Is example mein aap dekh sakte hain ki fun1 function explicitly fun2 ko call kar raha hai, jo phir se fun1 ko invoke kar raha hai. Isliye aap keh sakte hain ki ye indirect recursion ka ek example hai.
Memory Allocation of Recursive Method:
Har recursive call stack memory par function ka naya copy generate karta hai. Jab procedure kuch data return karta hai, tab copy storage se delete ho jaati hai. Har recursive call apne aap ko alag stack maintain karta hai kyunki saare parameters aur dusre variables jo functions ke andar define hote hain, wo stack par rakhe jaate hain. Stack us function se return huye value ke baad delete ho jaata hai.
Slam dusto! kese hain ap sab log mujhe umeed ha ap sab log kharyat say hon gay or market say acha munafa kar rahy hon gay. Aj main algorithm direct recursion bar bar karon ga or bata on ga kay algorithm direct recursion kia ha. Chaly agaz karty hain. Agar ek function apne function body mein baar baar khud ko call karta hai toh use algorithm direct recursive kaha jaata hai. Is definition ko behtar samajhne ke liye direct recursive program ki structure dekhein. Is program mein aapke paas fun naam ka ek method hai jo apne function body mein phir se khud ko call karta hai. Isliye aap keh sakte hain ki ye direct recursive hai.
Algorithect Recursion Recursion jisme function:
Recursion jisme function ek aur function ke through khud ko call karta hai, use indirect recursion kehte hain. Ab, indirect recursive program ki structure dekhein. int fun1(int z){int fun2(int y) {fun2(z-1) fun1(y-2)}
Example:
Is example mein aap dekh sakte hain ki fun1 function explicitly fun2 ko call kar raha hai, jo phir se fun1 ko invoke kar raha hai. Isliye aap keh sakte hain ki ye indirect recursion ka ek example hai.
Memory Allocation of Recursive Method:
Har recursive call stack memory par function ka naya copy generate karta hai. Jab procedure kuch data return karta hai, tab copy storage se delete ho jaati hai. Har recursive call apne aap ko alag stack maintain karta hai kyunki saare parameters aur dusre variables jo functions ke andar define hote hain, wo stack par rakhe jaate hain. Stack us function se return huye value ke baad delete ho jaata hai.
تبصرہ
Расширенный режим Обычный режим