Guillaume Posted October 15, 2012 Author Report Posted October 15, 2012 1. Need code for tortoise and hare algorithm 2. Given an array of numbers find the subsets whose sum is zero.
Thingarodu Posted October 15, 2012 Report Posted October 15, 2012 Google it.... direct ga answers dorukuthayi.... ivi chala common questions.....
Guillaume Posted October 15, 2012 Author Report Posted October 15, 2012 subset problem NP complete storing previous values lo problems vastunnayi
Thingarodu Posted October 15, 2012 Report Posted October 15, 2012 Google lo vethkithe below code dorikindhi.... run it and see how it works.... also geeksforgeeks lo direct question idi.... static void findNumbers(int[] list, int index, int current, int goal, string result) { if (list.Length < index || current>goal) return; for (int i = index; i < list.Length; i++) { if (current + list[i] == goal) { Console.WriteLine(result + " " + list[i].ToString()); } else if (current + list[i] < goal) { findNumbers(list, i + 1, current + list[i], goal, result + " " + list[i].ToString()); } } } 1
Guillaume Posted October 15, 2012 Author Report Posted October 15, 2012 thanks mama bu this checks for only two numbers from 1st to end subsets consider cheyadu thanks 4r de pointers [quote name='Thingarodu' timestamp='1350268447' post='1302629900'] Google lo vethkithe below code dorikindhi.... run it and see how it works.... also geeksforgeeks lo direct question idi.... static void findNumbers(int[] list, int index, int current, int goal, string result) { if (list.Length < index || current>goal) return; for (int i = index; i < list.Length; i++) { if (current + list[i] == goal) { Console.WriteLine(result + " " + list[i].ToString()); } else if (current + list[i] < goal) { findNumbers(list, i + 1, current + list[i], goal, result + " " + list[i].ToString()); } } } [/quote]
Recommended Posts