Re: [algogeeks] Facebook question!
A solution in java without arrays... class Combinations { static ArrayListString words = new ArrayListString(); static void getCombinations(ArrayListString words) { for(int j=0;jwords.length;word++) { //find the index of the word String word = words.get(j); //for each words, get the combinations for words AFTER IT for (int i=0;iword.length;word++){ //iterate thru the reamining words for(int m=j;mwords.size()-1;m++){ //get the next word String combWord =words.get(m); //now combine it with current 'LETTER' of this WORD for(int k=0;kcombWord.length;k++) { System.out.println(word.charAt(i)+combWord.charAt(k)); } } } } } public static void main (String args[]) { words.add(ace); words.add(bowl); words.add(put); getCombinations(words); } } On Monday, October 1, 2012 8:47:48 AM UTC-7, ((** VICKY **)) wrote: No we don't need to care about repeated strings. :) Thanks for the response folks. On Mon, Oct 1, 2012 at 8:42 PM, saurabh agrawal saura...@gmail.comjavascript: wrote: Do we need to handle cases when the same string will appear again?? In that case we can sort individual array and remove duplicates. On Mon, Oct 1, 2012 at 9:54 AM, Rahul Singh riit...@gmail.comjavascript: wrote: check this out.. #includeiostream #includestdlib.h using namespace std; void print_sets(string *s,int pos,int n,char *to_print) { if(pos==n) { return; } for(int i=0;is[pos].length();i++) { to_print[pos] = s[pos][i]; print_sets(s,pos+1,n,to_print); if(pos==n-1) { for(int j=0;jn;j++)coutto_print[j]; coutendl; } } return; } int main() { int n; cinn; string s[n]; for(int i=0;in;i++) { cins[i]; } char *to_print = new char[n]; print_sets(s,0,n,to_print); } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algo...@googlegroups.comjavascript: . To unsubscribe from this group, send email to algogeeks+...@googlegroups.com javascript:. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algo...@googlegroups.comjavascript: . To unsubscribe from this group, send email to algogeeks+...@googlegroups.com javascript:. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Cheers, Vicky -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/MbGDQZ6k2NEJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Facebook question!
check this out.. #includeiostream #includestdlib.h using namespace std; void print_sets(string *s,int pos,int n,char *to_print) { if(pos==n) { return; } for(int i=0;is[pos].length();i++) { to_print[pos] = s[pos][i]; print_sets(s,pos+1,n,to_print); if(pos==n-1) { for(int j=0;jn;j++)coutto_print[j]; coutendl; } } return; } int main() { int n; cinn; string s[n]; for(int i=0;in;i++) { cins[i]; } char *to_print = new char[n]; print_sets(s,0,n,to_print); } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Facebook question!
check this out.. #includeiostream #includestdlib.h using namespace std; void print_sets(string *s,int pos,int n,char *to_print) { if(pos==n) { return; } for(int i=0;is[pos].length();i++) { to_print[pos] = s[pos][i]; print_sets(s,pos+1,n,to_print); if(pos==n-1) { for(int j=0;jn;j++)coutto_print[j]; coutendl; } } return; } int main() { int n; cinn; string s[n]; for(int i=0;in;i++) { cins[i]; } char *to_print = new char[n]; print_sets(s,0,n,to_print); } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Facebook question!
Do we need to handle cases when the same string will appear again?? In that case we can sort individual array and remove duplicates. On Mon, Oct 1, 2012 at 9:54 AM, Rahul Singh riit1...@gmail.com wrote: check this out.. #includeiostream #includestdlib.h using namespace std; void print_sets(string *s,int pos,int n,char *to_print) { if(pos==n) { return; } for(int i=0;is[pos].length();i++) { to_print[pos] = s[pos][i]; print_sets(s,pos+1,n,to_print); if(pos==n-1) { for(int j=0;jn;j++)coutto_print[j]; coutendl; } } return; } int main() { int n; cinn; string s[n]; for(int i=0;in;i++) { cins[i]; } char *to_print = new char[n]; print_sets(s,0,n,to_print); } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Facebook question!
void combination(char str[2][100],int len,int row,int j) { static char prn[3]; int i=0,k=0,p=0; if(j==2) { prn[j]='\0'; printf(\n%s,prn); } for(p=row;plen;p++) { for(k=0;kstrlen(str[row]);k++) { prn[j]=str[row][k]; combination(str,len,p+1,j+1); } } } call : combination(str,len,0,0);// len = number of words in your eg call will be combination(str,2,0,0); On 9/30/12, ~*~VICKY~*~ venkat.jun...@gmail.com wrote: Given 'n' arrays each of variable sizes. Write code to print all combinations. Each combination contains one element from one array each. For eg: string str[]={hello, how} op will be hh ho hw eh eo ew lh lo lw lh lo lw oh oo ow 15 sets would come, includes repetition. My approach had bugs and didn't work. Help would be appreciated. -- Cheers, Vicky -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Facebook question!
my prev code was incorrect :- here is the correct code :- void combination(char str[3][100],int len,int row,int j) { static char prn[3]; int i=0,k=0,p=0; if(j==2) { prn[j]='\0'; printf(\n%s,prn); return; } for(p=row;plen;p++) { for(k=0;kstrlen(str[p]);k++) { prn[j]=str[p][k]; combination(str,len,p+1,j+1); } } } call : combination(str,len,0,0); // len = number of words for input : str[3][100]={hello,how,a}; output :- hh ho hw ha eh eo ew ea lh lo lw la lh lo lw la oh oo ow oa ha oa wa On 10/1/12, ~*~VICKY~*~ venkat.jun...@gmail.com wrote: Hi atul, Thanks for your response. I found your idea matches very much with my approach which i claimed buggy. The problem in my code is that It prints some extra strings in the end. For eg for the below input it prints 24(5*3+3*3) comb instead of 15(5*3). I couldn't recognize how to resolve it. Could any1 help me out. #includeiostream #includestring #includecstdio string str[]={hello, how,a}; void print_all(string sel, int k,int n) { if(k == n){ static int count =1; coutcount++ selendl; return; } for(int i = k; i n ; i++) { for(int j = 0; j str[i].length(); j++) { print_all(sel+str[i][j], k+1,n); } } } int main() { print_all(,0,2); } //code ends On Mon, Oct 1, 2012 at 12:33 AM, atul anand atul.87fri...@gmail.com wrote: void combination(char str[2][100],int len,int row,int j) { static char prn[3]; int i=0,k=0,p=0; if(j==2) { prn[j]='\0'; printf(\n%s,prn); } for(p=row;plen;p++) { for(k=0;kstrlen(str[row]);k++) { prn[j]=str[row][k]; combination(str,len,p+1,j+1); } } } call : combination(str,len,0,0);// len = number of words in your eg call will be combination(str,2,0,0); On 9/30/12, ~*~VICKY~*~ venkat.jun...@gmail.com wrote: Given 'n' arrays each of variable sizes. Write code to print all combinations. Each combination contains one element from one array each. For eg: string str[]={hello, how} op will be hh ho hw eh eo ew lh lo lw lh lo lw oh oo ow 15 sets would come, includes repetition. My approach had bugs and didn't work. Help would be appreciated. -- Cheers, Vicky -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Cheers, Vicky -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Facebook Question
@UTKARSH SRIVASTAV Give the implemetation logic instead of the name of the DS . -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Facebook Question
Find the distance between each of the points and the origin(0,0) and sort the points based on this distance. Also, divide the points based on which quadrant they belong. If the difference between their distance(from origin) between 2 points is less and they belong to the same quadrant, then they are likely to be close. So, instead of comparing each point with every other point as in the O(N^2) solution. We can compare a given point only with a subset of points that appear to be close. On Wed, Dec 21, 2011 at 1:00 AM, SAMMM somnath.nit...@gmail.com wrote: You are given a list of points in the plane, write a program that outputs each point along with the three other points that are closest to it. These three points ordered by distance. The order is less then O(n^2) . For example, given a set of points where each line is of the form: ID x-coordinate y-coordinate 1 0.0 0.0 2 10.1 -10.1 3 -12.212.2 4 38.3 38.3 5 79.99 179.99 Your program should output: 1 2,3,4 2 1,3,4 3 1,2,4 4 1,2,3 5 4,3,1 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Facebook Question
@Algoose, in worst case, this is still O(n^2), ain't it? On Wed, Dec 21, 2011 at 12:50 PM, Algoose chase harishp...@gmail.comwrote: Find the distance between each of the points and the origin(0,0) and sort the points based on this distance. Also, divide the points based on which quadrant they belong. If the difference between their distance(from origin) between 2 points is less and they belong to the same quadrant, then they are likely to be close. So, instead of comparing each point with every other point as in the O(N^2) solution. We can compare a given point only with a subset of points that appear to be close. On Wed, Dec 21, 2011 at 1:00 AM, SAMMM somnath.nit...@gmail.com wrote: You are given a list of points in the plane, write a program that outputs each point along with the three other points that are closest to it. These three points ordered by distance. The order is less then O(n^2) . For example, given a set of points where each line is of the form: ID x-coordinate y-coordinate 1 0.0 0.0 2 10.1 -10.1 3 -12.212.2 4 38.3 38.3 5 79.99 179.99 Your program should output: 1 2,3,4 2 1,3,4 3 1,2,4 4 1,2,3 5 4,3,1 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Facebook Question
Yup, it could be O(n^2) in the worst case. On Wed, Dec 21, 2011 at 1:59 PM, Carol Smith carol.interv...@gmail.comwrote: @Algoose, in worst case, this is still O(n^2), ain't it? On Wed, Dec 21, 2011 at 12:50 PM, Algoose chase harishp...@gmail.comwrote: Find the distance between each of the points and the origin(0,0) and sort the points based on this distance. Also, divide the points based on which quadrant they belong. If the difference between their distance(from origin) between 2 points is less and they belong to the same quadrant, then they are likely to be close. So, instead of comparing each point with every other point as in the O(N^2) solution. We can compare a given point only with a subset of points that appear to be close. On Wed, Dec 21, 2011 at 1:00 AM, SAMMM somnath.nit...@gmail.com wrote: You are given a list of points in the plane, write a program that outputs each point along with the three other points that are closest to it. These three points ordered by distance. The order is less then O(n^2) . For example, given a set of points where each line is of the form: ID x-coordinate y-coordinate 1 0.0 0.0 2 10.1 -10.1 3 -12.212.2 4 38.3 38.3 5 79.99 179.99 Your program should output: 1 2,3,4 2 1,3,4 3 1,2,4 4 1,2,3 5 4,3,1 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Facebook Question
@harish What if all the points are in the same quadrant and and are equidistant from 0,0. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/NjysUthIqgYJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Facebook Question
to find all points which lies on the same quadrant for a specific node(say 1) , we have to check all nodes...rite?? we have to find difference b/w 2 node(frome origin ) is less or greater than distance b/w 2 nodes...rite?? so if i am not getting it wrong it wil be O(n^2) anyhow. On Thu, Dec 22, 2011 at 8:14 AM, rahul rahul...@gmail.com wrote: @harish What if all the points are in the same quadrant and and are equidistant from 0,0. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/NjysUthIqgYJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Facebook Question
use k-d tree On Thu, Dec 22, 2011 at 9:25 AM, atul anand atul.87fri...@gmail.com wrote: to find all points which lies on the same quadrant for a specific node(say 1) , we have to check all nodes...rite?? we have to find difference b/w 2 node(frome origin ) is less or greater than distance b/w 2 nodes...rite?? so if i am not getting it wrong it wil be O(n^2) anyhow. On Thu, Dec 22, 2011 at 8:14 AM, rahul rahul...@gmail.com wrote: @harish What if all the points are in the same quadrant and and are equidistant from 0,0. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/NjysUthIqgYJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *UTKARSH SRIVASTAV CSE-3 B-Tech 3rd Year @MNNIT ALLAHABAD* -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.