[algogeeks] A Tough Bit Manipulation

2011-07-10 Thread anurag
You are given two integers n and k k signifies number of set bits i.e. if k = 3 then output should have 3 set bits. Output should be the nth smallest number having k set bits for example k=1 and n=3 output should be 4 (0100) -- You received this message because you are subscribed to the

[algogeeks] bitmap

2011-07-10 Thread Akshata Sharma
write a C program to create a bitmap of any size as determined by user. Say user says 64k bitmap, then create 64k long bitmap. Have set and unset methods -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

Re: [algogeeks] A Tough Bit Manipulation

2011-07-10 Thread ankit sambyal
Here is my approach : int main() { int a=1,k=1,n=3; while(k1) { k--; a=(a1) | 1; } while(n1) { a=a1; n--; } printf(%d,a); return 0; } On Sat, Jul 9, 2011 at 11:14 PM, anurag anurag19aggar...@gmail.com wrote: You are given two

Re: [algogeeks] puzzle

2011-07-10 Thread udit sharma
6,24,60,120,210,336.. (N^3 - N) where N=2,3,4 -- Regards UDIT DU- MCA -- 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

Re: [algogeeks] puzzle

2011-07-10 Thread vaibhav shukla
or it can be 2^3-2=6 3^3-3=24 4^3-4=60 5^3-5=120 6^3-6=210... On Sun, Jul 10, 2011 at 9:35 AM, Abhishek Soni ab.abhish...@gmail.comwrote: 6,24,60,120,210,336.. Explaination: 0 + (6*1) = 6, 6 + (6*3) = 24, 24+ (6*6) = 60, 60+ (6*10) = 120, 120 + (6*15) = 210, 210 + (6*21) = 336,...

Re: [algogeeks] Number Series

2011-07-10 Thread Puneet Ginoria
A[n] = n*(n+1)*(n+2) 1*2*3 = 6 2*3*4 = 24 3*4*5 = 60 4*5*6 = 120 so next numbers are 210,336 -- 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,

Re: [algogeeks] A Tough Bit Manipulation

2011-07-10 Thread Sunny T
Hi, this is the code i came up with.. #includestdio.h #includeconio.h int doMyWork(int k,int n); int main() { int k,n,nth_number; printf(\nEnter k and n\n); scanf(%d%d,k,n); nth_number=doMyWork(k,n); printf(\nThe nth number is %d\n,nth_number); getch();

Re: [algogeeks] GOOGLE Q1

2011-07-10 Thread Navneet Gupta
Try this 1. Find the min and max in O(n) time. 2. For A.P. = mix to max/N , we find max possible subsequence. For example 1,2,3,0,4,7,19,6,8,10,24.(could be more but trying to show the approach) We see min = 1 and max = 8 hence we need to try for diff = 1 to 8/size(arr) In this case, we

Re: [algogeeks] GOOGLE Q1

