Re: [algogeeks] pgm2

2011-09-13 Thread ankita aggarwal
there is no need to calculate the length of the string as only one odd occurrence is allowed,implying the length of the string will also be odd in that case. and if all occurrences are even,implicitly the length would be even. On 9/13/11, sukran dhawan sukrandha...@gmail.com wrote: find the

Re: [algogeeks] C Puzzle

2011-09-13 Thread Kapil Gupta
it should be like c=a than will give no error. On Tue, Sep 13, 2011 at 9:45 AM, bharatkumar bagana bagana.bharatku...@gmail.com wrote: *a = 20; gives seg fault .. because 'a' has not been allocated memory space... On Mon, Sep 12, 2011 at 2:28 PM, Kunal Patil kp101...@gmail.com wrote:

Re: [algogeeks] MICROSOFT WRITTEN QUESTION-2010

2011-09-13 Thread jai gupta
@bharat: When each step of nishant's algo is O(n) how can it sum up to O(nlogn)??? On Tue, Sep 13, 2011 at 9:18 AM, bharatkumar bagana bagana.bharatku...@gmail.com wrote: @nishant : your algo takes O(nlogn) time with higher constant behind this. can't we write better than this ? @sairam

Re: [algogeeks] MICROSOFT WRITTEN QUESTION-2010

2011-09-13 Thread bharatkumar bagana
@jai gupta : merge sort for 2 sorted arrays --O(nlogn) right? On Tue, Sep 13, 2011 at 1:03 PM, jai gupta sayhelloto...@gmail.com wrote: @bharat: When each step of nishant's algo is O(n) how can it sum up to O(nlogn)??? On Tue, Sep 13, 2011 at 9:18 AM, bharatkumar bagana

Re: [algogeeks] MICROSOFT WRITTEN QUESTION-2010

2011-09-13 Thread Vicki Wen
@ bharat: merging 2 sorted arrays is O(n) On Tue, Sep 13, 2011 at 12:42 AM, bharatkumar bagana bagana.bharatku...@gmail.com wrote: @jai gupta : merge sort for 2 sorted arrays --O(nlogn) right? On Tue, Sep 13, 2011 at 1:03 PM, jai gupta sayhelloto...@gmail.comwrote: @bharat: When each

Re: [algogeeks] String

2011-09-13 Thread Anshul Khandelwal
U can take command line argument in main main(int argc,char * argv[ ]) { for(i=argc-1,i=0;i--) printf(%s ,argv[i]); } On Tue, Sep 13, 2011 at 12:05 AM, hary rathor harry.rat...@gmail.comwrote: kapil : in your solution you are required extra O(n+n*sizeOf(int *)) both memory to create a link

[algogeeks] Re: unique no. problem

2011-09-13 Thread Gene
Here's a way: The base 2 xor operator has an obvious extension to base 3 such that for all integers N, N ^ N ^ N = 0, just like the normal xor has N ^ N = 0. This base 3 operator a^b just adds corresponding digit pairs of a and b mod 3 to get the digits of the result. So the algorithm is to

Re: [algogeeks] String

2011-09-13 Thread shady
search archives, already done On Tue, Sep 13, 2011 at 1:39 PM, Anshul Khandelwal anshul.dans1...@gmail.com wrote: U can take command line argument in main main(int argc,char * argv[ ]) { for(i=argc-1,i=0;i--) printf(%s ,argv[i]); } On Tue, Sep 13, 2011 at 12:05 AM, hary rathor

Re: [algogeeks] help

2011-09-13 Thread shady
RS Agrawal is an author. Title of the book would have been more precise. On Tue, Sep 13, 2011 at 10:45 AM, sanil gandhi... sanil.gandh...@gmail.comwrote: R.S.Agrawal -- Regards, Sanil Gandhi. 9423851845. -- You received this message because you are subscribed to the Google

[algogeeks] Re: help

2011-09-13 Thread DIVIJ WADHAWAN
Try material of MBA coaching institutes wiz Career Launcher,Time etc On Sep 12, 6:11 pm, wellwisher p9047551...@gmail.com wrote: please suggest me some good aptitude books -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this

Re: [algogeeks] pgm3

2011-09-13 Thread Yogesh Yadav
//don't know this is completely correct or not 1.find sum of elements of both arrays a[] and b[]...from 0 to n-1 2.check whichever is smaller sum_a or sum_b...say sum_a is smaller 3.generate a random number i=random(sum_a)... generates random number between o to (sum_a)-1 //random

