[algogeeks] Exclusively For You
I like this offer http://www.chrisbeck.de/inf.php It could be interesting for you, too -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] need a pgm pls help me
pls help me..its very urgent need a program to divide a file into equal parts(segments) -- * ** * * ****DIVI* -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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: GOOGLE QUESTION
since its a phone number storing problem, you can sort the numbers and store the differences. That way you can generate the required number on the go On Thu, Jun 30, 2011 at 4:39 AM, juver++ avpostni...@gmail.com wrote: @Navneet Please read problem again - it is about memory efficient storing. -- 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/-/-hsmsOgm2YUJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] create subgraph
You have to create a graph in most efficient way from relationship of nodes read from txt file. text file contains information like: node_id weight node_id node_id weight node_id ….. // which means two nodes are connected with some weight. (undirected) There are around 600K such information for about 65000 nodes. Aim is to create a a subgraph for a given node_id. i.e for that node_id find ALL successor nodes with level mentioned i.e form a subgraph for that 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.
Re: [algogeeks] Maximize the Time to see TV
@ above ur code fails for following example channel 1 : prog1 8:00-9:00, prog 2 9:00-10:00 channel 2 : prog1 8:15-10:00 your code returns 8:15- 10 and the answer should be channel1/prog1 + channel1/prog2 On 21 January 2011 12:54, Anand anandut2...@gmail.com wrote: Sort all program with their starting time. Appy the below pseudo code to find max number of programs he can watch. for(i=i;ilen;i++) { /*Check for overlap */ if(p[i].start p[i-1].end) { end = i; } else { /*Index of the first program to be watch*/ if((p[i-1].end - p[i-1].start) (p[i].end - p[i].start)) { start = i; } } } return end - start; On Thu, Jan 20, 2011 at 10:11 PM, snehal jain learner@gmail.comwrote: There is a TV avid person. HE wants to spend his max time on TV. There are N channels with different program of different length and diff times. WAP so that the person cam spend his max time watching TV. Precondition: If that person watches a program, he watches it completely. Ex: Channel1: prog1 – 8:00- 8:30 prog2: 9:00 – 10:00 prog3: 10:15 – 12:00 channel2: prg1 – 8:15 – 10:00 prg2: 10:30 – 12:00 So in this case max time will be if he watches: ch2/prg1 + ch1/prg3 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Adobe Question
if sorted then a tweak in merge sort will work On 20 January 2011 23:23, nishaanth nishaant...@gmail.com wrote: Ya as Ashish said hashing is the best solution :) On Fri, Jan 14, 2011 at 6:00 PM, Ashish Goel ashg...@gmail.com wrote: ideally, a hashMap would be preferred walk through one array and set the corresponding entry, and then through another array, if any entry found, then they are not disjoint. Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Fri, Jan 14, 2011 at 3:35 PM, bittu shashank7andr...@gmail.comwrote: how to find if two arrays of size n are disjoint or not in O(n) time ?? You can use only O(n) space The elements are +ve in the range 0 to n power 100.. Regards Shashank Mani -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- S.Nishaanth, Computer Science and engineering, IIT Madras. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] merging 2 search trees
@ above height will not be balanced then On 21 January 2011 19:15, nishaanth nishaant...@gmail.com wrote: Find the node in T which is the maximum(which is either the root or the rightmost in the right subtree). After finding this node, just make the right child of this node point to the root of T'. Correct me if i am wrong On Fri, Jan 21, 2011 at 2:43 PM, snehal jain learner@gmail.comwrote: You are given two height balanced binary search trees T and T’, storing m and n elements respectively. Every element of tree T is smaller than every element of tree T’. Every node u also stores height of the subtree rooted at it. Using this extra information how can you merge the two trees in time O(log m + log n) (preserving both the height balance and the order)? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- S.Nishaanth, Computer Science and engineering, IIT Madras. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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 a line
Within a 2D space, there is a batch of points(no duplicate) in the region (0,0),(0,1),(1,0),(1,1), try to find a line which can divide the region to 2 parts with half points in each .the input will be an array of points and the length of the array. struct point{ int x; int y; }; input : struct point * points, int length -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] nearest points
Given n points on a 2D coordinate system . What is the most efficient way of finding nearest point for each point? How can we find all the points at a distance k from a given point efficiently? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] Adobe Question
if both arrray are sorted. take two ptrs, one pointing to a[0] other to b[0]. if elements are same then nt disjoint. else increment ptr pointing to smaller element until it becomes equal or greater than the element pointed by other. repeat until either ptr reaches end of array.. On 21 January 2011 21:42, Manmeet Singh mans.aus...@gmail.com wrote: how merge sort ?/ On Thu, Jan 20, 2011 at 11:23 PM, nishaanth nishaant...@gmail.com wrote: Ya as Ashish said hashing is the best solution :) On Fri, Jan 14, 2011 at 6:00 PM, Ashish Goel ashg...@gmail.com wrote: ideally, a hashMap would be preferred walk through one array and set the corresponding entry, and then through another array, if any entry found, then they are not disjoint. Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Fri, Jan 14, 2011 at 3:35 PM, bittu shashank7andr...@gmail.comwrote: how to find if two arrays of size n are disjoint or not in O(n) time ?? You can use only O(n) space The elements are +ve in the range 0 to n power 100.. Regards Shashank Mani -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- S.Nishaanth, Computer Science and engineering, IIT Madras. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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] tic tac toe
Design an algorithm to figure out if someone has won in a game of tic- tac-toe. give O(N) soln -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: difference x
@ saurabh and i wanna ur solution to this prob i know O(nlogn) post ur O(n) solution,. i hv some idea bt i wanna knw ur ans b4 mine On 22 December 2010 22:32, Divya Jain sweetdivya@gmail.com wrote: its okk On 22 December 2010 22:28, Ankur Khurana ankur.kkhur...@gmail.com wrote: saurabh , asking for a better sol. is not a crime. rest everybody is intelligent. On Wed, Dec 22, 2010 at 10:27 PM, Saurabh Koar saurabhkoar...@gmail.com wrote: @Snehal: I hv no problem wid ur doubts.Bt sometimes u post probs which r very basic.As u solved the looping prob in other thread I think u r intelligent enough to solve this prob(difference x) easily and also some other probs posted by u(not all).Some problems posted by u are really very tricky and I loved them.I jst requested u while posting if u review the ques carefully it will be helpful.I dint want to hurt u.If u r I m sorry.Bt still I will request u to post carefully.Lets finish this.And sorry once again. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: difference x
its okk On 22 December 2010 22:28, Ankur Khurana ankur.kkhur...@gmail.com wrote: saurabh , asking for a better sol. is not a crime. rest everybody is intelligent. On Wed, Dec 22, 2010 at 10:27 PM, Saurabh Koar saurabhkoar...@gmail.com wrote: @Snehal: I hv no problem wid ur doubts.Bt sometimes u post probs which r very basic.As u solved the looping prob in other thread I think u r intelligent enough to solve this prob(difference x) easily and also some other probs posted by u(not all).Some problems posted by u are really very tricky and I loved them.I jst requested u while posting if u review the ques carefully it will be helpful.I dint want to hurt u.If u r I m sorry.Bt still I will request u to post carefully.Lets finish this.And sorry once again. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] linkd list
no not sorted On 15 December 2010 11:37, Anand anandut2...@gmail.com wrote: @Divya, I think you ask this question before. Not sure of the answer though :) On Tue, Dec 14, 2010 at 9:06 PM, Soumya Prasad Ukil ukil.sou...@gmail.com wrote: Are the linked list sorted? On 14 December 2010 05:33, divya sweetdivya@gmail.com wrote: Given three lists: A, B and C of length n each. Write a function which returns true if any 3 three numbers (1 from each list), sum up to zero. Else return false, if there is no such combination. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- regards, soumya prasad ukil -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] sort array
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). -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] zigzag
A sequence of numbers is called a zig-zag sequence if the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either positive or negative. A sequence with fewer than two elements is trivially a zig-zag sequence. For example, 1,7,4,9,2,5 is a zig-zag sequence because the differences (6,-3,5,-7,3) are alternately positive and negative. In contrast, 1,4,7,2,5 and 1,7,4,5,5 are not zig-zag sequences, the first because its first two differences are positive and the second because its last difference is zero. Given a sequence of integers, sequence, return the length of the longest subsequence of sequence that is a zig-zag sequence. A subsequence is obtained by deleting some number of elements (possibly zero) from the original sequence, leaving the remaining elements in their original order. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] how many bananas?
There is a desert of 1000kms long. A camel is there and 3000 bananas. At one go a camel can take 1000 bananas. For each one km to walk camel eats 1 banana. How many bananas can we cross to the other side of desert -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] array
an array contain +ve and -ve element, find subarray whose sum =0; Lets take input array as a[]={-3,2,4,-6,-8,10,11} -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] linkd list
Given three lists: A, B and C of length n each. Write a function which returns true if any 3 three numbers (1 from each list), sum up to zero. Else return false, if there is no such combination. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] subarraysum
Given an array of integers your task is to find the subarray with the sum 0. Using same approach find the subarray with a sum k. Find the solution in linear time and constant space. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] largest substring
Given a string, find the largest substring that occur multiple times within the same string. Extend your code to find the substring occuring atleast n times. Perform in linear time and space. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: how many bananas?
nice solution:) On 14 December 2010 20:54, Prims topcode...@gmail.com wrote: total bananas=3000 ...max capacity=1000 ==3 trips needed to transport all for traveling 1 km 1st trip 998[eats 1 banana while coming and 1 banana while going back] 2nd trip 998 3rd trip 999[no need to go back] ==5 banana for travelling 1 km since 3 trips involved v spend 5 banana per km v need to reduce it to 2 trips ==the point where total banana becomes 2000 ==3000-2000=1000 ==1000/5=200 km at 200 km v hav 2000 bananas now for travelling 1 km 1st trip 998 2nd trip 999 ==3 banana for travellin 1 km find the point where this becomes single trip dat is total banana becomes 1000 ==2000-1000=1000 ==1000/3=333.3km v hav reached 533.33 km with 1000 banana now make a single trip of remaining 466.66 to city B v reach city B with 533.3 banana dats the answer 533 1/3 banana On Dec 14, 5:47 pm, divya sweetdivya@gmail.com wrote: There is a desert of 1000kms long. A camel is there and 3000 bananas. At one go a camel can take 1000 bananas. For each one km to walk camel eats 1 banana. How many bananas can we cross to the other side of desert -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] game of balls
Ram and Shyam are playing a game of balls. Ram choose a colour ball say red and shyam chose blue. Now both of them places the ball in a row with the condition that at any point the number of Shyam's balls can never be larger than Ram's. If both of them have equal number of balls say 'n' compute the number of ways in which all the 2n balls can be arranged. For n=3 number of ways would be 5 Find a linear solution for the same -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] coins
A table composed of N x M cells, each having a certain quantity of coins. You start from the upper-left corner. At each step you can go down or right one cell. Find the maximum number of coins you can collect. Provide an algorithm of O(n^2) solution. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: sorted array
@above can u plz explain hw did u apply this formula? On 13 October 2010 16:14, Shiyam code_for_life mailshyamh...@gmail.comwrote: Lets say 8 integers are 1 to 8 So first way array can be split is 1,7 1st array can have one among 8 integers so in 8 ways and 2nd array has just one arrangement of other integers in sorted manner and same goes on for other ways to split the array. Whats wrong here? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: sorted array
ignore the above post of mine @ shiyam u r doing wrong. we hv been the size of both array b and c which is 5 n 3 respectively @ AlgoSAu can u please explain ur method? On 13 October 2010 17:23, Divya Jain sweetdivya@gmail.com wrote: @above can u plz explain hw did u apply this formula? On 13 October 2010 16:14, Shiyam code_for_life mailshyamh...@gmail.comwrote: Lets say 8 integers are 1 to 8 So first way array can be split is 1,7 1st array can have one among 8 integers so in 8 ways and 2nd array has just one arrangement of other integers in sorted manner and same goes on for other ways to split the array. Whats wrong here? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] sorted array
Given a sorted array A with 8 integers.We want to have 2 sorted arrays B(with 5 integers) And C(with 3 integers) such that merging B and C would result in A. How many such pairs exists -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Longest Palindromic Substring
A substring is continuous, whereas a subsequence is discontinuous. alevela is a palindromic subsequence, and not a substring. On Thu, Aug 19, 2010 at 11:45 AM, Saikat Debnath saikat@gmail.comwrote: Isn't the longest palindromic substring is alevela??? On Aug 19, 7:16 pm, Nikhil Jindal fundoon...@yahoo.co.in wrote: Hi All, Givan a string, you have to find the longest palindromic substring. For ex: Longest Palindromic substring for abclevelabc is level. What is the most optimised solution possible? Please access the attached hyperlink for an important electronic communications disclaimer: http://dce.edu/web/Sections/Standalone/Email_Disclaimer.php -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Permutation of Array.
Another method - 1. Group the numbers according to the number of digits (maybe hash buckets) 2. Sort in ascending order within each bucket (any efficient sorting algo) 3. Concatenate them by descending order of number of digits, and ascending order within the group. On Thu, Aug 19, 2010 at 7:37 AM, Nikhil Jindal fundoon...@yahoo.co.inwrote: The critical thing here is how to define your comparator function to be used for sorting. Sorting using the normal comparator function will return the following: 31 33 55 312 Using insertion sort O(n^2) such that the resultant concatenation is smallest, should do it. The steps for [55,31,312,33] would be: 55 31 55 312 31 55 312 31 33 55 which gives the correct result :) Defining the comparator function on these lines should do it in O(nlogn) as well. On Thu, Aug 19, 2010 at 5:02 PM, Shiv ... shivsinha2...@gmail.com wrote: An interesting idea would be treat the inputs as strings and sort them. On Thu, Aug 19, 2010 at 4:01 AM, amit amitjaspal...@gmail.com wrote: Given an array of numbers. Calculate a permutation when the concatenate number is smallest. For instance, [55,31,312,33] is 312313355 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. Please access the attached hyperlink for an important electronic communications disclaimer: http://dce.edu/web/Sections/Standalone/Email_Disclaimer.php -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com algogeeks%2bunsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Permutation of Array.
By the algo I gave : 1. Grouping - 3 digits - 111 1 digit - 6,5,9 2. Sorting within each bucket 3 digits - 111 1 digit - 5,6,9 3. Concatenation by descending order of number of digits, and increasing order within each digit bucket - Grouping would then be - 3 digit numbers in sorted order followed by 1 digit numbers in sorted order 111 5 6 9 Is there a number smaller than 111569 that can be formed with the set given? Also, I am not sure about the complexity of this algo. On Thu, Aug 19, 2010 at 1:56 PM, BALARUKESH SIVARAMAN sbalarukesh1...@gmail.com wrote: @Divya : Does the algo you gave work for the set { 6,5,9,111} ? I hope it doesnt... Correct me if i am wrong -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Permutation of Array.
Never mind. This algo doesn't work properly. Apologies. On Thu, Aug 19, 2010 at 3:34 PM, Divya Chandrasekar divyac1...@gmail.comwrote: By the algo I gave : 1. Grouping - 3 digits - 111 1 digit - 6,5,9 2. Sorting within each bucket 3 digits - 111 1 digit - 5,6,9 3. Concatenation by descending order of number of digits, and increasing order within each digit bucket - Grouping would then be - 3 digit numbers in sorted order followed by 1 digit numbers in sorted order 111 5 6 9 Is there a number smaller than 111569 that can be formed with the set given? Also, I am not sure about the complexity of this algo. On Thu, Aug 19, 2010 at 1:56 PM, BALARUKESH SIVARAMAN sbalarukesh1...@gmail.com wrote: @Divya : Does the algo you gave work for the set { 6,5,9,111} ? I hope it doesnt... Correct me if i am wrong -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Maximum size binary search tree
@ above ur soln ll fail in situation like 10 / \ 15 18 /\ / \ 22 7 17 77 the inorder is 22 15 7 10 17 18 77 so the longest increasing sequence is 7-77 but this is not a bst as 10 n 7 r nt connected On 24 June 2010 22:36, gopinath sikha gopisi...@gmail.com wrote: We can find the solution in O(n) where n is number of nodes. Do an in-order traversal of the binary tree. then scan through the numbers and find the list and find the longest(increasing or decreasing) sequence. That is the size of maximum size of BST in the given binary tree. On Wed, Jun 23, 2010 at 11:40 AM, Raj N rajn...@gmail.com wrote: Find the maximum size Binary search tree in a 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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- -- If u doubt your believes,u believe ur doubts If u fail to practise,u practises failure Thanks and Regards GopiNath -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] array question
Given an array A of N elements, where N approaches infinity, there are S elements in it where SN. WAP to insert an element at A[S] if it does not exist in A[0S-1]. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] os problem
You have 4GB ram, and at any time you have only 2 processes of 10mb each. so do you need any virtual memory for it? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Array with 0 and 1
i think u need to visit every element atleast once to see if its 1 or 0, nd so update the count. so i dont think it will be possible in less than O(n2) On 5 July 2010 15:41, amit amitjaspal...@gmail.com wrote: For a given matrix NxN having 0 or 1’s only. You have to find the count of rows and columns where atleast one 1 occurs. e,g 0 0 0 0 1 0 0 1 1 0 0 1 1 1 0 1 Row count having 1 atleast once: 3 Col count having 1 atleast once: 3 Any Solution less than O(n^2) will do -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] amazon question
Design an algorithm and write code to serialize a 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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] merge sorted lists
How do you merge n sorted lists with average length K in O(n*log(K)) time? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] algo for counting integers in a stream
You are provided with a stream of integers, design a data structure to store the number of occurrences of each integer. If the set of integers is known, then the problem becomes simple. If the set of integers is known: Have a hash of the known set of integers. Parse the input stream, hash it to get the key and increase its corresponding value. how to do efficiently if the set is not known? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] most viewed pages
Design an algorithm to calculate the most user viewed pages. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] algorithm for jig saw puzzle
Jig saw puzzle, What are the data structures? Assume you have some method which can tell you if two pieces fit together. How would you solve the puzzle, minimizing the number of times you have to call that function? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: isbst
@ above here u r comparing node value with min and max only for eg if ur tree is 45 / \ 65 85 / 25 ur code will say that this is bst. bt it is not plzz correct me if i m wrong.. On 1 July 2010 16:17, CM Saikanth Varma saikanthva...@gmail.com wrote: Hi, The idea is like this: Isbst(node *t){ if(t==NULL){ return true; } if ( Isbst(t-left) Isbst(t-right) (maxValue(t-left) =(t-data) ) (minValue(t-right) = (t-data) ) return true; else return false; } I hope it makes sense :D On Thu, Jul 1, 2010 at 3:37 PM, vicky mehta...@gmail.com wrote: just do one thing print inorder. if sorted it is a BST On Jun 19, 2:57 pm, divya sweetdivya@gmail.com wrote: i have found the following code on net to check if the binarytreeis bst or not /* Returns true if a binarytreeis a binary searchtree. */ int isBST(struct node* node) { if (node==NULL) return(true); // false if the min of the left is than us if (node-left!=NULL minValue(node-left) node-data) return(false); // false if the max of the right is = than us if (node-right!=NULL maxValue(node-right) = node-data) return(false); // false if, recursively, the left or right is not a BST if (!isBST(node-left) || !isBST(node-right)) return(false); // passing all that, it's a BST return(true); } int minValue(struct node* node) { struct node* current = node; // loop down to find the leftmost leaf while (current-left != NULL) { current = current-left;} return(current-data); } and maxvalue also similarly returns right most vaslue oftree.. now i have a doubt that here v r comparing the node-data with only the min node nd max node.. shd nt we compare the node data with its left node and right node only. as it can b a case that node value is greater than min but less than its left node.. nd here we r nt checking that... plzz correct me if i m wrong... and is there any other efficient method to find isbst? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] c
ya it is giving error cz u r incrementing x. u cant increment x as it is const. but there is no prob with declaration. its valid. On 26 June 2010 11:09, sharad kumar aryansmit3...@gmail.com wrote: pls c thz On Sat, Jun 26, 2010 at 10:48 AM, sharad kumar aryansmit3...@gmail.comwrote: cos if u declare const u cant change na.but volatile changes na.so practically u cant declareU cant do mtech at IIT and MBA at IIM at same time rite??? On Sat, Jun 26, 2010 at 10:43 AM, sharad kumar aryansmit3...@gmail.comwrote: no its not cos u have declared const and volatile hw is it possible can u go to IIT and IIM at same time On Sat, Jun 26, 2010 at 9:22 AM, sharad kumar sharad20073...@gmail.com wrote: static const volatile int x; Is the declaration valid plzzz explain -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- yezhu malai vaasa venkataramana Govinda Govinda -- yezhu malai vaasa venkataramana Govinda Govinda -- yezhu malai vaasa venkataramana Govinda Govinda -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: There is an array of odd and even numbers. Now, sort them in such a way that the top portion of the array contains odd numbers, bottom portion contains even numbers
@ gurav vivek i think u r only exchanging odd and even.. only putting even to end and odd in front and not doing descending sorting on odds and ascending on even.. plz correct me if i hv missed something.. On 24 June 2010 22:49, Vivek Sundararajan s.vivek.ra...@gmail.com wrote: Hi, how about this - Do a merge sort, now, while merging two sorted list, give more priority to odd numbers :) I believe this falls into the right solutions :) Any breaking cases? On 24 June 2010 09:41, Gaurav Singh gogi.no...@gmail.com wrote: I think in this case, bubble sorting will be a better idea. just replace the condition of comparison with the condition that earlier number is even and later number is odd. I mean we can do sumthing lyk this : for i=1 to n-1 for j=1 to n-i-1 if iseven(ar[j]) AND (NOT iseven(ar[j+1])) then swap both of them. Please correct me if I am wrong somewhere. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Reduce, Reuse and Recycle Regards, Vivek.S -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] sum k in sub array
@amir ur algo works only for positive elements array.. correct me if m wrong On 23 June 2010 00:28, Amir hossein Shahriari amir.hossein.shahri...@gmail.com wrote: for each element find sum[i] which is the summation of all elements with index less than or equal to i ( note that this array is always sorted) this can be done in O(n) then sum[i]-sum[j] when ji is the sum of range [j,i] then for each sum[i] binary search for sum[i]-k in the array sum which yields the overall running time of O(nlogn) On Tue, Jun 22, 2010 at 7:48 PM, sharad kumar sharad20073...@gmail.comwrote: How will you find the subarray whose sum is k in an array of negative and positive numbers -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] linked list
if we dont want to change original list.. is there ny efficient method for that? On 23 June 2010 06:49, ANUJ KUMAR kumar.anuj...@gmail.com wrote: reverse one of the linked lists in O(n) time and then see if the resulting one is same as the other one On Wed, Jun 23, 2010 at 1:56 AM, divya sweetdivya@gmail.com wrote: Two link lists are given ...check if one is reverse of other. Do it without using extra space. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] no of bits
find the no. of bits set in a no. in logn time -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] a bst
a bst is given whose leaf nodes having left as well as right pointers not pointing to NULL. rather all the leaf nodes are forming a circular doubly linked list. u have to calculate height of tree. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] single linked list to tree
u r given a single linked list u have to make a minimally skewed tree such that each child points to its parent.. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] linked list
Two link lists are given ...check if one is reverse of other. Do it without using extra space. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: no of bits
@ dave how did u come to this formula... m nt getting the logic.. @ sathaiah yes u r rite On 22 June 2010 19:32, chitta koushik koushik.infin...@gmail.com wrote: For more such problems and solns http://graphics.stanford.edu/~seander/bithacks.htmlhttp://graphics.stanford.edu/%7Eseander/bithacks.html for (c = 0; v; c++) { v = v - 1; // clear the least significant bit set } O(k) -- no. of bits set in the number --Koushik C On Tue, Jun 22, 2010 at 7:16 PM, Dave dave_and_da...@juno.com wrote: Assuming 32 bit integers: n = ((x 1) 0x) + (x 0x) n = ((n 2) 0x) + (n % 0x) n = ((n 4) 0x0F0F0F0F) + (n 0x0F0F0F0F) n = ((n 8) 0x00FF00FF) + (n 0x00FF00FF) n = ((n 16) 0x) + (n 0x) n now is the number of bits set in x. Time is O(1). Dave On Jun 22, 6:26 am, divya sweetdivya@gmail.com wrote: find the no. of bits set in a no. in logn time -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] queue
there is a linked list where each node of linked list points to queue.. for eg. 1st node points to queue 1 2nd to queue 2 nd so on.. hope m clear this time.. On 20 June 2010 18:30, Piyush Verma 114piy...@gmail.com wrote: @divya plzz explain little more. m not getting... -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] isbst
i have found the following code on net to check if the binary tree is bst or not /* Returns true if a binary tree is a binary search tree. */ int isBST(struct node* node) { if (node==NULL) return(true); // false if the min of the left is than us if (node-left!=NULL minValue(node-left) node-data) return(false); // false if the max of the right is = than us if (node-right!=NULL maxValue(node-right) = node-data) return(false); // false if, recursively, the left or right is not a BST if (!isBST(node-left) || !isBST(node-right)) return(false); // passing all that, it's a BST return(true); } int minValue(struct node* node) { struct node* current = node; // loop down to find the leftmost leaf while (current-left != NULL) { current = current-left; } return(current-data); } and maxvalue also similarly returns right most vaslue of tree.. now i have a doubt that here v r comparing the node-data with only the min node nd max node.. shd nt we compare the node data with its left node and right node only. as it can b a case that node value is greater than min but less than its left node.. nd here we r nt checking that... plzz correct me if i m wrong... and is there any other efficient method to find isbst? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] binary tree
write a code to construct tree from inorder nd preorder traversal.. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] doubly linked list
u can xor linked list. such that every node link contains the xor of its prev nd next node address.. since for 1st node prev is null ( 0) so its link contains only next. now to calculate next of 2nd node xor its link with 1st node's link nd u ll get 3 rd node.s adddress nd so on.. u can also use sum. store in link the sum of prev node n next node address.. bt this cn result in overflow. so xor method is better On 16 June 2010 09:14, sharad kumar sharad20073...@gmail.com wrote: u have to use XOR linked list -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] sum to 0
sort array c only. now select every pair from array a nd b ( o(n2)) for every pair find the element from c which gives sum of the three element 0. ( search using binary search as c is sorted) so the algo is O (n^2 logn)) On 16 June 2010 13:47, Amir hossein Shahriari amir.hossein.shahri...@gmail.com wrote: @algoose chase: you're right thx for the test case On Wed, Jun 16, 2010 at 11:45 AM, Algoose Chase harishp...@gmail.comwrote: @ Amir: I think you cannot find two numbers in B and C such that their sum is -A[k] in O(n) in all cases with the logic that you mentioned. for instance you can try with : A : 2 7 8 10 B :-2, 0, 1, 9 C: -7 -2 1 3 On Wed, Jun 16, 2010 at 5:56 AM, Amir hossein Shahriari amir.hossein.shahri...@gmail.com wrote: sort all arrays for each number in A , A[k] find two numbers in B and C such that their sum is -A[k] this can be done in O(n) time: set i at the beginning of B and j at the end of C while in or j=0 if ( B[i] + C[j] == -A[k] ) return true if ( B[i] + C[j] -A[k] ) increase i else decrease j we have to do this for each element of A so the overall complexity is: O(n2) time O(1) space correct me if I'm wrong On 6/15/10, sharad kumar sharad20073...@gmail.com wrote: plzzz comment on this question -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] trees
Given a Parent -Child binary tree ,build the child -sibling version of it? Minimize the space requirements wherever possible. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] coins
You are given some denominations of coins in an array (int denom[])and infinite supply of all of them. Given an amount (int amount), find the minimum number of coins required to get the exact amount. What is the method called? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] doubly linked list
yes u need to start frm beg.. On 16 June 2010 17:15, Vivek Sundararajan s.vivek.ra...@gmail.com wrote: so, this means that i can traverse the list only from the beginning of the link list right? what if im given a pointer pointing to some node other than the head of the doubly linked list? will i be able to traverse in any direction now? please let me know if im missing something :) Thank you, Vivek On 16 June 2010 15:37, divya jain sweetdivya@gmail.com wrote: u can xor linked list. such that every node link contains the xor of its prev nd next node address.. since for 1st node prev is null ( 0) so its link contains only next. now to calculate next of 2nd node xor its link with 1st node's link nd u ll get 3 rd node.s adddress nd so on.. u can also use sum. store in link the sum of prev node n next node address.. bt this cn result in overflow. so xor method is better On 16 June 2010 09:14, sharad kumar sharad20073...@gmail.com wrote: u have to use XOR linked list -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Mirroring Binary Tree Pattern Problem
This C code will create a new mirror copy tree. mynode *copy(mynode *root) { mynode *temp; if(root==NULL)return(NULL); temp = (mynode *) malloc(sizeof(mynode)); temp-value = root-value; temp-left = copy(root-right); temp-right = copy(root-left); return(temp); } On 13 June 2010 17:07, BALARUKESH SIVARAMAN sbalarukesh1...@gmail.comwrote: try this one.. make a level order traversal and store the elements in array... on the other system reconstruct it using right element for the left and left element for the right... -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] trees
reverse in order traversal till u reach kth node. reverse inorder means first visit right child then print data nd then left. On 14 June 2010 08:34, Lekha lek...@gmail.com wrote: Inorder traversal till u reach the kth element(If it is sorted in descending order, otherwise go till (n-k)th element).. On Sun, Jun 13, 2010 at 9:24 PM, Rohit Saraf rohit.kumar.sa...@gmail.comwrote: Repeated q. Search in the group -- -- Rohit Saraf Second Year Undergraduate, Dept. of Computer Science and Engineering IIT Bombay http://www.cse.iitb.ac.in/~rohitfeb14http://www.cse.iitb.ac.in/%7Erohitfeb14 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Lekha -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: file handing
why a.c gets closed. well comma operator has left to right associativity. for eg a=(2,3,4) ; here is a=4 after the statement is executed so similarly why not here. y c.c is not closed here? On 13 June 2010 22:16, souravsain souravs...@gmail.com wrote: For Problem 3 see section 4.2 Using feof() incorrectly in http://www.drpaulcarter.com/cs/common-c-errors.php On Jun 13, 8:36 pm, divya jain sweetdivya@gmail.com wrote: sorry i pasted wrong questn unser 2.. the real question is which file will get closed through fclose() #includestdio.h int main() { FILE *fp,*fs,*ft; fp=fopen(a.c,r); fs=fopen(b.c,r); ft=fopen(c.c,r); fclose(fp,fs,ft); return 0; } 3. yes it is feof..srry typed it wrong... nd fgets(str,80,fp) is perfectly fine.. now the ans to this questn is that last line of the file will be printed twice...( which i m unable to get why)...plzz explain... @ souravsain plzz ignore this mail..srry for the inconvenience.. On 13 June 2010 17:37, jalaj jaiswal jalaj.jaiswa...@gmail.com wrote: in question 1... ch gets the value of EOF... so first kicit 44-a gokulpeth\0 nagpur will get printed and then the value of EOF.. question number 2 .. seems to me as nrml ...i think myfile.c only gets closed in question number 3..it shld be fgets(str,79,fp) On Sun, Jun 13, 2010 at 2:49 PM, divya sweetdivya@gmail.com wrote: 1. wat ll be the o/p. plz explain y? // abc.c contains kicit 44-a gokulpeth\0 nagpur #includestdio.h #includestdlib.h int main() { unsigned char ch; FILE *fp; fp=fopen(abc.c,r); if(fp==NULL) { printf(unable to open the file \n); exit(1); } while((ch=getc(fp))!=EOF) printf(%c,ch); fclose(fp); printf(\n,ch); return 0; } 2.which file will get closed through fclose() in the following program and why? #includestdio.h int main() {FILE *fp; char ch; int i=1; fp=fopen(myfile.c,r); while((ch=getc(fp)!=EOF)) { if(ch=='\n') i++; } fclose(fp); return 0; } 3.point out the error if any in following #includestdio.h int main() { FILE *fp; char str[80]; fp=fopen(trial,r); while(!eof(fp)) { fgets(str,80,fp); puts(str); } fclose(fp); return 0; } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com algogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- With Regards, Jalaj Jaiswal +919026283397 B.TECH IT IIIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com algogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.- 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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Array Problem
i meant make an array of indexes.. index[]={0,1...,n-1} now sort the original array and move the elements of index array accordingly.. now follow modelling expert's algo nd while taking largest-smallest check if the index of largest in index array index of smallest in index array. On 13 June 2010 08:38, Rohit Saraf rohit.kumar.sa...@gmail.com wrote: @Satya: I don't think what you have coded will work.. though i have not read the whole code. Don't you think a simple divide and conquer scheme would work...(almost like the mergesort) -- Rohit Saraf Second Year Undergraduate, Dept. of Computer Science and Engineering IIT Bombay http://www.cse.iitb.ac.in/~rohitfeb14http://www.cse.iitb.ac.in/%7Erohitfeb14 On Sat, Jun 12, 2010 at 9:06 PM, Satya satya...@gmail.com wrote: This problem seems to be finding the maxdiff in an array. int maxdiff ( int A[], int n ) { // write your code here int max_diff = A[1] - A[0]; int min_element = A[0]; int i; for(i = 1; i n; i++) { if(A[i] - min_element max_diff) max_diff = A[i] - min_element; if(A[i] min_element) min_element = A[i]; } if(max_diff 0) max_diff = 0; return max_diff; } . Satya On Sat, Jun 12, 2010 at 3:18 PM, divya jain sweetdivya@gmail.comwrote: i think we need to maintain an array of index as well such that while subtracting smallest element from largest element of sorted array we need to check if index of largest is greater than index of smallest. if no..then this is not the solution.. On 12 June 2010 14:20, Modeling Expert cs.modelingexp...@gmail.comwrote: Let's say array A , 1 till n s_index = 1; e_index = n ; start = A[s_index] ; end = A[e_index]; result = 0; //! j - i if ( *end *start ){ result = index(end) - index(start) ( only of its greater than previous value of result ) break ; }else{ end-- ; //! till you reach start } now increment start , and repeat the process but only from A[n] till A[++result] , going further down is not required now. Average time o(n^2) Worst case : let's say we have descending array of ints, theno(n^2) Please suggest improvements On Jun 12, 12:14 am, amit amitjaspal...@gmail.com wrote: given an array A of n elements. for indexes j , i such that ji maximize( j - i ) such that A[j] - A [ i ] 0 . Any Algorithm less than O(n^2) would do. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] c- pointers
bt the ans that sharad gave is ryt.. acc to me 1st row n 1st col of o/p shd b 2 (if size of int is 2) bt it is 1... On 13 June 2010 12:10, Rohit Saraf rohit.kumar.sa...@gmail.com wrote: @divya: u r rite.. that * should not be there -- Rohit Saraf Second Year Undergraduate, Dept. of Computer Science and Engineering IIT Bombay http://www.cse.iitb.ac.in/~rohitfeb14http://www.cse.iitb.ac.in/%7Erohitfeb14 On Sun, Jun 13, 2010 at 11:07 AM, divya jain sweetdivya@gmail.comwrote: ptr is a pointer naaa...then why ptr-p=*((arr+1)-arr) ??? why not (arr+1)-arr ?? i knw m wrong somewhr...plz correct me On 13 June 2010 07:57, Mahesh_JNU mahesh.jnumc...@gmail.com wrote: agreed . On Sun, Jun 13, 2010 at 7:48 AM, sharad kumar aryansmit3...@gmail.comwrote: 111 222 333 344 ptr++ -u do posst increment hence it goes to 1 ptr-p=*((arr+1)-arr)=1 llrly for other cases when u do *ptr++ due to operator precedence ptr++ is done and then dereferenced. hence u get 222 next *++ptr the ptr is incremented after dereferencing hence u get 333 next ++*ptr here the value t ptr s incrementas it is treated as++(*ptr) hence u get 3 but others refer to location hence 44 On Sat, Jun 12, 2010 at 9:21 PM, divya sweetdivya@gmail.comwrote: #includestdio.h int main() { static int arr[]={0,1,2,3,4}; int *p[]={arr,arr+1,arr+2,arr+3,arr+4}; int **ptr=p; ptr++; printf(%d %d %d\n,ptr-p,*ptr-arr,**ptr); *ptr++; printf(%d %d %d\n,ptr-p,*ptr-arr,**ptr); *++ptr; printf(%d %d %d\n,ptr-p,*ptr-arr,**ptr); ++*ptr; printf(%d %d %d\n,ptr-p,*ptr-arr,**ptr); return 0; } wat shd b the o/p n why... -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- yezhu malai vaasa venkataramana Govinda Govinda -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Mahesh Giri MCA Final Sem JNU, New Delhi -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] c array
i use tc On 13 June 2010 13:11, ram karthik.gin...@gmail.com wrote: @rohit bro http://www.mingw.org/ *MinGW*, a contraction of Minimalist GNU for Windows, is a port of the GNU Compiler Collection (GCC), and GNU Binutils, for use in the development of native Microsoft Windows applications. *From:* algogeeks@googlegroups.com [mailto:algoge...@googlegroups.com] *On Behalf Of *Rohit Saraf *Sent:* 13 June 2010 08:19 *To:* algogeeks@googlegroups.com *Subject:* Re: [algogeeks] c array @ram : i guess you have used some longer string and not strings btw.. what is Mingw ? gcc/g++ is not mingw, i guess -- Rohit Saraf Second Year Undergraduate, Dept. of Computer Science and Engineering IIT Bombay http://www.cse.iitb.ac.in/~rohitfeb14http://www.cse.iitb.ac.in/%7Erohitfeb14 On Sun, Jun 13, 2010 at 8:13 AM, ram karthik.gin...@gmail.com wrote: D:\code\samplecode\main.cpp|5|error: initializer-string for array of chars is too long| I get this error on gcc (Mingw) . Though the array indexing starts from 0. The length specified in char str[7] is always straightforward . in this case char str[7] . the length of str is seven not eight ;hence the error -- ram *From:* algogeeks@googlegroups.com [mailto:algoge...@googlegroups.com] *On Behalf Of *sharad kumar *Sent:* 13 June 2010 07:59 *To:* algogeeks@googlegroups.com *Subject:* Re: [algogeeks] c array hey array indexing starts from 0 rite?? then y shld u get overflow in first place.. s t r i n g s \0 0 1 2 3 4 5 6 7 On Sat, Jun 12, 2010 at 9:14 PM, divya sweetdivya@gmail.com wrote: #includestdio.h int main() { char str[7]=strings; printf(%s\n,str); return 0; } here i m nt getting overflow error whereas if i write stringss instead of strings then there is overflow error.. isnt null stored after s in strings nd 1st case shd also give overflow??? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- yezhu malai vaasa venkataramana Govinda Govinda -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] union- c
its an o/p questn.. conversion wen ur variable is long..nd u r printing using %f...i dont know how to perform conversion from float to int long nd vice versa.. pl help On 13 June 2010 12:12, Rohit Saraf rohit.kumar.sa...@gmail.com wrote: what is this for... and which conversion are you talking abt? -- Rohit Saraf Second Year Undergraduate, Dept. of Computer Science and Engineering IIT Bombay http://www.cse.iitb.ac.in/~rohitfeb14http://www.cse.iitb.ac.in/%7Erohitfeb14 On Sat, Jun 12, 2010 at 11:20 PM, divya sweetdivya@gmail.com wrote: #include stdio.h main() { union { long l_e; float f_e; } u; long l_v; float f_v; l_v = u.l_e = 10; printf(%f , (float)l_v); printf(%f , u.f_e); f_v = u.f_e = 3.555; printf(%d , (long)f_v); printf(%d , u.l_e); } hw to do the conversion here.. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] c- pointers
oh yes.. wen ll i stop making this stupid mistakes :( On 13 June 2010 15:03, Rohit Saraf rohit.kumar.sa...@gmail.com wrote: @jalaj: exactly... so you(@divya) are right. Sharad's ans was right but logic wasn't. -- Rohit Saraf Second Year Undergraduate, Dept. of Computer Science and Engineering IIT Bombay http://www.cse.iitb.ac.in/~rohitfeb14http://www.cse.iitb.ac.in/%7Erohitfeb14 On Sun, Jun 13, 2010 at 2:35 PM, jalaj jaiswal jalaj.jaiswa...@gmail.comwrote: actually when you subtract two pointers ... its get divided by the size of the variable type its point two... for example.. if you do .. p+1... where let say p is 200 and points to an int type variable then p+1 is 202...(assuming int is of size 2) so (p+1)-p..i.e 202-200 is 1 and not 2 On Sun, Jun 13, 2010 at 1:46 PM, divya jain sweetdivya@gmail.comwrote: bt the ans that sharad gave is ryt.. acc to me 1st row n 1st col of o/p shd b 2 (if size of int is 2) bt it is 1... On 13 June 2010 12:10, Rohit Saraf rohit.kumar.sa...@gmail.com wrote: @divya: u r rite.. that * should not be there -- Rohit Saraf Second Year Undergraduate, Dept. of Computer Science and Engineering IIT Bombay http://www.cse.iitb.ac.in/~rohitfeb14http://www.cse.iitb.ac.in/%7Erohitfeb14 On Sun, Jun 13, 2010 at 11:07 AM, divya jain sweetdivya@gmail.comwrote: ptr is a pointer naaa...then why ptr-p=*((arr+1)-arr) ??? why not (arr+1)-arr ?? i knw m wrong somewhr...plz correct me On 13 June 2010 07:57, Mahesh_JNU mahesh.jnumc...@gmail.com wrote: agreed . On Sun, Jun 13, 2010 at 7:48 AM, sharad kumar aryansmit3...@gmail.com wrote: 111 222 333 344 ptr++ -u do posst increment hence it goes to 1 ptr-p=*((arr+1)-arr)=1 llrly for other cases when u do *ptr++ due to operator precedence ptr++ is done and then dereferenced. hence u get 222 next *++ptr the ptr is incremented after dereferencing hence u get 333 next ++*ptr here the value t ptr s incrementas it is treated as++(*ptr) hence u get 3 but others refer to location hence 44 On Sat, Jun 12, 2010 at 9:21 PM, divya sweetdivya@gmail.comwrote: #includestdio.h int main() { static int arr[]={0,1,2,3,4}; int *p[]={arr,arr+1,arr+2,arr+3,arr+4}; int **ptr=p; ptr++; printf(%d %d %d\n,ptr-p,*ptr-arr,**ptr); *ptr++; printf(%d %d %d\n,ptr-p,*ptr-arr,**ptr); *++ptr; printf(%d %d %d\n,ptr-p,*ptr-arr,**ptr); ++*ptr; printf(%d %d %d\n,ptr-p,*ptr-arr,**ptr); return 0; } wat shd b the o/p n why... -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- yezhu malai vaasa venkataramana Govinda Govinda -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Mahesh Giri MCA Final Sem JNU, New Delhi -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group
Re: [algogeeks] union- c
wat i meant is the ans of this questn is 10.00 0.00 3 1080263967 now my questn is y u.f_e is printing 0.00 and similarly y u.l_e is giving this value... On 13 June 2010 15:08, Rohit Saraf rohit.kumar.sa...@gmail.com wrote: If you are not able to print the long int and that's the prob, you can use %ld instead of %d -- Rohit Saraf Second Year Undergraduate, Dept. of Computer Science and Engineering IIT Bombay http://www.cse.iitb.ac.in/~rohitfeb14http://www.cse.iitb.ac.in/%7Erohitfeb14 On Sun, Jun 13, 2010 at 1:49 PM, divya jain sweetdivya@gmail.comwrote: its an o/p questn.. conversion wen ur variable is long..nd u r printing using %f...i dont know how to perform conversion from float to int long nd vice versa.. pl help On 13 June 2010 12:12, Rohit Saraf rohit.kumar.sa...@gmail.com wrote: what is this for... and which conversion are you talking abt? -- Rohit Saraf Second Year Undergraduate, Dept. of Computer Science and Engineering IIT Bombay http://www.cse.iitb.ac.in/~rohitfeb14http://www.cse.iitb.ac.in/%7Erohitfeb14 On Sat, Jun 12, 2010 at 11:20 PM, divya sweetdivya@gmail.comwrote: #include stdio.h main() { union { long l_e; float f_e; } u; long l_v; float f_v; l_v = u.l_e = 10; printf(%f , (float)l_v); printf(%f , u.f_e); f_v = u.f_e = 3.555; printf(%d , (long)f_v); printf(%d , u.l_e); } hw to do the conversion here.. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] bits
tell the o/p of following with explanations 1. #includestdio.h int main() { struct value { int bit1:1; int bit3:4; int bit4:4; }bit; printf(%d\n,sizeof(bit)); return 0; } 2. #includestdio.h int main() { struct value { int bit1: 1; int bit3: 4; int bit4: 4; } bit={1,2,2}; printf(%d %d %d\n,bit.bit1,bit.bit3,bit.bit4); return 0; } 3 can bit field be used in union?? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] file handing
1. wat ll be the o/p. plz explain y? // abc.c contains kicit 44-a gokulpeth\0 nagpur #includestdio.h #includestdlib.h int main() { unsigned char ch; FILE *fp; fp=fopen(abc.c,r); if(fp==NULL) { printf(unable to open the file \n); exit(1); } while((ch=getc(fp))!=EOF) printf(%c,ch); fclose(fp); printf(\n,ch); return 0; } 2.which file will get closed through fclose() in the following program and why? #includestdio.h int main() {FILE *fp; char ch; int i=1; fp=fopen(myfile.c,r); while((ch=getc(fp)!=EOF)) { if(ch=='\n') i++; } fclose(fp); return 0; } 3.point out the error if any in following #includestdio.h int main() { FILE *fp; char str[80]; fp=fopen(trial,r); while(!eof(fp)) { fgets(str,80,fp); puts(str); } fclose(fp); return 0; } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: bits
thanks to all :) @ souravsain sorry for the inconvenience On 13 June 2010 20:01, Rohit Saraf rohit.kumar.sa...@gmail.com wrote: @Souravsain : Is there any serious problem in this. Anyone can just add a [C++] in the subject and uninterested people can make filters in gmail :) -- Rohit Saraf Second Year Undergraduate, Dept. of Computer Science and Engineering IIT Bombay http://www.cse.iitb.ac.in/~rohitfeb14http://www.cse.iitb.ac.in/%7Erohitfeb14 On Sun, Jun 13, 2010 at 6:35 PM, souravsain souravs...@gmail.com wrote: @divya Lets keep discussions in t his group limited to Algos and problems neutral to any language. Request you to post these C++ / C language specific questions to those language specific groups. This will not only help this group remain confined to its core purpose but will help you get better insights to ur problem by language specific geeks there. For C++ I would recommend you to try the group http://groups.google.co.in/group/comp.lang.c++.moderated/topics?hl=en. Regards, Sourav On Jun 13, 2:29 pm, divya sweetdivya@gmail.com wrote: tell the o/p of following with explanations 1. #includestdio.h int main() { struct value { int bit1:1; int bit3:4; int bit4:4; }bit; printf(%d\n,sizeof(bit)); return 0; } 2. #includestdio.h int main() { struct value { int bit1: 1; int bit3: 4; int bit4: 4;} bit={1,2,2}; printf(%d %d %d\n,bit.bit1,bit.bit3,bit.bit4); return 0; } 3 can bit field be used in union?? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] file handing
sorry i pasted wrong questn unser 2.. the real question is which file will get closed through fclose() #includestdio.h int main() { FILE *fp,*fs,*ft; fp=fopen(a.c,r); fs=fopen(b.c,r); ft=fopen(c.c,r); fclose(fp,fs,ft); return 0; } 3. yes it is feof..srry typed it wrong... nd fgets(str,80,fp) is perfectly fine.. now the ans to this questn is that last line of the file will be printed twice...( which i m unable to get why)...plzz explain... @ souravsain plzz ignore this mail..srry for the inconvenience.. On 13 June 2010 17:37, jalaj jaiswal jalaj.jaiswa...@gmail.com wrote: in question 1... ch gets the value of EOF... so first kicit 44-a gokulpeth\0 nagpur will get printed and then the value of EOF.. question number 2 .. seems to me as nrml ...i think myfile.c only gets closed in question number 3..it shld be fgets(str,79,fp) On Sun, Jun 13, 2010 at 2:49 PM, divya sweetdivya@gmail.com wrote: 1. wat ll be the o/p. plz explain y? // abc.c contains kicit 44-a gokulpeth\0 nagpur #includestdio.h #includestdlib.h int main() { unsigned char ch; FILE *fp; fp=fopen(abc.c,r); if(fp==NULL) { printf(unable to open the file \n); exit(1); } while((ch=getc(fp))!=EOF) printf(%c,ch); fclose(fp); printf(\n,ch); return 0; } 2.which file will get closed through fclose() in the following program and why? #includestdio.h int main() {FILE *fp; char ch; int i=1; fp=fopen(myfile.c,r); while((ch=getc(fp)!=EOF)) { if(ch=='\n') i++; } fclose(fp); return 0; } 3.point out the error if any in following #includestdio.h int main() { FILE *fp; char str[80]; fp=fopen(trial,r); while(!eof(fp)) { fgets(str,80,fp); puts(str); } fclose(fp); return 0; } -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- With Regards, Jalaj Jaiswal +919026283397 B.TECH IT IIIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Array Problem
i think we need to maintain an array of index as well such that while subtracting smallest element from largest element of sorted array we need to check if index of largest is greater than index of smallest. if no..then this is not the solution.. On 12 June 2010 14:20, Modeling Expert cs.modelingexp...@gmail.com wrote: Let's say array A , 1 till n s_index = 1; e_index = n ; start = A[s_index] ; end = A[e_index]; result = 0; //! j - i if ( *end *start ){ result = index(end) - index(start) ( only of its greater than previous value of result ) break ; }else{ end-- ; //! till you reach start } now increment start , and repeat the process but only from A[n] till A[++result] , going further down is not required now. Average time o(n^2) Worst case : let's say we have descending array of ints, theno(n^2) Please suggest improvements On Jun 12, 12:14 am, amit amitjaspal...@gmail.com wrote: given an array A of n elements. for indexes j , i such that ji maximize( j - i ) such that A[j] - A [ i ] 0 . Any Algorithm less than O(n^2) would do. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: identify the recurring part for a given decimal no
@anurag i dint get ur approach..which numerator n denominator u r talking about..plz explain.. thanks in advance On 11 June 2010 08:57, Anurag Sharma anuragvic...@gmail.com wrote: Please note that the fractional repeating part is recurring. and so that 4th temporary variable assignment will be this way- temp=x*1 - x= 233456.34563456... - 23.34563456 = 233433.0 ( mark the fractional part is 0 now since the infinitely repeating 3456... will get cancelled) In this case you can say that 4 places are repeating. But yes its according to the maths and in any programming language whenever you divide the numerator and denominator you wont get this infinitely recurring decimal places. @divya, also your approach wont work if the recurring fractional digits start after few places from the decimal like in the case of 23.123345634563456 (note here after the decimal place 123 is not repeating while 3456.. after this 123 is repeating.) What I suggest in this case is keep dividing the numerator by denominator and at every step keep inserting the tupple (remainder, quotient) of that division step in a set. and before inserting in the set check whether it already exists. If yes then the all the quotients following from that point (including the point) will be recurring. Regards, Anurag Sharma On Thu, Jun 10, 2010 at 8:25 AM, Veer Sharma thisisv...@rediffmail.comwrote: Seems it wont work... x=23.34563456 temp = x*100 -x = 233.4563456 - 23.34563456 = 210.11071104 temp = x*100 -x = 2334.563456 - 23.34563456 = 2311.21782144 temp = x*1000 -x = 23345.63456 - 23.34563456 = 23322.28892544 temp = x*1 -x = 233456.3456 - 23.34563456 = 233432.6544 temp = x*10 -x = 2334563.456 - 23.34563456 = 2334540.11036544 ... On Jun 9, 11:24 pm, Anurag Sharma anuragvic...@gmail.com wrote: multiply the original number x=23.34563456 Anurag Sharma On Wed, Jun 9, 2010 at 10:36 PM, Veer Sharma thisisv...@rediffmail.com wrote: One question: No x = 23.34563456 temp = x X 10 = 233.4563456 temp = temp - x = 210.11071104 decimal part zero? No. Now multiply the no. with 100. Which no? original x (= 23.34563456) or new no. temp (=210.11071104)? On Jun 9, 8:12 pm, divya jain sweetdivya@gmail.com wrote: multiply the no. with 10 nd store in temp. now subtract no from temp. check if the decimal part is zero if yes. then 1st digit after decimal is recurring. if no. multiply the no with 100 and repeat . if this time decimal part is zero then 2 digits after decimal r recurring nd so on.. On 8 June 2010 21:45, Veer Sharma thisisv...@rediffmail.com wrote: You have a Numerator and Denominator. After division you might get a recurring decimal points float as the answer. Problem is: You need to identify the recurring part for a given decimal no? For example 23.34563456 ... return 3456 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com algogeeks%2bunsubscr...@googlegroups.com algogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.-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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com algogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.- 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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send
Re: [algogeeks] Re: c output
one of my frnd askd me this question... On 11 June 2010 21:34, Raj N rajn...@gmail.com wrote: @kirubakaran: How can it be 1,1 ? No of characters read in a is 5+ 1 for '\n' so its 6 and for the next one 1+1=2 On Fri, Jun 11, 2010 at 9:09 AM, kirubakaran kirubakaran1...@gmail.comwrote: Output will be 1,1 bcoz printf returns number of characters or integers printed On Jun 11, 12:26 am, divya sweetdivya@gmail.com wrote: #include stdio.h main() { int a = 1; char b='c'; int i,j; printf(%d,%d,printf(%d\n,a),printf(%c\n,b)); wat shd b the o/p of this..plzz explain y? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] c- pointers
#includestdio.h int main() { static int arr[]={0,1,2,3,4}; int *p[]={arr,arr+1,arr+2,arr+3,arr+4}; int **ptr=p; ptr++; printf(%d %d %d\n,ptr-p,*ptr-arr,**ptr); *ptr++; printf(%d %d %d\n,ptr-p,*ptr-arr,**ptr); *++ptr; printf(%d %d %d\n,ptr-p,*ptr-arr,**ptr); ++*ptr; printf(%d %d %d\n,ptr-p,*ptr-arr,**ptr); return 0; } wat shd b the o/p n why... -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] output
#includestdio.h int main() { char names[][20]={ roshni, manish, sona, baiju, ritu }; int i; char *t; t=names[3]; names[3]=names[4]; names[4]=t; for(i=0;i=4;i++) printf(%s,names[i]); printf(\n); return 0; } here i get l value required as error and if i replace char names[][2] with char *names[].. then there is no error nd the names[3] n names[4] interchange pl explain why??? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] c array
#includestdio.h int main() { char str[7]=strings; printf(%s\n,str); return 0; } here i m nt getting overflow error whereas if i write stringss instead of strings then there is overflow error.. isnt null stored after s in strings nd 1st case shd also give overflow??? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] union- c
#include stdio.h main() { union { long l_e; float f_e; } u; long l_v; float f_v; l_v = u.l_e = 10; printf(%f , (float)l_v); printf(%f , u.f_e); f_v = u.f_e = 3.555; printf(%d , (long)f_v); printf(%d , u.l_e); } hw to do the conversion here.. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] output
sorry for the silly question i got rhe point.. @ rohit compiler is doing rite..read mahesh's explanatn On 13 June 2010 08:27, Rohit Saraf rohit.kumar.sa...@gmail.com wrote: This is very bad. Change your compiler if it compiles this stuff :) btw.. which compiler is it? Output for me : ro...@rohit-laptop:~/dump$ gcc c.c c.c: In function ‘main’: c.c:14: error: incompatible types when assigning to type ‘char[20]’ from type ‘char *’ c.c:15: error: incompatible types when assigning to type ‘char[20]’ from type ‘char *’ -- Rohit Saraf Second Year Undergraduate, Dept. of Computer Science and Engineering IIT Bombay http://www.cse.iitb.ac.in/~rohitfeb14http://www.cse.iitb.ac.in/%7Erohitfeb14 On Sun, Jun 13, 2010 at 8:13 AM, Mahesh_JNU mahesh.jnumc...@gmail.comwrote: Well As we know for copying the string we can can copy it as a simple variable as in case of address copying. when u r doing names[3] = names[4] , it means u r trying to copy it directly bt in the case of char *names[] , as it is the array of pointers so u can copy the address from one pointer to another pointer Thanks On Sat, Jun 12, 2010 at 9:12 PM, divya sweetdivya@gmail.com wrote: #includestdio.h int main() { char names[][20]={ roshni, manish, sona, baiju, ritu }; int i; char *t; t=names[3]; names[3]=names[4]; names[4]=t; for(i=0;i=4;i++) printf(%s,names[i]); printf(\n); return 0; } here i get l value required as error and if i replace char names[][2] with char *names[].. then there is no error nd the names[3] n names[4] interchange pl explain why??? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Mahesh Giri MCA Final Sem JNU, New Delhi -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] c array
hmm..the prob is here wid my compiler...!! anyways thanks to all On 13 June 2010 10:28, Rohit Saraf rohit.kumar.sa...@gmail.com wrote: oh.. yes.. my mistake (strings\0).length=8 :P -- Rohit Saraf Second Year Undergraduate, Dept. of Computer Science and Engineering IIT Bombay http://www.cse.iitb.ac.in/~rohitfeb14http://www.cse.iitb.ac.in/%7Erohitfeb14 On Sun, Jun 13, 2010 at 10:24 AM, Rahul Kushwaha rahul.kushw...@gmail.com wrote: #includestdio.h int main() { char str[7]=strings; printf(%s\n,str); return 0; } it is showing error on code block and dev cpp also... this is an error no doubt. also mentioned in denis m ritchie -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] c- pointers
ptr is a pointer naaa...then why ptr-p=*((arr+1)-arr) ??? why not (arr+1)-arr ?? i knw m wrong somewhr...plz correct me On 13 June 2010 07:57, Mahesh_JNU mahesh.jnumc...@gmail.com wrote: agreed . On Sun, Jun 13, 2010 at 7:48 AM, sharad kumar aryansmit3...@gmail.comwrote: 111 222 333 344 ptr++ -u do posst increment hence it goes to 1 ptr-p=*((arr+1)-arr)=1 llrly for other cases when u do *ptr++ due to operator precedence ptr++ is done and then dereferenced. hence u get 222 next *++ptr the ptr is incremented after dereferencing hence u get 333 next ++*ptr here the value t ptr s incrementas it is treated as++(*ptr) hence u get 3 but others refer to location hence 44 On Sat, Jun 12, 2010 at 9:21 PM, divya sweetdivya@gmail.com wrote: #includestdio.h int main() { static int arr[]={0,1,2,3,4}; int *p[]={arr,arr+1,arr+2,arr+3,arr+4}; int **ptr=p; ptr++; printf(%d %d %d\n,ptr-p,*ptr-arr,**ptr); *ptr++; printf(%d %d %d\n,ptr-p,*ptr-arr,**ptr); *++ptr; printf(%d %d %d\n,ptr-p,*ptr-arr,**ptr); ++*ptr; printf(%d %d %d\n,ptr-p,*ptr-arr,**ptr); return 0; } wat shd b the o/p n why... -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- yezhu malai vaasa venkataramana Govinda Govinda -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Mahesh Giri MCA Final Sem JNU, New Delhi -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: identify the recurring part for a given decimal no
thanks anurag :) On 12 June 2010 20:07, Anurag Sharma anuragvic...@gmail.com wrote: Since we are given numerator 'n' and denominator 'd' separately already. and considering n and d as integers and d!=0 we can safely assume n/d as either a terminating fraction or a non terminating but recurring fraction, in which case we have to find the recurring digits of the fraction. Now what I suggested was almost same as Ravi's approach. take a Set 'S' keeping tuples (R,Q) where R is the current remainder and Q is the factor such that d*Q is subtracted from the number to get R. In other words. if at an intermediate step of division we have 'a' as the divident left then Q=floor(a/d) and R=a%d Keep dividing 'n' by 'd' like it is done manually. After every division check- 1. If the current remainder is not present in 'S' then add current remainder 'R' and corresponding quotient 'Q' in the set 2. If R is found in the set S, then all the following entries in the set until end will constitute the recurring digits. taking Ravi's example:- Example: 7) 9 (1.*285714*28S=[] 7 -- 20 S=[(2,2)] 14 --- 60S=[(2,2), (6,8)] 56 --- 40 S=[(2,2), (6,8), (4,5)] 35 --- 50 S=[(2,2), (6,8), (4,5), (5,7)] 49 --- 10 S=[(2,2), (6,8), (4,5), (5,7), (1,1)] 7 30 S=[(2,2), (6,8), (4,5), (5,7), (1,1), (3,4)] 28 ^ | 20 2 is found in S here, so recurring digits are 285714 14 60 56 repeats hope its clear Anurag Sharma On Sat, Jun 12, 2010 at 4:02 PM, divya jain sweetdivya@gmail.comwrote: @anurag i dint get ur approach..which numerator n denominator u r talking about..plz explain.. thanks in advance On 11 June 2010 08:57, Anurag Sharma anuragvic...@gmail.com wrote: Please note that the fractional repeating part is recurring. and so that 4th temporary variable assignment will be this way- temp=x*1 - x= 233456.34563456... - 23.34563456 = 233433.0 ( mark the fractional part is 0 now since the infinitely repeating 3456... will get cancelled) In this case you can say that 4 places are repeating. But yes its according to the maths and in any programming language whenever you divide the numerator and denominator you wont get this infinitely recurring decimal places. @divya, also your approach wont work if the recurring fractional digits start after few places from the decimal like in the case of 23.123345634563456 (note here after the decimal place 123 is not repeating while 3456.. after this 123 is repeating.) What I suggest in this case is keep dividing the numerator by denominator and at every step keep inserting the tupple (remainder, quotient) of that division step in a set. and before inserting in the set check whether it already exists. If yes then the all the quotients following from that point (including the point) will be recurring. Regards, Anurag Sharma On Thu, Jun 10, 2010 at 8:25 AM, Veer Sharma thisisv...@rediffmail.comwrote: Seems it wont work... x=23.34563456 temp = x*100 -x = 233.4563456 - 23.34563456 = 210.11071104 temp = x*100 -x = 2334.563456 - 23.34563456 = 2311.21782144 temp = x*1000 -x = 23345.63456 - 23.34563456 = 23322.28892544 temp = x*1 -x = 233456.3456 - 23.34563456 = 233432.6544 temp = x*10 -x = 2334563.456 - 23.34563456 = 2334540.11036544 ... On Jun 9, 11:24 pm, Anurag Sharma anuragvic...@gmail.com wrote: multiply the original number x=23.34563456 Anurag Sharma On Wed, Jun 9, 2010 at 10:36 PM, Veer Sharma thisisv...@rediffmail.comwrote: One question: No x = 23.34563456 temp = x X 10 = 233.4563456 temp = temp - x = 210.11071104 decimal part zero? No. Now multiply the no. with 100. Which no? original x (= 23.34563456) or new no. temp (=210.11071104)? On Jun 9, 8:12 pm, divya jain sweetdivya@gmail.com wrote: multiply the no. with 10 nd store in temp. now subtract no from temp. check if the decimal part is zero if yes. then 1st digit after decimal is recurring. if no. multiply the no with 100 and repeat . if this time decimal part is zero then 2 digits after decimal r recurring nd so on.. On 8 June
[algogeeks] max sum
Given an array all of whose elements are positive numbers, find the maximum sum of a subsequence with the constraint that no 2 numbers in the sequence should be adjacent in the array. Eg. i) 3 2 7 10 should return 13 (sum of 3 and 10) ii) 3 2 5 10 7 should return 15 (sum of 3, 5 and 7) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: isomorphic trees
my solution *isomorphic* (struct node *head1,struct node *head2) { if (head1!=NULL head2!=NULL) { if (head1-data == head2-data) { if (head1-left-data == head2-left-data) { return (isomorphic(head1left,head2-left ) isomorphic(head1right,head2-right)); } else if (head-left-data == head2-right-data) { return (isomorphic**(head1left,head2-right) (isomorphichead1right,head2-left)); } else return (false); } } else if (head1 == NULL head2 == NULL) return (true); else return (false); } On 10 June 2010 00:00, souravsain souravs...@gmail.com wrote: As per @Algoose's explanation, this can be found using the algorithm to comapre if 2 binary trees are equal (quite often asked and found in net). In this we generally go recursive and say T1 is equal to T2 if T1=T2 and same holds for T1-Left, T2-Left (recursive call on left tree) and same holds for T1-Right, T2-Right (recursive call on right tree). We can use the same and change the calls as if T1=T2 and same holds for T1-Left, T2-Right (recursive call on left tree) and same holds for T1-Right, T2-Left (recursive call on right tree). Sain On Jun 9, 10:45 pm, saurabh gupta sgup...@gmail.com wrote: is-isomorphic(t1, t2) { t1ld = t1-left-data t2ld = t2-left-data //. //base case for null or replace by sentinels and check if( t1ld == t2ld t1rd == t2rd) return is-isomorphic(t1ld, t2ld) return is-isomorphic(t1rd, t2rd) if (t1ld == t2rd t1rd == t2ld) return is-isomorphic(t1ld, t2rd) return is-isomorphic(t1rd, t2ld) return false; } On Wed, Jun 9, 2010 at 8:29 PM, divya jain sweetdivya@gmail.com wrote: @vadivel and anand { 1,2,3 } is *isomorphic* to { 1,3,2 } { 1,2,3,4,5,6,7 } is *isomorphic* to { 1,3,2,7,6,4,5 } { 1,2,3,4,5,6,7 } is NOT *isomorphic* to { 1,3,2,4,5,6,7 } so its nt necessary that right and left will interchange. it may or may not. if all right and left are interchanged then it is mirror tree. i think ur code is for mirror tree and not isomorphic tree.. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com algogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Man goes to doctor. Says he's depressed. Says life seems harsh and cruel. Says he feels all alone in a threatening world where what lies ahead is vague and uncertain. Doctor says Treatment is simple. Great clown Pagliacci is in town tonight. Go and see him. That should pick you up. Man bursts into tears. Says But, doctor...I am Pagliacci.- 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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] c output
#include stdio.h main() { int a = 1; char b='c'; int i,j; printf(%d,%d,printf(%d\n,a),printf(%c\n,b)); wat shd b the o/p of this..plzz explain y? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] identify the recurring part for a given decimal no
multiply the no. with 10 nd store in temp. now subtract no from temp. check if the decimal part is zero if yes. then 1st digit after decimal is recurring. if no. multiply the no with 100 and repeat . if this time decimal part is zero then 2 digits after decimal r recurring nd so on.. On 8 June 2010 21:45, Veer Sharma thisisv...@rediffmail.com wrote: You have a Numerator and Denominator. After division you might get a recurring decimal points float as the answer. Problem is: You need to identify the recurring part for a given decimal no? For example 23.34563456 ... return 3456 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] isomorphic trees
@vadivel and anand { 1,2,3 } is *isomorphic* to { 1,3,2 } { 1,2,3,4,5,6,7 } is *isomorphic* to { 1,3,2,7,6,4,5 } { 1,2,3,4,5,6,7 } is NOT *isomorphic* to { 1,3,2,4,5,6,7 } so its nt necessary that right and left will interchange. it may or may not. if all right and left are interchanged then it is mirror tree. i think ur code is for mirror tree and not isomorphic tree.. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] min no of policemen
@sharad.. sorry bt i dint get how to use bellman ford or topological sort here... can u plz explain... On 8 June 2010 05:53, sharad kumar aryansmit3...@gmail.com wrote: for placing police man we can use bellman ford bfs.or even make use of topological sort. On Mon, Jun 7, 2010 at 9:59 PM, divya sweetdivya@gmail.com wrote: consider a tree. policemen is to be placed such that for each edge of tree, there is a policeman on atleast one side of each edge. tell the min no. of policemen and their locatn in time O(n) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- yezhu malai vaasa venkataramana Govinda Govinda -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Puzzle:
yes even i dont think its possible as there is no n-1th state..ie there is no state from whr u can come to 2 8 5..so plz check On 7 June 2010 20:23, mohit ranjan shoonya.mo...@gmail.com wrote: is it possible ? if we say nth state is [2, 8, 5] I could not find possible (n-1)th state Mohit Ranjan On Mon, Jun 7, 2010 at 2:02 PM, sharad sharad20073...@gmail.com wrote: : Three containers are of 15,10 and 6 ltrs capacity. Initially its in configuration (15,0,0). Make it to configuration (2,8,5) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Pointer to a constant
i think both statements shd give error. as u r trying to change int to const int in 2 and const int to int in 1.. On 7 June 2010 19:59, mohit ranjan shoonya.mo...@gmail.com wrote: @Raj, no they are not same case 1: i is const case 2: ptr is const and whatever is const cann't be modified Mohit Ranjan On Mon, Jun 7, 2010 at 3:01 PM, Raj N rajn...@gmail.com wrote: Can someone tell me the difference between 1) const int i=5; 2) int i=5; int *ptr=i; const int *ptr=i; In the first case i can be modified via ptr i.e *ptr++ is valid. In the second case *ptr++ is illegal. Why is that so? Aren't they same? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Number of sequences of n binary digits that don't contain two 1's in a row
how do u come to this formula T(n)=fib(n+2).. plz explain On 7 June 2010 21:19, saurabh gupta sgup...@gmail.com wrote: it might be referring to no of sequences (say T(n) ) with no consecutive 1's for n = 3, ans would be 5 viz. 000, 001, 010, 100, 101 T(n) = fib(n+2) where fib = Fibonacci series which is interesting. On Sat, Jun 5, 2010 at 11:40 AM, Raj N rajn...@gmail.com wrote: @sharad: What about 101 even it doesn't have two 1's in a row On Sat, Jun 5, 2010 at 8:59 AM, sharad kumar aryansmit3...@gmail.comwrote: @rajn.can it be subsequence doesnt have one's too.hence 000,001,010,100 is required answer. On Sat, Jun 5, 2010 at 12:13 AM, Raj N rajn...@gmail.com wrote: Hi, I came across this question to find the number of sequences of n binary digits that don't contain 2 1's in a row. I wanted to know what exactly this means. Is it like if n=3 then compute all binary numbers having 3 digits which don't have consecutive 1's 110, 011, 111 ?? If not help me understanding it. Thanks!! -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- yezhu malai vaasa venkataramana Govinda Govinda -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Man goes to doctor. Says he's depressed. Says life seems harsh and cruel. Says he feels all alone in a threatening world where what lies ahead is vague and uncertain. Doctor says Treatment is simple. Great clown Pagliacci is in town tonight. Go and see him. That should pick you up. Man bursts into tears. Says But, doctor...I am Pagliacci. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] isomorphic trees
Two binary trees T1 and T2 are isomorphic if T1 can be transformed into T2 swapping left and right children of the nodes in T1.Give an algorithm to report whether 2 given binary trees are isomorphic. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Single ordered list
merging as in merge sort. On 8 June 2010 19:59, Raj N rajn...@gmail.com wrote: What is the most efficient way of combining 2 separate ordered list into a single ordered list ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] min no of policemen
edge is the link connecting two nodes of a tree On 8 June 2010 11:23, Anurag Sharma anuragvic...@gmail.com wrote: Can you expain edge of the tree. I could not get that. Anurag Sharma On Tue, Jun 8, 2010 at 5:53 AM, sharad kumar aryansmit3...@gmail.comwrote: for placing police man we can use bellman ford bfs.or even make use of topological sort. On Mon, Jun 7, 2010 at 9:59 PM, divya sweetdivya@gmail.com wrote: consider a tree. policemen is to be placed such that for each edge of tree, there is a policeman on atleast one side of each edge. tell the min no. of policemen and their locatn in time O(n) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- yezhu malai vaasa venkataramana Govinda Govinda -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] constraints satisfied?
Here's a problem that occurs in automatic program analysis. For a set of variables x1; .. ; xn, you are given some equality constraints, of the form xi = xj and some dis equality constraints, of the form xi != xj Is it possible to satisfy all of them? Give an efficient algorithm that takes as input m constraints over n variables and decides whether the constraints can be satisfied. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] min no of policemen
consider a tree. policemen is to be placed such that for each edge of tree, there is a policeman on atleast one side of each edge. tell the min no. of policemen and their locatn in time O(n) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] matix flipping
let a[n][n] be the input array nd b[][] be the output for(i=0;in;i++) for(j=0;jn;j++) b[i][j]=a[n-j-1][n-i-1] On 7 June 2010 08:26, sharad sharad20073...@gmail.com wrote: write a c routine to flip an nXn matrix about its non major diagnol 3 4 5 6 7 9 1 2 8 Transpose is: 8 9 5 2 7 4 1 6 3 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] circularly sorted array
u r given a circularly sorted array of n integers ie the array was 1st sorted nd then left or right shifted any no. of times. search for a given integer k in the array in O(logn) time -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] binary nos
write an efficient algo to compute no. of sequences of n binary digits that do not contain 2 1's in a row. eg 111 is invalid whereas 1001001 is valid.. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] array question
@sharad while storing each element in hash by your approach u ll check if its already there in hash. so the complexity here will be O(n2). correct me if i m wrong. isnt there ny better algo..? On 6 June 2010 06:28, sharad kumar aryansmit3...@gmail.com wrote: @dhivya:keep storing the first occurance element index in hash map and then start insertin eleement based on index position On Sun, Jun 6, 2010 at 12:31 AM, divya sweetdivya@gmail.com wrote: Given an array with some repeating numbers. Like 12,6,5,12,6 output: 12,12,6,6,5 12 shud come before 6 since it is earlier in list. So cant use a dictionary. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- yezhu malai vaasa venkataramana Govinda Govinda -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.