2011-07-10 Thread Navneet Gupta
Sorry typo below On Sun, Jul 10, 2011 at 12:49 PM, Navneet Gupta navneetn...@gmail.comwrote: Try this 1. Find the min and max in O(n) time. 2. For A.P. = mix to max/N , we find max possible subsequence. For example 1,2,3,0,4,7,19,6,8,10,24.(could be more but trying to show the

Re: [algogeeks] Re: find sol!!

2011-07-10 Thread Puneet Ginoria
n*n! = (n+1)! - n! -- 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

Re: [algogeeks] A Tough Bit Manipulation

2011-07-10 Thread Sunny T
sorry ankit... ur solution works only for.. k=1 and n=3... try for k=2 and n=6.. then the output should be 12... similarly for k=3 n=1.. the output should be...7... so plz correct ur code.. On Sun, Jul 10, 2011 at 12:38 PM, ankit sambyal ankitsamb...@gmail.comwrote: Here is my approach : int

Re: [algogeeks] Re: find sol!!

2011-07-10 Thread Anantha Krishnan
For, [ n*n!+(n+1)*(n+1)!+.+(n+m)*(n+m)! ] / (n+m+1)! = 1 - n!/(n+m+1)! On Sun, Jul 10, 2011 at 1:00 PM, Puneet Ginoria punnu.gino...@gmail.comwrote: n*n! = (n+1)! - n! -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to

[algogeeks] Re: GOOGLE Q

2011-07-10 Thread Dumanshu
how about this? take pointer p1 set to end of array A and pointer p2 set to end of array B. while(you get n values) { print A(p1),B(p2) now if( A(p1-1)+B(p2)A(p1)+B(p2-1) ) then print A(p1-1),B(p2) followed by print A(p1),B(p2-1) decrement p2 and p1 both } m i missing something? On Jul 9,

Re: [algogeeks] A Tough Bit Manipulation

2011-07-10 Thread Anurag Aggarwal
Sunny Don.t you think your method is very slow as you are checking every number that for number of set bits and if it is a equal to desired than you are decreasing n i.e. required number. Even if when n=1 and k=32 your solution will start with 0 and go up to 2^31 but the answer could be found in

Re: [algogeeks] A Tough Bit Manipulation

2011-07-10 Thread sunny agrawal
Smallest Number with k bits set will be the number with least significant k bits set ie. K=3 000111 K=4 000 and to find nth we can use thishttp://groups.google.com/group/algogeeks/msg/2b64c4f96fa3598e TC: O(n) On Sun, Jul 10, 2011 at 2:13 PM, Sunny T sunny.1...@gmail.com wrote:

Re: [algogeeks] A Tough Bit Manipulation

2011-07-10 Thread Sunny T
thanks sunny On Sun, Jul 10, 2011 at 2:19 PM, sunny agrawal sunny816.i...@gmail.comwrote: Smallest Number with k bits set will be the number with least significant k bits set ie. K=3 000111 K=4 000 and to find nth we can use

[algogeeks] C DEBUGGING

2011-07-10 Thread radha krishnan
#includestdio.h void main(){ signed x; unsigned y; x = 10 +- 10u + 10u +- 10; y = x; if(x==y) printf(%d %d,x,y); else if(x!=y) printf(%u %u,x,y); } OUTPUT? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks

Re: [algogeeks] C DEBUGGING

2011-07-10 Thread rajeev bharshetty
X and Y are equal and both are zeroes So the output is 0 0 On Sun, Jul 10, 2011 at 3:03 PM, radha krishnan radhakrishnance...@gmail.com wrote: #includestdio.h void main(){ signed x; unsigned y; x = 10 +- 10u + 10u +- 10; y = x; if(x==y) printf(%d %d,x,y); else

[algogeeks] Re: A Tough Bit Manipulation

2011-07-10 Thread Dave
@Anurag: See http://groups.google.com/group/algogeeks/msg/d90353c759125384?hl=en. Dave On Jul 10, 1:14 am, anurag anurag19aggar...@gmail.com wrote: You are given two integers n and k k signifies number of set bits i.e. if k = 3 then output should have 3 set bits. Output should be the nth

Re: [algogeeks] Re: O(n) Time is the problem. ..

2011-07-10 Thread atul purohit
For the code, here u go http://ideone.com/js1yV On Wed, Jun 29, 2011 at 10:49 AM, Dave dave_and_da...@juno.com wrote: @Sanket: You are wrong. Let T(n) be the time to solve the problem of size n. Then T(n) satisfies a recurrence T(n) = n + T(n/2). That is because after you have done n reads,

Re: [algogeeks] GOOGLE Q1

2011-07-10 Thread Yogesh Yadav
array a[] stores numbers for(i=1;in;i++) { diff[i-1]=a[i]-a[i-1]; } maxcount=1; tempcount=1; for(j=1;jn-1;j++) { if(diff[j]==diff[j-1]) tempcount++; else { if(tempcountmaxcount) maxcount=tempcount; tempcount=1; } } On Sat, Jul 9, 2011

Re: [algogeeks] macro

2011-07-10 Thread Yogesh Yadav
Thats wonderful para :) On Sat, Jul 9, 2011 at 10:50 AM, John Hayes agressiveha...@gmail.comwrote: refer KRit's clearly mentioned in it On Sun, Jul 10, 2011 at 12:12 AM, parag khanna khanna.para...@gmail.comwrote: no text substitution occurs if the identifier is within the quotes

