Re: [algogeeks] doubt in lca

2012-03-17 Thread sunny agrawal
C itself On Sat, Mar 17, 2012 at 8:39 PM, rahul sharma rahul23111...@gmail.comwrote: in binary tree.. suppose c is parent of dnow if i want to find least common ancesor of c and dwhther it is parent of c or c itself -- You received this message because you are subscribed to the

Re: [algogeeks] Array problem

2012-03-12 Thread sunny agrawal
. using AVL or RB for the given algo may screw it. On Mon, Mar 12, 2012 at 11:00 PM, sunny agrawal sunny816.i...@gmail.comwrote: @atul TC can be bound to O(nlgn) using any balanced tree ie: AVL tree, RB tree as already mentioned in her last post On Mon, Mar 12, 2012 at 10:44 PM, atul anand

Re: [algogeeks] Re: ARICENT PATTERN

2012-02-26 Thread sunny agrawal
this is not the right place to ask such queries On Sun, Feb 26, 2012 at 5:38 PM, vivek kumar kumarvivek1...@gmail.comwrote: hey guys any one have idea about aricent online paper .. plzzz tell me thankss On Sat, Feb 25, 2012 at 8:25 PM, vivek kumar kumarvivek1...@gmail.comwrote: can u

[algogeeks] Maximize XOR

2012-02-23 Thread sunny agrawal
Given an array of N integers, Find two Numbers with max XOR value. Naive Algorithm is O(N^2), what can be a better approach ? -- Sunny Aggrawal B.Tech. V year,CSI Indian Institute Of Technology,Roorkee -- You received this message because you are subscribed to the Google Groups Algorithm

Re: [algogeeks] Re : Any hints[kth smallest contiguous sum] ?

2012-02-21 Thread sunny agrawal
i dont know if a better solution exists but here is one with complexity O(N*logS)... N = no of elements in array S = max sum of a subarray that is sum of all the elements as all are positive algo goes as follows do a binary search in range 0-S, for each such candidate sum find how many sums are

Re: [algogeeks] Re : Any hints[kth smallest contiguous sum] ?

2012-02-21 Thread sunny agrawal
:16 AM, shady sinv...@gmail.com wrote: didn't get you, how to check for subsequences which doesn't start from the beginning ? can you explain for that same example... should we check for all contiguous subsequences of some particular length? On Tue, Feb 21, 2012 at 11:15 PM, sunny agrawal

Re: [algogeeks] Re : Any hints[kth smallest contiguous sum] ?

2012-02-21 Thread sunny agrawal
... On Wed, Feb 22, 2012 at 12:41 AM, sunny agrawal sunny816.i...@gmail.comwrote: we need to find how many sums are less than candidate Sum chosen in one iteration of binary search in range 0-S To count this, for each i we try to find how many sums ending at i are lesser than candidate sum

Re: [algogeeks] Re : Any hints[kth smallest contiguous sum] ?

2012-02-21 Thread sunny agrawal
?? will it not add to the complexity On Wed, Feb 22, 2012 at 9:59 AM, sunny agrawal sunny816.i...@gmail.comwrote: @atul there are 8 sums less than 7 sum[0 - 0] = 1 sum[1-1] = 2 sum[2 - 2] = 3 sum[3-3] = 4 sum[4-4] = 5 sum[0-1] = 3 sum[0-2] = 6 sum[1-2] = 5 contiguous sum (1,2) , (2,3

Re: [algogeeks] Re : Any hints[kth smallest contiguous sum] ?

2012-02-21 Thread sunny agrawal
are searching each element in given input array from range 0-S for given input = 1,2,3,4,5 S= 15 please clarify . sorry but i am not getting it ... On Wed, Feb 22, 2012 at 10:25 AM, sunny agrawal sunny816.i...@gmail.comwrote: Yes, read my first post On Wed, Feb 22, 2012 at 10

Re: [algogeeks]

2012-01-18 Thread sunny agrawal
in Miller Rabin random value a is lesser than n... i think u r missing it, isn't it ?? On Wed, Jan 18, 2012 at 3:28 PM, Sourabh Singh singhsourab...@gmail.comwrote: @ALL hi everyone m trying to make prime checker based on miller-rabin test . can some1 point out . wat's wrong with the code.

Re: [algogeeks]

2012-01-18 Thread sunny agrawal
That is Okay but for checking a number n to be prime the chosen values of a should be less than n according to algorithm On Wed, Jan 18, 2012 at 3:45 PM, Sourabh Singh singhsourab...@gmail.comwrote: @all output's to above code are just random.. some prime's. found correctly while some are not

Re: [algogeeks] probability of winning with two cards

2012-01-18 Thread sunny agrawal
isn't the answer will be 1/3, without any calculations :) On Thu, Jan 19, 2012 at 7:10 AM, Sundi sundi...@gmail.com wrote: there are 52 cards.. there are 3 players a1,a2,a3 each player is given 2 cards each one of A=2...J=11,Q=12,K=13..a user wins if his sum of cards is greater then the other

Re: [algogeeks] Re: number of form m^n

2011-12-27 Thread sunny agrawal
considering number to be a 32 number(also applicable in the same way to 64 bit) one possibility is let x be the number find log10x for 32 bit numbers max value of n is 64 so for n = 1 to 64 find p = logx10/n take antilog and take nearest integer as m m = 10^p; again find m^n if it is equal to x

Re: [algogeeks] Why moderated?

2011-12-27 Thread sunny agrawal
this is not suddenly, this is happening from the last few months, you might not have noticed. this was done because of a lot of unrelated topics and interview queries. one better thing that can be done is to allow some users for direct posting :) On Tue, Dec 27, 2011 at 3:34 PM, Lucifer

