Re: [algogeeks] Re: MICROSOFT QUESTION
well we can do with just one array. Overwrite the answer directly on left[] array. On Thu, Aug 16, 2012 at 6:47 PM, mohit mohitsingh1...@gmail.com wrote: here are the steps : 1) Construct a temporary array left[] such that left[i] contains product of all elements on left of A[i] excluding A[i]. 2) Construct another temporary array right[] such that right[i] contains product of all elements on on right of A[i] excluding A[i]. 3) To get OUT[], multiply left[] and right[]. time complexity : O(n) On Thursday, August 16, 2012 2:26:58 PM UTC+5:30, ram wrote: Hi, This is a microsoft question asked in our campus previous year. Anyone having idea please share it here... Given an array of n elements A[n]. Write a program to create a new array OUT[n], which has its elements as multiplication of all the elements in the input array A[n] except that element (i.e.) OUT[2] = A[0] * A[1] * A[3] * ? * A[n-1]. Constraint is one should not use division operator. -- 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/-/iqyLUMLQRS0J. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: MICROSOFT QUESTION
We have to consider cases when an element is zero. On Thu, Aug 16, 2012 at 7:07 PM, shady sinv...@gmail.com wrote: well we can do with just one array. Overwrite the answer directly on left[] array. On Thu, Aug 16, 2012 at 6:47 PM, mohit mohitsingh1...@gmail.com wrote: here are the steps : 1) Construct a temporary array left[] such that left[i] contains product of all elements on left of A[i] excluding A[i]. 2) Construct another temporary array right[] such that right[i] contains product of all elements on on right of A[i] excluding A[i]. 3) To get OUT[], multiply left[] and right[]. time complexity : O(n) On Thursday, August 16, 2012 2:26:58 PM UTC+5:30, ram wrote: Hi, This is a microsoft question asked in our campus previous year. Anyone having idea please share it here... Given an array of n elements A[n]. Write a program to create a new array OUT[n], which has its elements as multiplication of all the elements in the input array A[n] except that element (i.e.) OUT[2] = A[0] * A[1] * A[3] * ? * A[n-1]. Constraint is one should not use division operator. -- 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/-/iqyLUMLQRS0J. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: MICROSOFT QUESTION
@Navin: Why? No division is used. Dave On Thursday, August 16, 2012 9:20:03 AM UTC-5, Navin Kumar wrote: We have to consider cases when an element is zero. On Thu, Aug 16, 2012 at 7:07 PM, shady sin...@gmail.com javascript:wrote: well we can do with just one array. Overwrite the answer directly on left[] array. On Thu, Aug 16, 2012 at 6:47 PM, mohit mohitsi...@gmail.comjavascript: wrote: here are the steps : 1) Construct a temporary array left[] such that left[i] contains product of all elements on left of A[i] excluding A[i]. 2) Construct another temporary array right[] such that right[i] contains product of all elements on on right of A[i] excluding A[i]. 3) To get OUT[], multiply left[] and right[]. time complexity : O(n) On Thursday, August 16, 2012 2:26:58 PM UTC+5:30, ram wrote: Hi, This is a microsoft question asked in our campus previous year. Anyone having idea please share it here... Given an array of n elements A[n]. Write a program to create a new array OUT[n], which has its elements as multiplication of all the elements in the input array A[n] except that element (i.e.) OUT[2] = A[0] * A[1] * A[3] * ? * A[n-1]. Constraint is one should not use division operator. -- 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/-/iqyLUMLQRS0J. To post to this group, send email to algo...@googlegroups.comjavascript: . To unsubscribe from this group, send email to algogeeks+...@googlegroups.com javascript:. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algo...@googlegroups.comjavascript: . To unsubscribe from this group, send email to algogeeks+...@googlegroups.com javascript:. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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/-/cOrXdXwNPUQJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 question
refer to this link http://www.ics.uci.edu/~eppstein/161/960130.html. or Using quicksort , it can be done in O(n). One more way to do this is to make min heap of size-k. Then insert elements from the original array.If element is greater than root of the heap,swap them.In the Last, root of the heap would be the kth smallest element On Wed, Jun 20, 2012 at 8:47 PM, ajeet ajeet.sing...@gmail.com wrote: Hi, It looks like, The interviewer is expecting MinHeap from you, If modification to array is permitted just build the heap in place (from end bubbleUp n-1 time) and extract K elements in sorted order Otherwise you need minimum O(K) memory Again if you want to use the quick-sort, I would prefer only using partition part of quick sort.. 1. Select any pivot 'P' 2. Partition the array.. 3. position of the pivot p 4. if p k ( kth min lies on left part) repeat again for k 5 if p k ( kth min lies on right part) repeat again for k-p 6 if p = k ( You are lucky) exit Again in worst case it is o(N2) -Ajeet Thanks -A On Wednesday, 20 June 2012 00:56:36 UTC+5:30, adarsh kumar wrote: This can be done using the concept of median of medians, wherein we can achieve linear time complexity in the worst case. This is a concept used in parallel algorithms too, check it out. On Mon, Jun 18, 2012 at 5:38 PM, Prem Nagarajan prem.cmna...@gmail.comwrote: @enchantress : This problem can be solved using quicksort in O(nlogn). No need to go for selection sort. But O(n) solution is needed. On Mon, Jun 18, 2012 at 2:50 PM, enchantress elaenjoy...@gmail.comwrote: Hi all, A variation of selection sort can be used which takes O(nk) time. for i 1 to k min_index = i for j i+1 to n if a[j] a[min_index] min_index = j swap(a[i],a[min_index]) required element : a[k] On Sunday, 17 June 2012 08:13:18 UTC+5:30, Prem Nagarajan wrote: Give an array of unsorted elements, find the kth smallest element in the array. The expected time complexity is O(n) and no extra memory space should be used. Quickselect algorithm can be used to obtain the solution. Can anyone explain how quickselect works? -- 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/-/FABBRabzVqMJhttps://groups.google.com/d/msg/algogeeks/-/FABBRabzVqMJ . To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscribe@** googlegroups.com algogeeks%2bunsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/** group/algogeeks?hl=en 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+unsubscribe@** googlegroups.com algogeeks%2bunsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/** group/algogeeks?hl=en http://groups.google.com/group/algogeeks?hl=en. -- 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/-/sBvT2ztJpoUJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Abhishek Sharma Under-Graduate Student, PEC University of Technology -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 question
Can't we use k iterations of bubble sort ? On Jun 18, 2012 2:11 PM, Ramindar Singh ramin...@gmail.com wrote: We can use Median of medians http://en.wikipedia.org/wiki/Selection_algorithm#Linear_general_selection_algorithm_-_Median_of_Medians_algorithm On Sunday, 17 June 2012 08:13:18 UTC+5:30, Prem Nagarajan wrote: Give an array of unsorted elements, find the kth smallest element in the array. The expected time complexity is O(n) and no extra memory space should be used. Quickselect algorithm can be used to obtain the solution. Can anyone explain how quickselect works? -- 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/-/4lQsacmUPYUJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Microsoft question
Hi, It looks like, The interviewer is expecting MinHeap from you, If modification to array is permitted just build the heap in place (from end bubbleUp n-1 time) and extract K elements in sorted order Otherwise you need minimum O(K) memory Again if you want to use the quick-sort, I would prefer only using partition part of quick sort.. 1. Select any pivot 'P' 2. Partition the array.. 3. position of the pivot p 4. if p k ( kth min lies on left part) repeat again for k 5 if p k ( kth min lies on right part) repeat again for k-p 6 if p = k ( You are lucky) exit Again in worst case it is o(N2) -Ajeet Thanks -A On Wednesday, 20 June 2012 00:56:36 UTC+5:30, adarsh kumar wrote: This can be done using the concept of median of medians, wherein we can achieve linear time complexity in the worst case. This is a concept used in parallel algorithms too, check it out. On Mon, Jun 18, 2012 at 5:38 PM, Prem Nagarajan prem.cmna...@gmail.comwrote: @enchantress : This problem can be solved using quicksort in O(nlogn). No need to go for selection sort. But O(n) solution is needed. On Mon, Jun 18, 2012 at 2:50 PM, enchantress elaenjoy...@gmail.comwrote: Hi all, A variation of selection sort can be used which takes O(nk) time. for i 1 to k min_index = i for j i+1 to n if a[j] a[min_index] min_index = j swap(a[i],a[min_index]) required element : a[k] On Sunday, 17 June 2012 08:13:18 UTC+5:30, Prem Nagarajan wrote: Give an array of unsorted elements, find the kth smallest element in the array. The expected time complexity is O(n) and no extra memory space should be used. Quickselect algorithm can be used to obtain the solution. Can anyone explain how quickselect works? -- 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/-/FABBRabzVqMJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/sBvT2ztJpoUJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 question
This can be done using the concept of median of medians, wherein we can achieve linear time complexity in the worst case. This is a concept used in parallel algorithms too, check it out. On Mon, Jun 18, 2012 at 5:38 PM, Prem Nagarajan prem.cmna...@gmail.comwrote: @enchantress : This problem can be solved using quicksort in O(nlogn). No need to go for selection sort. But O(n) solution is needed. On Mon, Jun 18, 2012 at 2:50 PM, enchantress elaenjoy...@gmail.comwrote: Hi all, A variation of selection sort can be used which takes O(nk) time. for i 1 to k min_index = i for j i+1 to n if a[j] a[min_index] min_index = j swap(a[i],a[min_index]) required element : a[k] On Sunday, 17 June 2012 08:13:18 UTC+5:30, Prem Nagarajan wrote: Give an array of unsorted elements, find the kth smallest element in the array. The expected time complexity is O(n) and no extra memory space should be used. Quickselect algorithm can be used to obtain the solution. Can anyone explain how quickselect works? -- 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/-/FABBRabzVqMJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Microsoft question
@enchantress : This problem can be solved using quicksort in O(nlogn). No need to go for selection sort. But O(n) solution is needed. On Mon, Jun 18, 2012 at 2:50 PM, enchantress elaenjoy...@gmail.com wrote: Hi all, A variation of selection sort can be used which takes O(nk) time. for i 1 to k min_index = i for j i+1 to n if a[j] a[min_index] min_index = j swap(a[i],a[min_index]) required element : a[k] On Sunday, 17 June 2012 08:13:18 UTC+5:30, Prem Nagarajan wrote: Give an array of unsorted elements, find the kth smallest element in the array. The expected time complexity is O(n) and no extra memory space should be used. Quickselect algorithm can be used to obtain the solution. Can anyone explain how quickselect works? -- 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/-/FABBRabzVqMJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Microsoft Question
Priority Queue: when popped ... returns the max priority element and if the priorities of two or more elements are same...then they will popped as they are inserted .. when pushed the element : puts the element in the list according to the priority... For making priority queue into Queue:: on popping : make priority of every element same... so on popping... the element...(popped according to which they are inserted) on pushing : insert the element as same priority as other inserted elements For making priority queue into stack..: make priority of elements in increasing order... .. so on popping the element... will pop the topmost element(with the highest priority value).. on pushing the element... push the element... with the priority value more than topmost priority value... With regards, Praveen Raj DCE-IT 3rd yr 735993 praveen0...@gmail.com On Thu, Sep 15, 2011 at 6:37 PM, Yogesh Yadav medu...@gmail.com wrote: For Stack: just make a structure: struct stack_with_priorityqueue { int num; int priority; struct stack_with_priorityqueue *ptr; } now when we add another number just increase the priority... priority++ For Queue: do same...just decrease priority...priority-- ... On Wed, Sep 14, 2011 at 4:41 PM, bharatkumar bagana bagana.bharatku...@gmail.com wrote: The well known examples of priority queue is minheap and maxheap.. i guess the question is how do we implement one of these(at least) using queue? On Wed, Sep 14, 2011 at 9:08 AM, Ankuj Gupta ankuj2...@gmail.com wrote: I guess the functionality of priority should be maintained On Sep 13, 11:59 pm, Ankur Garg ankurga...@gmail.com wrote: But dude are u saying stack will be implemented as a map with value,priority and then choose element based on priority ? regards Ankur On Tue, Sep 13, 2011 at 10:16 PM, Ankuj Gupta ankuj2...@gmail.com wrote: For stack :- Keep incrementing the priority of each pushed element. So the last pushed element will have the greatest priority and the element pushed first will have lowest priority. For queue:- keep decrementing the priority of each inserted element. On Sep 13, 1:45 am, Ankur Garg ankurga...@gmail.com wrote: How to Implement a Queue with a Priority Queue Similarly how woud you implement Stack with Priority Queue -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- **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. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Microsoft Question
On 10/29/11, praveen raj praveen0...@gmail.com wrote: Priority Queue: when popped ... returns the max priority element and if the priorities of two or more elements are same...then they will popped as they are inserted .. when pushed the element : puts the element in the list according to the priority... For making priority queue into Queue:: on popping : make priority of every element same... so on popping... the element...(popped according to which they are inserted) on pushing : insert the element as same priority as other inserted elements For making priority queue into stack..: make priority of elements in increasing order... .. so on popping the element... will pop the topmost element(with the highest priority value).. on pushing the element... push the element... with the priority value more than topmost priority value... With regards, Praveen Raj DCE-IT 3rd yr 735993 praveen0...@gmail.com On Thu, Sep 15, 2011 at 6:37 PM, Yogesh Yadav medu...@gmail.com wrote: For Stack: just make a structure: struct stack_with_priorityqueue { int num; int priority; struct stack_with_priorityqueue *ptr; } now when we add another number just increase the priority... priority++ For Queue: do same...just decrease priority...priority-- ... On Wed, Sep 14, 2011 at 4:41 PM, bharatkumar bagana bagana.bharatku...@gmail.com wrote: The well known examples of priority queue is minheap and maxheap.. i guess the question is how do we implement one of these(at least) using queue? On Wed, Sep 14, 2011 at 9:08 AM, Ankuj Gupta ankuj2...@gmail.com wrote: I guess the functionality of priority should be maintained On Sep 13, 11:59 pm, Ankur Garg ankurga...@gmail.com wrote: But dude are u saying stack will be implemented as a map with value,priority and then choose element based on priority ? regards Ankur On Tue, Sep 13, 2011 at 10:16 PM, Ankuj Gupta ankuj2...@gmail.com wrote: For stack :- Keep incrementing the priority of each pushed element. So the last pushed element will have the greatest priority and the element pushed first will have lowest priority. For queue:- keep decrementing the priority of each inserted element. On Sep 13, 1:45 am, Ankur Garg ankurga...@gmail.com wrote: How to Implement a Queue with a Priority Queue Similarly how woud you implement Stack with Priority Queue -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- **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. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: 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: Microsoft Question
@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.
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: Microsoft Question
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.
Re: [algogeeks] Re: Microsoft Question
@piyush: what is time and space complexity of u'r sol.. On Mon, Sep 19, 2011 at 11:03 AM, Piyush Grover piyush4u.iit...@gmail.comwrote: sry, in the findWord function all a's are different e.g a0, a1a7 and if(!a) is actually if(a0||a1||...||a7) thnx piyush On Mon, Sep 19, 2011 at 1:10 AM, Piyush Grover piyush4u.iit...@gmail.comwrote: for(i = 0; i n; i++) for(j = 0; j n; j++){ setColor(i, j) = black; if(A[i][j] == str[0]){ setColor(i, j) = blue; a = findWord(A, i, j, str, 1) if(!a) setColor(i, j) = black; else break; } } findWord(A, i, j, str, k){ if(k == strlen(str)) return true; if(A[i-1][j-1] == str[k] getColor(i-1, j-1) != blue) setColor(i-1, j-1) = blue; a = findWord(A, i-1, j-1, str, k+1); if(A[i-1][j] == str[k] getColor(i-1, j) != blue) setColor(i-1, j) = blue; a = findWord(A, i-1, j, str, k+1); if(A[i-1][j+1] == str[k] getColor(i-1, j+1) != blue) setColor(i-1, j+1) = blue; a = findWord(A, i-1, j+1, str, k+1); if(A[i][j-1] == str[k] getColor(i, j-1) != blue) setColor(i, j-1) = blue; a = findWord(A, i, j-1, str, k+1); if(A[i][j+1] == str[k] getColor(i, j+1) != blue) setColor(i, j+1) = blue; a = findWord(A, i, j+1, str, k+1); if(A[i+1][j-1] == str[k] getColor(i+1, j-1) != blue) setColor(i+1, j-1) = blue; a = findWord(A, i+1, j-1, str, k+1); if(A[i+1][j] == str[k] getColor(i+1, j) != blue) setColor(i+1, j) = blue; a = findWord(A, i+1, j, str, k+1); if(A[i+1][j+1] == str[k] getColor(i+1, j+1) != blue) setColor(i+1, j+1) = blue; a = findWord(A, i+1, j+1, str, k+1); if(!a) setColor(i, j) = black; return a; } This is a pseudo code. I haven't considered the boundary cases to make it understandable. On Mon, Sep 19, 2011 at 12:21 AM, vikas vikas.rastogi2...@gmail.comwrote: hmm, nice questions, can we create an efficient DS to query the strings ?? tried using trie but memory prints are very large ( O(n^2) )? :-(( On Sep 18, 12:59 pm, Anup Ghatage ghat...@gmail.com wrote: For the mentioned scenario, it seems to be the only feasible solution. On Sun, Sep 18, 2011 at 3:57 AM, bharatkumar bagana bagana.bharatku...@gmail.com wrote: @anup : the time complexity will be very high ... O(n*M*M)...n=#characters to be checked...M=size of the matrix ... On Sat, Sep 17, 2011 at 8:30 AM, Anup Ghatage ghat...@gmail.com wrote: As WgpShashank once pointed out. Search the whole matrix for the first character instances, for each instance, send the array, string and that char's position to a function that will recursively check its direct neighbors for the next character. Exhaustively check like that for each starting characters appearance till you find the string, if any. On Fri, Sep 16, 2011 at 11:55 PM, Ankur Garg ankurga...@gmail.com wrote: In a matrix of. characters, find an string. String can be in any way (all 8 neighbours to be considered) like find Microsoft in below matrix. A C P *R *C* *X *S **O *P *C* V *O* V N *I* W G *F **M *N Q A *T* I T *Any Ideas How to Solve/Approach this problem ?* -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- **Please do not print this e-mail until urgent requirement. Go Green!! Save Papers = Save Trees *BharatKumar Bagana* **http://www.google.com/profiles/bagana.bharatkumar http://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. -- Anup Ghatage -- You received this message because you are subscribed to
Re: [algogeeks] Re: Microsoft Question
for(i = 0; i n; i++) for(j = 0; j n; j++){ setColor(i, j) = black; if(A[i][j] == str[0]){ setColor(i, j) = blue; a = findWord(A, i, j, str, 1) if(!a) setColor(i, j) = black; else break; } } findWord(A, i, j, str, k){ if(k == strlen(str)) return true; if(A[i-1][j-1] == str[k] getColor(i-1, j-1) != blue) setColor(i-1, j-1) = blue; a = findWord(A, i-1, j-1, str, k+1); if(A[i-1][j] == str[k] getColor(i-1, j) != blue) setColor(i-1, j) = blue; a = findWord(A, i-1, j, str, k+1); if(A[i-1][j+1] == str[k] getColor(i-1, j+1) != blue) setColor(i-1, j+1) = blue; a = findWord(A, i-1, j+1, str, k+1); if(A[i][j-1] == str[k] getColor(i, j-1) != blue) setColor(i, j-1) = blue; a = findWord(A, i, j-1, str, k+1); if(A[i][j+1] == str[k] getColor(i, j+1) != blue) setColor(i, j+1) = blue; a = findWord(A, i, j+1, str, k+1); if(A[i+1][j-1] == str[k] getColor(i+1, j-1) != blue) setColor(i+1, j-1) = blue; a = findWord(A, i+1, j-1, str, k+1); if(A[i+1][j] == str[k] getColor(i+1, j) != blue) setColor(i+1, j) = blue; a = findWord(A, i+1, j, str, k+1); if(A[i+1][j+1] == str[k] getColor(i+1, j+1) != blue) setColor(i+1, j+1) = blue; a = findWord(A, i+1, j+1, str, k+1); if(!a) setColor(i, j) = black; return a; } This is a pseudo code. I haven't considered the boundary cases to make it understandable. On Mon, Sep 19, 2011 at 12:21 AM, vikas vikas.rastogi2...@gmail.com wrote: hmm, nice questions, can we create an efficient DS to query the strings ?? tried using trie but memory prints are very large ( O(n^2) )? :-(( On Sep 18, 12:59 pm, Anup Ghatage ghat...@gmail.com wrote: For the mentioned scenario, it seems to be the only feasible solution. On Sun, Sep 18, 2011 at 3:57 AM, bharatkumar bagana bagana.bharatku...@gmail.com wrote: @anup : the time complexity will be very high ... O(n*M*M)...n=#characters to be checked...M=size of the matrix ... On Sat, Sep 17, 2011 at 8:30 AM, Anup Ghatage ghat...@gmail.com wrote: As WgpShashank once pointed out. Search the whole matrix for the first character instances, for each instance, send the array, string and that char's position to a function that will recursively check its direct neighbors for the next character. Exhaustively check like that for each starting characters appearance till you find the string, if any. On Fri, Sep 16, 2011 at 11:55 PM, Ankur Garg ankurga...@gmail.com wrote: In a matrix of. characters, find an string. String can be in any way (all 8 neighbours to be considered) like find Microsoft in below matrix. A C P *R *C* *X *S **O *P *C* V *O* V N *I* W G *F **M *N Q A *T* I T *Any Ideas How to Solve/Approach this problem ?* -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- **Please do not print this e-mail until urgent requirement. Go Green!! Save Papers = Save Trees *BharatKumar Bagana* **http://www.google.com/profiles/bagana.bharatkumar http://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. -- 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. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to
Re: [algogeeks] Re: Microsoft Question
sry, in the findWord function all a's are different e.g a0, a1a7 and if(!a) is actually if(a0||a1||...||a7) thnx piyush On Mon, Sep 19, 2011 at 1:10 AM, Piyush Grover piyush4u.iit...@gmail.comwrote: for(i = 0; i n; i++) for(j = 0; j n; j++){ setColor(i, j) = black; if(A[i][j] == str[0]){ setColor(i, j) = blue; a = findWord(A, i, j, str, 1) if(!a) setColor(i, j) = black; else break; } } findWord(A, i, j, str, k){ if(k == strlen(str)) return true; if(A[i-1][j-1] == str[k] getColor(i-1, j-1) != blue) setColor(i-1, j-1) = blue; a = findWord(A, i-1, j-1, str, k+1); if(A[i-1][j] == str[k] getColor(i-1, j) != blue) setColor(i-1, j) = blue; a = findWord(A, i-1, j, str, k+1); if(A[i-1][j+1] == str[k] getColor(i-1, j+1) != blue) setColor(i-1, j+1) = blue; a = findWord(A, i-1, j+1, str, k+1); if(A[i][j-1] == str[k] getColor(i, j-1) != blue) setColor(i, j-1) = blue; a = findWord(A, i, j-1, str, k+1); if(A[i][j+1] == str[k] getColor(i, j+1) != blue) setColor(i, j+1) = blue; a = findWord(A, i, j+1, str, k+1); if(A[i+1][j-1] == str[k] getColor(i+1, j-1) != blue) setColor(i+1, j-1) = blue; a = findWord(A, i+1, j-1, str, k+1); if(A[i+1][j] == str[k] getColor(i+1, j) != blue) setColor(i+1, j) = blue; a = findWord(A, i+1, j, str, k+1); if(A[i+1][j+1] == str[k] getColor(i+1, j+1) != blue) setColor(i+1, j+1) = blue; a = findWord(A, i+1, j+1, str, k+1); if(!a) setColor(i, j) = black; return a; } This is a pseudo code. I haven't considered the boundary cases to make it understandable. On Mon, Sep 19, 2011 at 12:21 AM, vikas vikas.rastogi2...@gmail.comwrote: hmm, nice questions, can we create an efficient DS to query the strings ?? tried using trie but memory prints are very large ( O(n^2) )? :-(( On Sep 18, 12:59 pm, Anup Ghatage ghat...@gmail.com wrote: For the mentioned scenario, it seems to be the only feasible solution. On Sun, Sep 18, 2011 at 3:57 AM, bharatkumar bagana bagana.bharatku...@gmail.com wrote: @anup : the time complexity will be very high ... O(n*M*M)...n=#characters to be checked...M=size of the matrix ... On Sat, Sep 17, 2011 at 8:30 AM, Anup Ghatage ghat...@gmail.com wrote: As WgpShashank once pointed out. Search the whole matrix for the first character instances, for each instance, send the array, string and that char's position to a function that will recursively check its direct neighbors for the next character. Exhaustively check like that for each starting characters appearance till you find the string, if any. On Fri, Sep 16, 2011 at 11:55 PM, Ankur Garg ankurga...@gmail.com wrote: In a matrix of. characters, find an string. String can be in any way (all 8 neighbours to be considered) like find Microsoft in below matrix. A C P *R *C* *X *S **O *P *C* V *O* V N *I* W G *F **M *N Q A *T* I T *Any Ideas How to Solve/Approach this problem ?* -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- **Please do not print this e-mail until urgent requirement. Go Green!! Save Papers = Save Trees *BharatKumar Bagana* **http://www.google.com/profiles/bagana.bharatkumar http://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. -- 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
Re: [algogeeks] Re: Microsoft Question
For Stack: just make a structure: struct stack_with_priorityqueue { int num; int priority; struct stack_with_priorityqueue *ptr; } now when we add another number just increase the priority... priority++ For Queue: do same...just decrease priority...priority-- ... On Wed, Sep 14, 2011 at 4:41 PM, bharatkumar bagana bagana.bharatku...@gmail.com wrote: The well known examples of priority queue is minheap and maxheap.. i guess the question is how do we implement one of these(at least) using queue? On Wed, Sep 14, 2011 at 9:08 AM, Ankuj Gupta ankuj2...@gmail.com wrote: I guess the functionality of priority should be maintained On Sep 13, 11:59 pm, Ankur Garg ankurga...@gmail.com wrote: But dude are u saying stack will be implemented as a map with value,priority and then choose element based on priority ? regards Ankur On Tue, Sep 13, 2011 at 10:16 PM, Ankuj Gupta ankuj2...@gmail.com wrote: For stack :- Keep incrementing the priority of each pushed element. So the last pushed element will have the greatest priority and the element pushed first will have lowest priority. For queue:- keep decrementing the priority of each inserted element. On Sep 13, 1:45 am, Ankur Garg ankurga...@gmail.com wrote: How to Implement a Queue with a Priority Queue Similarly how woud you implement Stack with Priority Queue -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- **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. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Question
The well known examples of priority queue is minheap and maxheap.. i guess the question is how do we implement one of these(at least) using queue? On Wed, Sep 14, 2011 at 9:08 AM, Ankuj Gupta ankuj2...@gmail.com wrote: I guess the functionality of priority should be maintained On Sep 13, 11:59 pm, Ankur Garg ankurga...@gmail.com wrote: But dude are u saying stack will be implemented as a map with value,priority and then choose element based on priority ? regards Ankur On Tue, Sep 13, 2011 at 10:16 PM, Ankuj Gupta ankuj2...@gmail.com wrote: For stack :- Keep incrementing the priority of each pushed element. So the last pushed element will have the greatest priority and the element pushed first will have lowest priority. For queue:- keep decrementing the priority of each inserted element. On Sep 13, 1:45 am, Ankur Garg ankurga...@gmail.com wrote: How to Implement a Queue with a Priority Queue Similarly how woud you implement Stack with Priority Queue -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- **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.
Re: [algogeeks] Re: Microsoft Question
But dude are u saying stack will be implemented as a map with value,priority and then choose element based on priority ? regards Ankur On Tue, Sep 13, 2011 at 10:16 PM, Ankuj Gupta ankuj2...@gmail.com wrote: For stack :- Keep incrementing the priority of each pushed element. So the last pushed element will have the greatest priority and the element pushed first will have lowest priority. For queue:- keep decrementing the priority of each inserted element. On Sep 13, 1:45 am, Ankur Garg ankurga...@gmail.com wrote: How to Implement a Queue with a Priority Queue Similarly how woud you implement Stack with Priority Queue -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Microsoft Question!
check this out: Considering all 4 bytes of int with no left or right shifts..!! ;) main() { unsigned int i,j,k,no=1; j=4; for(k=0;k32;k++) no*=2; no=no-j; cout\n The reverse isno; getch(); return 0; } On 7/22/11, nicks crazy.logic.k...@gmail.com wrote: see this http://geeksforgeeks.org/?p=726 On Fri, Jul 22, 2011 at 4:29 AM, adhyetha ranjith.kaga...@gmail.com wrote: reverse(int n) { int i, result = 0; for(i = 0; i 32; i++) result |= ((n i) 1) (31 - i); } assuming 32 bit integer to be reversed and assuming all 32 bits to be reversed.. i.e 100101 reverses to 10100100 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Microsoft Question!
sorry guys.. dont check the above siolution.. its wrong...!!! misread it.. On 7/22/11, Puneet Gautam puneet.nsi...@gmail.com wrote: check this out: Considering all 4 bytes of int with no left or right shifts..!! ;) main() { unsigned int i,j,k,no=1; j=4; for(k=0;k32;k++) no*=2; no=no-j; cout\n The reverse isno; getch(); return 0; } On 7/22/11, nicks crazy.logic.k...@gmail.com wrote: see this http://geeksforgeeks.org/?p=726 On Fri, Jul 22, 2011 at 4:29 AM, adhyetha ranjith.kaga...@gmail.com wrote: reverse(int n) { int i, result = 0; for(i = 0; i 32; i++) result |= ((n i) 1) (31 - i); } assuming 32 bit integer to be reversed and assuming all 32 bits to be reversed.. i.e 100101 reverses to 10100100 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Microsoft Question!
x = 0; while( n ){ x = 1; x = x | ( n 1); n = 1; } return x; On Fri, Jul 22, 2011 at 1:31 PM, Puneet Gautam puneet.nsi...@gmail.comwrote: sorry guys.. dont check the above siolution.. its wrong...!!! misread it.. On 7/22/11, Puneet Gautam puneet.nsi...@gmail.com wrote: check this out: Considering all 4 bytes of int with no left or right shifts..!! ;) main() { unsigned int i,j,k,no=1; j=4; for(k=0;k32;k++) no*=2; no=no-j; cout\n The reverse isno; getch(); return 0; } On 7/22/11, nicks crazy.logic.k...@gmail.com wrote: see this http://geeksforgeeks.org/?p=726 On Fri, Jul 22, 2011 at 4:29 AM, adhyetha ranjith.kaga...@gmail.com wrote: reverse(int n) { int i, result = 0; for(i = 0; i 32; i++) result |= ((n i) 1) (31 - i); } assuming 32 bit integer to be reversed and assuming all 32 bits to be reversed.. i.e 100101 reverses to 10100100 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Microsoft Question!
gr8 shubham On Fri, Jul 22, 2011 at 1:42 PM, Shubham Maheshwari shubham@gmail.comwrote: x = 0; while( n ){ x = 1; x = x | ( n 1); n = 1; } return x; On Fri, Jul 22, 2011 at 1:31 PM, Puneet Gautam puneet.nsi...@gmail.comwrote: sorry guys.. dont check the above siolution.. its wrong...!!! misread it.. On 7/22/11, Puneet Gautam puneet.nsi...@gmail.com wrote: check this out: Considering all 4 bytes of int with no left or right shifts..!! ;) main() { unsigned int i,j,k,no=1; j=4; for(k=0;k32;k++) no*=2; no=no-j; cout\n The reverse isno; getch(); return 0; } On 7/22/11, nicks crazy.logic.k...@gmail.com wrote: see this http://geeksforgeeks.org/?p=726 On Fri, Jul 22, 2011 at 4:29 AM, adhyetha ranjith.kaga...@gmail.com wrote: reverse(int n) { int i, result = 0; for(i = 0; i 32; i++) result |= ((n i) 1) (31 - i); } assuming 32 bit integer to be reversed and assuming all 32 bits to be reversed.. i.e 100101 reverses to 10100100 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING 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.
Re: [algogeeks] Re: Microsoft Question!
thnx ... :D On Fri, Jul 22, 2011 at 9:19 PM, sagar pareek sagarpar...@gmail.com wrote: gr8 shubham On Fri, Jul 22, 2011 at 1:42 PM, Shubham Maheshwari shubham@gmail.com wrote: x = 0; while( n ){ x = 1; x = x | ( n 1); n = 1; } return x; On Fri, Jul 22, 2011 at 1:31 PM, Puneet Gautam puneet.nsi...@gmail.comwrote: sorry guys.. dont check the above siolution.. its wrong...!!! misread it.. On 7/22/11, Puneet Gautam puneet.nsi...@gmail.com wrote: check this out: Considering all 4 bytes of int with no left or right shifts..!! ;) main() { unsigned int i,j,k,no=1; j=4; for(k=0;k32;k++) no*=2; no=no-j; cout\n The reverse isno; getch(); return 0; } On 7/22/11, nicks crazy.logic.k...@gmail.com wrote: see this http://geeksforgeeks.org/?p=726 On Fri, Jul 22, 2011 at 4:29 AM, adhyetha ranjith.kaga...@gmail.com wrote: reverse(int n) { int i, result = 0; for(i = 0; i 32; i++) result |= ((n i) 1) (31 - i); } assuming 32 bit integer to be reversed and assuming all 32 bits to be reversed.. i.e 100101 reverses to 10100100 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING 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. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Question!
thank u:) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Question!
To get complete 32 bit inverse : x=((x1)0x) | ((x1)0x); x=((x2)0x) | ((x2)0x); x=((x4)0x0F0F0F0F) | ((x4)0xF0F0F0F0); x=((x8)0x00FF00FF) | ((x8)0xFF00FF00); x=((x16)0x) | ((x16)0x); -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Question!
@ankit gupta: superb solutn On Thu, Jul 21, 2011 at 8:09 PM, SkRiPt KiDdIe anuragmsi...@gmail.comwrote: To get complete 32 bit inverse : x=((x1)0x) | ((x1)0x); x=((x2)0x) | ((x2)0x); x=((x4)0x0F0F0F0F) | ((x4)0xF0F0F0F0); x=((x8)0x00FF00FF) | ((x8)0xFF00FF00); x=((x16)0x) | ((x16)0x); -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Microsoft Question!
@ankit : smhow im not able to follow the steps ur also is taking fr input 0100 ,tho its fine fr 1011 and im not getting the required ans...can u plz explain... On Thu, Jul 21, 2011 at 8:31 PM, Aman Goyal aman.goya...@gmail.com wrote: @ankit gupta: superb solutn On Thu, Jul 21, 2011 at 8:09 PM, SkRiPt KiDdIe anuragmsi...@gmail.comwrote: To get complete 32 bit inverse : x=((x1)0x) | ((x1)0x); x=((x2)0x) | ((x2)0x); x=((x4)0x0F0F0F0F) | ((x4)0xF0F0F0F0); x=((x8)0x00FF00FF) | ((x8)0xFF00FF00); x=((x16)0x) | ((x16)0x); -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 9718388816 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Question!
i have tried solving so many tyms bt i dnt think dis also is wrking fine fr 0100 input..plz chk On Thu, Jul 21, 2011 at 9:49 PM, aditi garg aditi.garg.6...@gmail.comwrote: @ankit : smhow im not able to follow the steps ur also is taking fr input 0100 ,tho its fine fr 1011 and im not getting the required ans...can u plz explain... On Thu, Jul 21, 2011 at 8:31 PM, Aman Goyal aman.goya...@gmail.comwrote: @ankit gupta: superb solutn On Thu, Jul 21, 2011 at 8:09 PM, SkRiPt KiDdIe anuragmsi...@gmail.comwrote: To get complete 32 bit inverse : x=((x1)0x) | ((x1)0x); x=((x2)0x) | ((x2)0x); x=((x4)0x0F0F0F0F) | ((x4)0xF0F0F0F0); x=((x8)0x00FF00FF) | ((x8)0xFF00FF00); x=((x16)0x) | ((x16)0x); -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 9718388816 -- Aditi Garg Undergraduate Student Electronics Communication Divison NETAJI SUBHAS INSTITUTE OF TECHNOLOGY Sector 3, Dwarka New Delhi 9718388816 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Question!
@aditi-the algo is giving a problem when the last bit is 0..just like in ur case..when the number is being reversed instead of 0010 it is giving only 10 and neglecting the initial 0's since dey do not contribute in the number..i guess dis is d prob dat u r facing? On Thu, Jul 21, 2011 at 9:57 PM, aditi garg aditi.garg.6...@gmail.comwrote: i have tried solving so many tyms bt i dnt think dis also is wrking fine fr 0100 input..plz chk On Thu, Jul 21, 2011 at 9:49 PM, aditi garg aditi.garg.6...@gmail.comwrote: @ankit : smhow im not able to follow the steps ur also is taking fr input 0100 ,tho its fine fr 1011 and im not getting the required ans...can u plz explain... On Thu, Jul 21, 2011 at 8:31 PM, Aman Goyal aman.goya...@gmail.comwrote: @ankit gupta: superb solutn On Thu, Jul 21, 2011 at 8:09 PM, SkRiPt KiDdIe anuragmsi...@gmail.comwrote: To get complete 32 bit inverse : x=((x1)0x) | ((x1)0x); x=((x2)0x) | ((x2)0x); x=((x4)0x0F0F0F0F) | ((x4)0xF0F0F0F0); x=((x8)0x00FF00FF) | ((x8)0xFF00FF00); x=((x16)0x) | ((x16)0x); -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 9718388816 -- Aditi Garg Undergraduate Student Electronics Communication Divison NETAJI SUBHAS INSTITUTE OF TECHNOLOGY Sector 3, Dwarka New Delhi 9718388816 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Archita Monga -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 Question!
Ankit's Solution is actually based on the assumption that we will only reverse bits till MSB which is set. So, for 0100 It will reverse will 100, so the answer should be one. On 7/21/11, aditi garg aditi.garg.6...@gmail.com wrote: i have tried solving so many tyms bt i dnt think dis also is wrking fine fr 0100 input..plz chk On Thu, Jul 21, 2011 at 9:49 PM, aditi garg aditi.garg.6...@gmail.comwrote: @ankit : smhow im not able to follow the steps ur also is taking fr input 0100 ,tho its fine fr 1011 and im not getting the required ans...can u plz explain... On Thu, Jul 21, 2011 at 8:31 PM, Aman Goyal aman.goya...@gmail.comwrote: @ankit gupta: superb solutn On Thu, Jul 21, 2011 at 8:09 PM, SkRiPt KiDdIe anuragmsi...@gmail.comwrote: To get complete 32 bit inverse : x=((x1)0x) | ((x1)0x); x=((x2)0x) | ((x2)0x); x=((x4)0x0F0F0F0F) | ((x4)0xF0F0F0F0); x=((x8)0x00FF00FF) | ((x8)0xFF00FF00); x=((x16)0x) | ((x16)0x); -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 9718388816 -- Aditi Garg Undergraduate Student Electronics Communication Divison NETAJI SUBHAS INSTITUTE OF TECHNOLOGY Sector 3, Dwarka New Delhi 9718388816 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Microsoft Question!
Yes, that's correct what is wrong with that? Basically when n1 occurs, it kind of initiates the multiplication by m by setting m+=1. So, After that, m gets multiplied by 2 which is nothing but left shift by 1. n=100 m remains 0 as n1==0 so m=0; n- 10; 2. n=10 m*2- m=0; n1=0 so m=0; n-1; 3 n=1; m*2=0; n1 so m+1- m=1; n-0 On 7/21/11, aditi garg aditi.garg.6...@gmail.com wrote: No actually its fine if the number is 1100...bt for 0100 it gives only 0001 bec it only increments it once after shifting thrice and thn it becomes and it exits and so m nvr gets multiplied by 2... On Thu, Jul 21, 2011 at 10:01 PM, archita monga kool.arc...@gmail.comwrote: @aditi-the algo is giving a problem when the last bit is 0..just like in ur case..when the number is being reversed instead of 0010 it is giving only 10 and neglecting the initial 0's since dey do not contribute in the number..i guess dis is d prob dat u r facing? On Thu, Jul 21, 2011 at 9:57 PM, aditi garg aditi.garg.6...@gmail.comwrote: i have tried solving so many tyms bt i dnt think dis also is wrking fine fr 0100 input..plz chk On Thu, Jul 21, 2011 at 9:49 PM, aditi garg aditi.garg.6...@gmail.comwrote: @ankit : smhow im not able to follow the steps ur also is taking fr input 0100 ,tho its fine fr 1011 and im not getting the required ans...can u plz explain... On Thu, Jul 21, 2011 at 8:31 PM, Aman Goyal aman.goya...@gmail.comwrote: @ankit gupta: superb solutn On Thu, Jul 21, 2011 at 8:09 PM, SkRiPt KiDdIe anuragmsi...@gmail.comwrote: To get complete 32 bit inverse : x=((x1)0x) | ((x1)0x); x=((x2)0x) | ((x2)0x); x=((x4)0x0F0F0F0F) | ((x4)0xF0F0F0F0); x=((x8)0x00FF00FF) | ((x8)0xFF00FF00); x=((x16)0x) | ((x16)0x); -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 9718388816 -- Aditi Garg Undergraduate Student Electronics Communication Divison NETAJI SUBHAS INSTITUTE OF TECHNOLOGY Sector 3, Dwarka New Delhi 9718388816 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Archita Monga -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 9718388816 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Microsoft Question!
Solution assuming MSB the last digit x=((x1)0x) | ((x1)0x); x=((x2)0x) | ((x2)0x); x=((x4)0x0F0F0F0F) | ((x4)0xF0F0F0F0); x=((x8)0x00FF00FF) | ((x8)0xFF00FF00); x=((x16)0x) | ((x16)0x); while(!(x1))x=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.
Re: [algogeeks] Re: Microsoft Question!
I love the topcoder things. :) On Thu, Jul 21, 2011 at 8:09 PM, SkRiPt KiDdIe anuragmsi...@gmail.comwrote: To get complete 32 bit inverse : x=((x1)0x) | ((x1)0x); x=((x2)0x) | ((x2)0x); x=((x4)0x0F0F0F0F) | ((x4)0xF0F0F0F0); x=((x8)0x00FF00FF) | ((x8)0xFF00FF00); x=((x16)0x) | ((x16)0x); -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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.
Re: [algogeeks] Re: Microsoft Question!
see this http://geeksforgeeks.org/?p=726 On Fri, Jul 22, 2011 at 4:29 AM, adhyetha ranjith.kaga...@gmail.com wrote: reverse(int n) { int i, result = 0; for(i = 0; i 32; i++) result |= ((n i) 1) (31 - i); } assuming 32 bit integer to be reversed and assuming all 32 bits to be reversed.. i.e 100101 reverses to 10100100 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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.