Re: [algogeeks] macro

2011-07-10 Thread Yogesh Yadav
Thats wonderful parag :) On Sun, Jul 10, 2011 at 4:56 AM, Yogesh Yadav medu...@gmail.com wrote: Thats wonderful para :) On Sat, Jul 9, 2011 at 10:50 AM, John Hayes agressiveha...@gmail.comwrote: refer KRit's clearly mentioned in it On Sun, Jul 10, 2011 at 12:12 AM, parag khanna

Re: [algogeeks] macro

2011-07-10 Thread JAIDEV YADAV
good one Parag ... On Sun, Jul 10, 2011 at 12:20 AM, John Hayes agressiveha...@gmail.comwrote: refer KRit's clearly mentioned in it On Sun, Jul 10, 2011 at 12:12 AM, parag khanna khanna.para...@gmail.comwrote: no text substitution occurs if the identifier is within the quotes --

Re: [algogeeks] GOOGLE Q1

2011-07-10 Thread raj singh
@yogesh- can u explain with an example pls? -- 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.

Re: [algogeeks] GOOGLE Q1

2011-07-10 Thread Manmeet Singh
Can think of a O(n^2) solution On Sun, Jul 10, 2011 at 6:53 PM, raj singh ankurkaku...@gmail.com wrote: @yogesh- can u explain with an example pls? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

Re: [algogeeks] GOOGLE Q1

2011-07-10 Thread Yogesh Yadav
@raj : array a[]= 2,3,5,6,7,8,10,12 diff[]= 1,2,1,1,1,2,2 maxcount=tempcount=1 // because am not takin in consideration of 0th index value of diff[] now in for loop for j=1 check diff[j]==diff[j-1] //not equal so check tempcountmaxcount or not //its also not so maxcount remains same

Re: [algogeeks] GOOGLE Q1

2011-07-10 Thread Yogesh Yadav
i thinks mine is just O(n) On Sun, Jul 10, 2011 at 5:31 AM, Yogesh Yadav medu...@gmail.com wrote: @raj : array a[]= 2,3,5,6,7,8,10,12 diff[]= 1,2,1,1,1,2,2 maxcount=tempcount=1 // because am not takin in consideration of 0th index value of diff[] now in for loop for j=1 check

Re: [algogeeks] GOOGLE Q1

2011-07-10 Thread sunny agrawal
@Yogesh your solution will give maximum Contiguous AP only it will fail for the array A[] = {1,2,3,4,5,6,8,10,12,14} your algo will give output that there is an Longest AP of 6 elements which is wrong checkout this http://theory.cs.uiuc.edu/%7Ejeffe/pubs/pdf/arith.pdf for an O(n^2) algorithm On

Re: [algogeeks] GOOGLE Q1

2011-07-10 Thread Yogesh Yadav
@sunny: my algo will give 5 as answer and i guess its right... if am wrong plz explain where and why my logic is wrong On Sun, Jul 10, 2011 at 5:37 AM, sunny agrawal sunny816.i...@gmail.comwrote: @Yogesh your solution will give maximum Contiguous AP only it will fail for the array A[] =

Re: [algogeeks] GOOGLE Q1

2011-07-10 Thread Yogesh Yadav
@sunny: my algo will give 5 as answer and i guess its right... if am wrong plz explain where and why my logic is wrong On Sun, Jul 10, 2011 at 5:37 AM, sunny agrawal sunny816.i...@gmail.comwrote: @Yogesh your solution will give maximum Contiguous AP only it will fail for the array A[] =

Re: [algogeeks] GOOGLE Q1

2011-07-10 Thread Yogesh Yadav
@sunny: my algo will give 6 as answer and i guess its right... if am wrong plz explain where and why my logic is wrong On Sun, Jul 10, 2011 at 5:37 AM, sunny agrawal sunny816.i...@gmail.comwrote: @Yogesh your solution will give maximum Contiguous AP only it will fail for the array A[] =

