In the recursive function problem, many people use an algorithm called segmentation conquest.
Stop and sum up by continuing to divide a big problem and get a full answer to a small one
I think it's called divisional conquest.
But I don't understand even if I look at the example.
I would appreciate it if you could give me a simple example and understand the concept.
c recursive
The following is an example of an array [3, 7, 6, 1, 9, 3, 2] with seven numbers in ascending order.
The problem, which used to be seven number alignment, has been simplified to be two number alignment (A) and four number alignment (B) problems. For arrays of A, you can also compare them immediately to determine the order because there are two numbers to sort.
At the end of Phase 2, when tied together, it looks like this.
(1, [2]), 3, ([6, 3], 7, [9])
Repeat the same operation until the generated array length becomes one.
1, (2), 3, ([3], 6), 7, 9
Ascending sort completed.
With this divisional conquest, you can break up big problems (difficult problems) into small problems (easy problems) and combine them to solve difficult problems only with easy problems.
Thank you.
Not all recursive functions are used to solve segmental conquests, and segmental conquests can only be implemented as recursive functions. Recursive functions are simply tools.
For example, if you're going to use a recursive function to create a program that inversely outputs an odd number of n or less, you can make it like this:
#include <stdio.h>
void oddPrint(int i);
int main(){
oddPrint(8);
return 0;
}
void oddPrint(int i){
if (i<0)
return;
if (i%2 != 0){
printf("%d\n",i);
}
i--;
oddPrint(i);
}
The segmentation and conquest problem can also be created in stages, such as Phase 1 and Phase 2, through a loop.
A recursive function is a function that simply calls itself.
The reason why we write segmentation conquest as a recursive function is that it's easy to teach about the usefulness of the recursive function and it's convenient to write segmentation conquest in a way that's easy for people.
In fact, I understand that recursion functions are not recommended because your computer is wasting a lot of resources.
Thank you.
Let me give you a simple example of everyday life.
I'm going to decide the first place among 32 teams.
Let's make two groups of 16 teams. The person who wins the first place in each group will be the winner.
Now, in each group,
I'm going to decide the winner out of 16 teams.
Let's make two groups of 8 teams. The person who wins the first place in each group will be the winner.
Now, in each group,
I'm going to decide the first place among the eight teams.
Let's make two groups of four. The person who wins the first place in each group will be the winner.
...
582 PHP ssh2_scp_send fails to send files as intended
621 Uncaught (inpromise) Error on Electron: An object could not be cloned
613 GDB gets version error when attempting to debug with the Presense SDK (IDE)
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
573 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
© 2024 OneMinuteCode. All rights reserved.