Re: [algogeeks] Re: spoj problem
don't bother got AC was doing lot of extra overhead -- Amol Sharma Third Year Student Computer Science and Engineering MNNIT Allahabad http://gplus.to/amolsharma99 http://twitter.com/amolsharma99http://in.linkedin.com/pub/amol-sharma/21/79b/507http://youtube.com/amolsharma99 On Fri, Nov 18, 2011 at 1:53 PM, Amol Sharma amolsharm...@gmail.com wrote: hi all, i implemented the same problem with bfs but i'm getting TLE.plz tell how to reduce my running time my code is as follows... #includecstdio #includeiostream #includevector #includealgorithm #includecmath #includequeue using namespace std; int main() { int i,f,s,g,u,d;//f=no. of floors,s=start,g=goal,u=up,d=down scanf(%d%d%d%d%d,f,s,g,u,d); if(s==g) { printf(0\n); return 0; } vector vectorint v(f+1);//v[1] represents floors reachable from 1st floor..till v[f] //first task is to build the graph using no. of floor,up and down for(i=1;i=f;i++) { if( (i+u)=f ) v[i].push_back(i+u); if( (i-d)=1 ) v[i].push_back(i-d); } //graph created //now apply bfs from start node and check if we can reach goal...if yes then in how many steps.. queueint q; vectorint p(f+1,0);//visited flag q.push(s);//s is the start vertex p[s]=1; vectorint::iterator it; vectorint a(f+1,0);//array containing distances a[s]=0; while(!q.empty()) { i=q.front(); //get tail element from the queue q.pop(); for(it=v[i].begin();it!=v[i].end();it++) { if( *it==g ) { printf(%d\n,a[i]+1); return 0; } if(!p[*it])//we have not visited this vertex yet { a[*it]=a[i]+1; p[*it]=1; q.push(*it); } } } printf(use the stairs\n); return 0; } -- Amol Sharma Third Year Student Computer Science and Engineering MNNIT Allahabad http://gplus.to/amolsharma99 http://twitter.com/amolsharma99http://in.linkedin.com/pub/amol-sharma/21/79b/507http://youtube.com/amolsharma99 On Thu, Nov 17, 2011 at 5:48 PM, Anshul AGARWAL anshul.agarwa...@gmail.com wrote: finally got AC,(using bfs) thanx DON for provide such nice test case *Anshul Agarwal Nit Allahabad Computer Science** * On Wed, Nov 16, 2011 at 8:14 PM, SAMMM somnath.nit...@gmail.com wrote: U need to check for the case when (s==g) source and destination are same , I got stuck here , after handling this case I got accepted :) -- 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.
[algogeeks] Networking Question
How many bytes of data can be sent in 15 seconds over a serial link with baud rate of 9600 inasynchronous mode with odd parity and two stop bits in the frame? a)10,000 bytes b)12,000 bytes c) 15,000 bytes d)27,000 bytes Plz anyone explain me. Vijay.. -- 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.
[algogeeks] Re: COA Question
Thanks!! On Nov 17, 11:32 pm, Dave dave_and_da...@juno.com wrote: d) Formal parameters, because they are in the definition of the macro. If they were in an invocation of a macro, they would be actual parameters, as in ADD a,b a and b are actual parameters, and the macro expands as LOAD b MUL a STORE b Where each instance of a formal parameter has been replaced by its actual parameter. Dave On Nov 17, 5:32 am, Vijay Khandar vijaykhand...@gmail.com wrote: What are x and y in the following macro definition? macro ADD x,y LOAD y MUL x STORE y end macro a) Variables b)Identifiers c)Actual Parameters d) Formal Parameters plz anyone explain. -- 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.
[algogeeks] Re: Computer Organisation Q
but why? On Nov 18, 9:14 am, ((** VICKY **)) venkat.jun...@gmail.com wrote: False not necessarily. On Nov 17, 4:03 pm, Vijay Khandar vijaykhand...@gmail.com wrote: Can anyone explain following sentence- True or False and explain All instructions affect the flags Vijay Khandar... -- 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.
[algogeeks] Reading till EOF in python
Can anyone tell how to read till the end of file in python language ? -- 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.
[algogeeks] Re: Referral program @InMobi
Post it in interviewstreet group On Nov 17, 10:35 pm, Raunak Agrawal raunak.ra...@gmail.com wrote: Hi All, Please find the job description attached and let me know if anyone is interested in any openings. And also please mention the post you wanna apply for. Some brief note about InMobi: *This is a mobile ad networking company which bridges the gap between an advertiser and the publisher. It has got over 450+ employees across the globe and its second to google admob in mobile network advertising. We have got a funding of of $200 M which is one of the highest funding in any IT company. Moreover we have good food and great ppl to work with :) You can find more details on linkedIn, Facebook,www.inmobi.com, twitter etc etc.* Thanks, Raunak inmobi_engineering.pdf 139KViewDownload -- 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] Reading till EOF in python
Though its obvious but still to add an explanation to complete the response.On detecting EOF EOFError is exception is returned.I am catching that using pythons exception handling(just like try catch in c++).In except block u can include the operations that should be performed on catching EOF.Hope the answer is complete enough On Fri, Nov 18, 2011 at 6:10 PM, saurabh singh saurab...@gmail.com wrote: try: while 1: i=input() print i except EOFError: a='' One possible way..dont know if there are other elegant ways of doing the same. -- Saurabh Singh B.Tech (Computer Science) MNNIT ALLAHABAD -- Saurabh Singh B.Tech (Computer Science) 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.
[algogeeks] COA Question
Relative mode of addressing is most relevant to writing a)coroutines b)position-independent code c)shareble code d)interrupt handlers plz anyone give me answer with explation... -- 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] Reading till EOF in python
try: while 1: i=input() print i except EOFError: a='' One possible way..dont know if there are other elegant ways of doing the same. -- Saurabh Singh B.Tech (Computer Science) 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.
Re: [algogeeks] Reading till EOF in python
Hi shady, this is how you do it.. while True: try: x = input() except EOFError: break On Fri, Nov 18, 2011 at 4:26 PM, shady sinv...@gmail.com wrote: Can anyone tell how to read till the end of file in python language ? -- 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. -- *Krishna Bharadwaj* *www.krishnabharadwaj.info | @krishbharadwajhttp://www.twitter.com/krishbharadwaj * -- 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] Reading till EOF in python
try except statement will do.. for example, try: a=int(input()) except EOFError: break ... your code here -- Amol Sharma Third Year Student Computer Science and Engineering MNNIT Allahabad http://gplus.to/amolsharma99 http://twitter.com/amolsharma99http://in.linkedin.com/pub/amol-sharma/21/79b/507http://youtube.com/amolsharma99 On Fri, Nov 18, 2011 at 4:26 PM, shady sinv...@gmail.com wrote: Can anyone tell how to read till the end of file in python language ? -- 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] Reading till EOF in python
thanks all. On Fri, Nov 18, 2011 at 4:30 PM, Krishna Bharadwaj krishna.bm...@gmail.comwrote: Hi shady, this is how you do it.. while True: try: x = input() except EOFError: break On Fri, Nov 18, 2011 at 4:26 PM, shady sinv...@gmail.com wrote: Can anyone tell how to read till the end of file in python language ? -- 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. -- *Krishna Bharadwaj* *www.krishnabharadwaj.info | @krishbharadwajhttp://www.twitter.com/krishbharadwaj * -- 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.
[algogeeks] Problem
Q: Select the K elements in an array of size N which are having the minimum difference among them? For Example : If you have an array like arr[]={9,5,2,6,3,11} and value of K is 3. Then ans would be {2,3,5}. -- 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] Re: deep vs shallow copy
http://geeksforgeeks.org/forum/topic/deep-copy-vs-shallow-copy On Fri, Nov 18, 2011 at 12:58 PM, Gene gene.ress...@gmail.com wrote: The most extreme shallow copy is just copying a pointer to a large data structure like a graph or tree. Deep copy is copying the entire data structure and returning a new pointer. Here is a more common example: typedef struct list { struct list *next; void *data; } LIST_NODE; In practice you'd want to code these as loops instead of recursion. But this gives the idea. LIST_NODE *shallow_copy(LIST_NODE *lst) { return lst ? new_list_node(shallow_copy(lst-next), data) : NULL; } LIST_NODE *deep_copy(LIST_NODE *lst) { return lst ? new_list_node(deep_copy(lst-next), data_copy(data)) : NULL; } Where data_copy is assumed to copy its argument into fresh memory and return a poionter and new_list_node returns a freshly allocated node with given fields. On Nov 18, 6:33 am, rahul sharma rahul23111...@gmail.com wrote: plz give me xample of these two .as per from book m not able to get thesw clearly,...i have reda from wiki and got it but cant relate with these...plz differ b/w these two with xample..thnx in advance a shallow copy of an object copies all the member field values.this works well if the fields are values,but may not be what we want for fields that point to dynamically allocsted value.The pointer will be copied.But memory it point will not be copied. a deep cpy copies all fields,and makes copies of dynamically allocated memory pointed to by the fields.. -- 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] Re: deep vs shallow copy
http://www.learncpp.com/cpp-tutorial/912-shallow-vs-deep-copying/ On Fri, Nov 18, 2011 at 8:30 PM, Dheeraj Jain dheerajj...@gmail.com wrote: http://geeksforgeeks.org/forum/topic/deep-copy-vs-shallow-copy On Fri, Nov 18, 2011 at 12:58 PM, Gene gene.ress...@gmail.com wrote: The most extreme shallow copy is just copying a pointer to a large data structure like a graph or tree. Deep copy is copying the entire data structure and returning a new pointer. Here is a more common example: typedef struct list { struct list *next; void *data; } LIST_NODE; In practice you'd want to code these as loops instead of recursion. But this gives the idea. LIST_NODE *shallow_copy(LIST_NODE *lst) { return lst ? new_list_node(shallow_copy(lst-next), data) : NULL; } LIST_NODE *deep_copy(LIST_NODE *lst) { return lst ? new_list_node(deep_copy(lst-next), data_copy(data)) : NULL; } Where data_copy is assumed to copy its argument into fresh memory and return a poionter and new_list_node returns a freshly allocated node with given fields. On Nov 18, 6:33 am, rahul sharma rahul23111...@gmail.com wrote: plz give me xample of these two .as per from book m not able to get thesw clearly,...i have reda from wiki and got it but cant relate with these...plz differ b/w these two with xample..thnx in advance a shallow copy of an object copies all the member field values.this works well if the fields are values,but may not be what we want for fields that point to dynamically allocsted value.The pointer will be copied.But memory it point will not be copied. a deep cpy copies all fields,and makes copies of dynamically allocated memory pointed to by the fields.. -- 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] Problem
If I'm right you want a subset which has k elements and the difference of the smallest and the largest element is minimum. You can do it in O( Nlog(N) ). *Sort input* in ascending order, then iterate through the array and keep the difference of the last k elements. O( nlogn + n ) belongs to O(nlogn) 2 3 5 6 9 11 two iterators, first on 2, second on 5, then each time ++ both iterators and check the difference of these two elements, pick the minimum among all these values. On Fri, Nov 18, 2011 at 5:00 PM, Zyro vivkum...@gmail.com wrote: Q: Select the K elements in an array of size N which are having the minimum difference among them? For Example : If you have an array like arr[]={9,5,2,6,3,11} and value of K is 3. Then ans would be {2,3,5}. -- 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. -- MeHdi KaZemI -- 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.
[algogeeks] Re: Problem
what do you mean by difference among them ? do we need to select the elements to minimize the sum between consecutive elements ? or only the first and last element ? On Nov 18, 6:30 pm, Zyro vivkum...@gmail.com wrote: Q: Select the K elements in an array of size N which are having the minimum difference among them? For Example : If you have an array like arr[]={9,5,2,6,3,11} and value of K is 3. Then ans would be {2,3,5}. -- 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.
[algogeeks] Re: Problem
sorry...minimize sum of the difference between the elements of the subset.. On Nov 19, 10:03 am, shady sinv...@gmail.com wrote: what do you mean by difference among them ? do we need to select the elements to minimize the sum between consecutive elements ? or only the first and last element ? On Nov 18, 6:30 pm, Zyro vivkum...@gmail.com wrote: Q: Select the K elements in an array of size N which are having the minimum difference among them? For Example : If you have an array like arr[]={9,5,2,6,3,11} and value of K is 3. Then ans would be {2,3,5}. -- 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.
[algogeeks] Re: Problem
The Sum of the difference in the Subset containing the K elements must be minimum... As in above example {9,5,2,6,3,11} where K=3 In case of {2,3,5} 3-2=1 5-3=2 sum of the difference is 3...In all other subsets we cant have sum of the difference less than 3...so {2,3,5} is the required answer. On Nov 19, 10:03 am, shady sinv...@gmail.com wrote: what do you mean by difference among them ? do we need to select the elements to minimize the sum between consecutive elements ? or only the first and last element ? On Nov 18, 6:30 pm, Zyro vivkum...@gmail.com wrote: Q: Select the K elements in an array of size N which are having the minimum difference among them? For Example : If you have an array like arr[]={9,5,2,6,3,11} and value of K is 3. Then ans would be {2,3,5}. -- 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.
[algogeeks] Time Complexity
What is the time complexity of this code for Level Order Traversal. void printLevel(BinaryTree *p, int level) { if (!p) return; if (level == 1) { cout p-data ; } else { printLevel(p-left, level-1); printLevel(p-right, level-1); } } void printLevelOrder(BinaryTree *root) { int height = maxHeight(root); for (int level = 1; level = height; level++) { printLevel(root, level); cout endl; } } My guess is NlogN if tree is balanced if not it will be N^2. -- 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.