Re: [algogeeks] Re: Questions
We can do it by hashing. hash the 2-d array and then search for 1 d array in the hash table. -- 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/-/7PE1mqG4RRgJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] smallest segment in a document containing all the given words
Find out the smallest segment in a document containing all the given words. Desired Complexity is O nlogK ..n is the total no of words in the document and k is the number of input words -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: Linear time Binary tree re-construction
Hint : try with prestoring the preorder traversal element position in inorder traversal before constructing the tree -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Find the Minimum length Unsorted Subarray, sorting which makes the complete array sorted
Given an unsorted array arr[0..n-1] of size n, find the minimum length subarray arr[s..e] such that sorting this subarray makes the whole array sorted. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Recurrence relation
When i try to solve this T(n) = 2T(n/2) + 2 recurrence relation i get order N. But http://www.geeksforgeeks.org/archives/4583 claims that it is 3/2n-2. The order is still N only but how do we get the constants ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: Recurrence relation
Thanx Gene. Is there any other method than master's thm ? On Nov 23, 4:13 pm, Gene gene.ress...@gmail.com wrote: Solving recurrences is an art form. There are many techniques. One of the simplest is to assume you know the form of the result with some unknown coefficients. Then plug the form into the recurrence and try to solve for the coefficients. If you succeed, you're done. If not, look for another form or an entirely different technique. Here we assume T(n) = an + b. Substitute: T(n) = an + b = 2T(n/2) + 2 = 2[ a(n/2) + b ] + 2 = an + 2b + 2 Now subtracting an+b from both sides we have b = -2. To find a, we need the base case. With T(2) = 1, we have T(2) = an + b = a(2) - 2 = 1 This produces a = 3/2, so T(n) = 3/2 n - 2 as stated. On Nov 23, 3:59 am, Ankuj Gupta ankuj2...@gmail.com wrote: When i try to solve this T(n) = 2T(n/2) + 2 recurrence relation i get order N. But http://www.geeksforgeeks.org/archives/4583 claims that it is 3/2n-2. The order is still N only but how do we get the constants ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Does Y lies between x and z
There is a binary tree (Not a BST) in which you are given three nodes X,Y, and Z .Write a function which finds whether y lies in the path b/ w x and z. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] An Array Problem
Input: A unsorted array of size n. Output: An array of size n. Relationship: elements of input array and output array have 1:1 correspondence. output[i] is equal to the input[j] (ji) which is smaller than input[i] and jth is nearest to ith ( i.e. first element which is smaller). If no such element exists for Input[i] then output[i]=0. Eg. Input: 1 5 7 6 3 16 29 2 7 Output: 0 3 6 3 2 2 2 0 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.
[algogeeks] Re: An Array Problem
One way could be sorting the array and also storing the original index along with that. After that we can search linearly in the array. On Nov 23, 5:40 am, Anup Ghatage ghat...@gmail.com wrote: What do you mean by if this number is less than elements stored in stack There have be N comparisons in the worst case. And that way, you have to do it for every element. So it will be governed by O(n^2) On Wed, Nov 23, 2011 at 12:50 AM, Aamir Khan ak4u2...@gmail.com wrote: On Tue, Nov 22, 2011 at 11:50 PM, tech coder techcoderonw...@gmail.comwrote: here is an O(n) approach using a stack. problem can be stated as find the 1st smaller element on the right. put the first element in stack. take next element suppose num if this number is less than elements stored in stack, pop those elements , for these pooped elements num will be the required number. put the the element (num) in stack. repeat this. at last the elements which are in next , they will have 0 (valaue) @techcoder : If the numbers are not in sorted order, What benefit the stack would provide ? So, are you storing the numbers in sorted order inside the stack ? I can think of this solution : Maintain a stack in which the elements will be stored in sorted order. Get a new element from array and lets call this number as m. Push m into the stack. Now, find all elements which are = (m-1) using binary search. Pop out all these elements and assign the value m in the output array. Elements remaining at the end will have the value 0. I am not sure about the complexity of this algorithm... On Wed, Nov 23, 2011 at 12:02 AM, Anup Ghatage ghat...@gmail.com wrote: I can't think of a better than O(n^2) solution for this.. Any one got anything better? On Tue, Nov 22, 2011 at 8:23 PM, Ankuj Gupta ankuj2...@gmail.comwrote: Input: A unsorted array of size n. Output: An array of size n. Relationship: elements of input array and output array have 1:1 correspondence. output[i] is equal to the input[j] (ji) which is smaller than input[i] and jth is nearest to ith ( i.e. first element which is smaller). If no such element exists for Input[i] then output[i]=0. Eg. Input: 1 5 7 6 3 16 29 2 7 Output: 0 3 6 3 2 2 2 0 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. -- 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. -- * Regards* *The Coder* *Life is a Game. The more u play, the more u win, the more u win , the more successfully u play* -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Aamir Khan | 3rd Year | Computer Science Engineering | IIT Roorkee -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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.
[algogeeks] Re: Time Complexity
Try it once. It is for level order only in dfs way On Nov 19, 2:58 pm, shady sinv...@gmail.com wrote: this doesn't seem like level order printing, because you are simply printing the tree starting with the children as the root node. On Sat, Nov 19, 2011 at 12:57 PM, Ankuj Gupta ankuj2...@gmail.com wrote: What is the time complexity of this code for Level Order Traversal. void printLevel(BinaryTree *p, int level) { if (!p) return; if (level == 1) { cout p-data ; } else { printLevel(p-left, level-1); printLevel(p-right, level-1); } } void printLevelOrder(BinaryTree *root) { int height = maxHeight(root); for (int level = 1; level = height; level++) { printLevel(root, level); cout endl; } } My guess is NlogN if tree is balanced if not it will be N^2. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: Time Complexity
I guess its NlogN for balanced tree as it is traversing N nodes for H times ie the height of tree which is logN for balanced and N for skewed tree. So it should be Nlogn and N^2 On Nov 20, 9:27 am, tech coder techcoderonw...@gmail.com wrote: @ sravanreddy001 complexity is O(N^2) whether tree is balanced or not doesn't matter For each level it's visiting elements. all elements upto n-1 level . i dont know from where u got the concept of logn , the code is not making any decision to go in left or right , it is going in left and right both , so how it is nlogn. On Sun, Nov 20, 2011 at 3:12 AM, sravanreddy001 sravanreddy...@gmail.comwrote: Its NlogN if balanced.. Else N^2 For each element it's visiting at most log N elements.(assuming balanced) -- 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/-/hVQH5EtOfK4J. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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* *The Coder* *Life is a Game. The more u play, the more u win, the more u win , the more successfully u play* -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Given a int N, write a function to return the closest Fibonacci Number
O(N) method is trivial. Can we do better than this ? Using matrix f= { {1,1},{1,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.
[algogeeks] Time Complexity
What is the time complexity of this code for Level Order Traversal. void printLevel(BinaryTree *p, int level) { if (!p) return; if (level == 1) { cout p-data ; } else { printLevel(p-left, level-1); printLevel(p-right, level-1); } } void printLevelOrder(BinaryTree *root) { int height = maxHeight(root); for (int level = 1; level = height; level++) { printLevel(root, level); cout endl; } } My guess is NlogN if tree is balanced if not it will be N^2. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: kth smallest element
I tried to understand the logic of it but could not :( On Nov 11, 11:17 am, shady sinv...@gmail.com wrote: no, for eg. array1 = { 1, 2, 5, 6, 7, 7, 7, 23}; array2 = { 1, 2, 2, 4, 8, 9, 12 }; then for k = 2, answer = 1 k = 3, answer = 2 k = 4, answer = 2, k = 6, answer = 4. anyway to do it iteratively in logarithmic time On Fri, Nov 11, 2011 at 2:27 AM, sravanreddy001 sravanreddy...@gmail.comwrote: Is it (k)th smallest element (distict integers) or the element at position k, when both are merged? 455566777 -- Is 3rd smallest element '1' or '4' If four, I am not able to think of a log complexity. Can u post your recursive solution only if u meant '4' in above case. -- 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/-/Aq8q9OwfcaEJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Doubt in Lowest Common Ancestor
I have a doubt in calculating LCA. While calculating LCA of two nodes, should those two nodes can also be ancestor. As wikipedia states that The lowest common ancestor is defined between two nodes v and w as the lowest node in T that has both v and w as descendants (where we allow a node to be a descendant of itself). But usually we dont consider the nodes itself to be ancestor ? Which approach should be followed ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: Median of 2D matrix
I was thinking on the lines of heap On Nov 2, 8:33 pm, Anup Ghatage ghat...@gmail.com wrote: Median of Medians? On Tue, Nov 1, 2011 at 10:44 PM, Ankuj Gupta ankuj2...@gmail.com wrote: We have a N X N matrix whose rows and columns are in sorted order. How efficiently can we find the median of those N^2 keys ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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.
[algogeeks] Median of 2D matrix
We have a N X N matrix whose rows and columns are in sorted order. How efficiently can we find the median of those N^2 keys ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Print all path of the tree that sums up to the given value
Print all path of the tree that sums up to the given value. The path may start from any node. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: printK Distance Nodes
I am not getting what you said. For given tree a(2)b(7)c(5)d(2)e(6)f(9)g(5)h(11)i(4) if i say given node is 6 and distance is 1 then the output should be 7,5,11. The nodes below the given nodes can be easily printed. I am not getting the way to print nodes above the given node On Oct 31, 1:30 pm, SAMMM somnath.nit...@gmail.com wrote: As the problem states that the distance can be upwards and downwards . So we considering both the case . I am going to implement BFS to implement it (Because requires the poped elements to trace back to the Source node to check whether path is sorted) Consider the tree Given in this link .. I am taking tht as reference .http://en.wikipedia.org/wiki/Binary_tree Suppose the Source node is the left node of the root node . naming the nodes from A to I breadthwise . a(2)b(7)c(5)d(2)e(6)f(9)g(5)h(11)i(4) Case 1:- Traving from the root we note the distance from the Root to the source node but don't push it in the queue. Source node - b , Distance =3 --- Queue = b | d e | g h Distance = 0 | 1 1 | 2 2 PrevNode = --| b b | e e So we don't get any distance as 3 . Leave this and reinitialize the Queue , Distance and PrevNode . Case 2 :-Any now Repeat this process from Root node to the source node to see whether we get the Distance as 3 . Case 3:- If the distance from the Root to the Source node is less than 'K' distance , then repeat the BFS process from the Root . Source node - b , Distance =3 --- Queue = a | c | f | I Distance = 0 | 1 | 2 | 3 PrevNode = --| a | c | f Now the distance from the Root to the source node(d) is 1 here , s o we need to search for the node whose distance from the root is (K-d) . Here we will find the path with K=3 distance from the source node , But it will not be valid because it is not sorted .. So no node present will be printed . Hope I am clear . -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Given a node of BST make it the root
Given a node of a BST, modify it in such a way that the given node becomes the root. The tree should still be BST. One way I could get is store the Inoder traversal of the tree. Find that node in the traversal and recursively make the BST. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Binary tree to BST
How to convert a Binary tree to BST ? Naive way is to create each node of Binary tree one by one and keep on creating the BST. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: Reconstruct BST from preorder traversal
I had a doubt , if we simply go on constructing the tree from preorder traversal one gets the same tree back am I missing something here On Oct 19, 7:49 am, sravanreddy001 sravanreddy...@gmail.com wrote: @Sunny, Rahul: Thanks a lot.. :) @Anshu: the code is perfect, This would be h = n* (height of BST) -- O(h) O(n^2) is the worst case right? and has complexity similar to quick sort? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: Print all path of the tree that sums up to the given value
No constraint on path. Though it is not necessary that it starts from root only On Oct 31, 10:02 pm, Prakash D cegprak...@gmail.com wrote: any constraints for path? On Mon, Oct 31, 2011 at 11:19 AM, Ankuj Gupta ankuj2...@gmail.com wrote: Print all path of the tree that sums up to the given value. The path may start from any node. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] printK Distance Nodes
You are given a function printK Distance Nodes which takes in a root node of a binary tree, a start node and an integer K. Complete the function to print the value of all the nodes (one-per-line) which are a K distance from the given start node in sorted order. Distance can be upwards or downwards. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: Search an element in an Infinite array
What is the logic on choosing power of two as search indexes ? On Oct 24, 12:56 am, Ankur Garg ankurga...@gmail.com wrote: Use Binary Search start = 2^n-1 high =2^n where n=0,1 On Mon, Oct 24, 2011 at 12:28 AM, sunny agrawal sunny816.i...@gmail.comwrote: hint 1: try to find 2 indexes i, j such that a[i] = K = a[j] On Sun, Oct 23, 2011 at 11:23 PM, Ankuj Gupta ankuj2...@gmail.com wrote: Given a sorted array of Infinite size, find an element ‘K’ in the array without using extra memory in O (lgn) 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. -- Sunny Aggrawal B.Tech. V year,CSI Indian Institute Of Technology,Roorkee -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Search an element in an Infinite array
Given a sorted array of Infinite size, find an element ‘K’ in the array without using extra memory in O (lgn) 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.
[algogeeks] Re: Reconstruct BST from preorder traversal
@rahul can you order your trees properly :( For BST only preorder traversal is sufficient to reconstruct it back On Oct 18, 5:58 pm, rahul patil rahul.deshmukhpa...@gmail.com wrote: @Anshu: for a tree 15 15 7 18 and 7 17 17 18 inorder traversal is same: 7,15,17,18 then how it could be possible to recreate the specific one. Preorder of BST is sorted one, so possible solution could be any BST containing all the elements in the preorder array. On Tue, Oct 18, 2011 at 1:41 PM, anshu mishra anshumishra6...@gmail.comwrote: @Anand As given it is a BST so any single traversal(pre or post or in) is sufficient to construct the tree. :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. -- Regards, Rahul Patil -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: Inplace Array Convertion
Is the indexing correct ? For eg a1,a2,a3,b1,b2,b3,c1,c2,c3 for a2 the correct position is 3 but acc to the given formula it is 2. On Oct 17, 9:35 pm, Navneet navneetn...@gmail.com wrote: Great explanation Sunny. But with this approach, won't a single pass suffice? Select a card , find it's new position, insert the card at that position, initialize i to the position of the replaced card repeat till all cards have been processed. The thing we need to remember is whether relative to the new position of the current card, the previous insertion was before or after the newly computed position. Please comment. On Oct 16, 3:36 am, sravanreddy001 sravanreddy...@gmail.com wrote: cheers.. clear explanation. thanks for the effort.. :) so.. we swap 3 elements and.. run for one complete cycle of N/3 time in this prob.. Anika has a recusion of N/3 depth.. may be.. a loop that runs N/3 time should suffice. :) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Reconstruct BST from preorder traversal
How to reconstruct a BST from just the prorder traversal of that tree ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Time complexity of morris traversal
What is the time complexity of morris traversal ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Linked List Problem
There are two linked list of length m and n. There is some common data at the end of both. Find the starting position in both the linked list. I could suggest two methods 1) Reverse the list and check . 2) Use recursion to go to the last element and move back from there. Is there any other way ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Number of Multiplications
How do you deduce number of multiplication that when we perform a^b function using dividing the exponent by 2 at each stage to be log b? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] How to height balance a binary search tree ?
Given a bst how to height balance it ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Frequency of number
Infinite numbers are coming in a stream . how will you find the frequency of a given number ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: How to height balance a binary search tree ?
We are given a tree so one should go for reconstruction of tree using rotations ? On Sep 27, 10:19 pm, Ankur Garg ankurga...@gmail.com wrote: L , R ,LR , RL rotations On Tue, Sep 27, 2011 at 10:35 PM, sukran dhawan sukrandha...@gmail.comwrote: avl tree On Tue, Sep 27, 2011 at 10:15 PM, Ankuj Gupta ankuj2...@gmail.com wrote: Given a bst how to height balance it ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: Frequency of number
If we have to find frequency of say x inputs then ? On Sep 27, 10:40 pm, teja bala pawanjalsa.t...@gmail.com wrote: If we are to find frequency of only one number let us say 35 in infinite coming numbers , do xor operation with coming numbers If the result is 0 increment the value of temp variable by 1 if not scan next input until all numbers are over. On Tue, Sep 27, 2011 at 10:22 PM, Ankuj Gupta ankuj2...@gmail.com wrote: Infinite numbers are coming in a stream . how will you find the frequency of a given number ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Find lowest common ancestor of Binary Tree
Find lowest common ancestor of Binary Tree -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Doubt in templates
Hi I have written a simple template class. #include iostream using namespace std; template class T class vector { T *arr; int size; public: vector(int len) { arr = new T[size=len]; for(int i=0;ilen;i++) arr[i]=0; } vector(T *list) { for(int i=0;isize;i++) arr[i]=list[i]; } T operator *(vector obj) { T sum=0; for(int i=0;isize;i++) sum+=this-arr[i]*obj.arr[i]; return sum; } }; int main() { vector intv1(3); vector floatv2(3); int arr1[]={1,2,3}; float arr2[]={1.1,2.2,3.3}; v1=arr1; v2=arr2; float prod = v1*v2; //coutprod; return 0; } But on compiling it C++ gives error as error C2679: binary '*' : no operator found which takes a right-hand operand of type 'vectorT' (or there is no acceptable conversion) with [ T=float ] could be 'int vectorT::operator *(vectorT )' with [ T=int ] while trying to match the argument list '(vectorT, vectorT)' with [ T=int ] and [ T=float ] Is it because compiler could not find a way to convert from either float to int or vice versa or something else? Also what is the solution of 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.
[algogeeks] Doubts about realloc
Hi I have a doubt in functioning of realloc. Can we use realloc to shrink the memory already allocated ? If yes, will it also free the left over memory or programmer has to do it ? Also, while reallocating if it has to move to some other location does the earlier location gets freed or is it implementation dependent Thanks Ankuj -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: question
If it is the first largest ? On Sep 21, 8:02 pm, Dave dave_and_da...@juno.com wrote: @Prasanth: Since there is no requirement to find the next larger number, you can go for the largest. Extract the digits into an array using modulus and division by 10. Then sort the digits into descending order. Finally, construct the answer by repeated multiplication by 10 and addition. If you want, you can check to see if the resulting number is greater than the original and return an error code if it is just equal to it. E.g., 8755 already has its digits in decreasing order, so the above algorithm will reproduce 8755. Dave On Sep 21, 8:53 am, prasanth n nprasnt...@gmail.com wrote: You have given a positive number you have to find a number which is bigger than that by using same digits available in the number . Example :- You have given a number 7585 , your output should be 7855 . -- *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.
[algogeeks] Re: Time complexity
yes it is n^5 On Sep 22, 8:53 am, siva viknesh sivavikne...@gmail.com wrote: @Dave ... thanks dude.So it should be O(n^5) .. am i right ?? On Sep 22, 8:19 am, Dave dave_and_da...@juno.com wrote: @Siva: Work from the inside out, using the identities sum from i = 1 to n (i) = n*(n+1)/2 sum from i = 1 to n (i^2) = n*(n+1)*(2*n+1)/6 sum from i = 1 to n (i^3) = n^2*(n+1)^2/4 sum from i = 1 to n (i^4) = n^5/5 + n^4/2 + n^3/3 - n/30 Dave On Sep 21, 10:03 pm, siva viknesh sivavikne...@gmail.com wrote: somebody plz reply... On Sep 21, 10:53 pm, sivaviknesh s sivavikne...@gmail.com wrote: for(i=0;in;i++) for(j=0;ji*i;j++) for(k=0;kj;k++) sum++; Is it n^5 log n . n * (n^2 log n) * (n^2 log n) ??? correct me if i m wrong? also anybody can tell some easy approach to tackle these ques ?? I worked out for some values of n and arrived at the ans. -- Regards, $iva- 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.
[algogeeks] Doubt in C++
Consider a class class string { char *p; int len; public: string(char *a); }; string::string(char *a) { length = strlen(a); p= new char[length +1]; strcpy(p,a); } string s1,s2; char *name =test; s2=name; // statement Why does constructor gets called in statement , even though we are just assigning it ? Also this has to be done by operator overloading rather than a constructor -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: Interview Questions
It is still giving run time error On Sep 16, 4:40 am, Deoki Nandan deok...@gmail.com wrote: error due statement int*y; because it tries to allocate another pointer being uninitialized .It may happen that garbage address which was given to x is also try to give to y . This makes program crash ... You can check it by making *y=1000; sttmnt as comment and run after that comment both statement int*y; and *y=1000; . You will see what happen. On 16 September 2011 00:07, vikas singh shyguy1...@gmail.com wrote: On Thu, Sep 15, 2011 at 11:54 PM, SAMMM somnath.nit...@gmail.com wrote: I think u haven't ran the the code or compile it .. It give the output as 1000 10 . @SAMM : Dude, seg fault on g++ Check tht .. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Thanks and Regards VIKAS SINGH MCA- final year NIT DURGAPUR email: vikas.singh1...@gmail.com shyguy1...@gmail.com http://smrit.wordpress.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. -- **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.
[algogeeks] Re: Building a max heap takes O(n) time irrespective of the array being sorted / unsorted.
is talks of more tighter bound of O(nlogn) On Sep 15, 11:24 pm, sunny agrawal sunny816.i...@gmail.com wrote: Read CLRS On Thu, Sep 15, 2011 at 11:51 PM, saurabh agrawal saurabh...@gmail.comwrote: Building a max heap takes O(n) time irrespective of the array being sorted / unsorted. Can someone prove that. I already know that Heap can be constucted in o(n*log(n)) 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. -- Sunny Aggrawal B.Tech. V year,CSI Indian Institute Of Technology,Roorkee -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: Scanf in an infinite loop
What I am guessing is that the stdin used by scanf is not getting flushed after entering a char as a result of which it is running into infinite loop. If you use fflush(stdin) just after scanf it will not be infinite loop. But I am not able to get the reason for it. On Sep 13, 3:23 pm, Avinash Dharan avinashdha...@gmail.com wrote: #include stdio.h void main() { while(1) { int opt; scanf(%d,opt); printf(%d\n,opt); } } when i execute this program, if i give a character instead of an integer, it goes into an infinite loop. why is it so? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: Microsoft Question
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.
[algogeeks] Re: Scanf in an infinite loop
@Tanmay: fflush do work. Atleast it does not become a infinite loop. But still the output is some garbage value in case of character input On Sep 14, 1:04 am, Raghu Sarangapani raghu.sarangap...@gmail.com wrote: I modified your program as below. Every time, value of ret = 0. scanf is repeatedly failing cos there is some junk in the input stream Hence it prints junk values #include stdio.h void main() { while(1) { int opt, ret; ret=scanf(%d,opt); printf(opt is %d\n,opt); printf(ret is %d\n,ret); } } Regards, Raghu On Tue, Sep 13, 2011 at 3:23 AM, Avinash Dharan avinashdha...@gmail.comwrote: #include stdio.h void main() { while(1) { int opt; scanf(%d,opt); printf(%d\n,opt); } } when i execute this program, if i give a character instead of an integer, it goes into an infinite loop. why is it so? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: Microsoft Question
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.
[algogeeks] Book for C++
Hi Which is a good book for C++ ( Robert Lafore or Bjarne Stroustrup or Herbert Schildt) ? Ankuj -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: unique no. problem
Is there any restriction on the input like they are in given range ? On Sep 11, 11:10 pm, Neha Singh neha.ndelhi.1...@gmail.com wrote: You are given an array that contains integers. The integers content is such that every integer occurs 3 times in that array leaving one integer that appears only once. Fastest way to find that single integer eg: Input: [2,1,4,5,1,4,2,2,4,1] Answer: 5 The solution must be of O(n) time and O(1) space -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: Question -- plz answer
what is C and M On Sep 10, 7:40 pm, Ishan Aggarwal ishan.aggarwal.1...@gmail.com wrote: 1.) there is a pyramid with 1 cup at level , 2 at level 2 , 3 at level 3 and so on.. It looks something like this 1 2 3 4 5 6 every cup has capacity C. you pour L liters of water from top . when cup 1 gets filled , it overflows to cup 2,3 equally, and when they get filled , Cup 4 and 6 get water only from 2 and 3 resp but 5 gets water from both the cups and so on. Now given C and M .Find the amount of water in ith cup. -- 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.
[algogeeks] Re: What is the Output?? and How??
http://groups.google.com/group/algogeeks/browse_frm/thread/274f63b24388599d/da635c4f409d5e1b?lnk=gstq=print%28max%28x%2B%2B%2Cy%29%2Cx%2Cy%29%3B+#da635c4f409d5e1b On Sep 8, 2:04 am, htross htb...@gmail.com wrote: can u please explain this code or give the link to the thread u mentioned before??? On Sep 7, 10:35 pm, nagarajan naga4...@gmail.com wrote: please can u explain.. or copy the explained content??? On Wed, Sep 7, 2011 at 11:03 PM, sukran dhawan sukrandha...@gmail.comwrote: its already been explained in previous thread On Wed, Sep 7, 2011 at 11:01 PM, NAGARAJAN SIVARAMAN naga4...@gmail.comwrote: #includestdio.h #includeconio.h #define prn(a) printf(%d ,a) #define print(a,b,c) prn(a),prn(b),prn(c) #define max(a,b) (ab)?b:a void main() { int x=1,y=2; clrscr(); print(max(x++,y),x,y); printf(\n%d %d\n,x,y); print(max(x++,y),x,y); printf(\n%d %d\n,x,y); getch(); } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- Nagarajan S -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: convert a word into a palindrome with minimum addition of letters to it
I guess we cant modify the original string. For yahoo should it be yahoohay ? Please clarify On Sep 6, 12:56 am, Pratz mary pratima.m...@gmail.com wrote: int main() { char *s=nitan; int n,i,j,c=0; char *d; n=strlen(s)/2; //printf(%d,n); for(i=1;i=n;i++) { if(s[n-i]!=s[n+i]) break; } d=strcpy(d,s); for(j=i;j=n;j++) { if(d[n+j]!=d[n-j]) { c++; d[n+j]=d[n-j]; } } printf(%s %d,d,c); } On 6 September 2011 01:21, Pratz mary pratima.m...@gmail.com wrote: for yahoo shudnt min additions be yahay? On 6 September 2011 00:48, learner nimish7andr...@gmail.com wrote: @sandeep Explain Algorithm/logic Time Complexity ? 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. -- regards Pratima :) -- regards Pratima :) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: Algo Book
Data Structures and Algorithm Analysis by Mark Allen Weiss On Sep 6, 3:39 pm, siddharam suresh siddharam@gmail.com wrote: @neha: there is site calledhttp://library.nu register there, u'll get majority of the books. Thank you, Sid. On Tue, Sep 6, 2011 at 3:54 PM, Prashant Kulkarni prashant.r.k...@gmail.com wrote: The Algorithm Design Manual By Steve S. Skiena -- Prashant Kulkarni On Tue, Sep 6, 2011 at 3:48 PM, Udit Gupta uditgupta...@gmail.com wrote: Fundamentals of Computer Algorithms by Sartaj Sahni On Tue, Sep 6, 2011 at 3:45 PM, Neha Gupta nehagup...@gmail.com wrote: hey guys , do tell me a book for algo( other than cormen) with good no. of illustrations or any resource or link on net(especially for dp, backtracking, np problems 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. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: character count in array
@mohit: that will modify the original array On Sep 4, 6:40 pm, sarath prasath prasathsar...@gmail.com wrote: here is my approach where i left the non repeating characters as it is and done some good code.. char * runlengthencode(char* str,int size) { int i,j,flag=0; for(i=0,j=1;str[i]str[j]jsize;i++,j++) { while(str[i]==str[j]) { j++; flag=1; } if(flag) { j=j-1; str[i+1]=48+(j-i+1); flag=0; i=j; j++; } } return str; } On Sat, Sep 3, 2011 at 6:54 PM, Aman Kumar amanas...@gmail.com wrote: Hiii if array is given like this arr[]=aabcabbcdeadef convert this array into like arr[]=a4b3c2d2e2f1 how can we do this can we do it with space complexity O(1). reply asap -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: character count in array
If we take our input to be characters a-z ans A-Z then we require fixed space which can be treated as O(1). On Sep 3, 7:10 pm, teja bala pawanjalsa.t...@gmail.com wrote: this 'll work if u i/p the string in dis manner aaabbcc(consecutive same) a3b2c2 #includestdio.h #includeconio.h main() { int x=1,i=0; char a[100]; gets(a); while(a[i]!='\0') { while(a[i]==a[i+1]) { x++; i++; } printf(%c%d,a[i],x); x=1; i++; } getchar(); } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: c problem
because your are trying to edit an unmodifiable object which C- compiler will not allow On Sep 3, 6:18 pm, priya ramesh love.for.programm...@gmail.com wrote: ok but y does the compiler say lvalue required if you perform a++?? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: character count in array
if for all inputs you array remains of same size we can take it as constant space On Sep 3, 7:49 pm, rajul jain rajuljain...@gmail.com wrote: @ankuj just want to clarify that in hashing method we require array of fixed size let say arr[26] , so is it considered as constant space or not? On Sat, Sep 3, 2011 at 8:02 PM, siddharam suresh siddharam@gmail.comwrote: sol already posted please search old thread Thank you, Sid. On Sat, Sep 3, 2011 at 8:01 PM, Ankuj Gupta ankuj2...@gmail.com wrote: If we take our input to be characters a-z ans A-Z then we require fixed space which can be treated as O(1). On Sep 3, 7:10 pm, teja bala pawanjalsa.t...@gmail.com wrote: this 'll work if u i/p the string in dis manner aaabbcc(consecutive same) a3b2c2 #includestdio.h #includeconio.h main() { int x=1,i=0; char a[100]; gets(a); while(a[i]!='\0') { while(a[i]==a[i+1]) { x++; i++; } printf(%c%d,a[i],x); x=1; i++; } getchar(); } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: memory allocation question
p is a pointer to an array of 4 integers. So when you do (int(*) [col])malloc(row*sizeof(*p)) total of 48 bytes is allocated as sizeof(*p) is 12 bytes. On Sep 3, 4:14 pm, rohit rajuljain...@gmail.com wrote: how many bytes are allocated by following code? #includealloc.h #define col 4 #define row 3 int main() { int(*p)[col]; p=(int(*)[col])malloc(row*sizeof(*p)); return 0; } please explain 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.
[algogeeks] Algorithms for Interviews
If someone has Algorithms for Interviews please share with me. I tried the link which was earlier posted on the group but it says it is locked. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: Sort problem
Bitonic sort On Aug 31, 11:26 am, bharatkumar bagana bagana.bharatku...@gmail.com wrote: while increasing ... we have to use insertion sort which is in place algo .. while decreasing... any way that is sorted one .. so no need to maintain ... But it takes O(n^2) time .. On Wed, Aug 31, 2011 at 1:58 AM, Navneet Gupta navneetn...@gmail.comwrote: Given an array of size n wherein elements keep on increasing monotically upto a certain location after which they keep on decreasing monotically, then again keep on increasing, then decreasing again and so on. Sort the array in place (ie. using only O(1) extra memory) -- Regards, Navneet -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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.
[algogeeks] Re: probability question
I could not get it. What does first train mean here? On Sep 1, 1:08 am, Don dondod...@gmail.com wrote: Assuming that the man arrives at a random time during the 24-hour day, there are 228 minutes in the day when the next train will be the harbour line (2 minutes of every 10 for 19 hours). For the other 1212 minutes the main line will be the next train. Therefore, the probability of catching the main line train is 0.841666... Don On Aug 31, 8:37 am, swetha rahul swetharahu...@gmail.com wrote: In a railway station, there are two trains going. One in the harbour line and one in the main line, each having a frequency of 10 minutes. The main line service starts at 5 o'clock and the harbour line starts at 5.02A.M. A man goes to the station every day to catch the first train that comes.What is the probability of the man catching the first train? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: Find square root a number
U can use binary search method On Aug 30, 1:56 pm, Rajeev Kumar rajeevprasa...@gmail.com wrote: use Babylonian method(Efficient) algrithm.. Refer :http://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylo... public *void* getSquareRoot(double s) { double Xn = 2.0; double lastXn = 0.0; while (Xn != lastXn) { lastXn = Xn; Xn = (Xn + s / Xn) / 2.0; } return Xn; } On Tue, Aug 30, 2011 at 1:49 PM, Ankur Garg ankurga...@gmail.com wrote: @techcoder Making an array of 32768 or INT_MAX will make ur compiler cry Also ur case doesnt handle the scenario where square root is a decimal number On Tue, Aug 30, 2011 at 1:35 PM, tech coder techcoderonw...@gmail.comwrote: the sqrt of 32 bit number can't be more than 16 bits. have an array of 2^16 elemnts wtih elemts 1 2 3 4 5 32768 . now apply binary search i=a[mid] where mid=(lower+upper)/2 if(i*i==num) i is the sqrt increment lower and upper accordingly as we do in binary search so order is Ologn where n=2^16 On Tue, Aug 30, 2011 at 11:37 AM, Raghavan its...@gmail.com wrote: how to design this logic effectively? double squareRoot(int num){ } -- Thanks and Regards, Raghavan KL -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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. -- Thank You Rajeev Kumar -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: Problem on overflow
If both number are negative shouldn't be b min_int - a On Aug 28, 11:49 pm, Avinash LetsUncomplicate.. avin. 2...@gmail.com wrote: @Saurabh being ready to run your code for unsatisfactory input doesn't seem more logical than trying to find out if you can do something about it. i would have loved a kind reply from you. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: question on fork()
how can be there 20 greens ? On Aug 24, 12:12 am, DK divyekap...@gmail.com wrote: The standard library is neither multithread safe nor multiprocess safe. If you want the correct answer, use shared memory and maintain a shared counter. Alternatively, as a quick hack, insert a fflush(stdout) after the printf statements. Answer: red() - 6 green() - 20 -- DK http://twitter.com/divyekapoorhttp://gplus.to/divyekapoor -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: question on fork()
I am getting 6 calls to red and 8 calls to green when i built parent child tree but when i ran this code http://ideone.com/UBaBB I got 10 calls to red and 10 calls to green. Can some explain this ? On Aug 22, 9:31 pm, ghsjgl k ghsk...@gmail.com wrote: i saw this question in one of DREAM companies i dont know the answer On Mon, Aug 22, 2011 at 11:43 AM, dexter does dxterd...@gmail.com wrote: void red() { } void green() { } main() { fork(); int color=fork(); if(color==0) fork(); red(); if(color==0) fork(); green(); getch(); } How many times red and green are called and pls give an explanation for your 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.
[algogeeks] Re: amazon question
But the o/p at http://ideone.com/zKZuS seems to be different than what one is getting from parent child tree On Aug 8, 10:41 am, Kamakshii Aggarwal kamakshi...@gmail.com wrote: what will be the o/p of the following program: main() { int ret; ret=fork(); ret=fork(); ret=fork(); ret=fork(); if(!ret) printf(one); else printf(two); } -- 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.
[algogeeks] Re: find numbers whose difference is min
we take the difference with the maximum element found so far. So we need to keep track of 2 things: 1) Minimum difference found so far (min_diff). 2) Maximum number visited so far (max_element). min_diff=abs(a[0]-a[1]); max_elem=a[0] for(i=1;iarr_size;i++) if(abs(max_elem-a[i])min_diff) min_diff = abs(max_elem-a[i]); if(a[i]max_elem) max_elem=a[i]; Ankuj On Aug 16, 7:26 pm, Shuaib Khan aries.shu...@gmail.com wrote: Dave, I agree. :) On Tue, Aug 16, 2011 at 6:33 PM, Dave dave_and_da...@juno.com wrote: @Shuaib: We are talking about an array of numbers, arent't we? It is natural to assume that the numbers fall into one of the defined data types. Dave On Aug 16, 4:23 am, Shuaib aries.shu...@gmail.com wrote: Yes it will work in this specific case. What I meant was that Radix sort isn't always applicable in general to achieve linear time sorting. Its complexity isn't exactly O(N) rather O(d*N) where d is the number of bytes each of our item consumes. So if the elements in array aren't from a finite range, that would be an issue. Correct me if I am wrong. -- Shuaibhttp://twitter.com/ShuaibKhanhttp://www.bytehood.com/ On 16-Aug-2011, at 11:05 AM, Dave dave_and_da...@juno.com wrote: @Shuaib: It will work in all cases. If you don't think so, give a counterexample. Dave On Aug 16, 12:50 am, Shuaib aries.shu...@gmail.com wrote: That will work but not in all cases as radix sort isn't a generalized sorting algorithm, is it? :) -- Shuaibhttp://twitter.com/ShuaibKhanhttp://www.bytehood.com/ On 16-Aug-2011, at 10:10 AM, Dave dave_and_da...@juno.com wrote: @Shuaib: You could sort the numbers in O(n) with a radix sort, and then finding the min is easy. Mind you, the radix sort might be slower than an O(n log n) sort, but still it satisfies the O(n) constraint. Dave On Aug 15, 8:41 pm, Shuaib aries.shu...@gmail.com wrote: That won't work. And I don't think an O(n) solution is possible. -- Shuaibhttp://twitter.com/ShuaibKhanhttp://www.bytehood.com/ On 16-Aug-2011, at 6:25 AM, sukran dhawan sukrandha...@gmail.com wrote: find the minimum of two numbers in a loop o(n) and subtract the two On Tue, Aug 16, 2011 at 6:13 AM, Brijesh Upadhyay brijeshupadhyay...@gmail.com wrote: Algorithm to find the two numbers whose difference is minimum among the set of numbers. For example the sequence is 5, 13, 7, 0, 10, 20, 1, 15, 4, 19 The algorithm should return min diff = 20-19 = 1. Constraint - Time Complexity O(N) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visithttps:// groups.google.com/d/msg/algogeeks/-/U8gTWUISJn8J. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group athttp:// 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 athttp:// 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 athttp:// 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 athttp:// 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. -- Shuaibhttp://www.bytehood.comhttp://twitter.com/ShuaibKhan -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: find numbers whose difference is min
I assumed that we can find min diff when we subtract elements of array from the max element On Aug 16, 11:18 pm, Anurag Narain anuragnar...@gmail.com wrote: @ankuj: i think the solution is not correct.. could u please explain ur algo for 5,13,7,0,10,20,1,15,4,18 acc to ur algo answer is 2 but it should be 1(1-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.
[algogeeks] Re: find numbers whose difference is min
We can modify it by keeping track of minimum element as well and find diff of that with all elements(say max_diff) and at each iteration we can find the minimum of max_diff and min_diff On Aug 17, 9:34 am, Ankuj Gupta ankuj2...@gmail.com wrote: I assumed that we can find min diff when we subtract elements of array from the max element On Aug 16, 11:18 pm, Anurag Narain anuragnar...@gmail.com wrote: @ankuj: i think the solution is not correct.. could u please explain ur algo for 5,13,7,0,10,20,1,15,4,18 acc to ur algo answer is 2 but it should be 1(1-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.
[algogeeks] Re: m'th max element
We can use min heap. 1) Build a Min Heap MH of the first m elements (arr[0] to arr[m-1]) of the given array. O(m) 2) For each element, after the mth element (arr[m] to arr[n-1]), compare it with root of MH. a) If the element is greater than the root then make it root and call heapify for MH b) Else ignore it. O((n-m)*logm) 3) Finally, MH has m largest elements and root of the MH is the mth largest element. On Aug 8, 3:57 pm, vijay goswami vjrockks...@gmail.com wrote: run bubble sort for m passes On Mon, Aug 8, 2011 at 4:02 PM, Nitin Nizhawan nitin.nizha...@gmail.comwrote: Selection algorithm,http://en.wikipedia.org/wiki/Selection_algorithm On Mon, Aug 8, 2011 at 3:59 PM, nick tarunguptaa...@gmail.com wrote: how will you find the m'th maximum element in an unsorted array of integers? -- 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/-/aYU_PfGHiNkJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: Fwd: [algogeeks] Re: recursive nearest square
we can do it in logn by using binary search approach found n is the number whose square root has to be if(n==1) return 1; if(n==0) return 0; int low=0,high=n/2,mid,temp; while(1) { mid = (low+high)/2; temp = mid*mid; if(temp==n) return 1; else if(temp n) low = mid+1; else high = mid-1; if(low == mid || high == mid) return 0; } at the end high will have the required square root if not perfect square or if perfect square mid will have the required 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.
Re: Fwd: [algogeeks] Re: recursive nearest square
My bad but it can be made recursive :) On Aug 9, 8:17 pm, Dave dave_and_da...@juno.com wrote: @Ankuj: Yeah, but he asked for it to be recursive. Yours is iterative. Dave On Aug 9, 9:56 am, Ankuj Gupta ankuj2...@gmail.com wrote: we can do it in logn by using binary search approach found n is the number whose square root has to be if(n==1) return 1; if(n==0) return 0; int low=0,high=n/2,mid,temp; while(1) { mid = (low+high)/2; temp = mid*mid; if(temp==n) return 1; else if(temp n) low = mid+1; else high = mid-1; if(low == mid || high == mid) return 0; } at the end high will have the required square root if not perfect square or if perfect square mid will have the required 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.
[algogeeks] Re: Amazon question.
How is the time O(n^2).It is O(nlgn) On Aug 9, 7:53 pm, ankit sambyal ankitsamb...@gmail.com wrote: 1. Square each element of the array and then sort it---O(nlogn) 2. for(i=0;i(size-3);i++) { j=i+1; k=size-1; while(jk) { if(a[[i] + a[j] == a[k]) printf(\n%d %d %d,sqrt(a[i]),sqrt(a[j]),sqrt(a[k])); else if(a[i] + a[j] a[k]) j++; else k--; } }O(n^2) Time O(n^2) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: problem regarding output??
C++ will not allow void pointer to increment. But in C we can perform it where void will be treated as char* http://stackoverflow.com/questions/3523145/pointer-arithmetic-for-void-pointer-in-c On Aug 9, 6:39 pm, UMarius mar...@aseara.ro wrote: ++ on a void* will increase the address by 1 byte. ++ on a type* will increase the address by sizeof(type) bytes. As if the initial pointer were an array of type On Aug 9, 2:49 pm, Rajesh Kumar testalgori...@gmail.com wrote: why j and k point different location? #includestdio.h main() { int a=10,*j; void *k; j=k=a; k=(int *)k; k++; j++; printf(%u %u\n,j,k); } -- Regards Rajesh Kumar -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: MS Written Test
Has the results come ? On Jul 26, 12:32 pm, $hr! k@nth srithb...@gmail.com wrote: Nybody got shortlisted in MS written test which happened on 23rd july??? On Sun, Jul 24, 2011 at 7:32 PM, Bhanu Pratap Singh bp.mn...@gmail.comwrote: We can also use, c++ map... for implementing this! -- *with regards ... Bhanu P Singh (B!||-I~) B.Tech Final Year Computer Science And Engineering 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. -- Regards, $hr!k@nth -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.