Re: [algogeeks] GOOGLE Q1

2011-07-10 Thread sunny agrawal
Longest AP for that Example is of 7 elements 2,4,6,8,10,12,14 now see your mistake ... as i have already told you that u r looking for only contiguous AP's and that won't work On Sun, Jul 10, 2011 at 7:18 PM, Yogesh Yadav medu...@gmail.com wrote: @sunny: my algo will give 6 as

Re: [algogeeks] GOOGLE Q1

2011-07-10 Thread Yogesh Yadav
@sunny : thanks ..i got it... On Sun, Jul 10, 2011 at 5:55 AM, sunny agrawal sunny816.i...@gmail.comwrote: Longest AP for that Example is of 7 elements 2,4,6,8,10,12,14 now see your mistake ... as i have already told you that u r looking for only contiguous AP's and that won't

Re: [algogeeks] GOOGLE Q1

2011-07-10 Thread Yogesh Yadav
yeah then it will be possible in O(n^2) On Sun, Jul 10, 2011 at 5:57 AM, Yogesh Yadav medu...@gmail.com wrote: @sunny : thanks ..i got it... On Sun, Jul 10, 2011 at 5:55 AM, sunny agrawal sunny816.i...@gmail.comwrote: Longest AP for that Example is of 7 elements 2,4,6,8,10,12,14

Re: [algogeeks] GOOGLE Q1

2011-07-10 Thread JAIDEV YADAV
try Matrix search... On Sun, Jul 10, 2011 at 7:34 PM, Yogesh Yadav medu...@gmail.com wrote: yeah then it will be possible in O(n^2) On Sun, Jul 10, 2011 at 5:57 AM, Yogesh Yadav medu...@gmail.com wrote: @sunny : thanks ..i got it... On Sun, Jul 10, 2011 at 5:55 AM, sunny agrawal

Re: [algogeeks] GOOGLE Q1

2011-07-10 Thread Yogesh Yadav
Step 1: first make a diff[][] Step 2: search the diff in matrix Complexity will be O(n^2) On Sun, Jul 10, 2011 at 6:24 AM, JAIDEV YADAV jaid...@gmail.com wrote: try Matrix search... On Sun, Jul 10, 2011 at 7:34 PM, Yogesh Yadav medu...@gmail.com wrote: yeah then it will be possible in

[algogeeks] Largest BST subtree in Binary Tree

2011-07-10 Thread Decipher
Write a code in C/C++ to find the largest BST sub-tree in a binary tree . Eg:- 10 / \ 5 15

Re: [algogeeks] puzzle

2011-07-10 Thread aayush jain
thanx -- 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

[algogeeks] MS

2011-07-10 Thread Akshata Sharma
Given a rectangle with known width and height, design an algorithms to fill the rectangle using n squares(n is integer, also given) and make sure in the result the wasting area is minimized. Length of square doesn't have to be integer. I.e, given width=3,height=2,n=5, one solution is that

Re: [algogeeks] macro

2011-07-10 Thread Akshata Sharma
Thanks :) On Sun, Jul 10, 2011 at 6:26 PM, JAIDEV YADAV jaid...@gmail.com wrote: good one Parag ... On Sun, Jul 10, 2011 at 12:20 AM, John Hayes agressiveha...@gmail.comwrote: refer KRit's clearly mentioned in it On Sun, Jul 10, 2011 at 12:12 AM, parag khanna

Re: [algogeeks] macro

2011-07-10 Thread parag khanna
jaidev aur yogesh swaad na lo saalo ... padha tha maine ye kabhi isliye bta diya -- 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

Re: [algogeeks] macro

2011-07-10 Thread shady
awesome parag... i hope you will keep contributing to the group ~~~ this thread ends here On Sun, Jul 10, 2011 at 9:24 PM, parag khanna khanna.para...@gmail.comwrote: jaidev aur yogesh swaad na lo saalo ... padha tha maine ye kabhi isliye bta diya -- You

Re: [algogeeks] MS

