Re: [algogeeks] Linkedlist problem
if(nodeptr) { } On Mon, Sep 5, 2011 at 5:29 PM, $hr! k@nth srithb...@gmail.com wrote: Hi guyz, *Given only a pointer to a node to be deleted in a singly linked list, how do you delete it?* if that node is in between the list, we can copy the data from next node into this node and we can delete the next node. what if the node to be deleted is last node ?? if the list is circular linked list, does it make any difference?? -- Regards, $hr!k@nth -- 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] Print Hello infinite..................
int main(void) { inf_times: printf(Hello); goto inf_times; return 0; } On Fri, Mar 11, 2011 at 7:46 PM, UMESH KUMAR kumar.umesh...@gmail.comwrote: Hi my question is without Loop and Recursion function using??? On Fri, Mar 11, 2011 at 5:40 AM, Abhishek Mallick abhishek.mallick2...@gmail.com wrote: #include stdio.h int main() { while(printf(Hello)); return 0; } On Thu, Mar 10, 2011 at 11:58 AM, Nishant Agarwal nishant.agarwa...@gmail.com wrote: #includestdio.h void print1(); void print2() { printf(Hello\n); print1(); } void print1() { printf(Hello\n); print2(); } int main() { print1(); } On Thu, Mar 10, 2011 at 11:47 AM, nidhi jain nidhi.jain311...@gmail.com wrote: @abhishek:isn't it recursion? -- 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. -- 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: c output
The only gurantee in this is that the outer printf result will come first. Why ? because comma operator does not act as sequence point. -Arun prasath N On Sat, Jun 12, 2010 at 3:44 PM, divya jain sweetdivya@gmail.comwrote: thanks to all for explanantions :) On 12 June 2010 15:43, divya jain sweetdivya@gmail.com wrote: one of my frnd askd me this question... On 11 June 2010 21:34, Raj N rajn...@gmail.com wrote: @kirubakaran: How can it be 1,1 ? No of characters read in a is 5+ 1 for '\n' so its 6 and for the next one 1+1=2 On Fri, Jun 11, 2010 at 9:09 AM, kirubakaran kirubakaran1...@gmail.comwrote: Output will be 1,1 bcoz printf returns number of characters or integers printed On Jun 11, 12:26 am, divya sweetdivya@gmail.com wrote: #include stdio.h main() { int a = 1; char b='c'; int i,j; printf(%d,%d,printf(%d\n,a),printf(%c\n,b)); wat shd b the o/p of this..plzz explain y? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@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] a google question
The nature of the problem involves inserting some elements in heap and retriving back ..It could be solved in worst case O(n * lg(n)). Average case O(n) solution is not there I believe. -Arun prasath N On Fri, Apr 30, 2010 at 5:35 PM, divya sweetdivya@gmail.com wrote: Given two sorted postive integer arrays A(n) and B(n) (W.L.O.G, let's say they are decreasingly sorted), we define a set S = {(a,b) | a \in A and b \in B}. Obviously there are n^2 elements in S. The value of such a pair is defined as Val(a,b) = a + b. Now we want to get the n pairs from S with largest values. The tricky part is that we need an O(n) algorithm. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@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] tree from linked list
This does not create a balanced tree but ensures that every element in the tree is accessible by lg(n) time. Time : Complexity O(n) [a...@91blore-srv1 ~]$ cat recursion.c #include stdlib.h #includeunistd.h #include stdio.h #define TEST2 #ifdef TEST1 int arr[] = { 1,2,3,4,5,6,7}; int max_elems = sizeof(arr)/sizeof(arr[0]); #endif #ifdef TEST2 int arr[] = { 1,2,3,4,5}; int max_elems = sizeof(arr)/sizeof(arr[0]); #endif #ifdef TEST3 int arr[] = { 1,2,3,4,5,6,7,8}; int max_elems = sizeof(arr)/sizeof(arr[0]); #endif #define LIST_EMPTY -1 struct tree { int data; struct tree * left,* right; }; struct tree* function( int , int); void print_inorder( struct tree *); int return_next_from_list(void) { static int nxt_elem = 0; if(nxt_elem max_elems) return arr[nxt_elem++]; return LIST_EMPTY;// empty condition } int main() { unsigned int x = max_elems; struct tree* head; while( x (x - 1) ) { x = x (x - 1) ; } head = function(0, x); print_inorder(head); free(head); return 0; } struct tree* function(int mid, int i) { int val = mid + i ; if (val 1) { struct tree * leaf = malloc( sizeof(struct tree) ); leaf-left = leaf-right = NULL; leaf-data = return_next_from_list(); if(leaf-data == LIST_EMPTY) { free(leaf); return NULL; } return leaf; } struct tree *non_leaf = malloc( sizeof(struct tree) ) ; non_leaf-left = function( mid, i/2); non_leaf-data = return_next_from_list(); if (non_leaf-data == LIST_EMPTY) { struct tree *tmp = non_leaf-left; free(non_leaf); return tmp; } non_leaf-right = function( mid+i, i/2); return non_leaf; } void print_inorder( struct tree* root) { struct tree * trav = root; if (!trav) { return; } print_inorder(trav-left); if(trav-left) free(trav-left); printf({%d}, trav-data); print_inorder(trav-right); if(trav-right) free(trav-right); } [a...@91blore-srv1 ~]$ On Sun, May 2, 2010 at 6:38 PM, divya sweetdivya@gmail.com wrote: u are given a sorted lnked list construct a balanced binary search tree from it. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@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:
144 On Tue, Jun 2, 2009 at 3:00 PM, Aminooo~ amin...@gmail.com wrote: *Dear Friends,* * * *A question for the genius, the one who solve the problem will write the name in the attached file.* *IF; 2+3=10* * 7+2=63* * 6+5=66* * 8+4=96* *THEN;* * 9+7=???* *The answer is the password to open the file attached* * * * * *Best Regards* *Aminooo.com* http://www.aminooo.com --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
[algogeeks] Re: whether 2 lists produce identical BST's or not?
Recursion based on the above 3 stmt won't work . * how do we know the root in level i , where i belongs to {0,1,...depth-1} . It looks like a problem of isomorphism how do we check for it without constructing a tree. Arun prasath N On Nov 3, 3:16 am, Arun [EMAIL PROTECTED] wrote: i think either me or u have misunderstood the problem. A list can be transformed to serveral BSTsA list will give only one BST. (First node is always root). There is only one way of consrtucting a BST. Isnt it? Again this will be badly balanced depending the order of elements in the list. And I believe the right solution should be the same way arun kumar manickan provided. Its time complexity can be reduce to O(n) by comparing the orders of each lists(String in former post is a type error).this is wat i meant in my prev. mail :) although i think his second condition is redundant. I dont know, how u can achieve this O(n). O(n^2) is easy and maybe O(nlgn) by tweaking a sorting algorithm. On 11/2/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: A list can be transformed to serveral BSTs (If the number of elements is n, then you can caculate the numbers of its BSTs). But, if we chose a specified method or process (just as ravi supposed) to construct the BST, then it will be unique. I have the same opinion with Vijendra Singh. He said If the two lists have same elements, then these *can* produce identical BSTs. as for any list, there are number of ways to construct a BST, And I believe the right solution should be the same way arun kumar manickan provided. Its time complexity can be reduce to O(n) by comparing the orders of each lists(String in former post is a type error). I will put my program tomorrow in my time, as now I am kinda busy. On Nov 2, 5:17 pm, Arun [EMAIL PROTECTED] wrote: In fact, if two lists have identical elements, they have identical BSTsets. this is not correct. its order sensitive. if u see his example L1 and L3 cannot be simply compared like strings. There can be many ways to have the same elements given in slightly different order yet produce the same BST. Im not sure why Ravi doesnt want to construct the BST. That wud give O(n) time easily. (but also O(n) memory) For now, the only way I can think of, is by actually constructing the BST in some form. Another way (O(n^2) time ) without constructing the BST can be formed by making this observation: For an element L[i] in the list , see the next smaller element than L[i]. Call it L[j] . If in both the lists for all i, order of L[i] and its corresponding L[j] are same (that is either L[i] comes first then L[j] or otherwise) then the lists give the same BST. Sorry ,its hard for me to picturise it here. Correct me if this is wrong :) On 11/2/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: :). Apparently, Ravi has an assumption that each BST should be constructed with same method. And the first one is choosen as a root. In fact, if two lists have identical elements, they have identical BST sets. At least, if we focus on Ravi's problem, this problem will be reduced to order comparison between two strings. And it can be handled in O(N). On Nov 1, 2:23 pm, Vijendra Singh [EMAIL PROTECTED] wrote: Oh ok.. I got confused... lemme think about this one. I think it has a recursive soltuion but will confirm it. -Vijju On 11/1/06, ravi [EMAIL PROTECTED] wrote: I think u have misunderstood the question. I am not asking about the two lists have identical elements or not? If we have two lists then how will we check whther two lists produce identical BSTs or not? For example L1 = { 10, 5, 15 } L2 = { 5 , 10, 15 } L3 = { 10, 15, 5 } L1, L2, L3 all have identical elements. But only L1, L3 will produce identical BSTs. L1, L3 produce tree as10 515 L2 produce BST as 5 10 15 I think now the question is clear?- Hide quoted text -- Show quoted text - --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups-beta.google.com/group/algogeeks -~--~~~~--~~--~--~---