Re: [algogeeks] doubt in lca

2012-03-17 Thread sunny agrawal
C itself On Sat, Mar 17, 2012 at 8:39 PM, rahul sharma wrote: > 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 Google Groups > "

Re: [algogeeks] Array problem

2012-03-12 Thread sunny agrawal
RB for the given algo may screw it. > > > On Mon, Mar 12, 2012 at 11:00 PM, sunny agrawal > wrote: > >> @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 a

Re: [algogeeks] Array problem

2012-03-12 Thread sunny agrawal
@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 wrote: > @payal: > TC will not alwayz be O(nlogn) bcozz we are not sure if the tree formed is > balanced. > so worst would be O(n^2) >

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 wrote: > 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 wrote: > >> can u provide me some question >> >> >> On Thu, Feb 2

[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 Geek

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

2012-02-21 Thread sunny agrawal
s that you 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 > wrote: > >>

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

2012-02-21 Thread sunny agrawal
iven input ?? will it not add > to the complexity > > > On Wed, Feb 22, 2012 at 9:59 AM, sunny agrawal wrote: > >> @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 >&

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

2012-02-21 Thread sunny agrawal
if i am wrong... > > > On Wed, Feb 22, 2012 at 12:41 AM, sunny agrawal > wrote: > >> 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

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

2012-02-21 Thread sunny agrawal
less than 7 On Wed, Feb 22, 2012 at 12:16 AM, shady 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? >

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 sm

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 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 two players sum

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 wrote: > @all output's to above code are just random.. some prime's. found > correctly while some are not > > why i used certain

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 wrote: > @ALL hi everyone m trying to make prime checker based on miller-rabin > test . can some1 point out . wat's wrong with the code. thank's alot > in advance.

Re: [algogeeks] fork command confusion

2012-01-17 Thread sunny agrawal
that is because output is buffered. when printf("hello") is executed, "hello" goes to the output buffer and it waits for a new line after fork there will be two instances of the program and both will output "helloworld" try putting a new line in the first printf statement, you will get expected out

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 r

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 wrot

Re: [algogeeks] spoj problem:Street parade

2011-12-20 Thread sunny agrawal
@ Anshul it will be nice if you post your logic rather than Code, and also Code posting without logic and comments is not allowed in the group. i don't know who approved this post but take care of this from next time. On Tue, Dec 20, 2011 at 7:41 PM, Anshul AGARWAL wrote: > problem:street parade:

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 wrote: > @Lucifer :

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 wrote: > more clarification , why number of comparisons are 3k , because we are > looking for only those nodes whi

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] 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 wrote: > 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 wrote: > >> @aayush >> Lots

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 wrote: > > > On Tue, Dec 13, 2011 at 3:2

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 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 > floodfill tool.So it w

[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 T

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 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 and increase "p " b

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 wrote: > is ur brute force O(1) for space? > > On Nov 4, 10:24 am, sunny agrawal wrote: >> What can be a

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 wrote: > plz post a samle input output.. > > On Nov 4, 10:24 am, sunny agrawal wrote: >> What can be a better solution than a Brute Force O(N^2* No of iteration) >> &g

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 : CODECHEF question

2011-11-02 Thread sunny agrawal
at 7:25 PM, shady 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 > wrote: >> >> This is a challenge problem >

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 ta

Re: [algogeeks] Re: Unique partition

2011-10-31 Thread sunny agrawal
; >> >} >> > } >> > >> > you can improve internal for loop by using map : if freq[a[i]] becomes >> 0 >> > delete the node from array. >> > On Sun, Oct 30, 2011 at 10:35 PM, SAMM >> wrote: >> > >> >> No t

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 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 > "Algorithm Geeks" gr

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 wrote: > Given a sorted array of Infinite size, find an element ‘K’ in the > array without using extra memory in O (lgn) time > > -- > You received this message because you are subscribed

Re: [algogeeks] FACEBOOK ONLINE CODING ROUND

2011-10-21 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
yes u r wrong 11 11<<1 = 110 but sequence will be 11 101 110 On Thu, Oct 20, 2011 at 12:18 AM, tin 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

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
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 = NC

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 Aggr

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 wrote: > Wee are already members.. What is expected from us.. > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group

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

2011-10-15 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 wrote: > Given two number A and B, count all the number lies between them > including both which have no more than two digit in common

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 wrote: > This is calalan Number. where n = k+1 > > very interesting and complex probs... > > http://e

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: 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 at

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 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 Geeks" group. >

[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: 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 wrote: > @Gaurav how will u do for >

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 wrote: > 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 ->

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) push(i+1,j)

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

2011-10-12 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 1

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 both the codes On Thu, Oct 13, 2011 at 5:44 AM, Hatta wrote: > being accepted doesn't imply in being correct > maybe I'm wrong but given this Test Case I think BOB

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 wrote: > @Shiva, not necessarily in upp

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, st

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 Tries

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 wrote: > I think this can be done through tries > > Any better solution ? > > On Mon, Oct 10, 2011 at 10:59 PM, sachin goyal wrote: > >> remove duplicate words from a string with

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 t

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 wrote: > 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 wrote: > &

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 9:20

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 underly

Re: [algogeeks] IVY comptech????