2011-07-10 Thread vaibhav shukla
wastage can be minimized if side of square is maximized. so largest size of square would be = H.C.F of width and height . and also number of squares needed will be = (width*height)/side^2 . On Sun, Jul 10, 2011 at 9:11 PM, Akshata Sharma akshatasharm...@gmail.comwrote: Given a rectangle with

Re: [algogeeks] MS

2011-07-10 Thread vaibhav agarwal
@vaibhav this fails as n will be provided in the question. On Sun, Jul 10, 2011 at 9:56 PM, vaibhav shukla vaibhav200...@gmail.comwrote: wastage can be minimized if side of square is maximized. so largest size of square would be = H.C.F of width and height . and also number of squares needed

Re: [algogeeks] MS

2011-07-10 Thread vaibhav shukla
with n=(height*width)/side^2 .. u can calculate the side if n would be given. On Sun, Jul 10, 2011 at 10:37 PM, vaibhav agarwal vibhu.bitspil...@gmail.com wrote: @vaibhav this fails as n will be provided in the question. On Sun, Jul 10, 2011 at 9:56 PM, vaibhav shukla

Re: [algogeeks] Largest BST subtree in Binary Tree

2011-07-10 Thread sunny agrawal
Define Largest: Total no of nodes in sub-tree or Height of sub-tree On Sun, Jul 10, 2011 at 8:50 PM, Decipher ankurseth...@gmail.com wrote: Write a code in C/C++ to find the largest BST sub-tree in a binary tree . Eg:- 10

[algogeeks] Precedence of operators

2011-07-10 Thread rShetty
#includestdio.h int main() { int i=0,j=1,k=1,z=0; z = j || k i ; printf(%d,z); return 0; } The output is 1 for the above program . But according to associativity of logical operators , the evaluation should be from left to right , But is it taking from right to left ? What is the exact

Re: [algogeeks] Largest BST subtree in Binary Tree

2011-07-10 Thread Decipher
no of nodes -- 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/-/MuNISw2QkYIJ. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe

Re: [algogeeks] Precedence of operators

2011-07-10 Thread vaibhav shukla
associativity comes into play when operators are of same precedence. On Sun, Jul 10, 2011 at 11:08 PM, vaibhav shukla vaibhav200...@gmail.comwrote: has higher precedence than || the expression is evaluated as z=j || ( k i ); hence the output i.e 1 ;) On Sun, Jul 10, 2011 at 11:06 PM,

Re: [algogeeks] GOOGLE Q1

2011-07-10 Thread DK
@Sunny: Can you please explain that paper in simple english please?? Thoda zyaada complex ho gaya hai. O(N^3) DP is simple and understandable. -- DK http://twitter.com/divyekapoor http://www.divye.in -- You received this message because you are subscribed to the Google Groups Algorithm Geeks

Re: [algogeeks] Largest BST subtree in Binary Tree

2011-07-10 Thread sunny agrawal
can be done using some modification in postorder traversal call to left subtree will return that if left subtree is a BST of not call to right subtree will return that if right subtree is a BST of not if both subtrees are BST's check for curr and return its status 2 additional pass by ref.

[algogeeks] Re: Largest BST subtree in Binary Tree

2011-07-10 Thread vigneshr
I donno if my idea is efficient. I'll do a breath-first traversal and check IsBST on each node(modified to also get the count of nodes) So at each level, the largest BST is kept track of and end of the level, the largest subtree can be returned. If there is no BST at that level go down one level

[algogeeks] Re: Precedence of operators

2011-07-10 Thread rShetty
Got it Thanks . On Jul 10, 10:40 pm, vaibhav shukla vaibhav200...@gmail.com wrote: associativity comes into play when operators are of same precedence. On Sun, Jul 10, 2011 at 11:08 PM, vaibhav shukla vaibhav200...@gmail.comwrote: has higher precedence than ||  the

Re: [algogeeks] GOOGLE Q1

2011-07-10 Thread DK
Never mind. Figured it out, though in possibly different from the paper. Principle of optimality to the rescue! :) O(n^2) DP equations: LAP[i, j] = Longest AP in range [i,j] of the sequence LAP[0, j] = max{LAP[0, k] (for all k in range [0, j-1]) extended with a[j],1 (the element a[j] itself)}

