Jump to content

Algorithms Lo Dhitamga Unnavalu Unnara


Recommended Posts

Posted

1. Need code for tortoise and hare algorithm
2. Given an array of numbers find the subsets whose sum is zero.

Posted

Google it.... direct ga answers dorukuthayi.... ivi chala common questions.....

Posted

subset problem NP complete storing previous values lo problems vastunnayi

Posted

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());
}
}
}

  • Upvote 1
Posted

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]

×
×
  • Create New...