Re: [algogeeks] Re: Suggest Algo for this Question

2011-12-15 Thread sunny agrawal
oops... wanted to write the same but yeah its meaning turns out to be totally different :( anyways very well explained by Lucifier @shashank i think now u will be able to get why there will be only 2k comparisons in the worst case On Thu, Dec 15, 2011 at 10:51 PM, atul anand

Re: [algogeeks] Re: Suggest Algo for this Question

2011-12-14 Thread sunny agrawal
i am Considering given heap as min heap Sol - because heap has property that root will has lower value than all the elements in its left sub tree and right sub tree so in main we will call a function passing root and value k and x if at any time root is greater than x and k 0 that means rest of

Re: [algogeeks] Re: Suggest Algo for this Question

2011-12-14 Thread sunny agrawal
@shashank nope only 2k comparisions k numbers which are greater than x and k which are less than x dont think in terms of root and child On Thu, Dec 15, 2011 at 12:57 PM, WgpShashank shashank7andr...@gmail.comwrote: more clarification , why number of comparisons are 3k , because we are looking

Re: [algogeeks] MYSIS AND DRISHTI-SOFT

2011-12-13 Thread sunny agrawal
@aayush Lots of member are here but that doesn't mean that you should start posting the things which are strictly banned on this group. I hope you will take care next time while posting anything in this group. On Tue, Dec 13, 2011 at 7:40 PM, rahul sharma rahul23111...@gmail.comwrote: On

Re: [algogeeks] MYSIS AND DRISHTI-SOFT

2011-12-13 Thread sunny agrawal
http://groups.google.com/group/interview-street On Tue, Dec 13, 2011 at 10:19 PM, tech coder techcoderonw...@gmail.comwrote: which other group u people are talking about, i would like to join that group. On Tue, Dec 13, 2011 at 9:21 PM, sunny agrawal sunny816.i...@gmail.comwrote: @aayush

Re: [algogeeks] Fill tool

2011-12-04 Thread sunny agrawal
http://www.gild.com/challenges/details/295 No of connected components, use BFS/DFS On Sun, Dec 4, 2011 at 9:12 PM, rajesh ko ko.rajes...@gmail.com wrote: We have given a black and white image and a fill tool that turn an area of black pixel into white pixels. Fill tool works like a 8-way

[algogeeks] Modular Arithmetic and Number Theory

2011-11-26 Thread sunny agrawal
Given a, n, P find the value of a^(nth Fibonacci number) % P where a and P are *not* Co-prime -- Sunny Aggrawal B.Tech. V year,CSI Indian Institute Of Technology,Roorkee -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group,

Re: [algogeeks] Re: Finding the repeated element

2011-11-24 Thread sunny agrawal
i also doubt about the time and space complexity of the problem, i has been asked a number of times with these constraints but never been answered the required, as far as i remember the best solution to this problem that has been discussed so far is using hashing and that too theoretically having

Re: [algogeeks] spoj problem

2011-11-14 Thread sunny agrawal
one solution is use BFS On Mon, Nov 14, 2011 at 8:52 PM, Anshul AGARWAL anshul.agarwa...@gmail.com wrote: i m try to increase current floor c by push up button until it equal or greater than  g  and increase co-responding push p.when my current floor is greater than g.i push down button once

Re: [algogeeks] Re: Facebook Campus Test Question

2011-11-04 Thread sunny agrawal
i/p o/p files are attached in the post, see carefully :-o On Fri, Nov 4, 2011 at 6:23 PM, Dumanshu duman...@gmail.com wrote: plz post a samle input output.. On Nov 4, 10:24 am, sunny agrawal sunny816.i...@gmail.com wrote: What can be a better solution than a Brute Force O(N^2* No of iteration

Re: [algogeeks] Re: Facebook Campus Test Question

2011-11-04 Thread sunny agrawal
No,O(N^2) because all the flips happens simultaneously, it can be reduce to O(2N) if each tile is represented using a single bit On Fri, Nov 4, 2011 at 11:12 PM, Dumanshu duman...@gmail.com wrote: is ur brute force O(1) for space? On Nov 4, 10:24 am, sunny agrawal sunny816.i...@gmail.com wrote

Re: [algogeeks] Re : CODECHEF question

2011-11-02 Thread sunny agrawal
This is a challenge problem and you don't need to find a best solution for each case, optimal solutions are acceptable if they satisfy the problem constraints for this problem the constraint is cuts should be made so that both are able to eat equal no of each available ingredient Examples: Lets

Re: [algogeeks] Re : CODECHEF question

2011-11-02 Thread sunny agrawal
at 7:25 PM, shady sinv...@gmail.com wrote: actually i wanted to know what approach the problem setter is using, since this problem is NP hard so optimal solution is not always possible. On Wed, Nov 2, 2011 at 7:20 PM, sunny agrawal sunny816.i...@gmail.com wrote: This is a challenge problem

Re: [algogeeks] Shuffling Arrays

2011-11-02 Thread sunny agrawal
O(n) is possible using in-shuffle but doing it in-place was the problem in case of in-shuffle we need to know which of the elements have been shuffle so we need O(n) bits of extra space; O(nlgn) is possible using a quick sort like divide and conquer algorithm.i read it somewhere and will

Re: [algogeeks] Re: Unique partition

2011-10-31 Thread sunny agrawal
to make sure all the partitions are unique . The partitions can hav some elements ( K) in common but not the entire elements in a partition (Should be UNIQUE) . On 10/30/11, sunny agrawal sunny816.i...@gmail.com wrote: Is there any condition like all sets should have same

Re: [algogeeks] Re: Unique partition

2011-10-30 Thread sunny agrawal
Is there any condition like all sets should have same no. Of elements On 10/30/11, SAMMM somnath.nit...@gmail.com wrote: But how does it ensure tht the elements been removed wouldnot give the same set again -- You received this message because you are subscribed to the Google Groups

Re: [algogeeks] Search an element in an Infinite array

2011-10-23 Thread sunny agrawal
hint 1: try to find 2 indexes i, j such that a[i] = K = a[j] On Sun, Oct 23, 2011 at 11:23 PM, Ankuj Gupta ankuj2...@gmail.com wrote: Given a sorted array of Infinite size, find an element ‘K’ in the array without using extra memory in O (lgn) time -- You received this message because you

Re: [algogeeks] FACEBOOK ONLINE CODING ROUND

2011-10-22 Thread sunny agrawal
yea i know 1st Approach is much better and is Only O(N^2) for precomputing all the values for nck and then O(k) for finding no of bits set in The Kth number and another loop of O(k) to find the required number i posted 2nd approach in the context to vandana's tree approach of sorting 2^N numbers,

Re: [algogeeks] FACEBOOK ONLINE CODING ROUND

2011-10-19 Thread sunny agrawal
although input is small so a brute force will also do but some optimization can be like 1. first we can find that how many bits will be set in Kth Codewords using the following method no of codewords with N bits set = 1 no of codewords with N-1 bits set = NC1 no of codewords with N-2 bits set =

Re: [algogeeks] FACEBOOK ONLINE CODING ROUND

2011-10-19 Thread sunny agrawal
No need of creating a tree simply take an array of size 2^N in which all a[i] initialized to i now sort the array first depending upon the set bits in the a[i] if set bits are equal then use value this function call to sort function of algorithms will do the required bool cmp(int x, int y){ int

Re: [algogeeks] FACEBOOK ONLINE CODING ROUND

2011-10-19 Thread sunny agrawal
yes u r wrong 11 111 = 110 but sequence will be 11 101 110 On Thu, Oct 20, 2011 at 12:18 AM, tin a.gu...@tin.it wrote: Can you just generate them sorted? 1 is the minimum 1 1 is the next in line 1 2 is the next one 1 N 11 11 1 and so on Am i wrong? Il 19/10/2011 19:33,

Re: [algogeeks] Reconstruct BST from preorder traversal

2011-10-18 Thread sunny agrawal
@sravan yes you are given the sequence of elements in the order in which they are traversed in the given traversal (in/pre/post) a BST can be constructed from its post or pre order only but can not be constructed from only inorder in case of inorder we also need one more traversal -- Sunny

Re: [algogeeks] Please Mention Your Info. Name/Collage/Country and Reason for Joining Algogeek to Minimize Spamming

2011-10-17 Thread sunny agrawal
if(you are a member already) No need to post anything, just ignore the post :) On Mon, Oct 17, 2011 at 5:38 PM, sravanreddy001 sravanreddy...@gmail.comwrote: Wee are already members.. What is expected from us.. -- You received this message because you are subscribed to the Google Groups

Re: [algogeeks] Find THE NUMBERS URGENT PLZZZZZ HELP...........

2011-10-16 Thread sunny agrawal
This Question is from ACM-ICPC 2011 Amritapuri online round which ends today at 1pm so no answers to this post till 1 pm On Sun, Oct 16, 2011 at 11:12 AM, Pradex pradam.prad...@gmail.com wrote: Given two number A and B, count all the number lies between them including both which have no more

Re: [algogeeks] Counting Diagonals in a Polygon

2011-10-15 Thread sunny agrawal
CSI : Computer Science Integrated (5yr) CSE is 4 year On Sat, Oct 15, 2011 at 1:59 PM, hary rathor harry.rat...@gmail.com wrote: sunny : are you in 5th year . i have heard that b-tech is 4 year degree?. -- You received this message because you are subscribed to the Google Groups Algorithm

Re: [algogeeks] Re: Inplace Array Convertion

2011-10-15 Thread sunny agrawal
i have already mentioned the source it is famous shuffling algorithm. u can seach some papers on In-Shuffle and Out-Shuffle the original question in the shuffling is like how many times we need to shuffle the cards after which they will return back to initial sequence. On Sat, Oct 15, 2011

Re: [algogeeks] Re: Inplace Array Convertion

2011-10-15 Thread sunny agrawal
In/Out Shuffle are two shuffling algorithms used for shuffling cards consider a pack of cards (so N = 52) and let cards are numbered from 1, 52 *In Shuffle *: cards are divided into 2 piles (k = 2) (1,2,3.26) (27,28,...52) afer one shuffle operation cards will be like (27,1)(28,2)

Re: [algogeeks] Re: Counting Diagonals in a Polygon

2011-10-15 Thread sunny agrawal
Are you talking about 7th application th wiki of catalan numbers?? i think here case is differentregions are not necessarily triangles.. ??? On Sun, Oct 16, 2011 at 3:43 AM, sravanreddy001 sravanreddy...@gmail.comwrote: This is calalan Number. where n = k+1 very interesting and complex

Re: [algogeeks] Re: Inplace Array Convertion

2011-10-14 Thread sunny agrawal
Its Out Shuffle not In shuffle, although both are similar and you can read both On Fri, Oct 14, 2011 at 8:26 PM, sunny agrawal sunny816.i...@gmail.comwrote: this problem is like Card shuffling problem(search for In-shuffle) i think solution is if indexing is zero based each i will go

Re: [algogeeks] Re: Inplace Array Convertion

2011-10-14 Thread sunny agrawal
this problem is like Card shuffling problem(search for In-shuffle) i think solution is if indexing is zero based each i will go to - k*i % (N-1) k = 3 and N = 3*n -1 n = no of cards in one pile Or No of a's On Fri, Oct 14, 2011 at 7:52 PM, shiva@Algo shiv.jays...@gmail.com wrote:

[algogeeks] Counting Diagonals in a Polygon

2011-10-14 Thread sunny agrawal
Given a n vertex polygon, find in how many ways k non intersecting diagonals can be drawn ? or in How many ways it can be divided into k+1 regions such that no 2 diagonals intersect ? Limits:1 = k = N = 10^9 -- Sunny Aggrawal B.Tech. V year,CSI Indian Institute Of Technology,Roorkee --

Re: [algogeeks] Re: Algo for Search in a 2D Matrix

2011-10-13 Thread sunny agrawal
@Anshu pushing adjacent element will cause duplicate entries in the heap try the following example: 1 2 3 4 5 6 7 2 3 4 5 6 7 8 3 4 5 6 7 8 9 4 5 6 7 8 9 10 so we also need to maintain a data structure that can efficiently tell that which cell has been pushed into the heap already. On Thu, Oct

Re: [algogeeks] Re: Algo for Search in a 2D Matrix

2011-10-13 Thread sunny agrawal
Nopes Still it does not ensure that duplicates will not be there in the priority queue what i mean is you cannot write directly do k times{ data = pop() // let i,j are row and col of data push(i+1,j); push(i,j+1); } you need to add the following checks if((i+1,j) is not in the heap)

Re: [algogeeks] Re: Algo for Search in a 2D Matrix

2011-10-12 Thread sunny agrawal
i dont think k*k submatrix approach works at all what if k =n size of submatrix will be n*n, which is matrix itself heap seems to be a good approach with a coloring scheme that helps in avoiding duplicates in heap ?? On Wed, Oct 12, 2011 at 7:18 PM, vikas vikas.rastogi2...@gmail.com wrote:

Re: [algogeeks] Stone Game

2011-10-12 Thread sunny agrawal
your solution seems to be the right one... testcases may be faulty try submitting here http://www.codechef.com/problems/RESN04/ both the codes On Thu, Oct 13, 2011 at 5:44 AM, Hatta tmd...@gmail.com wrote: being accepted doesn't imply in being correct maybe I'm wrong but given this Test Case

Re: [algogeeks] remove duplicate words from a string

2011-10-11 Thread sunny agrawal
1. how we can store the word each seperated by space into array if we are considering binary tree??? Ans: Each Node will Have an array of Some Const Size limited by Max Word length 2. how we can measure which is smaller than other according to property?? Ans Obviously strcmp(str1,

Re: [algogeeks] Fwd: why we can not swap values using macro?

2011-10-10 Thread sunny agrawal
Macros can Swap Pointers. and That is what the above code is doing. On Mon, Oct 10, 2011 at 5:52 PM, rahul sharma rahul23111...@gmail.comwrote: macros i thnik cant swap pointers..i have doubt for same it is test ur c skil question On Sun, Oct 9, 2011 at 10:08 PM, sunny agrawal sunny816.i

Re: [algogeeks] Give Algo to do this in O(n)

2011-10-10 Thread sunny agrawal
Counting Sort is really a Bad option for this Problem as range is not given yes range can be find in single traversal but think if largest element is 10^9 and size of the array is just about 10^3 Counting Sort = O(10^9) Simple Sorting = O(10^4) Counting sort will perform bad in this case both in

Re: [algogeeks] remove duplicate words from a string

2011-10-10 Thread sunny agrawal
Trie will take too much space.. Balanced Binary tree can be Better ...?? On Tue, Oct 11, 2011 at 12:16 AM, Ankur Garg ankurga...@gmail.com wrote: I think this can be done through tries Any better solution ? On Mon, Oct 10, 2011 at 10:59 PM, sachin goyal monugoya...@gmail.comwrote: remove

Re: [algogeeks] remove duplicate words from a string

2011-10-10 Thread sunny agrawal
@Ankur in Trie at each Node there will be 26 Pointers Stored, and Most of them would be NULL, thats why i think it will waste space, in Balanced Binary Tree i was thinking of storing the Complete Words at a Node. But now i think this is Better - Ternary Search

Re: [algogeeks] what is the use of fflush ?

2011-10-09 Thread sunny agrawal
these are some lines form fflush man pages For output streams, fflush() forces a write of all user-space buffered data for the given output or update stream via the stream's underlying write function. *For input streams, fflush() discards any buffered data that has been fetched from the

Re: [algogeeks] Fwd: why we can not swap values using macro?

2011-10-09 Thread sunny agrawal
because you have not made any call to swap values of x and y I Don't know what you are trying to do here if you want to swap values why are you not calling macro swap(x,y,int) you are making a macro call to swap pointers and you can check that pointer will get swapped. On Sun, Oct 9, 2011 at

Re: [algogeeks] IVY comptech????

2011-10-08 Thread sunny agrawal
@Wasif Yes Now this post is Irrelevant to Algogeeks. @Others Discuss about companies and interview Questions at new formed group Interview Street http://groups.google.com/group/interview-street?hl=en else you will be banned without any warnings On Sat, Oct 8, 2011 at 11:31 AM, raj kumar

Re: [algogeeks] Re: another group?

2011-10-07 Thread sunny agrawal
No, 2 Groups will be better because now a days 95% of the mails are regarding companies, rather than mails part most of the people are joining this group only because of this, because they are told by their friends that here most recent Company interview Questions are posted. 1. Most of the

Re: [algogeeks] can somebody kindly explain what would be the output for the following program

2011-10-06 Thread sunny agrawal
Shiva is right and that is the answer * if you try to change the values in a character array literal, the behavior is undefined* so on some compilers like Turbo C u may get o/p -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this

Re: [algogeeks] Re: rise and fall of power

2011-10-04 Thread sunny agrawal
I also Faced the same problem when i tried this one and when i got to know the mistake it was not very happy :( Use methods powl and log10l instead of pow and log10 and u will get 9 digits of precision :) On Tue, Oct 4, 2011 at 10:21 PM, gaurav yadav gauravyadav1...@gmail.comwrote: n

Re: [algogeeks] suggestion

2011-10-03 Thread sunny agrawal
There is a Website that was initiated after the success of its community Algorithms on ORKUT but if i will post the link here people will start spamming there also :P like shady sad :( People have taken this group from Algorithms Group to X_Interview_Questions_Database_Group. seriously Bad :(

Re: [algogeeks] suggestion

2011-10-03 Thread sunny agrawal
, 2011 at 8:09 PM, sunny agrawal sunny816.i...@gmail.comwrote: There is a Website that was initiated after the success of its community Algorithms on ORKUT but if i will post the link here people will start spamming there also :P like shady sad :( People have taken this group from Algorithms

Re: [algogeeks] Re: rise and fall of power

2011-10-03 Thread sunny agrawal
For Last K Gene has posted the right Approach. For First K Hint : Logarithms log(N^N) = NlgN On Tue, Oct 4, 2011 at 1:14 AM, Gene gene.ress...@gmail.com wrote: I have not done this, so I'm not sure. But there are some tricks. You can first break up the computation to exploit repeated

Re: [algogeeks] Segment Tree Optimization

2011-09-27 Thread sunny agrawal
implement segment tree with lazy propagation :) On Tue, Sep 27, 2011 at 1:19 PM, Aamir Khan ak4u2...@gmail.com wrote: I am trying to solve http://www.spoj.pl/problems/LITE/ using segment tree. Here's the code but i am getting TLE. Can somebody help me to optimize the code ? #includecstdio

Re: [algogeeks] Sorting:-

2011-09-24 Thread sunny agrawal
I think it can be proved by contradiction that there does not exist a better sorting algorithm than O(mnlogmn) because if there is one then that means we can sort an array better than O(nlgn) by assuming an array as 2D array of k rows and Ceiling(n/k) columns. and if the elements belongs to some

Re: [algogeeks] Re: sqrt function...

2011-09-24 Thread sunny agrawal
let x be the number initialize ans to some value like x or x/2 now repeatedly do the following ans = (ans + x/ans)/2 each time you perform this operation you will move closer to the sqrt value and depending upon the precision required stop On Sat, Sep 24, 2011 at 11:17 PM, siddharth

Re: [algogeeks] Building a max heap takes O(n) time irrespective of the array being sorted / unsorted.

2011-09-15 Thread sunny agrawal
Read CLRS On Thu, Sep 15, 2011 at 11:51 PM, saurabh agrawal saurabh...@gmail.comwrote: Building a max heap takes O(n) time irrespective of the array being sorted / unsorted. Can someone prove that. I already know that Heap can be constucted in o(n*log(n)) time. -- You received this

Re: [algogeeks] MS

2011-08-02 Thread sunny agrawal
is it like that all the square should be of same size ? On Tue, Aug 2, 2011 at 11:54 AM, Kamakshii Aggarwal kamakshi...@gmail.comwrote: Given a rectangle with known width and height, design an algorithm to fill the rectangle using n squares(n is integer given) and make sure in the result the

Re: [algogeeks] Sort IT

2011-08-02 Thread sunny agrawal
Radix sort is one of the solution. because this Question is in the section Radix sort in CLRS. :) On Tue, Aug 2, 2011 at 11:10 AM, Ravinder Kumar ravinde...@gmail.comwrote: I have little thought on this : divide the whole array by n and store their remainder also in an array now number in

Re: [algogeeks] Novell - Algorithms round

2011-07-29 Thread sunny agrawal
can be found in lg(n) using Matrix Exponential method | 1 1 |^n | 1 0 | [f(i) f(i-1)]* |1 1| = [f(i+1) f(i)] |1 0| On Fri, Jul 29, 2011 at 12:05 PM, Reynald reynaldsus...@gmail.com wrote: Write and implement an algorithm to find the nth Fibonacci number, optimized for space

Re: [algogeeks] longest common string!!!!!

2011-07-29 Thread sunny agrawal
String need to be contiguous or not ? On Fri, Jul 29, 2011 at 12:23 PM, AMAN AGARWAL mnnit.a...@gmail.com wrote: please give the solution for this problem... Give an algorithm to find the Longest common string of strings with lengths m,n respectively and also analyse their time

Re: [algogeeks] Novell - Puzzle

2011-07-29 Thread sunny agrawal
No ans will be sum of all final fib. number is the no of she-calves of age 0 second last is number is she-calves of age 1 ...and so on so answer is sum of all On Fri, Jul 29, 2011 at 1:09 PM, Reynald Suz reynaldsus...@gmail.comwrote: Shivnarayan, why should we add all Fibonacci number? Since

Re: [algogeeks] [offtopic] Something to share for those preparing for Amazon Campus Interviews!

2011-07-29 Thread sunny agrawal
http://www.topcoder.com/tc?module=Staticd1=tutorialsd2=alg_index On Fri, Jul 29, 2011 at 1:31 PM, Rahul Menon menonrahul1...@gmail.comwrote: @RAHUL SINGHAL Sorry to bother you! Unfortunately I cant find any such links in topcoder. Can you just share a link here! -- You received this

Re: [algogeeks] DS representation.

2011-07-29 Thread sunny agrawal
Array that that stores A,B,C,D,E. it looks like u r on some telephonic interview :P On Fri, Jul 29, 2011 at 3:06 PM, Puneet Gautam puneet.nsi...@gmail.comwrote: Hi, pls tell me which data structure has following representation:: A+Bx+Cx(^2)+Dx(^3)+...+Nx(^n-1).?? reply

Re: [algogeeks] DS representation.

2011-07-29 Thread sunny agrawal
, sunny agrawal sunny816.i...@gmail.comwrote: Array that that stores A,B,C,D,E. it looks like u r on some telephonic interview :P On Fri, Jul 29, 2011 at 3:06 PM, Puneet Gautam puneet.nsi...@gmail.comwrote: Hi, pls tell me which data structure has following representation

Re: Re : [algogeeks] Re: size of self referential structure

2011-07-28 Thread sunny agrawal
Okay. I was a bit wrongactually the thing is that The exact number of bytes allocated for various C data types depends on *both the machine and the compiler.** *so it may be the that the compiler u are using is 32 bit.. one thing that u can try out is that on ubuntu install 64 bit

Re: [algogeeks] puzzle

2011-07-28 Thread sunny agrawal
@Hemlatha this is one of the possible solution the Question is to find Number of such solutions On Thu, Jul 28, 2011 at 12:09 PM, Hemalatha hemalatha.amru...@googlemail.com wrote: Give all the primary and secondary diagonal Elements a value -1 and the rest as 1s. -1 1 1 1 1 -1 1 -1 1 1

Re: [algogeeks] puzzle

2011-07-28 Thread sunny agrawal
to get to the same answer? On Thu, Jul 28, 2011 at 12:11 PM, sunny agrawal sunny816.i...@gmail.comwrote: @Hemlatha this is one of the possible solution the Question is to find Number of such solutions On Thu, Jul 28, 2011 at 12:09 PM, Hemalatha hemalatha.amru...@googlemail.com wrote: Give

Re: [algogeeks] Re: Blocked/Unrolled linked list with no duplicates and sorted

2011-07-28 Thread sunny agrawal
Nice Problem :) i think taking care of duplicates is very simple...but main point is sorted insertion that has to very carefully done there are many cases that need to be taken care of 1. if the value to be inserted is between two nodes and both nodes are fullthen a new node will be

Re: [algogeeks] Least Common Ancestor

2011-07-28 Thread sunny agrawal
Solution in the link is for BST, not for BT On Thu, Jul 28, 2011 at 3:15 PM, kavitha nk kavithan...@gmail.com wrote: http://geeksforgeeks.org/?p=1029 follow the link fa one more soln.. //BE COOL// kavi -- You received this message because you are subscribed to the Google Groups

Re: [algogeeks] Re: Facebook Interview question at NIT Warangal

2011-07-28 Thread sunny agrawal
as Number of possible sets are nCk i think complexity of the best solution will be O(k*nCk) (as in siddarths solution) siddharth's solution will fail in case k 64 a simple recursive program is possible i think in same complexity. On Thu, Jul 28, 2011 at 6:40 PM, Tushar Bindal

Re: [algogeeks] Re: Facebook Intern F2F Interview

2011-07-28 Thread sunny agrawal
Okay... i was reading % as Modulus operator :( did u gave the solution Nikhil posted , i think that should be the answer. On Thu, Jul 28, 2011 at 9:10 PM, KK kunalkapadi...@gmail.com wrote: @Nikhil: ya true but i dont know wht else was he expecting. @sunny and Muthu: like suppose u pass

Re: [algogeeks] Find the number of solutions.

2011-07-28 Thread sunny agrawal
2 solutions - {1,2} On Fri, Jul 29, 2011 at 11:10 AM, vaibhav_iiit honeys...@gmail.com wrote: how many values of x are possible in the following equation. x^(x^x) - (x^x)^x = 0 where a^b =power(a,b). -- You received this message because you are subscribed to the Google Groups Algorithm

Re: [algogeeks] Re: binary search tree question!!!!

2011-07-28 Thread sunny agrawal
Node* x = TREE_MINIMUM(root); for(int i = 0; i k-1; i++){ x = TREE-SUCCESSOR(x); } return x; On Fri, Jul 29, 2011 at 11:08 AM, noobcoder ase.as...@gmail.com wrote: Iterative inorder of tree till you have traversed k elements. Last element is the kth smallest. On Jul 29, 10:10 am, AMAN

Re: [algogeeks] Re: Amazon Question

2011-07-27 Thread sunny agrawal
@shiva viknesh this is a different Question... @saurabh how is nlgn possible, total no of possible substrings are n^2 this is the O(n^2) solutionOn Wed, Jul 27, 2011 at 8:09 AM, saurabh singh for(int l = 0; l len; l++){                 for(int i = 0; i len-l; i++){                        

Re: [algogeeks] Re: MS interview:

2011-07-27 Thread sunny agrawal
There is a Book: Advance Programming in Unix Environment by Richard Stevens in Chapter 2 i think there is a code that does the job of directory Listing for given Directory this is the code - for directory listing *#include dirent.h int main(int argc, char *argv[]) { DIR *dp; struct

Re: [algogeeks] Re: Amazon Question

2011-07-27 Thread sunny agrawal
suffix tree is constructed, needs to traverse in dfs order appending the node found on the way. total complexity would be O(construction of suffix tree ) + O(traverse time). surender On Wed, Jul 27, 2011 at 12:00 PM, sunny agrawal sunny816.i...@gmail.comwrote: @shiva viknesh

Re: [algogeeks] MS interview:

2011-07-27 Thread sunny agrawal
yes Preorder recursion will be good for displaying in User Friendly way... On Wed, Jul 27, 2011 at 12:49 PM, Anand Saha anands...@gmail.com wrote: Implement Preorder Traversal in the File system tree. -- On Wed, Jul 27, 2011 at 12:06 PM, geek forgeek geekhori...@gmail.comwrote: Function

Re: [algogeeks] Re: Amazon Question

2011-07-27 Thread sunny agrawal
, 2011 at 12:46 PM, sunny agrawal sunny816.i...@gmail.comwrote: But still Printing O(N^2) substrings will take O(N^2) time isn't it ? On Wed, Jul 27, 2011 at 12:39 PM, surender sanke surend...@gmail.comwrote: @sunny consider *uncompressed* suffix tree, even with distinct elements maximum

Re: Re : [algogeeks] Re: size of self referential structure

2011-07-27 Thread sunny agrawal
computer architecture !!! 64 bit machine has word size of 8 bytes so pointers are of 8 bytes you never got size as 8 byte because u might be working on a 32 bit machine !! On Wed, Jul 27, 2011 at 2:18 PM, hary rathor harry.rat...@gmail.com wrote: @sunny : what you means by machine dependent

Re: [algogeeks] how to calculate the complexity

2011-07-27 Thread sunny agrawal
Master theorem can be used when we know the recurrence relation. You can read the 2nd Chapter of CLRS.. On Thu, Jul 28, 2011 at 1:16 AM, rajeev bharshetty rajeevr...@gmail.comwrote: Masters Theorem http://en.wikipedia.org/wiki/Master_theorem On Thu, Jul 28, 2011 at 1:14 AM, NITIN

Re: [algogeeks] problem tree minimum sum in binary

2011-07-26 Thread sunny agrawal
It dont look like a tree its more like a triangle and if the values are stored in the matrix can be simply done using a Dynamic Programming bottom up approach On Tue, Jul 26, 2011 at 2:27 PM, Charlotte Swazki charlotteswa...@yahoo.frwrote: Hi, I want to implement an algorithm to determine

Re: [algogeeks] size of self referential structure

2011-07-26 Thread sunny agrawal
4+20+4 = 28 bytes it should be i think On Tue, Jul 26, 2011 at 6:10 PM, Puneet Gautam puneet.nsi...@gmail.comwrote: #includestdio.h #includestddef.h struct node{ int a; char *b[5]; struct node *link; }; main() { int a; a=sizeof(struct node);

Re: Re : [algogeeks] Re: size of self referential structure

2011-07-26 Thread sunny agrawal
yes on a 64 bit machine ans will be 4+5*8+8 = 52 bytes pointers take 8 byte on 64 bit machine On Tue, Jul 26, 2011 at 8:00 PM, vaibhav shukla vaibhav200...@gmail.comwrote: will there be any difference in size on 32 machine and on 64 bit machine ? how and what ? On Tue, Jul 26, 2011 at 7:58

Re: [algogeeks] Re: SPOJ

2011-07-25 Thread sunny agrawal
First Thing is that i will support Shady's point. Please Post the question and the idea u r trying to solve the questionnot the complete Code so that algorithm can be discussed here and then u can identify your mistake. because this happens most of the time when someone posts code,

Re: [algogeeks] Poison River

2011-07-25 Thread sunny agrawal
For N=3, if the people are named A,B, and C: A wears the shoes and carries B across the river. is there any condition that one can carry only one with him? On Tue, Jul 26, 2011 at 10:02 AM, Someshwar Chandrasekaran somseka...@gmail.com wrote: On Tue, Jul 26, 2011 at 3:19 AM, Don

Re: [algogeeks] output plzz

2011-07-24 Thread sunny agrawal
char five[7] - string of length 7 charlie - 7 length string declare it as char[8] u will get expected output On Sun, Jul 24, 2011 at 12:15 PM, Anurag atri anu.anurag@gmail.comwrote: yup , on ideone it indeed is giving the output you suggested .. On Sun, Jul 24, 2011 at 12:10 PM,

Re: [algogeeks] output plzz

2011-07-24 Thread sunny agrawal
'\0'... isn't it ? On Sun, Jul 24, 2011 at 12:25 PM, sunny agrawal sunny816.i...@gmail.comwrote: char five[7] - string of length 7 charlie - 7 length string declare it as char[8] u will get expected output On Sun, Jul 24, 2011 at 12:15 PM, Anurag atri anu.anurag@gmail.comwrote

Re: [algogeeks] Coding..........

2011-07-22 Thread sunny agrawal
@atul Your algo is not stable http://www.ideone.com/DrV5J BTW what are u trying to do instead of posting a code please prefer posting a simple algorithm in text coding part is very easy once the correct algorithm is found On Fri, Jul 22, 2011 at 11:43 AM, Puneet Gautam

Re: [algogeeks] Coding..........

2011-07-22 Thread sunny agrawal
left to it are even and right odd.Its an implementation of quick sort as discussed earlier.Its o(n) no doubt but its not stable. On Fri, Jul 22, 2011 at 11:51 AM, sunny agrawal sunny816.i...@gmail.comwrote: @atul Your algo is not stable http://www.ideone.com/DrV5J BTW what are u trying

  1   2   3   4   >