[algogeeks] An interview querstion

2011-07-10 Thread TIRU REDDY
Today I attended an interview. Just wanna share a good Q. Rows are represented using alphabets. Example: first row - 'A' second row: 'B' . . . 26th row : 'Z' 27th: 'AA' . . Now given a number, we need to find the corresponding alphabet representation. Say Given 78 Answer should be BZ Given 26

[algogeeks] c++ doubt

2011-07-10 Thread himanshu kansal
class a { int x; public: a() { } a(int i){x=i;coutin a xendl;} a(a obj){coutin copy cons of aendl;} }; a obj1=14; //error no matching call to a::a(a) why. and just adding a const in the constructor saves me from error...but how --

Re: [algogeeks] c++ doubt

2011-07-10 Thread rahul
use a(int arg) { x = arg; } ur call will work...:) On Sun, Jul 10, 2011 at 11:46 PM, himanshu kansal himanshukansal...@gmail.com wrote: class a { int x; public: a() { } a(int i){x=i;coutin a xendl;} a(a obj){coutin copy cons of aendl;}

Re: [algogeeks] c++ doubt

2011-07-10 Thread rahul
my badadd const in copy construcori think...that compiler expect... On Sun, Jul 10, 2011 at 11:48 PM, rahul rahulr...@gmail.com wrote: use a(int arg) { x = arg; } ur call will work...:) On Sun, Jul 10, 2011 at 11:46 PM, himanshu kansal himanshukansal...@gmail.com wrote:

Re: [algogeeks] c++ doubt

2011-07-10 Thread himanshu kansal
a obj3(obj1);but this statement works fine.so it means it is calling copy constt. perfectly... On Sun, Jul 10, 2011 at 11:49 PM, rahul rahulr...@gmail.com wrote: my badadd const in copy construcori think...that compiler expect... On Sun, Jul 10, 2011 at 11:48 PM, rahul

Re: [algogeeks] c++ doubt

2011-07-10 Thread Sandeep Jain
The reason is... that when u write a obj1=14; it is same as writing a obj1 = a(14); So first a temporary object is created using the constructor a(int i) And this temporary object is passed in the copy constructor. BUT since it is temp object it must be referred by a const alias. Regards,

Re: [algogeeks] c++ doubt

2011-07-10 Thread himanshu kansal
thanku sir...sir 1 more thngcn u gv a link or some pdf for studying virtual inheritance elaborating the vptr mechanism more clearly... On Sun, Jul 10, 2011 at 11:56 PM, Sandeep Jain sandeep6...@gmail.comwrote: The reason is... that when u write a obj1=14; it is same as writing a obj1 =

Re: [algogeeks] c++ doubt

2011-07-10 Thread Sandeep Jain
http://www.parashift.com/c++-faq-lite/virtual-functions.html Its one of my favorite sites... :) Regards, Sandeep Jain On Mon, Jul 11, 2011 at 12:02 AM, himanshu kansal himanshukansal...@gmail.com wrote: thanku sir...sir 1 more thngcn u gv a link or some pdf for studying virtual

Re: [algogeeks] GOOGLE Q1

2011-07-10 Thread sunny agrawal
@Divye Sir I just came to know this is not a general Algorithm This works only for sorted Array this is Some description about the algo in paper this algo uses the property of a AP that for every 3 consecutive elements of an AP(a1,a2,a3) a1+a3 = 2*a2 *L[i j] stores the maximum length of an

[algogeeks] Re: GOOGLE Q

2011-07-10 Thread DK
Largest value is of course A(n) + B(n). Second largest value is either A(n) + B(n-1) or A(n-1) + B(n). Select the largest among both and continue down that array. Maintain 2 pairs: Pair 1: Hold first value constant, go down the second array. Pair 2: Hold 2nd value const. and go down the first

[algogeeks] Re: An interview querstion

2011-07-10 Thread DK
The answer is a simple encoding of the number in base 26. There is no need to calculate anything else. -- DK http://twitter.com/divyekapoor http://www.divye.in -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the

[algogeeks] C OUTPUT HELP