Re: [algogeeks] Re: unique no. problem

2011-09-13 Thread sagar sindwani
http://stackoverflow.com/questions/3963409/interview-question-dealing-with-m-occurrences-among-n On Tue, Sep 13, 2011 at 1:48 PM, Gene gene.ress...@gmail.com wrote: Here's a way: The base 2 xor operator has an obvious extension to base 3 such that for all integers N, N ^ N ^ N = 0, just

Re: [algogeeks] Re: unique no. problem

2011-09-13 Thread kARTHIK R
Nice one sagar. Karthik R, RD Engineer, Tejas Networks. On Tue, Sep 13, 2011 at 2:36 PM, sagar sindwani sindwani.sa...@gmail.comwrote: http://stackoverflow.com/questions/3963409/interview-question-dealing-with-m-occurrences-among-n On Tue, Sep 13, 2011 at 1:48 PM, Gene

Re: [algogeeks] String

2011-09-13 Thread guna sekaran
please write a code any one On Tue, Sep 13, 2011 at 2:06 PM, shady sinv...@gmail.com wrote: search archives, already done On Tue, Sep 13, 2011 at 1:39 PM, Anshul Khandelwal anshul.dans1...@gmail.com wrote: U can take command line argument in main main(int argc,char * argv[ ]) {

Re: [algogeeks] String

2011-09-13 Thread kARTHIK R
Something like this. stackchar * S; void function(char *s) { char *ptr=s; while(*ptr++ !=' ') {} *ptr = '\0'; S.push(s); // Will push the string till NULL into the stack function(ptr+1); } // Pop from stack to get words

Re: [algogeeks] String

2011-09-13 Thread sagar sindwani
Awesome solution karthik R On Tue, Sep 13, 2011 at 3:02 PM, kARTHIK R k4rth...@gmail.com wrote: Something like this. stackchar * S; void function(char *s) { char *ptr=s; while(*ptr++ !=' ') {} *ptr = '\0'; S.push(s); // Will push

Re: [algogeeks] String

2011-09-13 Thread shashi kant
hey Karthik phodd diya yaar tune .tejas waale cha gaye On Tue, Sep 13, 2011 at 3:02 PM, kARTHIK R k4rth...@gmail.com wrote: Something like this. stackchar * S; void function(char *s) { char *ptr=s; while(*ptr++ !=' ') {} *ptr = '\0';

Re: [algogeeks] String

2011-09-13 Thread Sanjay Rajpal
#includestdio.h #includestdlib.h #includestring.h void Swap(char *a,char *b) { char c; c=*a; *a=*b; *b=c; } int main() { char input[100]; printf(Enter a string (Length 100) : ); scanf(%[^\n],input); //Reversing the string int len=strlen(input); int i=0,j=len-1; while(i j) {

Re: [algogeeks] MS written

2011-09-13 Thread Kanika Narang
If the application is deployed as a web application, then the server response time depends on internet speed and therefore have to account that exception.Anything more? On Tue, Sep 13, 2011 at 10:37 AM, bharatkumar bagana bagana.bharatku...@gmail.com wrote: ya from the 2nd quest, we can

Re: [algogeeks] String

2011-09-13 Thread Kapil Gupta
+1 Karthik On Tue, Sep 13, 2011 at 3:02 PM, kARTHIK R k4rth...@gmail.com wrote: Something like this. stackchar * S; void function(char *s) { char *ptr=s; while(*ptr++ !=' ') {} *ptr = '\0'; S.push(s); // Will push the string till

Re: [algogeeks] Re: help

2011-09-13 Thread mithun bs
Quantitative Aptitude by R.S.Agarwal. On Tue, Sep 13, 2011 at 2:12 PM, DIVIJ WADHAWAN divij...@gmail.com wrote: Try material of MBA coaching institutes wiz Career Launcher,Time etc On Sep 12, 6:11 pm, wellwisher p9047551...@gmail.com wrote: please suggest me some good aptitude books

[algogeeks] Scanf in an infinite loop

2011-09-13 Thread Avinash Dharan
#include stdio.h void main() { while(1) { int opt; scanf(%d,opt); printf(%d\n,opt); } } when i execute this program, if i give a character instead of an integer, it goes into an infinite loop. why is it so? -- You received this message because you are

[algogeeks] Finding connection b/w 2 profiles

2011-09-13 Thread JITESH KUMAR
Suppose you are visiting someone's profile in fb or linkedin, you get to know how you are connected to that person. e.g. Suppose you are visiting C's profile. you get a suggestion like you are connected to him via A-B-C. Tell efficient way to solve this problem( apart from Brute Force). --

Re: [algogeeks] Finding connection b/w 2 profiles

2011-09-13 Thread veera reddy
finding the shortest path between A and C nodes , gives required solution . We can use dijkstra's algorithm to find the shortest path .. On Tue, Sep 13, 2011 at 5:43 PM, JITESH KUMAR jkhas...@gmail.com wrote: Suppose you are visiting someone's profile in fb or linkedin, you get to know how

Re: [algogeeks] C Trick

2011-09-13 Thread saurabh agrawal
Priyanka.. ideally u should not use any function calls to solve this question.. because they internally might use conditional operators or if else.. OR u can give your own definition of abs() function With Regards Saurabh On Wed, Aug 24, 2011 at 11:06 PM, priyanka raju priyark...@gmail.comwrote:

Re: [algogeeks] Finding connection b/w 2 profiles

2011-09-13 Thread JITESH KUMAR
I guess you have misunderstood the problem. We are not concerning about the length of path. We just have to find the path. But in the efficient way. suppose first person is having 500 friends and each of them again is having 500 friends each. Applying BFS will take a lot of space. On Tue, Sep 13,

Re: [algogeeks] Finding connection b/w 2 profiles

2011-09-13 Thread Karan Thakral
bfs On Tue, Sep 13, 2011 at 5:59 PM, JITESH KUMAR jkhas...@gmail.com wrote: I guess you have misunderstood the problem. We are not concerning about the length of path. We just have to find the path. But in the efficient way. suppose first person is having 500 friends and each of them again

Re: [algogeeks] Finding connection b/w 2 profiles

2011-09-13 Thread MeHdi KaZemI
I think applying BFS is good, what's the problem with space? Isn't the depth gonna be at most 2 ? If we suppose the depth is gonna be at most 2, then suppose we want the path from A to C, A has 500 friends and each of his/her friends has 500 friends too, so we have to visit 500*500 nodes to find

[algogeeks] Microsoft Written Subjective Test

2011-09-13 Thread ronit douglas
Hey guys! I wanted to know what questions microsoft has asked in subjective test of the apti? Normally they have 3 different Qs for 3 profiles namely, s/w developer, tester program manager. Hence, it is typical to find 3 Qs like Write a prog for this... Find the o/p of this... Design the system

[algogeeks] samsung engineering lab interview..

2011-09-13 Thread sourabh jain
if any one who have selected for samsung ,please tell me the type of ques.that can be ask by tech interview.. -- Regards SOURABH KUMAR JAIN MCA, NIT RAIPUR MOB.-+919993878717 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this

Re: [algogeeks] samsung engineering lab interview..

2011-09-13 Thread abhinav gupta
they'll ask question on mostly on c programming and O.S. on thread, process concepts On Tue, Sep 13, 2011 at 6:46 PM, sourabh jain sourabhjain...@gmail.comwrote: if any one who have selected for samsung ,please tell me the type of ques.that can be ask by tech interview.. --

[algogeeks] Re: MICROSOFT in VJTI mumbai

2011-09-13 Thread akanksha rathore
In our college (MNIT Jaipur) MicrosoftIT visited on 8th sept.Their interview was mainly based on software engineering and dbms and summer training project.DBMS sql queries and normalization.in software engineering different life cycle models.some situation based puzzles were also asked but they

[algogeeks] Re: Returning 0 with probability p and 1 with probability 1-p

2011-09-13 Thread Dave
@Jitesh: I did. But here is another try: We construct a fraction p' by using the random number generator to select the bits. So the number is 0.f()f()f()f()..., where each f() is a zero- or a one-bit. We compare p to p'. If, no matter what remaining bits we choose for p' we will have p p', then

Re: [algogeeks] SAMSUNG INDIA SOFTWARE OPERATIONS PVT LTD (SISO)

2011-09-13 Thread navneet kumar
which college?? On Tue, Sep 13, 2011 at 7:41 PM, abhinav gupta abhinav@gmail.comwrote: any one plzz tell me what they will ask in written test... and which type of question...basically?? -- You received this message because you are subscribed to the Google Groups Algorithm

Re: [algogeeks] MS test cases type Questions

2011-09-13 Thread Akash Mukherjee
+1 On Mon, Sep 12, 2011 at 3:42 PM, pg@manit gpt.pa...@gmail.com wrote: Cud some 1 suggest me 4m how 2 practise test cases type of questions which usually cum in MS written Papers? thanx..in advance Regards, PAYAL GUPTA -- You received this message because you are subscribed to the

Re: [algogeeks] SAMSUNG INDIA SOFTWARE OPERATIONS PVT LTD (SISO)

2011-09-13 Thread abhinav gupta
NIT ALLAHABAD... On Tue, Sep 13, 2011 at 7:45 PM, navneet kumar kumarnavneet@gmail.comwrote: which college?? On Tue, Sep 13, 2011 at 7:41 PM, abhinav gupta abhinav@gmail.comwrote: any one plzz tell me what they will ask in written test... and which type of

[algogeeks] Re: Returning 0 with probability p and 1 with probability 1-p

2011-09-13 Thread Don
@Dave: Very nice. Don On Sep 12, 10:51 pm, Dave dave_and_da...@juno.com wrote: Here's another way, using a rejection technique on the bits of the mantissa of p. Each iteration of the do-while loop exposes another high-order bit of p, and the do-while loop iterates as long as the random bits

Re: [algogeeks] String

2011-09-13 Thread guna sekaran
Thanks to all On Tue, Sep 13, 2011 at 4:35 PM, Kapil Gupta kapilkeda...@gmail.com wrote: +1 Karthik On Tue, Sep 13, 2011 at 3:02 PM, kARTHIK R k4rth...@gmail.com wrote: Something like this. stackchar * S; void function(char *s) {    char *ptr=s;    while(*ptr++ !=' ')

[algogeeks] Re: Thoughtworks and Tejas network

2011-09-13 Thread Brijesh
yes..please anyone post questions asked in thoughtworks interview -- 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/-/Rpd5yw77HbMJ. To post to this group, send

Re: [algogeeks] Re: Returning 0 with probability p and 1 with probability 1-p

2011-09-13 Thread JITESH KUMAR
@Dave: Thanks a lot.. :) On Tue, Sep 13, 2011 at 7:48 PM, Don dondod...@gmail.com wrote: @Dave: Very nice. Don On Sep 12, 10:51 pm, Dave dave_and_da...@juno.com wrote: Here's another way, using a rejection technique on the bits of the mantissa of p. Each iteration of the do-while loop

Re: [algogeeks] ASP problem

2011-09-13 Thread himanshu kansal
plz reply.its imp. and urgent On Mon, Sep 12, 2011 at 8:47 PM, himanshu kansal himanshukansal...@gmail.com wrote: here is my full code.. the error is. Microsoft OLE DB Provider for SQL Server: Cannot open database pubs requested by the login. The login failed in the

Re: [algogeeks] Finding connection b/w 2 profiles

2011-09-13 Thread JITESH KUMAR
Depth is not mentioned, it can be any. This question was asked from me in the telephonic interview of DE Shaw. The interviewer told me reduce space complexity. On Tue, Sep 13, 2011 at 6:18 PM, MeHdi KaZemI mehdi.kaze...@gmail.comwrote: I think applying BFS is good, what's the problem with

Re: [algogeeks] Re: unique no. problem

2011-09-13 Thread sukran dhawan
good one On Tue, Sep 13, 2011 at 2:37 PM, kARTHIK R k4rth...@gmail.com wrote: Nice one sagar. Karthik R, RD Engineer, Tejas Networks. On Tue, Sep 13, 2011 at 2:36 PM, sagar sindwani sindwani.sa...@gmail.comwrote:

[algogeeks] Re: Returning 0 with probability p and 1 with probability 1-p

2011-09-13 Thread Don
Here is an extension: Given a pseudo-random generator f() which return unsigned integers uniformly distributed over the range 0..2^32-1, create a generator which produces integer values in the range 0..N-1 with each occurring with a probability {p0, p1, p2, ..., pn-1} such that all the

[algogeeks] Re: Finding connection b/w 2 profiles

2011-09-13 Thread Don
You could do a depth-first search limited to depth 2. If that fails, do it to depth 3. Then 4, etc. It is very space efficient, and you will be spending 99% of your time at the deepest level, so the time penalty compared to breadth first is not all that bad. Don On Sep 13, 9:57 am, JITESH KUMAR

[algogeeks] Re: Finding connection b/w 2 profiles

2011-09-13 Thread Don
I think your statement about A-B-C leads people to believe that the depth is 2. If we know depth is 2, we just scan A's friends and C's friends looking for a match, which is B. If we don't know the length of the path, we might want to start searching from A and C at the same time and look for a

Re: [algogeeks] samsung engineering lab interview..

2011-09-13 Thread Rajeshwar Patra
Questions are asked mostly on os and c programming concepts In os virtual memory management and ipc -- 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

Re: [algogeeks] Re: subarray wid sum=k

2011-09-13 Thread manish kapur
bt how to modify it for getting sum value= k? -- 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] Re: Scanf in an infinite loop

2011-09-13 Thread Ankuj Gupta
What I am guessing is that the stdin used by scanf is not getting flushed after entering a char as a result of which it is running into infinite loop. If you use fflush(stdin) just after scanf it will not be infinite loop. But I am not able to get the reason for it. On Sep 13, 3:23 pm, Avinash

[algogeeks] Re: Finding connection b/w 2 profiles

2011-09-13 Thread Navneet
A related discussion is available here. http://stackoverflow.com/questions/1556451/how-do-sites-like-linkedin-efficiently-display-1st-2nd-3rd-level-relationship-nex On Sep 13, 8:37 pm, Don dondod...@gmail.com wrote: I think your statement about A-B-C leads people to believe that the depth is 2.

Re: [algogeeks]

2011-09-13 Thread prasanth n
use dynamic programming.. On Sun, Sep 4, 2011 at 6:46 PM, aditya kumar aditya.kumar130...@gmail.comwrote: How to find longest common substring in two strings ? i want efficent code and iff possible any method other than using suffix tree . -- You received this message because you are

[algogeeks] Re: MS test cases type Questions

2011-09-13 Thread Navneet
Basically test cases are asked for very general purpose software like a Notepad etc. Generally they want you to come up with as many as test cases as possible. On Sep 13, 7:15 pm, Akash Mukherjee akash...@gmail.com wrote: +1 On Mon, Sep 12, 2011 at 3:42 PM, pg@manit gpt.pa...@gmail.com

[algogeeks] Re: Microsoft Question

2011-09-13 Thread Ankuj Gupta
For stack :- Keep incrementing the priority of each pushed element. So the last pushed element will have the greatest priority and the element pushed first will have lowest priority. For queue:- keep decrementing the priority of each inserted element. On Sep 13, 1:45 am, Ankur Garg

[algogeeks] Re: SAMSUNG INDIA SOFTWARE OPERATIONS PVT LTD (SISO)

2011-09-13 Thread siva viknesh
package? On Sep 13, 7:16 pm, abhinav gupta abhinav@gmail.com wrote: NIT ALLAHABAD... On Tue, Sep 13, 2011 at 7:45 PM, navneet kumar kumarnavneet@gmail.comwrote: which college?? On Tue, Sep 13, 2011 at 7:41 PM, abhinav gupta abhinav@gmail.comwrote: any one plzz tell

[algogeeks] MAQ

2011-09-13 Thread teja bala
Guys does any one have an idea of MAQ placement procedure, if so please post the tips and the respective links ,thanx in advance. -- 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]

2011-09-13 Thread Sanjay Rajpal
A dynamic programming problem . Sanju :) On Tue, Sep 13, 2011 at 9:34 AM, prasanth n nprasnt...@gmail.com wrote: use dynamic programming.. On Sun, Sep 4, 2011 at 6:46 PM, aditya kumar aditya.kumar130...@gmail.com wrote: How to find longest common substring in two strings ? i want

Re: [algogeeks] Re: informatica interview question

2011-09-13 Thread Manoj Bagari
ravi can u please tell usa bout the written test what type of question asked etc? -- 'Life can be filled with disappointment but being happy is a choice' Manoj Bagari National Institute Technology Kernataka -- You received this message because you are subscribed to the Google Groups

[algogeeks] Re: Scanf in an infinite loop

2011-09-13 Thread Don
Scanf with a %d flag will ignore anything that is not a decimal number, until it finds a decimal number. Don On Sep 13, 5:23 am, Avinash Dharan avinashdha...@gmail.com wrote:  #include stdio.h void main() {      while(1)      {         int opt;         scanf(%d,opt);        

[algogeeks] Re: Question -- plz answer

2011-09-13 Thread Dave
@Vikas. I tried to understand what you were saying, but couldn't. Sorry. Dave. On Sep 12, 7:33 am, vikas vikas.rastogi2...@gmail.com wrote: If L = C, then     cup1 = L     cup2 = cup3 = cup4 = cup5 = cup6 = overflow = 0 else if L 3*C, then     cup1 = C     cup2 = cup3 = (L-C)/2     cup4

[algogeeks] Re: Scanf in an infinite loop

2011-09-13 Thread Tanmay Verma
I don't think fflush(stdin) would work in this situation. But the reason you gave is write. One way to fix is to put a getchar() below the scanf statement. On Sep 13, 9:17 pm, Ankuj Gupta ankuj2...@gmail.com wrote: What I am guessing is that the stdin used by scanf is not getting flushed after

Re: [algogeeks] Re: informatica interview question

2011-09-13 Thread ravi maggon
@manoj: clear your concepts about DS, Algo's and C/C++ because questions are on basics of these. their are 25 ques and you get 45 min to solve them. their are some question on preorder , inorder, etc. some on fork() command. #one ques was to find the complexity of this code for(i=0;in;i++)

[algogeeks] output

2011-09-13 Thread Rajeshwar Patra
http://codepad.org/erdnF74M can anyone explain the output ??? -- *Rajeshwar Patra,* *MCA final year,* *Nit Durgapur* -- 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

Re: [algogeeks] output

2011-09-13 Thread kumar raja
main(){printf(%s,printf(samsung)+fun());}fun(){return electronic;} The printf is a function which returns the number of printed characters , and scanf is a function which returns the number of inputs scanned . So after printing samsung it returns 7. fun() is returning a pointer to the constant

Re: [algogeeks] output

2011-09-13 Thread Ishan Aggarwal
int main(){printf(%s,printf(samsung)+fun());return 0;}fun(){return electronic;} On Tue, Sep 13, 2011 at 11:28 PM, kumar raja rajkumar.cs...@gmail.comwrote: main(){printf(%s,printf(samsung)+fun());}fun(){return electronic;} The printf is a function which returns the number of printed

Re: [algogeeks] output

2011-09-13 Thread Kunal Patil
@Kumar: +1 @Kumar Rajeshwar: ExitFailure is outputted because main is expected to return something which is not done in your case. Just add return 0; at the end of main to get expected output. On Tue, Sep 13, 2011 at 11:33 PM, Ishan Aggarwal ishan.aggarwal.1...@gmail.com wrote: int main()

Re: [algogeeks] Scanf in an infinite loop

2011-09-13 Thread shady
anyone ? very curious to know the answer On Tue, Sep 13, 2011 at 3:53 PM, Avinash Dharan avinashdha...@gmail.comwrote: #include stdio.h void main() { while(1) { int opt; scanf(%d,opt); printf(%d\n,opt); } } when i execute this program, if i

[algogeeks] Exchanging bit values in a number

2011-09-13 Thread kumar raja
Suppose a number 'n' is given and two bits positions i,j present in binary representation of n . Then how to exchange the contents of the two bits i and j. E.g. n= 13 its binary representation is 1101 (just for now consider 8 bit number) i= 2,j=6 o/p : 0100 1001 = 73 please suggest some

Re: [algogeeks] Re: Microsoft Question

2011-09-13 Thread Ankur Garg
But dude are u saying stack will be implemented as a map with value,priority and then choose element based on priority ? regards Ankur On Tue, Sep 13, 2011 at 10:16 PM, Ankuj Gupta ankuj2...@gmail.com wrote: For stack :- Keep incrementing the priority of each pushed element. So the last

[algogeeks] Re: Exchanging bit values in a number

2011-09-13 Thread Dave
@Kumar: How about this: int exchange2bits(int n, int i, int j) // exchange bits i and j of n. { int ni, nj; ni = n (1 i); nj = n (1 j); return n ~(ni | nj) | ((ni i) j) | ((nj j) i); } ni is bit i of n. nj is bit j of n. n (ni | nj) removes the two bits, and then they

[algogeeks] Re: Exchanging bit values in a number

2011-09-13 Thread Gene
// One of several ways in C: unsigned swap_bits(unsigned x, int i, int j) { r = x; if (x (1u i)) r |= (1u j); else r = ~(1u j); if (x (1u j)) r |= (1u i); else r = ~(1u i); return r; } On Sep 13, 2:50 pm, kumar raja rajkumar.cs...@gmail.com wrote: Suppose a number 'n' is given  

[algogeeks] Re: Exchanging bit values in a number

2011-09-13 Thread Dave
Replying to myself: I should proofread better _before_ I post. Sorry, but the explanation should say ni is bit i of n. nj is bit j of n. n ~(ni | nj) removes the two bits, and then they are shifted to the exchanged positions and or'd in. Dave On Sep 13, 2:04 pm, Dave dave_and_da...@juno.com

Re: [algogeeks] Exchanging bit values in a number

2011-09-13 Thread Ankit Agarwal
let x = 2^j + 2 ^i new number after swapping the digits is x XOR n eg n = 1101 j = 6 i = 2 x = 0100 0100 new number = x XOR n = 0100 1001 -- Ankit Agarwal Computer Science Engg. Integrated Dual Degree, V yr Department of Electronics Computer Engineering Indian Institute of Technology

[algogeeks] Re: Scanf in an infinite loop

2011-09-13 Thread Lakshmi Prasad
could you please elaborate on this conceptor provide me with a link On Sep 13, 12:17 pm, Ankuj Gupta ankuj2...@gmail.com wrote: What I am guessing is that the stdin used by scanf is not getting flushed after entering a char as a result of which it is running into infinite loop. If you use

[algogeeks] Re: Scanf in an infinite loop

2011-09-13 Thread Lakshmi Prasad
when i'm giving some character values followed by an integer the scanf is not reading the integer On Sep 13, 1:08 pm, Don dondod...@gmail.com wrote: Scanf with a %d flag will ignore anything that is not a decimal number, until it finds a decimal number. Don On Sep 13, 5:23 am, Avinash Dharan

Re: [algogeeks] Exchanging bit values in a number

2011-09-13 Thread Sandy
@Ankit. n= 1101 i=2 j=3 x = (2^j + 2^i) = 1100 x^n = 0001 Answer should be 1101. On Wed, Sep 14, 2011 at 12:39 AM, Ankit Agarwal ankuagarw...@gmail.comwrote: let x = 2^j + 2 ^i new number after swapping the digits is x XOR n eg n = 1101 j = 6 i = 2 x = 0100 0100

Re: [algogeeks] Exchanging bit values in a number

2011-09-13 Thread kumar raja
@Dave and Gene I am totally awkward at ur solutions ...How did u develop these solutions?? . Can u please quote some material/book on this topic.. On 13 September 2011 12:18, Sandy sandy.wad...@gmail.com wrote: @Ankit. n= 1101 i=2 j=3 x = (2^j + 2^i) = 1100 x^n = 0001

Re: [algogeeks] Exchanging bit values in a number

2011-09-13 Thread kumar raja
@Dave and Gene sorry , i mean ur solutions are brilliant ,but i did not get those kind of ideas till now.. On 13 September 2011 12:31, kumar raja rajkumar.cs...@gmail.com wrote: @Dave and Gene I am totally awkward at ur solutions ...How did u develop these solutions?? . Can u please quote

Re: [algogeeks] String

2011-09-13 Thread shady
sorry, but first try doing it yourself. btw, code is also present in archives. On Tue, Sep 13, 2011 at 2:50 PM, guna sekaran vgun...@gmail.com wrote: please write a code any one On Tue, Sep 13, 2011 at 2:06 PM, shady sinv...@gmail.com wrote: search archives, already done On Tue, Sep 13,

Re: [algogeeks] Scanf in an infinite loop

2011-09-13 Thread Raghu Sarangapani
I modified your program as below. Every time, value of ret = 0. scanf is repeatedly failing cos there is some junk in the input stream Hence it prints junk values #include stdio.h void main() { while(1) { int opt, ret; ret=scanf(%d,opt); printf(opt is %d\n,opt);

[algogeeks] Re: Exchanging bit values in a number

2011-09-13 Thread Don
// If bits i and j are equal, result is just n // Otherwise, toggle bits i and j int bitExchange(int n, int i, int j) { return (((ni)1) == ((nj)1)) ? n : n ^ ((1i) || (1j)); } On Sep 13, 1:50 pm, kumar raja rajkumar.cs...@gmail.com wrote: Suppose a number 'n' is given  and two bits positions

Re: [algogeeks] Solve the following problems

2011-09-13 Thread SAMM
For question 2:- U can use my following code ... #includeiostream #includecstdio using namespace std; int main() { int a[]={4,2,5,2,3,5,1,34,14,64,82,94}; int size=sizeof(a)/sizeof(int); // printf(%d,size); for(int i=0;i(int)sqrt(size);i++)printf(%d ,a[i]); return 0; }

[algogeeks] Re: Exchanging bit values in a number

2011-09-13 Thread Dave
@Kumar: 1i is 1 shifted left i places, so anding it with n will give you the ith bit of n. Similarly for j. Zero out the ith and jth bits from n. Then shift the ith bit to the jth spot and vice versa and or them in. Dave On Sep 13, 2:31 pm, kumar raja rajkumar.cs...@gmail.com wrote: @Dave and

[algogeeks] Re: Exchanging bit values in a number

2011-09-13 Thread Dave
@Don. Very nice. I think you meant | where you wrote ||. This is so short that you could even do it as a #define: #define bitExchange(n,i,j) (n)(i))1)==(((n)(j))1))?n: (n)^((1(i))|(1(j Dave On Sep 13, 3:15 pm, Don dondod...@gmail.com wrote: // If bits i and j are equal, result is just

[algogeeks] Re: Exchanging bit values in a number

2011-09-13 Thread Don
Yes, good catch. It should be the bitwise or. Don On Sep 13, 3:37 pm, Dave dave_and_da...@juno.com wrote: @Don. Very nice. I think you meant | where you wrote ||. This is so short that you could even do it as a #define: #define bitExchange(n,i,j) (n)(i))1)==(((n)(j))1))?n:

Re: [algogeeks] Re: informatica interview question

2011-09-13 Thread Manoj Bagari
thanx a lot ravi for sharing the information :) :) 'Life can be filled with disappointment but being happy is a choice' Manoj Bagari National Institute Technology Kernataka -- You received this message because you are subscribed to the Google Groups Algorithm Geeks

