Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Hello..i have a set of different correct integers and a series of this numbers is required so that the difference between two consecutive numbers is either one increase or minus one for example: i have the following numbers: 1 , 2 , 2 , 1 , 3 , 4 , 4 , 5 , 5 , 6
it becomes : 1 , 2 , 1 , 2 , 3 , 4 , 5 , 4 , 5 , 6
or becomes: 1 , 2 , 1 , 2 , 3 , 4 , 5 , 6 , 5 , 4
and this set of numbers has no solution :1 , 1 , 2 , 2 , 3 , 4 , 4 , 5 , 5 , 7
now i want to write a backtracking algorithm to find all possible solution to this issue... anyone can help me

What I have tried:

I tried a lot but did not find a solution
Posted
Updated 30-May-18 0:15am
v2

Quote:
anyone can help me

No because the help you want is "Do my HomeWork"
HomeWork problems are simplified versions of the kind of problems you will have to solve in real life, their purpose is learning and practicing.
We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help your teacher spot your weaknesses and set remedial actions.
Any failure of you will help you to learn what works and what don't, it is called 'trial and error' learning.
So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.

Show your work and explain what is you exact problem.
Quote:
I tried a lot but did not find a solution

Backtracking algorithm is not complicated, it is trial and error.
You start to compose a solution 1 number at the time, when you reach a point where you have no possible number, you have to go back to previous step and try another number.
Backtracking - Wikipedia[^]
 
Share this answer
 
v3
Comments
CPallini 30-May-18 6:14am    
5.
Patrice T 30-May-18 6:20am    
Thank you
My solution is very short, since I'm not providing a code solution for your question. Normally, you will *NOT* need any of backtracking algorithms. Instead, you'll have to use a classical genetic algorithm (GA) to produce sets of solutions (i.e. numbers). Make sure that you'll find and use objective fitness function to select that exactly correspond to the results you're expecting to obtain as just you've listed in your question. :)
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900