2011-07-10 Thread nicks
Someone please help me in understanding the following output - Problem *1.* #includestdio.h #ifdef getchar //this expression is evaluated to zero.why is so happening ??getchar is defined as macro in stdio.h.i mean else part shouldn't be executed which is happening #undef

Re: [algogeeks] Re: An interview querstion

2011-07-10 Thread TIRU REDDY
Agreed. On 11 Jul 2011 00:38, DK divyekap...@gmail.com wrote: The answer is a simple encoding of the number in base 26. There is no need to calculate anything else. -- DK http://twitter.com/divyekapoor http://www.divye.in -- You received this message because you are subscribed to the Google

Re: [algogeeks] C OUTPUT HELP

2011-07-10 Thread Sandeep Jain
*Problem 2:* I think u are using TurboC, since you have written void main() Secondly, printf (since based on macros) scans through the format string. And the it process arguments one by one depending on the format specifiers given in this string. I've observed that whenever there is a mismatch

Re: [algogeeks] Re: GOOGLE Q

2011-07-10 Thread sunny agrawal
@DK sir I was just assuming n^2 values as the 2D matrix..not creating although i am using a O(n^2) space that keep track of which cell is already in heap and need not be inserted againso initially all the need to be initialized..that will make it O(n^2) Now I have a Doubt - Is

Re: [algogeeks] C OUTPUT HELP

2011-07-10 Thread Kamakshii Aggarwal
for the first question...it will take #ifdef getchar to be '1' only when it is defined as a MACRO in your program..if u dont define macro it will not take it into consideration even if it is defined in header file. On Mon, Jul 11, 2011 at 12:38 AM, nicks crazy.logic.k...@gmail.com wrote:

[algogeeks] PeP

2011-07-10 Thread swetha rahul
Hi, Has anyone attended PeP (Particiaptory exam for palcement).Can u give me some guidance..?? -- 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

[algogeeks] Re: PeP

2011-07-10 Thread swetha rahul
Sry it is Participatory exam for placement. On Mon, Jul 11, 2011 at 1:16 AM, swetha rahul swetharahu...@gmail.comwrote: Hi, Has anyone attended PeP (Particiaptory exam for palcement).Can u give me some guidance..?? -- You received this message because you are subscribed to the

Re: [algogeeks] C OUTPUT HELP

2011-07-10 Thread Kamakshii Aggarwal
probelm 5:It must be giving runtime error not segmentation fault coz it is an infinite recursion On Mon, Jul 11, 2011 at 1:09 AM, Kamakshii Aggarwal kamakshi...@gmail.comwrote: for the first question...it will take #ifdef getchar to be '1' only when it is defined as a MACRO in your

Re: [algogeeks] GOOGLE Q1

2011-07-10 Thread DK
@Sunny: We don't need ever to calculate generic L[i,j] as we can do this problem by simply calculating L[0,j] which reduces the dimensionality of the problem. Here's a modified solution on the same lines as the one originally proposed. Version 2 uses hash table. Complexity is O(N^2) (if hash

[algogeeks] Yahoo Question

2011-07-10 Thread aanchal goyal
These are the various ways to swap 2 variables a) Using temporary Variable b) Usnig some Arithmentic operation c) Using bitwise XOR operation Explain which operation is better and Why? What if we need to swap -ive as well as floating point numbers also. -- Regards,* Aanchal Goyal*. -- You

Re: [algogeeks] Re: GOOGLE Q

2011-07-10 Thread DK
Well, technically, if you have to initialize O(N^2) space with *any* value, then your algo is O(N^2). In practice, memset is pretty fast, however, that just reduces the constant factor - it will not (eventually) beat an O(N) algo. BTW, my solution is O(N). -- DK http://twitter.com/divyekapoor

Re: [algogeeks] Yahoo Question

2011-07-10 Thread vaibhav shukla
On Mon, Jul 11, 2011 at 1:51 AM, aanchal goyal goyal.aanch...@gmail.comwrote: These are the various ways to swap 2 variables a) Using temporary Variable always inefficient. using extra memory. b) Usnig some Arithmentic operation works for all numbers even floating points