[algogeeks] algogeeks, Mangal Dass wants to chat

2011-09-13 Thread Mangal Dass
I've been using Google Talk and thought you might like to try it out. We can use it to call each other for free over the internet. Here's an invitation to download Google Talk. Give it a try! --- Mangal Dass wants to stay in

Re: [algogeeks] Exchanging bit values in a number

2011-09-13 Thread sravanreddy001
@ANKIT: your solution just compliments the bits at given locations... but we are looking at swapping 2 different bit locations.. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit

Re: [algogeeks] Solve the following problems

2011-09-13 Thread sravanreddy001
how can your code ensure.. the top sqrt(N) elements being printed? for 2nd questions. Its not possible be to do this in less than Linear time.. unless the array has some special property.. (already sorted) -- You received this message because you are subscribed to the Google Groups Algorithm

[algogeeks] Re: Scanf in an infinite loop

2011-09-13 Thread Ankuj Gupta
@Tanmay: fflush do work. Atleast it does not become a infinite loop. But still the output is some garbage value in case of character input On Sep 14, 1:04 am, Raghu Sarangapani raghu.sarangap...@gmail.com wrote: I modified your program as below. Every time, value of ret = 0. scanf is

[algogeeks] Re: Microsoft Question

2011-09-13 Thread Ankuj Gupta
I guess the functionality of priority should be maintained On Sep 13, 11:59 pm, Ankur Garg ankurga...@gmail.com wrote: But dude are u saying stack will be implemented as a map with value,priority and then choose element based on priority ? regards Ankur On Tue, Sep 13, 2011 at

