[algogeeks] MS Question
MS IDC interview question: Given a memory location say from 0 - 1023. Now there are many threads that are reading and writing in this memory locations at any time 0t 1t 2t ... and so on. For ex a thread no.4 is writing to memory location 512 at time 3t. So we get a quadruple {4,512,W,3t}. Suppose we have lot of quadruples for lots of threads.At any particular time we have to tell which of the threads are doing memory clash. Memory clash is defined as two thread accessing same memory location with time difference less than equal to 5 and atleast one of the thread is doing write operation. That interviewer didnt needed the code bt the approach.I first told him to hash the threads based on memory location and search for memory clash threads for that memory location,bt he was not understanding how it can be implemented for large no. of threads. -- *Dheeraj Sharma* -- 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] MS QUESTION_LINKED LIST
Correct me if am wrong.. i think we can use Stack as follows node * minFun(node *head) { stacknode * st; return fun(head,st); } node * fun(node *ptr,stacknode * st) { if(ptr) { node *x=fun(ptr-next,st); while(!st.empty() (ptr-data)(st.top()-data)) st.pop(); if(!st.empty()) ptr-high=st.top(); st.push(ptr); return (x?((ptr-data)(x-data)?ptr:x):ptr); } return NULL; } On Sun, Mar 25, 2012 at 12:20 AM, atul anand atul.87fri...@gmail.comwrote: after push(s,next) move head also head=head-next; On Sun, Mar 25, 2012 at 12:10 AM, atul anand atul.87fri...@gmail.comwrote: @all : i am getting this right , i guess given a linked list ...you need to point to next larger element. so if input linked list is 7 3 5 1 5 9 then nextLarger of each node will point as follows:- 3-5 1-5 5-9 7-9 9-NULL; i have no idea why the linked list is modified using merge sort... anywayzz if the expected output is similar to one i have mentioned above there this woud work using stack .. complexity O(n) n=number of nodes. findLarger(node *head) { s1 s; node *ele,*next; s.top=NULL; push(s,head); head=head-next; while(head!=NULL) { next-data=head-data; if(isEmpty(s)) { ele=pop(s); while(ele-data next-data) { ele-nextLarger=next; if(isEmpty(s)==0) { break; } ele=pop(s); } if(ele-data next-data) { push(s,ele); } } push(s,next); } On Sat, Mar 24, 2012 at 12:50 AM, Atul Singh atulsingh7...@gmail.comwrote: Given a linked list with each node having two pointers : one pointing to next node other to null; how will u point the second pointer to next larger no. and return the pointer to smallest node -- ATul Singh | Final Year | Computer Science Engineering | NIT Jalandhar | 9530739855 | -- 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. -- *Dheeraj Sharma* -- 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: Check if one tree is sub tree of other
Yeah..i wrote sumthig similar..i placed L for left null and R for right null..and then checked for substring in preorder traversal..i dont know if its correct or not.. On 3/21/12, atul anand atul.87fri...@gmail.com wrote: @amrit : i guess this will work. On Wed, Mar 21, 2012 at 1:51 PM, amrit harry dabbcomput...@gmail.comwrote: i have an idea to solve this. use preorder traversal and a sentinal(#) on the place of Null nodes. lets take a example Main tree 1 subtree 1 2 3 2 4 3 preorder travesal for Main: 12##34###for sub tree 12#3### now chk for the sub string in Main string one more case Main1 / \ 34 / \ 51 / \ 34 preorder traversal= 1353##4##1##4## sub 5 /\ 3 4 preorder traversal 53##4## now this substring exist in Main substring so it is a sub tree correct me if me wrong. Thanks Amrit On Wed, Mar 21, 2012 at 1:34 PM, amrit harry dabbcomput...@gmail.comwrote: @shady consider this case Main tree 1 subtree 1 2 3 2 4 3 preorder of Main= 1234 subtree= 123 but not subtree On Wed, Mar 21, 2012 at 1:24 PM, shady sinv...@gmail.com wrote: seems correct with pre-order traversal if not give some example On Wed, Mar 21, 2012 at 10:32 AM, Mahesh Thakur tmahesh...@gmail.comwrote: First Tree: 1 2 3 4 5 67 Inorder traverse will be : 4251637 Second Tree: 6 1 3 Inorder traversal is 163. But they second tree is not subset. let me know if i got the question wrong. On Wed, Mar 21, 2012 at 10:27 AM, shady sinv...@gmail.com wrote: @Sid +100 On Wed, Mar 21, 2012 at 10:20 AM, siddharam suresh siddharam@gmail.com wrote: get the inorder traversal both tree (into strings) check weather one string substring of other if yes then one tree is sub tree of other. Thank you, Sid. phone:+91-8971070727, +91-9916809982 On Wed, Mar 21, 2012 at 9:23 AM, HARSHIT PAHUJA hpahuja.mn...@gmail.com wrote: bool isSubtree(Tree * A,Tree *B) { if(!B) return true; if(!A)return false; if(A-data==B-data) return (isSubtree(A-left,B-left) isSubtree(A-right,B-right)); else return (isSubtree(A-left,B) isSubtree(A-right,B)); } } On Wed, Mar 21, 2012 at 2:33 AM, Don dondod...@gmail.com wrote: bool equals(node *t1, node *t2) { return (t1 t2) ? (t1-value == t2-value) equals(t1-left, t2- left) equals(t1-right, t2-right) : !t1 !t2; } bool check(node *t1, node *subtree) { return t1 ? equals(t1, subtree) || check(t1-left, subtree) || check(t1-right, subtree) : !subtree; } On average this is the same as a traversal, but worst case could be very slow. Imagine a large tree with millions of nodes, where all the nodes = 1, and a somewhat smaller subtree with 100,000 nodes=1 and one node at the far right of the tree = 2. It would require a lengthy comparision at each node which would ultimately find no matching sub tree. If they are binary search trees, it could be more efficient. Did you mean to ask about binary search trees? Don On Mar 20, 7:24 am, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: How to check if one binary tree is a sub tree of other? Any Solution other then bruteforce? Prototype bool check(node *t1,node *subtree) -- Sent from my mobile device *Dheeraj Sharma* -- 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. -- HARSHIT PAHUJA M.N.N.I.T. 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. -- 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
[algogeeks] Check if one tree is sub tree of other
How to check if one binary tree is a sub tree of other? Any Solution other then bruteforce? Prototype bool check(node *t1,node *subtree) -- Sent from my mobile device *Dheeraj Sharma* -- 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] Check if one tree is sub tree of other
How to check if one binary tree is a sub tree of other? Any Solution other then bruteforce? Prototype bool check(node *t1,node *subtree) -- Sent from my mobile device *Dheeraj Sharma* -- 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: Check if one tree is sub tree of other
Geeksforgeeks gives brute force approach @shady.. No its not..the sub tree should be a perfect sub tree..there should be no node below that sub tree in the main tree On 3/20/12, rahul sharma rahul23111...@gmail.com wrote: http://www.geeksforgeeks.org/archives/13942 then call for On Tue, Mar 20, 2012 at 7:16 PM, shady sinv...@gmail.com wrote: 5 /\ 3 4 is this subtree of 1 / \ 34 / \ 51 / \ 34 / 9 ? On Tue, Mar 20, 2012 at 5:54 PM, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: How to check if one binary tree is a sub tree of other? Any Solution other then bruteforce? Prototype bool check(node *t1,node *subtree) -- Sent from my mobile device *Dheeraj Sharma* -- 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. -- Sent from my mobile device *Dheeraj Sharma* -- 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: Check if one tree is sub tree of other
No..am nt talking about binary search tree..bt about binary tree.. It was asked in my amazon written @shady..doing the substring search..as we have to search for subset of tree..it searchng substrn might find some false nodes..that doesnt belong to that subtree On 3/21/12, Don dondod...@gmail.com wrote: bool equals(node *t1, node *t2) { return (t1 t2) ? (t1-value == t2-value) equals(t1-left, t2- left) equals(t1-right, t2-right) : !t1 !t2; } bool check(node *t1, node *subtree) { return t1 ? equals(t1, subtree) || check(t1-left, subtree) || check(t1-right, subtree) : !subtree; } On average this is the same as a traversal, but worst case could be very slow. Imagine a large tree with millions of nodes, where all the nodes = 1, and a somewhat smaller subtree with 100,000 nodes=1 and one node at the far right of the tree = 2. It would require a lengthy comparision at each node which would ultimately find no matching sub tree. If they are binary search trees, it could be more efficient. Did you mean to ask about binary search trees? Don On Mar 20, 7:24 am, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: How to check if one binary tree is a sub tree of other? Any Solution other then bruteforce? Prototype bool check(node *t1,node *subtree) -- Sent from my mobile device *Dheeraj Sharma* -- 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. -- Sent from my mobile device *Dheeraj Sharma* -- 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] Array problem
you have to calculate the sum of elements which are less than..that particular element...this is not the question of calculating cumulative sum On Wed, Mar 14, 2012 at 11:22 AM, sachin sabbarwal algowithsac...@gmail.com wrote: @gaurav popli: how about this one?? findsummat(int arr[],int n) { int *sum ; sum =(int*)malloc(sizeof(int)*n); for(int i=0;in;i++) sum[i] = 0; for(int i=0;in;i++) sum[i] = sum[i-1] + arr[i-1]; //now print the sum array } it works very well plz tell me if anything is wrong with this solution. On Tue, Mar 13, 2012 at 12:03 PM, atul anand atul.87fri...@gmail.comwrote: @piyush : sorry dude , didnt get your algo . actually you are using different array and i get confused which array to be considered when. On Mon, Mar 12, 2012 at 5:19 PM, Piyush Kapoor pkjee2...@gmail.comwrote: 1)First map the array numbers into the position in which they would be, if they are sorted,for example {30,50,10,60,77,88} --- {2,3,1,4,5,6} 2)Now for each number ,find the cumulative frequency of index ( = the corresponding number in the map - 1). 3)Output the cumulative frequency and increase the frequency at the position (=the corresponding number in the map) by the number itself. Example {3,5,1,6,7,8} Map of which would be {2,3,1,4,5,6} Process the numbers now, 1)3 comes ,find the cumulative frequency at index 1 ( = 2-1) which is 0. so output 0 Increase the frequency at index 2 to the number 3. 2)5 comes,find the CF at index 2( = 3-1) which is equal to 3 .output 3. Increase the frequency at index 3 to the number 5. 3)1 comes,CF at index 0 (=1-1) = 0 so output 0.increase the F at position 1 by 1. Similarly for others. -- 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. -- *Dheeraj Sharma* -- 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: Microsoft Interview Question
http://www.geeksforgeeks.org/archives/1155 On Tue, Mar 13, 2012 at 11:31 AM, Umer Farooq the.um...@gmail.com wrote: Yes that is exactly what they wanted. I proposed BFS for this solution. Anyway, there was another problem that I was able to solve; but the interviewer brought up a much more efficient approach. The problem was: - Given a linked a linked list with one pointer pointing to next, another pointer pointing to any random pointer in the list. The random pointer can be before or after the current pointer or it can even be at the same node. Write a piece of code that can produce an exact copy of the linked list. On Tue, Mar 13, 2012 at 10:57 AM, Umer Farooq the.um...@gmail.com wrote: Yes that is exactly what they wanted. I proposed BFS for this solution. Anyway, there was another problem that I was able to solve; but the interviewer brought up a much more efficient approach. The problem was: Given a linked l On Mon, Mar 12, 2012 at 11:31 PM, Gene gene.ress...@gmail.com wrote: Since there is no mention of weights, you are looking for any spanning tree. Primm and Kruskal are for _minimum_ spanning tree. They are overkill for this problem. You can construct a spanning tree in any graph with DFS. Just record every edge you find that reaches a vertex that has never been visited before. This has to find every vertex, and since you are recording only the first edge used to arrive at each vertex, these edges must form a tree. This works even if there are cycles. The algorithm is O(| E|). Note that in general a graph doesn't have a single root. So you'd search from all roots. Another way to think about this: introduce your own dummy root and edges to each vertex where there are no incident in edges. Of course you don't report the dummy edges. On Mar 12, 1:09 pm, atul anand atul.87fri...@gmail.com wrote: i guess they were talking abt spanning tree , so you can use prism or kruskal algo to do the same. On Mon, Mar 12, 2012 at 3:05 PM, Umer Farooq the.um...@gmail.com wrote: Hello friends, I recently had an onsite MS interview. One of the questions that they asked was: - Given a directed graph, write a program that takes root of the graph and returns root of a tree which comprises of all the nodes of the graph in the same way as they appeared in the graph (the graph contains no cycles). -- Umer -- 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. -- Umer -- Umer -- 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. -- *Dheeraj Sharma* -- 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] Array problem
we can use self balancing BST for this problem to yield the complexity O(nlogn) ..where every node will contain the sum of the node values on it left sub tree .. you can check this post..its pretty similar (Method 2) http://www.geeksforgeeks.org/archives/17235 On Mon, Mar 12, 2012 at 12:58 AM, Piyush Kapoor pkjee2...@gmail.com wrote: This can be done very easily with the help of a Binary Indexed Tree,and it is very short to code as well.Simply process the numbers in order,and for each number output the cumulative frequency of the index of the number you are processing. -- 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. -- *Dheeraj Sharma* -- 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: Array Problem
heres a O(n) solution.. correct me if am wrong.. 1. In order to get the count in O(1) we need to place the count of each number in their respective index.So before storing the count we need to swap the nos. in such a way that all k=n are at their respective index.This can be done in O(n) int arr[]={1,2,1,0,4}; int sz=sizeof(arr)/sizeof(int); int x,y; for(int i=0;isz;i++) { while(arr[i]!=arr[arr[i]]) { x=arr[i]; y=arr[arr[i]]; arr[i]=y; arr[x]=x; } } This will take O(n) time ...as for every loop we are setting one number to its respective index and then moving to the next number. 2. Now set the count to -1 for all i..such that arr[i] equal to i. for(int i=0;isz;i++) { if(arr[i]==i) arr[i]=-1; } 3. Now for all the numbers that are 0 ,we need to increment the count in their respective index.And set their count =0 as there is no such number for which arr[i]==i. for(int i=0;isz;i++) { if(arr[i]0) { arr[arr[i]]--; arr[i]=0; } } 4.Now this array contains the count at their respective index. int fun(int arr[],int x) { return -arr[x]; } On Wed, Feb 15, 2012 at 10:48 PM, Dave dave_and_da...@juno.com wrote: @Tushar: If we are going to use A[i] as an index into the array A[], we must have 0 = A[i] N. We can use a negative in A[i] to indicate that i occurs -A[i] times. The code would look something like this: //preprocessing... int i, j, m; for( i = 0 ; i N, ++i ) { j = A[i]; while( j = 0 ) { if( A[j] = 0 ) { m = A[j]; A[j] = -1; j = m; if( j = i ) break; } else { A[j]--; break; } } } Here is how this works: For each value of i, if A[i] 0, we already have processed it, so nothing more is required. Otherwise, suppose that A[i] has the value j. Then if A[j] 0 then we already have processed at least one occurrence of j, so we just decrement A[j] to indicate that an additional value j has occurred in A. But if A[j] = 0, this is the first time j has occurred. We set the value of A[j] to -1 to indicate that j has occurred once, but before we lose the value of A[j], we have to process its value. This results in the while loop to run through the chain of numbers until we get to an entry we already have processed. Prerocessing is O(N) because the statement A[j] = -1 in the while loop can be executed at most k times and A[j]-- can be executed at most N-1 times during all iterations of the for loop. And since one of these is executed on every iteration of the while loop, the while loop itself can be executed no more than N+k-1 2*N times during all iterations of the for loop. //determining count of number of original A[i] == x... count = A[x] 0 ? -x : 0; Dave On Feb 14, 10:10 pm, TUSHAR tusharkanta.r...@gmail.com wrote: Given an array of size N having numbers in the range 0 to k where k=N, preprocess the array inplace and in linear time in such a way that after preprocessing you should be able to return count of the input element in O(1). Please give some idea !! Thanks.. -- 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. -- *Dheeraj Sharma* -- 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: spoj
yeah..we need to calculate some formula On Wed, Feb 15, 2012 at 10:21 PM, pavan pavankri...@gmail.com wrote: @Utkarsh: yeah it is josephsus problem with a slight change.using a linked list will give u TLE i guess. On Feb 14, 10:36 pm, vickywiz vickywiz...@gmail.com wrote: in 1 2 3 4 5 6...o/p ll b 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. -- *Dheeraj Sharma* -- 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] how to convert a floating point number into binary representation.
you can use concept of union to display floating in binary union x { float z; int a; }; set the value of z..and represent it by a assuming int and float have same size On Mon, Jan 23, 2012 at 8:42 AM, Ashish Goel ashg...@gmail.com wrote: string ftob(string s) { int intPart= Integer.parseInt(s.substring(0, s.indexOf('.'))); double fraction = Double.parseDouble(s.substring( s.indexOf('.'), s.length())); string intString=; while (intPart) { int bit=intPart1; intPart =1; intString = bit + intString; } string fracString = ; int fracLen = 0; while((fracLen 32) (fraction0)) { fraction *=2; if (fraction1) { fraction -=1; fracString.append('1');} else { fracString.append('0'); fracLen++; } return (intString + '.' + fracString); } Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Tue, May 24, 2011 at 12:09 PM, saurabh agrawal saurabh...@gmail.comwrote: -- 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. -- *Dheeraj Sharma* -- 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] Colorful Number
Determine whether a number is colorful or not. 263 is a colorful number because (2,6,3,2x6,6x3,2x3x6) are all different whereas 236 is not because (2,3,6,2x3,3x6,2x3x6) have 6 twice. So take all consecutive subsets of digits, take their product and ensure all the products are different . Any other approach then O(n^2) -- *Dheeraj Sharma* -- 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] Dynamic programming question
i thnk it can be done using dynamic programming.. let the array b 25 3 25 1 10 2 5 now at at every point in the matrix..there can be two ways..to reach that point..either from left..or from right.. for example to reach at the center of the above matrix..we can come from 2-5-5 or 2-2-5..and can select the path that give max apples..similarly..we can calculate this..for every point in the 2D array the above matrix can be transformed into maximum apples at every point 2 7 10 4 12 13 14 1621 for top most row and left most column..we only add..the previous value..(because we dont have second direction) for arr(1,1) we calculate the max..that is from 7 and 4..and add it to the center value..to get 12 for arr(1,2) we calculate the max ..that if rom 12 and 10 and add it to arr(1,2) to get ..13.. this is how..we can do for..arr(2,1) and arr(2,2)... this is what we can do.. correct me if am wrong..i am naive solution provider On Tue, Dec 13, 2011 at 4:14 PM, Azhar Hussain azhar...@gmail.com wrote: We have apples arranged in a mxn matrix. We start from the upper left corner and have to reach bottom right corner with maximum apples. We can only move either down or right. Now if we can start any where in the matrix and have to reach anywhere on the right(reach n column). We can either up, down, right(but not left). We have to collect maximum apples from a given location. I am trying to solve problem. solution for the first one is given at http://community.topcoder.com/tc?module=Staticd1=tutorialsd2=dynProg . What data structure would be suitable for the second problem and will dynamic programming work. Thanks in advance. Azhar. -- 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. -- *Dheeraj Sharma* -- 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]
yeah..u r rite..i got it On Sun, Dec 11, 2011 at 5:08 PM, Lucifer sourabhd2...@gmail.com wrote: @Dheeraj The ans for 14532 should be 15234.. I am calculating using the above given algo to get to the ans: 1) 4 is the value where A[i] A[i+1] when scanned from the end. 2) The closest element grater than equal to 4 in the subarray 532 is 5. 3) Swap (4,5) : 14532 - 15432 4) Now, as we have identified in step 1 the index of i, we need to reverse the array from A[i+1, n] i.e. in 15(432) (432) needs to be reversed and hence we will get 15234... On Dec 11, 12:43 pm, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: @Lucifer.. i thnk for 14532..ur ans wud be..21354..but it shu..21345.. instread of reversing those..we have to sort them On Tue, Dec 6, 2011 at 4:13 PM, Lucifer sourabhd2...@gmail.com wrote: @payel and anurag.. The algo that i have given is the same one that is used by next_permutation.. And yes, its returns the next higher permutation.. In case ur input already points to the largest number then it will return the smaller number... On Dec 6, 12:38 pm, payel roy smithpa...@gmail.com wrote: @anurag, does the vector's next permutation return next higher element? On Dec 6, 8:10 am, Anurag Sharma anuragvic...@gmail.com wrote: In context of C++ 1. Populate the digits of the given number in a vector V 2. call next_permutation() on V 3. print the vector [?] Thanks, Anurag Sharma +91-8712218874 On Tue, Dec 6, 2011 at 2:23 AM, sourabh sourabhd2...@gmail.com wrote: This problem is a direct implication of next_permutation defined in C ++ STL algorithms. 1) From the end, keep decrementing till A[i] A[i+1].. 2) Now, find the closest element , greater than equal, to A[i] in A[i +1 ... n]. Say, the index of the found element is j. 3) Swap (A[i], A[j]) 4) Reverse array A[i+1 .. n] On Dec 6, 12:37 am, Anup Ghatage ghat...@gmail.com wrote: Hmm here is a thought. In the given number, check the second digit from the left. if it is the maximum, find the digit that is the next greater digit from the left most digit. append it to the start and append all the other numbers in sorted order. if the second from left isn't the largest, find the next digit that is greater than the last digit and swap places with it. On Mon, Dec 5, 2011 at 11:05 PM, raushan kumar raushan.vns2...@gmail.comwrote: Given a number,find the next higher number using the same digits in the number. eg: 15432 :: 21345 14532 -- 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. -- Anup Ghatage -- 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. 330.gif 1KViewDownload- 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 algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Dheeraj Sharma* -- 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. -- *Dheeraj Sharma* -- 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] A bst problem
My algorithm is like: 1.Take two pointers. one pointer track..where the node should be inserted..and other..to keep track of inorder successor. first pointer=root; second pointer=null; 2.if the first pointer moves to the left of a particular node(which becomes its parent)..then the set the value of second pointer=parent. else if the first pointer moves to the right of particular node (which becomes its parent)..the let the value of second pointer as it is.. finally when the node has been inserted at leaf..set the inorder successor of the node=second pointer value Correct me if am wrong On Sat, Dec 10, 2011 at 3:38 PM, sayan nayak sayanna...@gmail.com wrote: hi, here is the code: == struct node { int data; struct node *left; struct node *right; struct node *inordersuccessor; }; struct node *createnode(int info){ struct node* temp; temp-data=info; temp-left=temp-right=temp-inordersuccessor=NULL; return temp; }; struct node *addNode(struct node *node,int info){ struct node* temp=Createnode(info); if(node==NULL){ node=(struct node*)malloc(sizeof(struct node); if (node==NULL) fatalerror(Out of space); else { node-data=info; node-left=node-right=node-inordersuccessor=NULL; } } if (node-left==NULL info(node-data)){ node-left=temp; temp-inordersuccessor=node; } else if (node-right==NULL info(node-data)){ node-right=temp; temp-inordersuccessor=node-inordersuccessor; node-inordersuccessor=temp; } else { if (info(node-data)) node-left=addnode(node-left,info); else node-right=addnode(node-right,info); } return node; } I have run a few test cases..It's working.Pls let me know in case of any failure test cases. I'm also checking. Regards, Sayan On Sat, Dec 10, 2011 at 1:33 PM, AMAN AGARWAL mnnit.a...@gmail.comwrote: Hi, Construct a BST where each node has 3 pointers instead of 2. the structure is struct node { int data; struct node *left; struct node *right; struct node *inordersuccessor; } write a code to add nodes in a binary search tree . inordersuccessor pointing to inorder successor. Regards, Aman. -- AMAN AGARWAL Success is not final, Failure is not fatal: It is the courage to continue that counts! -- 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. -- *Dheeraj Sharma* -- 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]
@Lucifer.. i thnk for 14532..ur ans wud be..21354..but it shu..21345.. instread of reversing those..we have to sort them On Tue, Dec 6, 2011 at 4:13 PM, Lucifer sourabhd2...@gmail.com wrote: @payel and anurag.. The algo that i have given is the same one that is used by next_permutation.. And yes, its returns the next higher permutation.. In case ur input already points to the largest number then it will return the smaller number... On Dec 6, 12:38 pm, payel roy smithpa...@gmail.com wrote: @anurag, does the vector's next permutation return next higher element? On Dec 6, 8:10 am, Anurag Sharma anuragvic...@gmail.com wrote: In context of C++ 1. Populate the digits of the given number in a vector V 2. call next_permutation() on V 3. print the vector [?] Thanks, Anurag Sharma +91-8712218874 On Tue, Dec 6, 2011 at 2:23 AM, sourabh sourabhd2...@gmail.com wrote: This problem is a direct implication of next_permutation defined in C ++ STL algorithms. 1) From the end, keep decrementing till A[i] A[i+1].. 2) Now, find the closest element , greater than equal, to A[i] in A[i +1 ... n]. Say, the index of the found element is j. 3) Swap (A[i], A[j]) 4) Reverse array A[i+1 .. n] On Dec 6, 12:37 am, Anup Ghatage ghat...@gmail.com wrote: Hmm here is a thought. In the given number, check the second digit from the left. if it is the maximum, find the digit that is the next greater digit from the left most digit. append it to the start and append all the other numbers in sorted order. if the second from left isn't the largest, find the next digit that is greater than the last digit and swap places with it. On Mon, Dec 5, 2011 at 11:05 PM, raushan kumar raushan.vns2...@gmail.comwrote: Given a number,find the next higher number using the same digits in the number. eg: 15432 :: 21345 14532 -- 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. -- Anup Ghatage -- 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. 330.gif 1KViewDownload- 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 algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- *Dheeraj Sharma* -- 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: Questions
cant we use knuth morris algorithm..to find pattern..in a row? On Thu, Oct 27, 2011 at 10:28 PM, Anup Ghatage ghat...@gmail.com wrote: I guess this is just like finding a word in a matrix On Thu, Oct 27, 2011 at 7:32 PM, SAMMM somnath.nit...@gmail.com wrote: Forgot to mention this was asked in Amazon Interview .. -- 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. -- Anup Ghatage -- 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. -- *Dheeraj Sharma* -- 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] Basic Algorithm
1.hashing performance o(n) space o(n) keep incrementing the count..by hashing the each character 2.sort the input O(nlogn) check for succesive occurence of the character..the most occured wud b the ans. 3.Assume the array if of int type..Let A be at index 0,B at index 1..and so on. now start from index=0 to end arr[arr[index]%26]+=26 //that is..keep on incrementing the value by 26 at index 0 if it is A% is used because..the value can be greater then 26. now for index upto 25 check the maximum among arr[index]/26. performance O(n) no additional space...assumes character are from a-z and array greater than 26 On Sat, Oct 8, 2011 at 3:41 PM, ManishMCS manishdaw...@gmail.com wrote: A string of characters are given. Find the highest occurrence of a character and display that character. E.g Input: AEGBCNAVNEETGUPTAEDAGPE Output: E. Please give the efficient algorithm w.r.t both space and time.. -- 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. -- *Dheeraj Sharma* -- 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: Algo
try this..after passing root pointer and 0 to the function void summer(node *r,int sum) { if(r) { if(!r-left !r-right) { coutsum+r-dataendl; return; } summer(r-left,sum+(r-data)); summer(r-right,sum+(r-data)); } } On Fri, Oct 7, 2011 at 10:31 PM, Deepak arora deepakarora...@gmail.comwrote: thanks tpawan10 -- 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. -- *Dheeraj Sharma* -- 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] Tree Question
1.How to construct a tree from the list representation for ex.- construct tree from (A(B(E(K,L),F),D(H(M,I),J))) the tree would be binary the structure of the node would be struct node{ int data; struct node *left,*right; }; 2.Given a binary tree..give its list representaion..(reverse of above question) -- *Dheeraj Sharma* -- 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] Tree Question
yeah..but am looking for code..that takes the input...as string of (A(B(E(K,L),F),D(H(M,I),J))) and returns head of tree.. On Tue, Oct 4, 2011 at 2:11 PM, Raghav Garg rock.ragha...@gmail.com wrote: *you have to check for the braces where they have been used..in comman brace that means they are on same level..i am providing answer to your problem in attached file.. check that out.. *Raghav garg On Tue, Oct 4, 2011 at 1:53 PM, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: 1.How to construct a tree from the list representation for ex.- construct tree from (A(B(E(K,L),F),D(H(M,I),J))) the tree would be binary the structure of the node would be struct node{ int data; struct node *left,*right; }; 2.Given a binary tree..give its list representaion..(reverse of above question) -- *Dheeraj Sharma* -- 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. -- *Dheeraj Sharma* -- 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: constant
doesnt work in dev cpp On Tue, Oct 4, 2011 at 4:22 PM, prajon jondhale.pra...@gmail.comwrote: main() {const int a=123; printf(%d,a); *(int *)a=345; printf(%d,a); } On Oct 4, 3:48 pm, prajon jondhale.pra...@gmail.com wrote: can u change and if yes how to change value of constant variable? -- 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. -- *Dheeraj Sharma* -- 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] zigzag matrix
i gues..this will serve ur purpose n = rows,m=columns ,arr[n][m] is matrix for(int i=0;in;i++) { int j=0,k=i; while(k=0 jm) { coutarr[k][j] ; k--; j++; } coutendl; } for(int i=1;im;i++) { int j=i,k=n-1; while(k=0 jm) { coutarr[k][j] ; k--; j++; } coutendl; } On Mon, Oct 3, 2011 at 12:11 AM, Anika Jain anika.jai...@gmail.com wrote: for a N * M matrix is is possible to print zigzag fashion of that matrix? For example: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 i want print like 1 6 2 11 7 3 12 8 4 13 9 5 14 10 15 I am able to get this where N !=M.. How can i do this, ?? -- 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. -- *Dheeraj Sharma* -- 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] MS Question - Median of a BST without using extra space and in O(n)
keep a global pointer and a global variable check=0 do inorder traversal..instead of printing the value do if(check==0) save pointer check==1 else check==0; correct me if m wrong On Tue, Sep 27, 2011 at 2:22 PM, anshu mishra anshumishra6...@gmail.comwrote: do the inorder traversal as soon as reached at n/2th element that will be median. -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra -- 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: MS Question - Median of a BST without using extra space and in O(n)
@anshu can middle element can be found if the no. of nodes are not given... On Tue, Sep 27, 2011 at 8:34 PM, vikas vikas.rastogi2...@gmail.com wrote: a simple one is rabit-tortoise method, and using stackless traversal, facing a lot of corner cases in coding this, can someone check this as well? On Sep 27, 6:41 pm, anshu mishra anshumishra6...@gmail.com wrote: its not o(n) it is O(max height of tree) :P i have not seen the constraint. -- 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. -- *Dheeraj Sharma* -- 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 : Non Decreasing Numbers
yeah exactly..yogesh..i was confused with factorial On Sun, Sep 25, 2011 at 12:21 PM, Yogesh Yadav medu...@gmail.com wrote: mistake in last post...it was not factorialsum upto n i.e =n(n+1)/2 i.e 10! is wrong ...it will be 10(10+1)/2 On Sun, Sep 25, 2011 at 12:14 PM, Yogesh Yadav medu...@gmail.com wrote: n=1 n=2 n=3 n=4 01010!(10!)! 1 9 9! (9!)! 2 8 8! 3 7 7! 4 6 6! 5 5 5! 6 4 4! 7 3 3! 8 2 2! 9 1 1! sum 10 55220 and so on On Sun, Sep 25, 2011 at 11:46 AM, Sanjay Rajpal srn...@gmail.com wrote: Can you plz tell the answer for for 3 answer=? nd for 4 answer=? Sanju :) On Sat, Sep 24, 2011 at 10:39 PM, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: can u plz be more..clear ..with wat the input will consist of.. wat does this mean for 2 answer=55 does that mean..that how many non decreasing digits can be formed by 2 digit num On Sun, Sep 25, 2011 at 1:08 AM, shady sinv...@gmail.com wrote: A number is said to be made up of non-decreasing digits if all the digits to the left of any digit is less than or equal to that digit. for eg. 1122, 234, 2 , 0011 is a possible 4 digit non decreasing number so given a number n, how many n digit numbers exist ? for 2 answer = 55 Can someone post complexity and their approach -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra -- 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] Searching Problems !!
Q1 int fun(int arr[],int left,int right,int num) { int mid=(left+right)/2; if(mid==0) return 0; if(mid==num-1) return 1; if( arr[mid]arr[mid-1] arr[mid]=(arr[mid]+1)) return (num-mid); else if(arr[mid]=arr[left]) return fun(arr,mid+1,right,num); else if(arr[mid]=arr[left]) return fun(arr,left,mid-1,num); } fun(arr,0,size-1,size) COrrect Me if am wrong.. On Sun, Sep 25, 2011 at 9:39 PM, prasanth n nprasnt...@gmail.com wrote: @ Decipher: Q1) find where the rotation begins and do binary search in the first half or the second half depending upon the search element On Sun, Sep 25, 2011 at 8:58 PM, Decipher ankurseth...@gmail.com wrote: Q1) A sorted array is rotated unknown number of times , write an algorithm to search an element in this rotated array in O(log n) . Hint : Modify binary search Q2) Write an algorithm to traverse a rectangular matrix spirally. -- 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/-/0WBV1uzAe5AJ. 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. -- *prasanth* -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra -- 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] Searching Problems !!
it has some errors..lemme modify it On Sun, Sep 25, 2011 at 10:45 PM, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: Q1 int fun(int arr[],int left,int right,int num) { int mid=(left+right)/2; if(mid==0) return 0; if(mid==num-1) return 1; if( arr[mid]arr[mid-1] arr[mid]=(arr[mid]+1)) return (num-mid); else if(arr[mid]=arr[left]) return fun(arr,mid+1,right,num); else if(arr[mid]=arr[left]) return fun(arr,left,mid-1,num); } fun(arr,0,size-1,size) COrrect Me if am wrong.. On Sun, Sep 25, 2011 at 9:39 PM, prasanth n nprasnt...@gmail.com wrote: @ Decipher: Q1) find where the rotation begins and do binary search in the first half or the second half depending upon the search element On Sun, Sep 25, 2011 at 8:58 PM, Decipher ankurseth...@gmail.com wrote: Q1) A sorted array is rotated unknown number of times , write an algorithm to search an element in this rotated array in O(log n) . Hint : Modify binary search Q2) Write an algorithm to traverse a rectangular matrix spirally. -- 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/-/0WBV1uzAe5AJ. 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. -- *prasanth* -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra -- 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] Amazon Interview Question
i think this travels only once ... correct me if am wrong #includestdio.h #includestring.h #define SWAP(a,b,c) (c)=(a),(a)=(b),(b)=(c) int main() { int t,x; scanf(%d,t); while(t--) { char str[100]; scanf(%s,str); int i=0,j=0,k=strlen(str)-1; while(str[i]=='0') i++; while(str[k]=='2') k--; j=i; while(j=k) { if(str[j]=='2') { SWAP(str[j],str[k],x); k--; } if(str[j]=='0') { SWAP(str[i],str[j],x); i++; } if(str[j]!='2') j++; } printf(%s\n,str); } return 0; } On Sat, Sep 24, 2011 at 11:39 AM, Yogesh Yadav medu...@gmail.com wrote: we cant traverse the string twice... if there is an error in my logic then plz tell my logic is: we have to take starting and ending indexes for '0','1','2' like below 0 1 2 starting_index ending_index now suppose our string 102112011 so we start from the left and traverse the whole string first character ='1' 0 1 2 starting_index 0 ending_index 0 next character = '0' 0 1 2 starting_index 1 0 ending_index 1 0 ( ending_index0 ending_index1 ) so we swap the numbers according to Starting_index not according to Ending_index So it will become 0 1 2 starting_index 0 1 ending_index 0 1 and string will become 01 next character '2' 0 1 2 starting_index 0 1 2 ending_index 0 1 2 (ending_index0ending_index1ending_index2)so ending indexes in increasing order...so no need to swap so string is now 012 next character '1' 0 1 2 starting_index 0 1 2 ending_index 0 3 2 (ending_index1ending_index2) so we swap the current 1 with starting index of 2 so string will become 0112 0 1 2 starting_index 0 1 3 ending_index 0 2 3 next character '1' 0 1 2 starting_index 0 1 3 ending_index 0 4 3 (ending_index1ending_index2) so we swap the current 1 with starting index of 2 so string will become 01112 0 1 2 starting_index 0 1 4 ending_index 0 3 4 next character '2' 0 1 2 starting_index 0 1 4 ending_index 0 3 5 (ending_index0ending_index1ending_index2) so no swap so string will become 011122 next character '0' 0 1 2 starting_index 0 1 4 ending_index 6 3 5 (ending_index0ending_index1ending_index2) so we swap the current 0 with staring index of 2 first and then with starting index of 1 so string will become 0011122 0 1 2 starting_index 0 2 5 ending_index 1 4 6 and so on i hope its much explained... On Sat, Sep 24, 2011 at 10:30 AM, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: char str[100],t; scanf(%s,str); char ch='0'; int i=0,j=0; while(jstrlen(str)) { if(str[j]==ch) { SWAP(str[i],str[j],t); i++; } j++; } ch='1'; j=i; while(jstrlen(str)) { if(str[j]==ch) { SWAP(str[i],str[j],t); i++; } j++; } printf(%s\n,str
Re: [algogeeks] Amazon OS question
5 4? On Sun, Sep 25, 2011 at 9:33 AM, sivaviknesh s sivavikne...@gmail.comwrote: A parallel program consists of 8 tasks – T1 through T8. Each task requires one time step to be executed on a single processor. Let X - Y denote the fact that task X must be executed before task Y is executed. Suppose only the tasks X, Y are to be executed. On any multiprocessor machine it would require at least 2 time steps since in the first step X could be executed, and Y could be executed in the next time step (since it requires X to complete first). Now, suppose the following dependencies exist between the tasks T1 – T8: T1 - T2 T2 - T3 T3 - T6 T2 - T4 T4 - T7 T2 - T5 T5 - T8 What is the minimum number of time steps required to execute these 8 tasks on a 2 processor machine and a 4 processor machine? a)4 2 b)5 2 c)5 4 d)6 2 -- Regards, $iva -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra -- 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] Reverse the string word by word . Can someone tell what is wrong in my code ?
u shud do TWO things in..your reverseword function.. first is str[i]=='\0' and not str[i]='\0' second is while(i=len) and not while(ilen) On Sun, Sep 25, 2011 at 6:49 AM, Deoki Nandan deok...@gmail.com wrote: //Reverse String word by word // if string is :- I am a good boy //output string should be :- boy good a am I #includestdio.h #includestring.h void reverse(char *p,char*q) { int i;char c; while(pq) { c=*p;*p=*q;*q=c; p++; q--; } } void reverseWordByWord(char str[],int len) { int i=0,j=0; while(ilen) { if((str[i]==' ')||(str[i]=='\t')||(str[i]='\0')) { reverse(str[j],str[i-1]); j=i+1; } i++; } } int main() { char A[]=Ram is a good person; int i; int len=strlen(A); reverse(A[0],A[len-1]); printf(%s\n,A); reverseWordByWord(A,len); printf(%s\n,A); return 0; } -- **With Regards Deoki Nandan Vishwakarma * * -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra -- 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 : Non Decreasing Numbers
can u plz be more..clear ..with wat the input will consist of.. wat does this mean for 2 answer=55 does that mean..that how many non decreasing digits can be formed by 2 digit num On Sun, Sep 25, 2011 at 1:08 AM, shady sinv...@gmail.com wrote: A number is said to be made up of non-decreasing digits if all the digits to the left of any digit is less than or equal to that digit. for eg. 1122, 234, 2 , 0011 is a possible 4 digit non decreasing number so given a number n, how many n digit numbers exist ? for 2 answer = 55 Can someone post complexity and their approach -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra -- 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] Amazon Interview Question
char str[100],t; scanf(%s,str); char ch='0'; int i=0,j=0; while(jstrlen(str)) { if(str[j]==ch) { SWAP(str[i],str[j],t); i++; } j++; } ch='1'; j=i; while(jstrlen(str)) { if(str[j]==ch) { SWAP(str[i],str[j],t); i++; } j++; } printf(%s\n,str); On Sat, Sep 24, 2011 at 9:55 AM, Anup Ghatage ghat...@gmail.com wrote: Is this like the segregating all the 1's to the right and the 0's to the left or am i missing something? On Sat, Sep 24, 2011 at 9:39 AM, VIHARRI viharri@gmail.com wrote: You are given a string (consisting of 0's, 1's or 2's) where 0 represents a blue ball, 1 a red ball, and 2 a black ball. Using only swap operations (counting sort not allowed) rearrange the string such that all blue balls are together on one side, followed by all red balls, and then all black balls. You can iterate through the string only once. Eg 102112011 should produce 00122? -- 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. -- Anup Ghatage -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra -- 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: question
@Ratan: i think the next largest here would be 784559 On Thu, Sep 22, 2011 at 12:39 PM, Ratan success.rata...@gmail.com wrote: @kartik : to some extent ur code is giving the right answer... btw somehow check tis let for example the no be 759854 then the next biggest no is 794558 btw ur program is giving 795854 which is undoubtedly wrong the code would give more appropriate result if u sort the numbers from from i to n on meeting the condition of (a[i-1]a[i]) On Thu, Sep 22, 2011 at 11:53 AM, Ramakant Sharma ramakant...@gmail.com wrote: starting from right find first digit less then right most digit,if no any digit is less,then move to next right most and compair when found exchange those no, now sort the no.s up to that index of the given no which is exchanged: Ex: 43987723893239876 first required sequence: 439877238932[3]987[6] swap these no 439877238932[6]{987[3]} now sort in decreasing order 439877238932[6]{3789} this is the required no correct me if any thing wrong -- 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. -- Ratan Kumar B. Tech 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra -- 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: question
#includeiostream #includeconio.h #includestring.h #define swap(a,b,c) (c)=(a),(a)=(b),(b)=(c) using namespace std; int main() { char str[100],t; cinstr; int len=strlen(str); int i,x,boo=1; for(i=len-1;i0boo;i--) { for(x=i-1;x=0boo;x--) { if(str[x]str[i]) { swap(str[x],str[i],t); boo=0; } } } if(i0) { //Sorting... for(int l=x+2;llen-1;l++) { int min=l; for(int k=l+1;klen;k++) { if(str[k]str[min]) min=k; } swap(str[min],str[l],t); } } coutstr; getch(); } correct me..if m wrong.. On Thu, Sep 22, 2011 at 2:01 PM, Ratan success.rata...@gmail.com wrote: @dheeraj ... ya u r ryt thnxs for the correction On Thu, Sep 22, 2011 at 1:30 PM, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: @Ratan: i think the next largest here would be 784559 On Thu, Sep 22, 2011 at 12:39 PM, Ratan success.rata...@gmail.com wrote: @kartik : to some extent ur code is giving the right answer... btw somehow check tis let for example the no be 759854 then the next biggest no is 794558 btw ur program is giving 795854 which is undoubtedly wrong the code would give more appropriate result if u sort the numbers from from i to n on meeting the condition of (a[i-1]a[i]) On Thu, Sep 22, 2011 at 11:53 AM, Ramakant Sharma ramakant...@gmail.com wrote: starting from right find first digit less then right most digit,if no any digit is less,then move to next right most and compair when found exchange those no, now sort the no.s up to that index of the given no which is exchanged: Ex: 43987723893239876 first required sequence: 439877238932[3]987[6] swap these no 439877238932[6]{987[3]} now sort in decreasing order 439877238932[6]{3789} this is the required no correct me if any thing wrong -- 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. -- Ratan Kumar B. Tech 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. -- Dheeraj Sharma Comp Engg. NIT Kurukshetra -- 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. -- Ratan Kumar B. Tech 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra -- 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] help nedded
for 2nd one #includeiostream #includeconio.h using namespace std; int main() { char str[100]; cinstr; char ch=str[0]; int count=0,i=0; while(str[i]) { if(str[i]==ch) count++; else { coutchcount; ch=str[i]; count=1; } i++; } coutchcount; getch(); } On Thu, Sep 22, 2011 at 11:58 AM, rahul sharma rahul23111...@gmail.comwrote: i found a question of ms earlier but know i not able to find it.plz post link or thread i/p::a3b2c4: o/p:aaabb i/p:aaabbc o/p:a3b2c1 -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra -- 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] help nedded
for 1st #includeiostream #includeconio.h #includestring.h using namespace std; int main() { char str[100]; cinstr; int len=strlen(str); int i=1; while(ilen) { int x=str[i]-48; while(x--) coutstr[i-1]; i+=2; } getch(); } On Thu, Sep 22, 2011 at 3:42 PM, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: for 2nd one #includeiostream #includeconio.h using namespace std; int main() { char str[100]; cinstr; char ch=str[0]; int count=0,i=0; while(str[i]) { if(str[i]==ch) count++; else { coutchcount; ch=str[i]; count=1; } i++; } coutchcount; getch(); } On Thu, Sep 22, 2011 at 11:58 AM, rahul sharma rahul23111...@gmail.comwrote: i found a question of ms earlier but know i not able to find it.plz post link or thread i/p::a3b2c4: o/p:aaabb i/p:aaabbc o/p:a3b2c1 -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra -- 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: question
in nlog(n) #includeiostream #includeconio.h #includestring.h #define swap(a,b,c) (c)=(a),(a)=(b),(b)=(c) using namespace std; int t; void quicksort(char arr[],int left,int right) { if(leftright) { int piv=right; int i=left,j=left; while((iright) (jright)) { if(arr[j]arr[piv]) { swap(arr[i],arr[j],t); i++; } j++; } swap(arr[i],arr[piv],t); quicksort(arr,left,i-1); quicksort(arr,i+1,right); } } int main() { char str[100],t; int arr[100],i=0; cinstr; int min=0; int len=strlen(str); while(str[i]) { if(str[i]=str[min]) min=i; arr[i]=min; i++; } i=len-1; while((arr[i]==i)(i0)) i--; swap(str[i],str[arr[i]],t); if(i0) quicksort(str,arr[i]+1,len-1); coutstr; getch(); } On Thu, Sep 22, 2011 at 3:33 PM, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: #includeiostream #includeconio.h #includestring.h #define swap(a,b,c) (c)=(a),(a)=(b),(b)=(c) using namespace std; int main() { char str[100],t; cinstr; int len=strlen(str); int i,x,boo=1; for(i=len-1;i0boo;i--) { for(x=i-1;x=0boo;x--) { if(str[x]str[i]) { swap(str[x],str[i],t); boo=0; } } } if(i0) { //Sorting... for(int l=x+2;llen-1;l++) { int min=l; for(int k=l+1;klen;k++) { if(str[k]str[min]) min=k; } swap(str[min],str[l],t); } } coutstr; getch(); } correct me..if m wrong.. On Thu, Sep 22, 2011 at 2:01 PM, Ratan success.rata...@gmail.com wrote: @dheeraj ... ya u r ryt thnxs for the correction On Thu, Sep 22, 2011 at 1:30 PM, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: @Ratan: i think the next largest here would be 784559 On Thu, Sep 22, 2011 at 12:39 PM, Ratan success.rata...@gmail.com wrote: @kartik : to some extent ur code is giving the right answer... btw somehow check tis let for example the no be 759854 then the next biggest no is 794558 btw ur program is giving 795854 which is undoubtedly wrong the code would give more appropriate result if u sort the numbers from from i to n on meeting the condition of (a[i-1]a[i]) On Thu, Sep 22, 2011 at 11:53 AM, Ramakant Sharma ramakant...@gmail.com wrote: starting from right find first digit less then right most digit,if no any digit is less,then move to next right most and compair when found exchange those no, now sort the no.s up to that index of the given no which is exchanged: Ex: 43987723893239876 first required sequence: 439877238932[3]987[6] swap these no 439877238932[6]{987[3]} now sort in decreasing order 439877238932[6]{3789} this is the required no correct me if any thing wrong -- 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. -- Ratan Kumar B. Tech 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. -- Dheeraj Sharma Comp Engg. NIT Kurukshetra -- 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. -- Ratan Kumar B. Tech 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. -- *Dheeraj Sharma* Comp Engg. NIT
Re: [algogeeks] Re: Microsoft Question
@kartik: i thnk u r searching for string...that may have characters..in the 2d matrix ..NO MATTER WHERE THEY ARE.. On Wed, Sep 21, 2011 at 7:10 PM, kartik sachan kartik.sac...@gmail.comwrote: i think i can solve this in O(n^2) here is code http://ideone.com/Gk69A # includestdio.h# includestring.hchar a[100][100];int findword(int *b,int n,int m){ int i,j,flag=0; char s[1]; for(i=0;in;i++) for(j=0;jm;j++) s[a[i][j]]++; for(i=0;istrlen(b);i++) if(s[b[i]]!=0) s[b[i]]--; else {flag=0; break;} if(flag==0) return 0; else return 1;}int main(){ int i,j,n,m; char str[1]; scanf(%d %d,n,m); for(i=0;in;i++) for(j=0;jm;j++) scanf(%c,a[i][j]); scanf(%s,str); if(findword(str,n,m)) printf http://www.opengroup.org/onlinepubs/009695399/functions/printf.html(word is there in matrix); else printf http://www.opengroup.org/onlinepubs/009695399/functions/printf.html(word is not there in matrix);return 0;} plzz correct me if i am worng -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra -- 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: question
@bharat...so i thnk 7585 shud hav 7855 as ans..!! On Thu, Sep 22, 2011 at 5:42 PM, Arpit Sood soodfi...@gmail.com wrote: @yogesh nice algo... it is not even required to sort the left out array, just reverse it :) On Thu, Sep 22, 2011 at 5:05 PM, Yogesh Yadav medu...@gmail.com wrote: @ratan: thanks for correction little correction in my logic... start from rightmost digit and search towards left a digit less than this... if found ... just swap...now after swapping save the index with which you are swapping ...and after that sort the array in ascending order...u got the answer... if no small digit found then select second rightmost digit and follow the same process...and so on... for ex: 759354 rightmost digit =4 search for smaller digit than 4 towards left... it will be 3... then 7594(53) now make the array in brackets in ascending order... answer 759435 now am i right?? On Thu, Sep 22, 2011 at 4:55 PM, Ratan success.rata...@gmail.com wrote: the answer should be 759435... On Thu, Sep 22, 2011 at 4:45 PM, Yogesh Yadav medu...@gmail.com wrote: my logic: if wrong then plz tell... start from rightmost digit and search towards left a digit less than this... if found ... just swap...u got the answer... if no small digit found then select second rightmost digit and follow the same process...and so on... for ex: 759354 rightmost digit =4 search for smaller digit than 4 towards left... it will be 3... then answer 759453 On Thu, Sep 22, 2011 at 4:40 PM, Yogesh Yadav medu...@gmail.com wrote: @algo geek: there is some error in your logic... consider a number 759845 according to ur logic the number greater than this will be 784559 but it should be 759854 . On Thu, Sep 22, 2011 at 4:24 PM, algo geek geeka...@gmail.com wrote: Keep a pointer ont the rightmost digit. Keep moving right until you find the number in increasing number. As soon as this breaks. stop. Swap the digit at the current position with the smallest digit, but larger than the current position digit, sort the array to the right of the current position in descending order. explanation: NUMBER:759854 INDEX: 012356 Keep the pointer at index 6. Keep moving right as long as numbers are in increasing fashion. Stop at index 1. swap this digit with the smallest digit larger than 5 i.e. 8 78(9554) now sort the array in parenthesis in descending order ans : 784559 For the implementation you can actually create an array of length 10, to keep track of all the digits encounters while moving left. This will help in sorting as well (similar to counting sort). One pass will do the work. You can print the answer directly afterwards. With Regards Unknown On Thu, Sep 22, 2011 at 4:13 PM, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: in nlog(n) #includeiostream #includeconio.h #includestring.h #define swap(a,b,c) (c)=(a),(a)=(b),(b)=(c) using namespace std; int t; void quicksort(char arr[],int left,int right) { if(leftright) { int piv=right; int i=left,j=left; while((iright) (jright)) { if(arr[j]arr[piv]) { swap(arr[i],arr[j],t); i++; } j++; } swap(arr[i],arr[piv],t); quicksort(arr,left,i-1); quicksort(arr,i+1,right); } } int main() { char str[100],t; int arr[100],i=0; cinstr; int min=0; int len=strlen(str); while(str[i]) { if(str[i]=str[min]) min=i; arr[i]=min; i++; } i=len-1; while((arr[i]==i)(i0)) i--; swap(str[i],str[arr[i]],t); if(i0) quicksort(str,arr[i]+1,len-1); coutstr; getch(); } On Thu, Sep 22, 2011 at 3:33 PM, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: #includeiostream #includeconio.h #includestring.h #define swap(a,b,c) (c)=(a),(a)=(b),(b)=(c) using namespace std; int main() { char str[100],t; cinstr; int len=strlen(str); int i,x,boo=1; for(i=len-1;i0boo;i--) { for(x=i-1;x=0boo;x--) { if(str[x]str[i]) { swap(str[x],str[i],t); boo=0; } } } if(i0) { //Sorting... for(int l=x+2;llen-1;l++) { int min=l; for(int k=l+1;klen;k++) { if(str[k]str[min]) min=k
Re: [algogeeks] Re: Microsoft Question
@kartik.,...where are u searching..that ..the next character should be present..only around the 8 possible locations around that character On Thu, Sep 22, 2011 at 6:34 AM, kartik sachan kartik.sac...@gmail.comwrote: @dheeraj i didn't get what u want to say explain me with the help of example -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra -- 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: Question --
...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Kind Regards Ishan Aggarwal [image: Aricent Group] Presidency Tower-A, M.G.Road,Sector-14 Gurgaon,Haryana.122015 INDIA Phone : +91-9654602663 ishan2.aggar...@aricent.com puneet.ar...@aricent.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?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. -- Kind Regards Ishan Aggarwal [image: Aricent Group] Presidency Tower-A, M.G.Road,Sector-14 Gurgaon,Haryana.122015 INDIA Phone : +91-9654602663 ishan2.aggar...@aricent.com puneet.ar...@aricent.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?hl=en. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra -- 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] Directi Questions - needed answers
ans 7. - 15 km east and 12 km south of origin On Sat, Sep 17, 2011 at 11:29 AM, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: Ans 8. 62.5 % ??? On Sat, Sep 17, 2011 at 9:11 AM, VIHARRI viharri@gmail.com wrote: 1. Minimum no.of comparisons required to select the 2nd max element in an array of N numbers. 2. What are the number of counting ties for four horses. ( example for two horses A and B there are three cases - A wins, B wins, A B ties ). 3. What are the minimum no.of tournaments needed to get the winner. A player is out when he loses two matches. Total players are 51. ( Badminton ). 4. while(true) { sleep 1sencond; if( getpid() % 2 == 0 ) { fork(); } } How many no.of processes are created by the end of 12th second, if time starts from 0th second? Process id's start from 0. 5. Which of the following are thread safe? a) Atomic operations b) Mutual exclusion c) Re-entrant d) Queuing 6. When a dice is rolled the outcome of the face is summed up each time, and rolling is stopped when the sum becomes greater than 100. Which of the following have more probability to become sum. a) 103 b) 102 c) 100 d) all have equal probability e) 101 7. A man moves 1km east, 2km north, 3km west, 4km south, 5km east, 6km north, 7km west and so on until he travels total of 300km so what will be the distance from origin? 8. Alam bought 5pens, 7 pencils, 4 erasers. Ashok bought 6 pens, 8 erasers, 14 pencils and paid half more the amount Alam paid. What is the percentage of amount did Alam spent on buying pens? 9. Time complexity to get min elements from MAX heap. -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra -- 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] Directi Questions - needed answers
@ashima...its asking just for pens..and that of alam..so wat i still think..is 62.5% On Sat, Sep 17, 2011 at 5:09 PM, aditya kumar aditya.kumar130...@gmail.comwrote: see here the basic operation is comparision so we can express comaprision in terms of order of O(n). newazz we still require n-1 comparisions to find second max . On Sat, Sep 17, 2011 at 5:06 PM, Yogesh Yadav medu...@gmail.com wrote: @aditya: comparing isn't complexity here... here it means no. of comparisons between 2 numbers... On Sat, Sep 17, 2011 at 5:04 PM, aditya kumar aditya.kumar130...@gmail.com wrote: @yogesh: we can get second max by comparing n elements ie O(n). On Sat, Sep 17, 2011 at 4:59 PM, Ashima . ashima.b...@gmail.com wrote: ans 8: it should be 40% @dheeraj: if total is 100 percent and other person paid more than 1st person.Than how can the 1st person's percentage be more than 50%? Ashima M.Sc.(Tech)Information Systems 4th year BITS Pilani Rajasthan On Sat, Sep 17, 2011 at 4:20 AM, Yogesh Yadav medu...@gmail.comwrote: Ans 1. apply bubble sort. outer loop should run just two times because in 2nd time the 2nd largest element will be at 2nd last position... comparisons=(n-1)+(n-2) On Sat, Sep 17, 2011 at 4:27 PM, Ashima . ashima.b...@gmail.comwrote: ans 2: http://www.qbyte.org/puzzles/p131s.html Ashima M.Sc.(Tech)Information Systems 4th year BITS Pilani Rajasthan On Sat, Sep 17, 2011 at 1:46 AM, Ashima . ashima.b...@gmail.comwrote: ans1: i think 2n but may be better solution is posible Ashima M.Sc.(Tech)Information Systems 4th year BITS Pilani Rajasthan On Fri, Sep 16, 2011 at 11:19 PM, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: ans 7. - 15 km east and 12 km south of origin On Sat, Sep 17, 2011 at 11:29 AM, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: Ans 8. 62.5 % ??? On Sat, Sep 17, 2011 at 9:11 AM, VIHARRI viharri@gmail.comwrote: 1. Minimum no.of comparisons required to select the 2nd max element in an array of N numbers. 2. What are the number of counting ties for four horses. ( example for two horses A and B there are three cases - A wins, B wins, A B ties ). 3. What are the minimum no.of tournaments needed to get the winner. A player is out when he loses two matches. Total players are 51. ( Badminton ). 4. while(true) { sleep 1sencond; if( getpid() % 2 == 0 ) { fork(); } } How many no.of processes are created by the end of 12th second, if time starts from 0th second? Process id's start from 0. 5. Which of the following are thread safe? a) Atomic operations b) Mutual exclusion c) Re-entrant d) Queuing 6. When a dice is rolled the outcome of the face is summed up each time, and rolling is stopped when the sum becomes greater than 100. Which of the following have more probability to become sum. a) 103 b) 102 c) 100 d) all have equal probability e) 101 7. A man moves 1km east, 2km north, 3km west, 4km south, 5km east, 6km north, 7km west and so on until he travels total of 300km so what will be the distance from origin? 8. Alam bought 5pens, 7 pencils, 4 erasers. Ashok bought 6 pens, 8 erasers, 14 pencils and paid half more the amount Alam paid. What is the percentage of amount did Alam spent on buying pens? 9. Time complexity to get min elements from MAX heap. -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra -- 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
Re: [algogeeks] Directi Questions - needed answers
12 west and 10 south.. i thnk..is the correct one.. On Sat, Sep 17, 2011 at 5:22 PM, Yogesh Yadav medu...@gmail.com wrote: yeah it will be 62.5% On Sat, Sep 17, 2011 at 5:14 PM, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: @ashima...its asking just for pens..and that of alam..so wat i still think..is 62.5% On Sat, Sep 17, 2011 at 5:09 PM, aditya kumar aditya.kumar130...@gmail.com wrote: see here the basic operation is comparision so we can express comaprision in terms of order of O(n). newazz we still require n-1 comparisions to find second max . On Sat, Sep 17, 2011 at 5:06 PM, Yogesh Yadav medu...@gmail.com wrote: @aditya: comparing isn't complexity here... here it means no. of comparisons between 2 numbers... On Sat, Sep 17, 2011 at 5:04 PM, aditya kumar aditya.kumar130...@gmail.com wrote: @yogesh: we can get second max by comparing n elements ie O(n). On Sat, Sep 17, 2011 at 4:59 PM, Ashima . ashima.b...@gmail.comwrote: ans 8: it should be 40% @dheeraj: if total is 100 percent and other person paid more than 1st person.Than how can the 1st person's percentage be more than 50%? Ashima M.Sc.(Tech)Information Systems 4th year BITS Pilani Rajasthan On Sat, Sep 17, 2011 at 4:20 AM, Yogesh Yadav medu...@gmail.comwrote: Ans 1. apply bubble sort. outer loop should run just two times because in 2nd time the 2nd largest element will be at 2nd last position... comparisons=(n-1)+(n-2) On Sat, Sep 17, 2011 at 4:27 PM, Ashima . ashima.b...@gmail.comwrote: ans 2: http://www.qbyte.org/puzzles/p131s.html Ashima M.Sc.(Tech)Information Systems 4th year BITS Pilani Rajasthan On Sat, Sep 17, 2011 at 1:46 AM, Ashima . ashima.b...@gmail.comwrote: ans1: i think 2n but may be better solution is posible Ashima M.Sc.(Tech)Information Systems 4th year BITS Pilani Rajasthan On Fri, Sep 16, 2011 at 11:19 PM, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: ans 7. - 15 km east and 12 km south of origin On Sat, Sep 17, 2011 at 11:29 AM, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: Ans 8. 62.5 % ??? On Sat, Sep 17, 2011 at 9:11 AM, VIHARRI viharri@gmail.comwrote: 1. Minimum no.of comparisons required to select the 2nd max element in an array of N numbers. 2. What are the number of counting ties for four horses. ( example for two horses A and B there are three cases - A wins, B wins, A B ties ). 3. What are the minimum no.of tournaments needed to get the winner. A player is out when he loses two matches. Total players are 51. ( Badminton ). 4. while(true) { sleep 1sencond; if( getpid() % 2 == 0 ) { fork(); } } How many no.of processes are created by the end of 12th second, if time starts from 0th second? Process id's start from 0. 5. Which of the following are thread safe? a) Atomic operations b) Mutual exclusion c) Re-entrant d) Queuing 6. When a dice is rolled the outcome of the face is summed up each time, and rolling is stopped when the sum becomes greater than 100. Which of the following have more probability to become sum. a) 103 b) 102 c) 100 d) all have equal probability e) 101 7. A man moves 1km east, 2km north, 3km west, 4km south, 5km east, 6km north, 7km west and so on until he travels total of 300km so what will be the distance from origin? 8. Alam bought 5pens, 7 pencils, 4 erasers. Ashok bought 6 pens, 8 erasers, 14 pencils and paid half more the amount Alam paid. What is the percentage of amount did Alam spent on buying pens? 9. Time complexity to get min elements from MAX heap. -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra -- 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
Re: [algogeeks] Re: royal bank of scotland
yeah...correct .. On Fri, Sep 16, 2011 at 5:57 PM, rahul sharma rahul23111...@gmail.comwrote: cpa:- 6 elitmus considered 100% packakge around 7-7.5 On Fri, Sep 16, 2011 at 1:36 PM, siva viknesh sivavikne...@gmail.comwrote: and also package?? On Sep 16, 12:24 pm, aashish bansal aashish.b...@gmail.com wrote: and what is their shortlisting criteria?do they consider elitmus score only or percentage as well? On Sep 14, 8:01 pm, rahul sharma rahul23111...@gmail.com wrote: they take elitmus test..and then interviewws On Wed, Sep 14, 2011 at 12:17 PM, deepikaanand swinyanand...@gmail.comwrote: wat is selection procedure of RBS (for internships or placements) -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra -- 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: MICROSOFT WRITTEN IN VASAVI
char str[10]; int length,count; void fun(int x) { if(x==length) printf(%d %s\n,++count,str); else { fun(x+1); str[x]-=32; fun(x+1); str[x]+=32; } } int main() { scanf(%s,str); length=strlen(str); fun(0); getch(); } On Wed, Sep 14, 2011 at 10:05 AM, mohit verma mohit89m...@gmail.com wrote: take an array containing all original upper-case letters and their smaller case letters and now the problem is reduced to print all substrings containing length of original string. On Wed, Sep 14, 2011 at 8:55 PM, teja bala pawanjalsa.t...@gmail.comwrote: //dis one works check it out.. #includectype.h #includestdio.h #includestring.h #includeassert.h void toggler(char* x, int pos) { if(pos==0){ printf(%s\n,x); return; } // printf(String is now: %s\n,x); x[pos-1] = toupper(x[pos-1]); toggler(x, pos-1); x[pos-1] = tolower(x[pos-1]); toggler(x, pos-1); return; } int main(void){ char str[500]; scanf(%s,str); toggler(str, strlen(str)); return 0; } On Wed, Sep 14, 2011 at 7:22 PM, Dave dave_and_da...@juno.com wrote: @Teja: Oops. I was wrong. By the time I fix my conceptual error, the code is no shorter than Anshu's. Dave On Sep 14, 8:14 am, teja bala pawanjalsa.t...@gmail.com wrote: @DAVE dis was the o/p for ur prog. aBC abC abC abc abc abc abc abc #includeiostream.h main() { int i, n = 3; char *s=ABC; for( i = 0 ; i (1n) ; ++i ) { s[i^(i1)] ^= 'a' ^ 'A'; cout s endl; } }- 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 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. -- *MOHIT VERMA* -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra -- 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] yahoo
whch collg wat package? last time when it came to our collg..it has 4 questions on probablity..2-3 on c..and rest 15 20 on unix.. On Fri, Sep 9, 2011 at 3:40 PM, htross htb...@gmail.com wrote: hi everyone yahoo is coming to our college on september 30 what kind of questions will be asked in first round??? how to prepare for the first round -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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: yahoo
yeah..after that their was..one coding..round..and then interviews... i didnt gave the coding round..bt i know..that there was..coding round.. On Fri, Sep 9, 2011 at 5:15 PM, htross htb...@gmail.com wrote: its offering 9.55was there a coding round also On Sep 9, 4:19 pm, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: whch collg wat package? last time when it came to our collg..it has 4 questions on probablity..2-3 on c..and rest 15 20 on unix.. On Fri, Sep 9, 2011 at 3:40 PM, htross htb...@gmail.com wrote: hi everyone yahoo is coming to our college on september 30 what kind of questions will be asked in first round??? how to prepare for the first round -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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] IOCL
can anyone tell me the procedure for IOCL? paper nd all -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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] Aps
am getting 16.8 elephants :( ...if i dont consider the legs of mahout that are sitting on elephant On Wed, Sep 7, 2011 at 9:23 PM, Ishan Aggarwal ishan.aggarwal.1...@gmail.com wrote: why wont u consider those.. Its no where mentioned in the problem that u are not supposed to count those mahouts sitting on the elephants... The statement is just to make it tricky nothing else... On Wed, Sep 7, 2011 at 9:19 PM, Mani Bharathi manibharat...@gmail.comwrote: how? mahouts sitting on the elephants shouldn't be considered -- 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/-/9hWKNBJXPYEJ. 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. -- Kind Regards Ishan Aggarwal [image: Aricent Group] Presidency Tower-A, M.G.Road,Sector-14 Gurgaon,Haryana.122015 INDIA Phone : +91-9654602663 ishan2.aggar...@aricent.com puneet.ar...@aricent.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?hl=en. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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] os
wats the ans... 21?? On Wed, Sep 7, 2011 at 9:42 PM, vivek goel vivek.thapar2...@gmail.comwrote: can anyone explain me how?? plsss On Wed, Sep 7, 2011 at 9:40 PM, rahul vatsa vatsa.ra...@gmail.com wrote: 19 prs will be created, total 20 prs. we have discussed this a few days back. plz check the old thread for any explanation. On Wed, Sep 7, 2011 at 12:01 PM, Mohit Goel mohitgoel291...@gmail.comwrote: a. 15 b. 19 c. 21 d. 27 e. 31 these are the only options. -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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] os
ups...19 i guess On Wed, Sep 7, 2011 at 9:52 PM, Dheeraj Sharma dheerajsharma1...@gmail.comwrote: wats the ans... 21?? On Wed, Sep 7, 2011 at 9:42 PM, vivek goel vivek.thapar2...@gmail.comwrote: can anyone explain me how?? plsss On Wed, Sep 7, 2011 at 9:40 PM, rahul vatsa vatsa.ra...@gmail.comwrote: 19 prs will be created, total 20 prs. we have discussed this a few days back. plz check the old thread for any explanation. On Wed, Sep 7, 2011 at 12:01 PM, Mohit Goel mohitgoel291...@gmail.comwrote: a. 15 b. 19 c. 21 d. 27 e. 31 these are the only options. -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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] C output????
in case of constant strings..they all return the same pointer..where they are defined.. but in case of non constant strings..like a[]=sumthing and b[]=sumthing...they will have separate memory allocations.. On Tue, Sep 6, 2011 at 9:12 PM, aditi garg aditi.garg.6...@gmail.comwrote: It is basically comparing the addresses of the two and since p contains the memory address of persons it gives the output as technical persons... infact ull be surprised to see dis #includestdio.h main(){char p[]=persons;char q[]=persons;if(p==q) printf http://www.opengroup.org/onlinepubs/009695399/functions/printf.html(technical %s,p);elseprintf http://www.opengroup.org/onlinepubs/009695399/functions/printf.html(true %s,p);return 0;} output : true persons #includestdio.h main(){char *p=persons;char *q=persons;if(p==q) printf http://www.opengroup.org/onlinepubs/009695399/functions/printf.html(technical %s,p);elseprintf http://www.opengroup.org/onlinepubs/009695399/functions/printf.html(true %s,p);return 0; } bt Here output will be Technical persons On Tue, Sep 6, 2011 at 9:04 PM, sivaviknesh s sivavikne...@gmail.comwrote: main() { char *p=persons; clrscr(); if(p==persons) printf(technical %s,p); else printf(true %s,p); return 0; } ..op : technical persons ..plz explain .. how come it works like an strcmp operation??? -- Regards, $iva -- 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. -- Aditi Garg Undergraduate Student Electronics Communication Divison NETAJI SUBHAS INSTITUTE OF TECHNOLOGY Sector 3, Dwarka New Delhi -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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] Min no of moves
i thnk n/2 swaps are required... 1/4 is of the total glasses present.. i.e. 2n/4 ..=n/2 On Mon, Sep 5, 2011 at 11:52 AM, sachin goyal monugoya...@gmail.com wrote: PLEASE CORRECT ME ADITYA On Mon, Sep 5, 2011 at 11:52 AM, sachin goyal monugoya...@gmail.comwrote: 12345|12345 F|E WE HAVE TO CREATE THE PATTERN LIKE F E F E F E F E F E ACCORDING TO MY UNDERSTANDING WE CAN DIRECTLY REPLACE THE 2ND WITH SECOND AND 4TH WITH 4TH TELL CORRECT ME IF I AM WRONG AND I AM TRATING WRONG??? On Sun, Sep 4, 2011 at 8:04 PM, *$* gopi.komand...@gmail.com wrote: yes n/4 swaps are required. +1 aditya kumar On Sun, Sep 4, 2011 at 6:32 PM, aditya kumar aditya.kumar130...@gmail.com wrote: swap n/2-1 with n/2+1 , and then n/2-3 with n/2+3 till we reach n-1 . so we need n/4 swaps . On Sun, Sep 4, 2011 at 5:28 PM, Anup Ghatage ghat...@gmail.com wrote: That's interesting. when n = 3 We have been given this :F F F | E E E Swap the middle element and it becomes: F E F | E F E Which is what you want, but when n = 5 F F F F F | E E E E E And you swap the middle element it becomes: F F E F F | E E F E E So the same startegy doesn't apply. But if you do with from the center for every alternate element, it works for n = 3 F F F | E E E F F E | F E E E F E | E F E It also works for n = 5 etc. So, It is a more uniform solution if you may. -- 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. -- Thx, --Gopi -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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] Min no of moves
solution is like (assuming the array starts from 1 and ends at 2n) i=2; j=2n-1; while(ij) { SWAP(arr[i],arr[j]); i+=2; j-=2; } correct me if m wrong On Mon, Sep 5, 2011 at 5:31 PM, Aditya Virmani virmanisadi...@gmail.comwrote: doesnt ur soln fails for even n? suppose initial config : || now starting with second n +2 th FEFF||EFEE next 4, n+4: FEFE || EFEF 4th 5th EE are continuous, correct me if m wrong: my soln wud rather start with swaping 2nd 2n - 2 th element... n/4 swaps... On Sun, Sep 4, 2011 at 3:24 PM, SHIVAM AGRAWAL shivi...@gmail.com wrote: There are 2n glasses standing next to each other in a row, the first n of them are filled with a soda drink, while the remaining n glasses are empty. Make the glasses alternate in a filledempty- filled-empty pattern in the minimum no of glass moves. my soln is start with 2nd and (n+2)th swap them and then move to 4th and n+4th this is to be done n/2 times.total swaps are n/2 .. and total moves n/2*2 ie n... mine is n moves ...any1 with some better answer ??? -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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] explain the output..!!
yeah same as sukran.. On Mon, Sep 5, 2011 at 7:55 PM, Dheeraj Sharma dheerajsharma1...@gmail.comwrote: placing 0 before the numbers..makes it in octal notation... On Mon, Sep 5, 2011 at 7:48 PM, Mohit Goel mohitgoel291...@gmail.comwrote: 1) #include stdio.h #include stdlib.h #define SIZEOF(arr) (sizeof(arr)/sizeof(arr[0])) #define PrintInt(expr) printf(%s:%d\n,#expr,(expr)) int main () { /* The powers of 10 */ int pot[] = { 0001,0010,0100,1000 }; int i; for(i=0;iSIZEOF(pot);i++) PrintInt(pot[i]); return 0; } -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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] MICROSOFT
count sort in reverse order would help i guess :) On Sat, Sep 3, 2011 at 11:49 PM, mohit verma mohit89m...@gmail.com wrote: Ohh my bad. the complexity should be O(nlogn) + O(mlogm) +O(m) = O(tlogt) where t=max(m,n) On Sat, Sep 3, 2011 at 11:46 PM, mohit verma mohit89m...@gmail.comwrote: create a binary search tree by scanning the whole array and if the value already exists increase count field in that node O(nlogn). Now traverse the tree in any order by creating another tree with kery - count. O(nlogn). Doing reverse inorder traversal print value field of each node count number of times O(n). overall complexity - O(nlogn)+O(nlogn)+O(n) = O(nlogn). On Sat, Sep 3, 2011 at 11:16 PM, Siddhartha Banerjee thefourrup...@gmail.com wrote: perhaps we can make it O(mlogm), m= no of distinct elements... just create a hash table and store the count of the number of time elements occur... O(n), now sort the m elements and proceed as above... it is obviously not possible to do it faster than O(mlogm), where m = no of distinct elements... so order = O(n+mlogm)=O(mlogm)(???, assuming m!n) -- 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. -- *MOHIT VERMA* -- *MOHIT VERMA* -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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] Pattern Matching
for * it can be like.. for example we have any string say *ab*c*de* it is composed of three strings ..that has to be searched.in that sequece in only..which means..first ab would appear..then c ..then de.. first search for pattern ab in string..using pattern matching function.. then search for c in the remaining string(which can be found..using the pointer returned by first) then search for de in the remaining string(which can be found..using the pointer returned by second) the string b/w first and last pointer would be the result.. Correct me if am wrong.. On Sat, Sep 3, 2011 at 12:10 PM, Abhishek Yadav algowithabhis...@gmail.comwrote: Implement a function that receive a string S and a pattern containing wild characters ( * and ? only) in string P. Function return true if S matches the pattern P. -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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] Pattern Matching
for '?' u just increment ur pointer(which is returned by previous one.) by 1.. On Sun, Sep 4, 2011 at 12:09 AM, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: for * it can be like.. for example we have any string say *ab*c*de* it is composed of three strings ..that has to be searched.in that sequece in only..which means..first ab would appear..then c ..then de.. first search for pattern ab in string..using pattern matching function.. then search for c in the remaining string(which can be found..using the pointer returned by first) then search for de in the remaining string(which can be found..using the pointer returned by second) the string b/w first and last pointer would be the result.. Correct me if am wrong.. On Sat, Sep 3, 2011 at 12:10 PM, Abhishek Yadav algowithabhis...@gmail.com wrote: Implement a function that receive a string S and a pattern containing wild characters ( * and ? only) in string P. Function return true if S matches the pattern P. -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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] MICROSOFT
yeah..we it works for +ve number..within some specified range..it was alternate to O(nlogn) solution..if range is known On Sun, Sep 4, 2011 at 12:07 AM, mohit verma mohit89m...@gmail.com wrote: @dheeraj - for count sort we need to know the range the numbers are in. Otherwise how will u initialize array keeping count? On Sun, Sep 4, 2011 at 12:03 AM, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: count sort in reverse order would help i guess :) On Sat, Sep 3, 2011 at 11:49 PM, mohit verma mohit89m...@gmail.comwrote: Ohh my bad. the complexity should be O(nlogn) + O(mlogm) +O(m) = O(tlogt) where t=max(m,n) On Sat, Sep 3, 2011 at 11:46 PM, mohit verma mohit89m...@gmail.comwrote: create a binary search tree by scanning the whole array and if the value already exists increase count field in that node O(nlogn). Now traverse the tree in any order by creating another tree with kery - count. O(nlogn). Doing reverse inorder traversal print value field of each node count number of times O(n). overall complexity - O(nlogn)+O(nlogn)+O(n) = O(nlogn). On Sat, Sep 3, 2011 at 11:16 PM, Siddhartha Banerjee thefourrup...@gmail.com wrote: perhaps we can make it O(mlogm), m= no of distinct elements... just create a hash table and store the count of the number of time elements occur... O(n), now sort the m elements and proceed as above... it is obviously not possible to do it faster than O(mlogm), where m = no of distinct elements... so order = O(n+mlogm)=O(mlogm)(???, assuming m!n) -- 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. -- *MOHIT VERMA* -- *MOHIT VERMA* -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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. -- *MOHIT VERMA* -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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] Padding....
i thnk it should be 4 for int 1 for char 4 for float 3 padding to make multiple of 4..i read it from http://forums.techarena.in/software-development/1241260.htm correct me if am wrong On Sun, Sep 4, 2011 at 1:54 AM, Karthikeyan palani karthikeyan...@gmail.com wrote: in 32 bit m/c 4 for int 1 for char + 3 padding 4 for float so, totally it takes 12 bytes.. On 03/09/2011, rahul sharma rahul23111...@gmail.com wrote: ans is: 16 i thninkj... float take 8 bytes so pdding is :- int take 4 bytes 1 char 3 bytes pad + 8 byte float=16 On Sat, Sep 3, 2011 at 10:30 PM, siddharam suresh siddharam@gmail.comwrote: each object in the structure will take one memory word.(if one object then its size of that object) Thank you, Sid. On Sat, Sep 3, 2011 at 10:27 PM, Debabrata Das debabrata.barunhal...@gmail.com wrote: how output is 12 on typical 32 bit system and why? #includestdio.h struct x { int y; char x; float z; }; main() { printf(%d,sizeof(struct x)); } what is the rule of padding -- 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. -- karthikeyankkn -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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] How to find median of 2 sorted arrays of different length
let the total sum of the lengths of the two array is 'Len' Median is Len/2 (if the two arrays are combined and sorted) int count=0,i=0,j=0; while(count(Len/2)) { if(arr1[i]arr2[j]) i++; else j++; count++; } if(arr1[i]arr2[j]) arr1[i]=median else arr2[j]=median On Thu, Sep 1, 2011 at 9:01 PM, Ankur Garg ankurga...@gmail.com wrote: Can anybody explain logic ? -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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] stack interview question
b f g On Wed, Aug 31, 2011 at 11:49 AM, shiva shiva8ve...@gmail.com wrote: Suppose that a client performs an intermixed sequence of (stack) push and pop operations. The push operations put the integers 0 through 9 in order on to the stack; the pop operations print out the return value. Which of the following sequences could not occur? (a) 4 3 2 1 0 9 8 7 6 5 (b) 4 6 8 7 5 3 2 9 0 1 (c) 2 5 6 7 4 8 9 3 1 0 (d) 4 3 2 1 0 5 6 7 8 9 (e) 1 2 3 4 5 6 9 8 7 0 (f) 0 4 6 5 3 8 1 7 2 9 (g) 1 4 7 9 8 6 5 3 0 2 (h) 2 1 4 3 6 5 8 7 9 0 -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra -- 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] C output
8 3 is correct..winshuttle mein aaya tha ;) On Wed, Aug 31, 2011 at 9:30 PM, aditi garg aditi.garg.6...@gmail.comwrote: No sizeof ignores \0 On Wed, Aug 31, 2011 at 9:27 PM, SANDEEP CHUGH sandeep.aa...@gmail.comwrote: its 4 3 i think On Wed, Aug 31, 2011 at 9:25 PM, aditi garg aditi.garg.6...@gmail.comwrote: 8 3 On Wed, Aug 31, 2011 at 9:22 PM, rohit raman.u...@gmail.com wrote: output?? int main() { char *d = abc\0def\0; printf(%d %d,sizeof(d),strlen(d)); getch(); } -- 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/-/nf_M_Yoep_EJ. 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. -- Aditi Garg Undergraduate Student Electronics Communication Divison NETAJI SUBHAS INSTITUTE OF TECHNOLOGY Sector 3, Dwarka New Delhi -- 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. -- Aditi Garg Undergraduate Student Electronics Communication Divison NETAJI SUBHAS INSTITUTE OF TECHNOLOGY Sector 3, Dwarka New Delhi -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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] C output
for this char *d = abc\ldef\l; the output is 4 8 not 4 9 \l treated as one character On Wed, Aug 31, 2011 at 9:34 PM, aditi garg aditi.garg.6...@gmail.comwrote: @dheeraj yea true,,,bt ut ws an array...its a pointer here...so output will be 4 3... infact it wud be 9 3 in the case u r considering On Wed, Aug 31, 2011 at 9:32 PM, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: 8 3 is correct..winshuttle mein aaya tha ;) On Wed, Aug 31, 2011 at 9:30 PM, aditi garg aditi.garg.6...@gmail.comwrote: No sizeof ignores \0 On Wed, Aug 31, 2011 at 9:27 PM, SANDEEP CHUGH sandeep.aa...@gmail.comwrote: its 4 3 i think On Wed, Aug 31, 2011 at 9:25 PM, aditi garg aditi.garg.6...@gmail.comwrote: 8 3 On Wed, Aug 31, 2011 at 9:22 PM, rohit raman.u...@gmail.com wrote: output?? int main() { char *d = abc\0def\0; printf(%d %d,sizeof(d),strlen(d)); getch(); } -- 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/-/nf_M_Yoep_EJ. 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. -- Aditi Garg Undergraduate Student Electronics Communication Divison NETAJI SUBHAS INSTITUTE OF TECHNOLOGY Sector 3, Dwarka New Delhi -- 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. -- Aditi Garg Undergraduate Student Electronics Communication Divison NETAJI SUBHAS INSTITUTE OF TECHNOLOGY Sector 3, Dwarka New Delhi -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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. -- Aditi Garg Undergraduate Student Electronics Communication Divison NETAJI SUBHAS INSTITUTE OF TECHNOLOGY Sector 3, Dwarka New Delhi -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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] Two Pointers Missing
A doubly linked list has one Left pointer missing and at some point..one Right pointer missing..how to repair the doubly linked list? ? -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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] Two Pointers Missing
no no.. First right pointer is missing then after few nodes..left pointer is missing On Wed, Aug 31, 2011 at 9:57 PM, Sanjay Rajpal srn...@gmail.com wrote: Is it given that first left pointer is missing and there after right pointer is missing ? Or first right pointer may also be missing ? Sanju :) On Wed, Aug 31, 2011 at 9:23 AM, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: A doubly linked list has one Left pointer missing and at some point..one Right pointer missing..how to repair the doubly linked list? ? -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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: Two Pointers Missing
i get more clear to my quest.. 1.Doubly Linked List 2.Firstly some right pointer is missingand lately..some left pointer is missing 3.Head of pointer is given. 4.Repair the list.. On Wed, Aug 31, 2011 at 10:12 PM, Sanjay Rajpal srn...@gmail.com wrote: Chris : he said first, right pointer is missing, how can u repair that left pointer first as you can't go forward ? Sanju :) On Wed, Aug 31, 2011 at 9:39 AM, Chris lokr...@gmail.com wrote: When you say missing, I assume the left or right pointer is null. If that's the case, this could be a possible solution: // this fixes the missing left pointers traversing from the head node* curr = head; while (curr-right != null ) { if (curr-right-left == null) { curr-right-left = curr; } curr = curr-right; } // reverse the logic to fix pointers in the other direction starting at the end of the list node* curr = tail; while (curr-left != null) { if (curr-left-right == null) { curr-left-right = curr; } curr = curr-left; } On Aug 31, 10:23 am, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: A doubly linked list has one Left pointer missing and at some point..one Right pointer missing..how to repair the doubly linked list? ? -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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] apti????
66 sec On Wed, Aug 31, 2011 at 11:00 PM, htross htb...@gmail.com wrote: If a 6 o'clock the clock strikes 6times. The difference between the first and the last strike is 30 secs. Find the time taken when it strikes 12 -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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: Two Pointers Missing
head - node1 - node2 - node3 - node4 - node5 - node6 - ^ missing right ^missing left node7 - tail now head and tail are given..is there any way to fix the pointers again? On Wed, Aug 31, 2011 at 11:07 PM, Chris lokr...@gmail.com wrote: Being a doubly linked list you should have a head and tail (kinda the reason why you'd use a doubly linked list in the first place). If you don't then I'm not sure how you'd fix that as the rest of the list after the first missing right pointer would essentially be orphaned in memory with no valid pointers allowing you to fix the rest of the list. head - node1 - node2 - node3 - node4 - node5 - node6 - node7 - tail ^ missing left ^ missing right. Given this example, using the forward traversing while loop you would be able to fix the link between node2 and node3, but would end on node4 without any way to fix the missing right pointer since nothing would be able to access the rest of the list without a tail. And without a tail pointer, we would not know that any nodes in memory actually point back at node4 so we would just think that's the end of the list... Short of scanning the entire heap to find some memory that contains node4's address (somehow) that data is just inaccessible and orphaned now. On Aug 31, 10:44 am, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: i get more clear to my quest.. 1.Doubly Linked List 2.Firstly some right pointer is missingand lately..some left pointer is missing 3.Head of pointer is given. 4.Repair the list.. On Wed, Aug 31, 2011 at 10:12 PM, Sanjay Rajpal srn...@gmail.com wrote: Chris : he said first, right pointer is missing, how can u repair that left pointer first as you can't go forward ? Sanju :) On Wed, Aug 31, 2011 at 9:39 AM, Chris lokr...@gmail.com wrote: When you say missing, I assume the left or right pointer is null. If that's the case, this could be a possible solution: // this fixes the missing left pointers traversing from the head node* curr = head; while (curr-right != null ) { if (curr-right-left == null) { curr-right-left = curr; } curr = curr-right; } // reverse the logic to fix pointers in the other direction starting at the end of the list node* curr = tail; while (curr-left != null) { if (curr-left-right == null) { curr-left-right = curr; } curr = curr-left; } On Aug 31, 10:23 am, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: A doubly linked list has one Left pointer missing and at some point..one Right pointer missing..how to repair the doubly linked list? ? -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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: apti????
1-2,2-3,3-4,4-5,5-6 1 2 3 4 5 30/5=6 per tick similarly for 12..we will have 11 * 6 = 66 On Wed, Aug 31, 2011 at 11:19 PM, htross htb...@gmail.com wrote: how did u do it??? On Aug 31, 10:46 pm, annarao kataru kataruanna...@gmail.com wrote: it takes 66 sec after 12correct me if i am wrong -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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] query for nit kurukshtra students
yeah it came yesterday..the paper was very easy 1.u have to find loop in linked list.. 2.u are given a number..you have to print it down to zero(subtracting 5) and then print from 0 to that number(adding 5) without using local variables. 3.two C questions ..that were very easy.. 4.Print the sum of the even terms occuring in Fibbonaci (till 1000 terms) rest i dont remember..as i didnt gave the paper..this is what my frnds told me.. On Tue, Aug 30, 2011 at 9:23 PM, rahul sharma rahul23111...@gmail.comwrote: had microsoft came in nit kurukshetra in last weekif yes then guys from nit kurukshetra plz tell there procedure n questions???thnx in advance guys -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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]
u need to place..sscanf instead of scanf...to read the date..u can use %d/%d/%d... for further info..read this.. http://www.java-samples.com/showtutorial.php?tutorialid=564 On Tue, Aug 30, 2011 at 10:16 PM, rahul aravind rahularavin...@gmail.comwrote: can anyone explain the output of this program #includeiostream #includestdio.h #includeconio.h using namespace std; class date { int day,month,year; public: date(char *str); date(int m,int d,int y); date::date(); void show(); }; date::date(char *str) { scanf(str,*c*cd,month,day,year); } date::date(int m,int d,int y) { day=d; month=m; year=y; } date::date() { coutEnter month_day_year:; cinday; cinmonth; cinyear; } void date::show() { coutmonth'/'day'/'; coutyear'\n'; } main() { date sdate(11/1/1999); date idate(12,2,1998); date indate; sdate.show(); idate.show(); indate.show(); getch(); return 0; } output:1 Enter month_day_year:2 3 1 5060224/108/27 12/2/1998 3/2/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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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] query for nit kurukshtra students
int num=15 //global variable void fun() { if(num=0) { printf(0\n); return; } printf(%d\n,num); num-=5; fun(); num+=5; printf(%d\n,num); } On Wed, Aug 31, 2011 at 10:59 AM, bharatkumar bagana bagana.bharatku...@gmail.com wrote: can u pls tell me the answer for the 2nd question.. On Tue, Aug 30, 2011 at 12:04 PM, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: yeah it came yesterday..the paper was very easy 1.u have to find loop in linked list.. 2.u are given a number..you have to print it down to zero(subtracting 5) and then print from 0 to that number(adding 5) without using local variables. 3.two C questions ..that were very easy.. 4.Print the sum of the even terms occuring in Fibbonaci (till 1000 terms) rest i dont remember..as i didnt gave the paper..this is what my frnds told me.. On Tue, Aug 30, 2011 at 9:23 PM, rahul sharma rahul23111...@gmail.comwrote: had microsoft came in nit kurukshetra in last weekif yes then guys from nit kurukshetra plz tell there procedure n questions???thnx in advance guys -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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. -- **Please do not print this e-mail until urgent requirement. Go Green!! Save Papers = Save Trees *BharatKumar Bagana* **http://www.google.com/profiles/bagana.bharatkumarhttp://www.google.com/profiles/bagana.bharatkumar * Mobile +91 8056127652* bagana.bharatku...@gmail.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?hl=en. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra -- 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] Probability
i was abt to write it :) but u googled it :D On Mon, Aug 29, 2011 at 5:57 PM, Naman Mahor naman.ma...@gmail.com wrote: i hv googled it and the answer is like The enemy aircraft will be brought down even if one of the four shots hits the aircraft. The opposite of this situation is that none of the four shots hit the aircraft. The probability that none of the four shots hit the aircraft is given by (1-0.7)(1-0.6)(1-0.5)(1-0.4) = 0.3*0.4*0.5*0.6 = 0.036 So, the probability that at least one of the four hits the aircraft = 1 – 0.036 = 0.964. On Mon, Aug 29, 2011 at 5:54 PM, vishwa vishwavam...@gmail.com wrote: is it 0.55... On Mon, Aug 29, 2011 at 5:49 PM, Abhishek Yadav algowithabhis...@gmail.com wrote: i guess it would be 0.7 + 0.3*0.6 + 0.3*0.4*0.5 + 0.3*0.4*0.5*0.4 =.964.correct me if i am wrong.?? On Mon, Aug 29, 2011 at 5:34 PM, Naman Mahor naman.ma...@gmail.comwrote: An anti aircraft gun can fire four shots at a time. If the probabilities of the first, second, third and the last shot hitting the enemy aircraft are 0.7, 0.6, 0.5 and 0.4, what is the probability that four shots aimed at an enemy aircraft will bring the aircraft down? -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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] Probability
u mean to say .964 and not .946..isnt it? On Mon, Aug 29, 2011 at 5:58 PM, Sanjay Rajpal srn...@gmail.com wrote: It should be 1 - no one hits, i.e. 1 - 0.3*0.6*0.5*0.6 = 1 - 0.0540=0.9460. Correct me if m wrong.. Sanju :) On Mon, Aug 29, 2011 at 5:19 AM, Abhishek Yadav algowithabhis...@gmail.com wrote: i guess it would be 0.7 + 0.3*0.6 + 0.3*0.4*0.5 + 0.3*0.4*0.5*0.4 =.964.correct me if i am wrong.?? On Mon, Aug 29, 2011 at 5:34 PM, Naman Mahor naman.ma...@gmail.comwrote: An anti aircraft gun can fire four shots at a time. If the probabilities of the first, second, third and the last shot hitting the enemy aircraft are 0.7, 0.6, 0.5 and 0.4, what is the probability that four shots aimed at an enemy aircraft will bring the aircraft down? -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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] String Reverse
void rev_str(int i) { if(i==((length/2))) return ; rev_str(i+1); SWAP(str[i],str[length-1-i],t); } passing 0 as parameter... On Mon, Aug 29, 2011 at 5:43 PM, mani walia manis...@gmail.com wrote: aa chak code #includeconio.h #includestdio.h void rev(char*); int main() { rev(hello sexy how are you); getch(); } void rev(char *t) { if(*t) { rev(t+1); } printf(%c,*t); } khush reh... lol On Mon, Aug 29, 2011 at 5:38 PM, saurabh singh saurab...@gmail.comwrote: http://www.ideone.com/kSaff On Mon, Aug 29, 2011 at 4:17 PM, rohit agarwal agarwal.rohi...@gmail.com wrote: Print the last character of a string and call the function recursively with remaining string (of length (n-1)) -- * Thanks and Regards* ┌─┐ Rohit Agarwal Final Year B.Tech (Information Technology) NIT Durgapur http://www.nitdgp.ac.in └─┘ -- 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. -- 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. -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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] informatica
which collg?when its coming? On Mon, Aug 29, 2011 at 5:26 PM, mani walia manis...@gmail.com wrote: can anyone tell me about their procedure and written test .. plz -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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: bits
class A { public: A() { static int cou; cout++couendl; } }; make object A x[10]; On Sun, Aug 28, 2011 at 11:30 AM, shady sinv...@gmail.com wrote: already discussed, search the forum On Aug 28, 10:53 am, guna sekaran vgun...@gmail.com wrote: print 1 to 10 without using if,loops,goto, function call.recursion,etc -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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] Some bit manipulation help
yeah..dat we all know..bt wat actually this code is doing..this is wat am thinking!!! On Sun, Aug 28, 2011 at 2:12 AM, Debabrata Das debabrata.barunhal...@gmail.com wrote: Another approach!! while(x) { x=x(x-1); count++; } On Sun, Aug 28, 2011 at 2:26 PM, Nikhil Gupta nikhilgupta2...@gmail.comwrote: Here is a small piece of program which counts the number of bits set in a number. I found it online somewhere. InputOutput00(000)52(101)73(111) *int* CountBits (*unsigned* *int* x ) { *static* *unsigned* *int* mask[] *=* { 0x, 0x, 0x0F0F0F0F, 0x00FF00FF, 0x } ; *int* i ; *int* shift ; /* Number of positions to shift to right*/ *for* ( i *=*0, shift *=*1; i ** 5; i *++*, shift **=* 2) x *=* (x ** mask[i ])*+* ( ( x ** shift) ** mask[i]); *return* x; } Can anyone explain how this is working? -- Nikhil Gupta Senior Co-ordinator, Publicity CSI, NSIT Students' Branch NSIT, New Delhi, India -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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] Rotating 1D array clockwise
oh yeah..sorry ;) n thanks for the solution :) On Sat, Aug 27, 2011 at 11:26 AM, Sanjay Rajpal srn...@gmail.com wrote: u have mentioned clockwise, but o/p u r giving is anti-clock wise. solution for clockwise : See Reverse last k and first n-k numbers e.g. 5 4 3 2 1 8 7 6 now reverse whole array. 6 7 8 1 2 3 4 5. solution for anti-clockwise : See Reverse first k and last n-k numbers e.g. 3 2 1 8 7 6 5 4 now reverse whole array. 4 5 6 7 8 1 2 3 Hope u got it. Sanju :) On Fri, Aug 26, 2011 at 10:49 PM, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: How to rotate 1d array of length clockwise 'k' times?? (1,2,3,4,5,6,7,8)-(4,5,6,7,8,1,2,3) for k=3 n= 8 Give solutions which do not swap the array k times!! i.e less than O(nk) -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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] maximum XOR
brute force :P On Sat, Aug 27, 2011 at 10:22 AM, Sanjay Rajpal srn...@gmail.com wrote: +1 t jai. Sanju :) On Fri, Aug 26, 2011 at 9:46 PM, raj kumar megamonste...@gmail.comwrote: good test case jai -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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] apti!
ans is 20 *Stop Cramming Start Thinking* -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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] Given an array A[] and a integer num. Find four no.s in the array whose sum is equal to given num.
create an array of all possible PAIR sums..that would be done in O(n^2)..sort it..O(log(n))now..search this array for two pairs..that sum to the required value.. this can be done by maintaining two index..one at the lowest value..one at the highest value..and moving them accordingly..(if sum of pair exceeds given value..move up highest value pointer..else move down..lowest value pointer) On Sat, Aug 27, 2011 at 10:59 PM, tech coder techcoderonw...@gmail.comwrote: Given an array A[] and a integer num. Find four no.s in the array whose sum is equal to given num. -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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] Tejas networks
its still to come in our college..but u can go through this link..i hope it wud help u.. http://sameerbsws.blogspot.com/2010/12/latest-tejas-networks-placement-papers.html coz i thnk..u r frnd of one of mah close frnd ;) On Sat, Aug 27, 2011 at 11:45 PM, Kamakshii Aggarwal kamakshi...@gmail.comwrote: can anyone tell about tejas networks recruitment procedure? and also what topics are being asked? -- Regards, Kamakshi kamakshi...@gmail.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?hl=en. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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] Rotating 1D array clockwise
How to rotate 1d array of length clockwise 'k' times?? (1,2,3,4,5,6,7,8)-(4,5,6,7,8,1,2,3) for k=3 n= 8 Give solutions which do not swap the array k times!! i.e less than O(nk) -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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: Concept of Pointer
* and + have same precedence so right to left associatvty for first printf..and the rest printf statements are similar On Wed, Aug 24, 2011 at 2:54 PM, Avinash LetsUncomplicate.. avin.2...@gmail.com wrote: ++ is simply post increment will increment after use so *s is printed in first printf.. precedence doesnt matter coz its a single operand on which post increment has to be done also no copncept of associativity i think associativity is for same precedence operators .. Avinash NIT 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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 dot
yeah..the interview was total nakli :D .. they always..take the toppers.. :) i mean..among the top ten who are sitting.. @Sachin:- they also asked , what is Drishti ? :D On Tue, Aug 23, 2011 at 1:54 PM, Sanjay Rajpal srn...@gmail.com wrote: 7.7 LPA @ NIT Kurukshetra. Sanju :) On Mon, Aug 22, 2011 at 10:47 PM, siddharam suresh siddharam@gmail.com wrote: how much they are offering ? Thank you, Siddharam On Tue, Aug 23, 2011 at 11:12 AM, ranjith kumar v.ranjithcar...@gmail.com wrote: They shortlist candidates based on cgpa and select the highest cgpa candidate. -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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] Linklist question
u can keep a count..which is incremented when the nodes are inserted and decremented when the nodes are deleted On Wed, Aug 24, 2011 at 9:31 AM, Ankur Goel goel.anku...@gmail.com wrote: How to Count the number of nodes in a linked list without traversing the list?. -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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] probability ques
y its 45/98 and not 45/100 ?? On Wed, Aug 24, 2011 at 9:41 AM, Manoj Bagari manojbag...@gmail.com wrote: oh sorry i thought it was a+100/a50 because this same question asked by national instrument 2 day ago. in this case passibe cases wil be 44 [3-47} no so it'll be 44/100 -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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: probability ques
ok thanks On Wed, Aug 24, 2011 at 10:02 AM, Dave dave_and_da...@juno.com wrote: @Dheeraj: Because there are 98 numbers between 1 and 100. They are 2, 3, 4, ..., 99. It is a matter of semantics. 1 and 100 are not between 1 and 100. Dave On Aug 23, 11:21 pm, Dheeraj Sharma dheerajsharma1...@gmail.com wrote: y its 45/98 and not 45/100 ?? On Wed, Aug 24, 2011 at 9:41 AM, Manoj Bagari manojbag...@gmail.com wrote: oh sorry i thought it was a+100/a50 because this same question asked by national instrument 2 day ago. in this case passibe cases wil be 44 [3-47} no so it'll be 44/100 -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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: binary tree ques
let the nodes are stored in array like arr[1] arr[2] arr[3] . . . arr[7]. where arr is a structure having int x,int y. i=1 initally we set the root(i.e arr[i]) x and y = n/2,log(n) respectively i++ then we iterate in the followin way while(i=n) { arr[i].x=parent(arr[i]).x-1 arr[i].y=parent(arr[i]).y-1 i++; arr[i].x=parent(arr[i]).x+1 arr[i].y=parent(arr[i]).y-1 } Thus all node structures will contain there x and y coordinate.. m nt sure..bt it can work On Wed, Aug 24, 2011 at 10:34 AM, shashi kant shashiski...@gmail.comwrote: an improvement to above solution take a dynamic linear array structure storing (node name and y-index) and whose index tells x value of NodeName Algo: do inorder traversal and when reach the leftmost end of the tree start updating the structure. On Wed, Aug 24, 2011 at 1:53 AM, DK divyekap...@gmail.com wrote: Let Left = -1, Right = +1 For each node Set: X = Sigma{Left or Right for each node on the path from root to node} Y = -Depth of the node in the tree Go through the tree once and set X and Y values using any traversal (say postorder) in an array. Also, during that traversal, find max_height and the number of nodes in the left subtree of root. Go through the array and output: Node Name (X + num_left_nodes_of_root, Y + max_height) -- DK http://gplus.to/divyekapoor http://twitter.com/divyekapoor -- 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/-/qp4FZ3vE5WcJ. 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. -- *Shashi Kant * ***Think positive and find fuel in failure* *+919002943948* Final Yr. Cse ,Undergraduate Student, *National Institute Of Technology Durgapur.* -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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] array problem
while(a) ( a=(a-1) count++ ) counts number of 1s in number 'a'.. Loop can be breaken if count exceeds 16.. On 8/21/11, himanshu kansal himanshukansal...@gmail.com wrote: problem: There is an array containing integers. for every bit in the integer,you have to print a 1 if no of 1s corresponding to that bit is more than no of 0s corresponding to that bit (counting that bit in all the integers) otherwise print a 0(if no of 0s corresponding to that bit are more). this you have to do for all bits in the integers. assumption:integers are of 32bits. no of integers in array are odd...(i.e. there is no case like no. of 1s=no. of 0s) i have done this by counting the no of 1s and 0s for all bits. but can anyone suggest any other efficient approach (somewhat using bitwise operators). -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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] array problem
yeah i took it in the another way..i ll post it v soon On 8/21/11, himanshu kansal himanshukansal...@gmail.com wrote: problem: There is an array containing integers. for every bit in the integer,you have to print a 1 if no of 1s corresponding to that bit is more than no of 0s corresponding to that bit (counting that bit in all the integers) otherwise print a 0(if no of 0s corresponding to that bit are more). this you have to do for all bits in the integers. assumption:integers are of 32bits. no of integers in array are odd...(i.e. there is no case like no. of 1s=no. of 0s) i have done this by counting the no of 1s and 0s for all bits. but can anyone suggest any other efficient approach (somewhat using bitwise operators). -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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] array problem
yeah bt..when we talk abt the complexity..we consider abt the worst case On 8/21/11, himanshu kansal himanshukansal...@gmail.com wrote: problem: There is an array containing integers. for every bit in the integer,you have to print a 1 if no of 1s corresponding to that bit is more than no of 0s corresponding to that bit (counting that bit in all the integers) otherwise print a 0(if no of 0s corresponding to that bit are more). this you have to do for all bits in the integers. assumption:integers are of 32bits. no of integers in array are odd...(i.e. there is no case like no. of 1s=no. of 0s) i have done this by counting the no of 1s and 0s for all bits. but can anyone suggest any other efficient approach (somewhat using bitwise operators). -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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] matrix
complexity nd all? O(n^4) works? On 8/21/11, prasanth n nprasnt...@gmail.com wrote: given a matrix with +ve and -ve numbers, find the submatrix with maximum sum?? -- *prasanth* -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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]
if we take two pointers..one ahead of another initially..then jump one of the pointer twice..until it reaches the beginning(printing the valu) n similar for the another pointer does ptr-next-next means ha.f travelling the list? On 8/21/11, muthu raj muthura...@gmail.com wrote: Segregate the Odd and even nodes in the list by traversing in O(n). Then print the resulting list in O(n). So no additional space required and solution in O(n) time also :) *Muthuraj R IV th Year , ISE PESIT , Bangalore* On Fri, Aug 19, 2011 at 9:48 AM, priya ramesh love.for.programm...@gmail.com wrote: +1 sagar! i too have the same answer :) -- 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. -- *Dheeraj Sharma* Comp Engg. NIT Kurukshetra +91 8950264227 -- 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.