[algogeeks] Re: BIT MANIPULATION

2011-07-10 Thread DK
@Dave: Thanks for the link. Just a point of discussion - this kind of code would probably never pass code-review (or would be heavily documented with references and warnings that say HANDS OFF ;) ) -- DK http://twitter.com/divyekapoor http://www.divye.in -- You received this message because

[algogeeks] Re: Yahoo Question

2011-07-10 Thread Dave
@Vaibhav: Your method b doesn't work for floating point numbers because they have finite precision. E.g.,as an extreme example, try it on a = 1 and b = 1d-25. When you form a+b, the result is 1, not 1 + 1d-25. Then 1 - 1d-25 gives 1 (which is correct), and 1 - 1 = 0. The latter should be 1d-25, so

[algogeeks] Re: BIT MANIPULATION

2011-07-10 Thread Dave
@DK. Yes. But you must admit that it is a bit-twiddler's delight! Dave On Jul 10, 3:58 pm, DK divyekap...@gmail.com wrote: @Dave: Thanks for the link. Just a point of discussion - this kind of code would probably never pass code-review (or would be heavily documented with references and

Re: [algogeeks] Re: Yahoo Question

2011-07-10 Thread Piyush Sinha
using a temp variable is considered to be the best option.. On 7/11/11, Dave dave_and_da...@juno.com wrote: @Vaibhav: Your method b doesn't work for floating point numbers because they have finite precision. E.g.,as an extreme example, try it on a = 1 and b = 1d-25. When you form a+b, the

[algogeeks] Re: remove duplicate chars in a string without using extra memory

2011-07-10 Thread Yaw
Quite new to java what do you think of mine? import java.util.*; public class RemoveDuplicates { public static void main(String[] args){ while(true) { System.out.println(Enter String); Scanner input = new Scanner(System.in); String str =

Re: [algogeeks] C OUTPUT HELP

2011-07-10 Thread nicks
@sandeep,kamakshiithanks both...your replies were really helpfuli understood my fault in 3,4,5...they are clea now..but i am still stuck with problem 1 and 2 @sandeepwhat if i am using turbo C...though i am using gcc on terminal in my linux system. moreover acc. t KR printf

Re: [algogeeks] C OUTPUT HELP

2011-07-10 Thread Sandeep Jain
TurboC has many flaws, one of the simplest examples would be char *p; scanf(%s, p); In gcc/g++ this will surely lead to segmentation fault as memory has not been allocated. Whereas in TC it will execute fine in most of the cases. Infact this will crash when your code is really large. As for

Re: [algogeeks] Re: Largest BST subtree in Binary Tree

2011-07-10 Thread Harshal
@vigneshr, no your method is not that efficient since you will be calling IsBST for a node many times in the process. It will be O(nlogn) assuming complete Binary Tree, Sunny's algorithm runs in O(n) time. On Sun, Jul 10, 2011 at 11:25 PM, vigneshr rvignesh1...@gmail.com wrote: I donno if my

Re: [algogeeks] Re: GOOGLE Q

2011-07-10 Thread sunny agrawal
A = 0 1 4 5 9 11 20 B = 0 2 3 6 8 13 15 (20, 15) (20, 15) - (20,15) (20,13) (11,15) - (20,13) (20,8) (11,15) - (20,8) (20,6) (11,15) - assume (20,6) (20,3) (11,15) - (11,15) (20,3) (9,15)- On Mon, Jul 11, 2011 at 1:06 AM, sunny agrawal sunny816.i...@gmail.comwrote:

Re: [algogeeks] Re: GOOGLE Q

2011-07-10 Thread sunny agrawal
A = 0, 1, 4, 5, 9, 11, 20 B = 0, 2, 3, 6, 8, 13, 15 (20, 15) (20, 15) - (20,15) (20,13) (11,15) - (20,13) (20,8) (11,15) - (20,8) (20,6) (11,15) - assume (20,6) (20,3) (11,15) - (11,15) (20,3) (9,15)- (9,15) (20,3) (5,15)- (20,3) .problem (11,13) has higher