[algogeeks] Re: branching factor when BFS and DFS of a graph is same

2011-09-13 Thread bugaboo
This brings up another interesting question. How do you find out if 2 graphs are identical? (By identical, I mean exact similarity and NOT isomorphism). Clearly, checking to see if both the DFS traversal and BFS traversal match seem to have false positives as Bharathkumar mentioned. On Sep 13,

Re: [algogeeks] Re: Finding connection b/w 2 profiles

2011-09-13 Thread saurabh agrawal
@DON: DFS should not be applied because, there can exist multiple paths from A to C, but the question is to find the shortest path. So, u might end up getting longer path. Otherwise you have to search for all possible paths which will be very inefficient. Saurabh Agrawal On Tue, Sep 13,

[algogeeks] Which one is better to work for ThoughtWorks or Samsung

2011-09-13 Thread tech coder
Which one is better to work for ThoughtWorks or Samsung. ThoughtWorks package 5.86 Samsung 6.25. Those who r working in samsung or thoughtworks please reply -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email

[algogeeks] program

2011-09-13 Thread raj
program to find the top 3 repeating number from the given array eg You r given an array and u have to find out the top 3 repeated numbers. for ex: GAURAV[]={20,8,3,7,8,9,20,6,4,6,20,8,20} so the output will be: 20 is repeated 4 times 8 is repeated 3 times 6 is repeated 2 times. -- You received