2011-10-07 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 else you will be banned without any warnings On Sat, Oct 8, 2011 at 11:31 AM, raj kumar wrote:

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 Interv

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 g

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 wrote: > nk > > 34

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 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 squaring. > Rather than n-1

Re: [algogeeks] suggestion

2011-10-03 Thread sunny agrawal
Oct 3, 2011 at 8:09 PM, sunny agrawal wrote: > 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 f

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 :( O

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 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 ? > > #include > #include > > struct

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 srivastava

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] 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 wrote: > Building a max heap takes O(n) time irrespective of the array being sorted > / unsorted. > Can someone prove that. I already know that Heap can be constucted in > o(n*log(n)) time. > > -- > You received this message because

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 wrote: > I have little thought on this : > > divide the whole array by n and store their remainder also in an array > now number in original array are

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 wrote: > 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 wasting area is min

Re: [algogeeks] DS representation.

2011-07-29 Thread sunny agrawal
t; I thought there might be a predefined ds for such representation... > > What is an SLL..? > > On 7/29/11, rajeev bharshetty wrote: > > You can use a Hash map which maps the coefficients of the equation and > their > > exponents. > > Is this feasible ?? > > >

Re: [algogeeks] do while problem

2011-07-29 Thread sunny agrawal
when you enter two numbers and press Enter new line character is passed as character c Change your code as Follows: printf("do you want to continue(y/n):"); getchar(); scanf("%c",&c); On Fri, Jul 29, 2011 at 4:31 PM, nullpointer wrote: > #include > void add(); > void subtract(); > int main() >

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 wrote: > Hi, > > pls tell me which data structure has following representation:: > > A+Bx+Cx(^2)+Dx(^3)+...+Nx(^n-1).?? > > reply asap...!! > > -- >

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=Static&d1=tutorials&d2=alg_index On Fri, Jul 29, 2011 at 1:31 PM, Rahul Menon wrote: > @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 message because you a

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 wrote: > Shivnarayan, why should we add all Fibonacci number? Since 1+1 both digits > repres

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

2011-07-28 Thread sunny agrawal
String need to be contiguous or not ? On Fri, Jul 29, 2011 at 12:23 PM, AMAN AGARWAL 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 complexities > > -- > AMAN

Re: [algogeeks] Novell - Algorithms round

2011-07-28 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 wrote: > Write and implement an algorithm to find the nth Fibonacci number, > optimized for space and time. > > -- > You

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 wrote: > Iterative inorder of tree till you have traversed k elements. Last > element is the kth smallest. > > On Jul 29, 10:10 am, AMAN AGARWAL wrote: > >

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 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 Geeks" g

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 wrote: > @Nikhil: ya true but i dont know wht else was he expecting. > > @sunny and Muthu: like suppose u pass 20 then func should re

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 wrote: > though th

Re: [algogeeks] Facebook Intern F2F Interview

2011-07-28 Thread sunny agrawal
@KK can you plz explain the return type of function a bit more what do you mean by It should return true x% of times n false otherwise what is n here (is it "and" or some number) .. On Thu, Jul 28, 2011 at 4:46 PM, Muthu Raj wrote: > Please elaborate upon the question a little more :)

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 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 > "Algorithm Geeks" gr

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 insert

Re: [algogeeks] puzzle

2011-07-28 Thread sunny agrawal
ple way to get to the same answer? On Thu, Jul 28, 2011 at 12:11 PM, sunny agrawal wrote: > @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...@google

Re: [algogeeks] puzzle

2011-07-27 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

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

2011-07-27 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 code

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 wrote: > Masters Theorem > http://en.wikipedia.org/wiki/Master_theorem > > > On Thu, Jul 28, 2011 at 1:14 AM, NITIN SHARMA wrote: > >

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 wrote: > @sunny : what you means by machine dependent means 64 bit: you means

Re: [algogeeks] Re: Amazon Question

2011-07-27 Thread sunny agrawal
bc* > prints *c* > > surender > > > On Wed, Jul 27, 2011 at 12:46 PM, sunny agrawal > wrote: > >> 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 wrote: >> >>> &g

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 wrote: > Implement Preorder Traversal in the File system tree. > > -- > > > > On Wed, Jul 27, 2011 at 12:06 PM, geek forgeek wrote: > >> Function to display the directory struc

Re: [algogeeks] Re: Amazon Question

2011-07-27 Thread sunny agrawal
gt; once 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 > wrote: &

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 int main(int argc, char *argv[]) { DIR *dp; struct dirent *dirp;

Re: [algogeeks] Re: Lucky numbers

2011-07-26 Thread sunny agrawal
As we start every time from the beginning, so 1 will never be deleted hence in last it will remain there I faced the same Question in MS Written where question was..Given a number find if the number is Lucky or not? that can be easily found because every time we remove the numbers at even indexes

Re: [algogeeks] Re: Amazon Question

2011-07-26 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: 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 wrote: > 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 PM, kavitha nk wrote

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 wrote: > #include > #include > struct node{ > int a; > char *b[5]; > struct node *link; > }; > main() > { > int a; > a=sizeof(struct node); > printf("%d",a); > getchar

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 wrote: > Hi, > > I want to implement an algorithm to determine the shortest path from t

  1   2   3   4   >