[algogeeks] Tree Center Problem

2011-10-06 Thread Nitin Nizhawan
hi, given a tree with N nodes find the node such that its average total distance from each other node is smallest i.e. if nodes are labeled 0N-1 then find i such that[ SUM d(i, j ){0=jN}] /N is minimum NOTE: This is different from the classic problem of finding

[algogeeks] Re: Tree Center Problem

2011-10-06 Thread Nitin Nizhawan
anyone? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group

Re: [algogeeks] Syllogism

2011-08-23 Thread Nitin Nizhawan
Thus above statement is true if and only it is given that there are some girls who are not Beautiful. On Tue, Aug 23, 2011 at 7:50 PM, Bharat Kul Ratan bharat.kra...@gmail.comwrote: Statement: Some girls are beautiful IMO , this means you a set of all girls and after that comes statement

Re: [algogeeks] convert a vector containing octal representation of a number to decimal number

2011-08-21 Thread Nitin Nizhawan
int num = 0; for(int i=0;iA.size();i++){ num=num||(A[i]3*i); } printf(%d,num); I think this will do. On Sun, Aug 21, 2011 at 2:25 PM, sarvesh saran aquarian.thun...@gmail.comwrote: Hi, I have a vectorint A or an array (for C guys) that contains the octal representation of a number. So

Re: [algogeeks] convert a vector containing octal representation of a number to decimal number

2011-08-21 Thread Nitin Nizhawan
int num = 0; for(int i=0;iA.size();i++){ num=num||(A[i]3*i); } printf(%d,num); I think this will do. Given the number is with in the range of integer. On Sun, Aug 21, 2011 at 3:40 PM, Nitin Nizhawan nitin.nizha...@gmail.comwrote: int num = 0; for(int i=0;iA.size();i++){ num=num||(A[i]3

Re: [algogeeks] convert a vector containing octal representation of a number to decimal number

2011-08-21 Thread Nitin Nizhawan
a hexadecimal string say 02F9A to its decimal representation in C++? thanks, Sarvesh thanks, Sarvesh On Sun, Aug 21, 2011 at 3:41 PM, Nitin Nizhawan nitin.nizha...@gmail.com wrote: int num = 0; for(int i=0;iA.size();i++){ num=num||(A[i]3*i); } printf(%d,num); I think this will do

Re: [algogeeks] convert a vector containing octal representation of a number to decimal number

2011-08-21 Thread Nitin Nizhawan
srn...@gmail.com wrote: @Nitin : could u explain ur logic ? Sanju :) On Sun, Aug 21, 2011 at 9:24 AM, Nitin Nizhawan nitin.nizha...@gmail.comwrote: @sanjay, oops, my intention was bitwise OR On Sun, Aug 21, 2011 at 4:25 PM, sarvesh saran aquarian.thun...@gmail.com wrote: Hi

Re: [algogeeks] Syllogism

2011-08-20 Thread Nitin Nizhawan
Statement: Some girls are beautiful' Ex B(x) , there exist at least one girl who is beautiful Some girls are not beautiful Ex !B(x), there exist at least one girl who is beautiful I do not think first implies the second. On Sat, Aug 20, 2011 at 3:13 PM, vikas singh shyguy1...@gmail.com wrote:

Re: [algogeeks] Syllogism

2011-08-20 Thread Nitin Nizhawan
, Aug 20, 2011 at 6:49 PM, Nitin Nizhawan nitin.nizha...@gmail.comwrote: Statement: Some girls are beautiful' Ex B(x) , there exist at least one girl who is beautiful Some girls are not beautiful Ex !B(x), there exist at least one girl who is beautiful I do not think first implies the second

Re: [algogeeks] Syllogism

2011-08-20 Thread Nitin Nizhawan
@geek_one, its false, some girls are beautiful does not imply that some girls are not beautiful On Sat, Aug 20, 2011 at 10:36 PM, Yogesh Bhati ybha...@gmail.com wrote: conclusion : Is at least some girls are beautiful dnt knw abt rest bt some are -- You received this message because

Re: [algogeeks] Prime numbers

2011-08-17 Thread Nitin Nizhawan
Hi Dod, Could you pls expalin what this algorithm is doing and from where you got it. Thanks Nitin On Wed, Aug 17, 2011 at 2:56 AM, Don dondod...@gmail.com wrote: I wrote a program to print prime numbers, but it is not very fast. Can someone help me figure out why? #include stdio.h /*

Re: [algogeeks] Re: Number theory

2011-08-17 Thread Nitin Nizhawan
@Puneet, you are right but we can have only n-1 dividers. On Wed, Aug 17, 2011 at 4:15 PM, Puneet Goyal puneetgoya...@gmail.comwrote: I think it should be 2^n -1 Explanation We can visualize it as n balls are placed and we have to place some dividers (max=n) in betweek to divide them into

Re: [algogeeks] Factorial Algorithms

2011-08-17 Thread Nitin Nizhawan
. On Fri, Aug 12, 2011 at 3:00 PM, Nitin Nizhawan nitin.nizha...@gmail.com wrote: http://www.luschny.de/math/factorial/FastFactorialFunctions.htm Does anyone know of resource for good/detailed explanation of factorial algorithms on this site? -- You received this message because you

Re: [algogeeks] GS apti ques!

2011-08-17 Thread Nitin Nizhawan
a = (1-0.2) b = (1-0.3) c = (1- 0.4) a*b*(1-c) + a*(1-b)*c + (1-a)*b*c + a*b*c = 0.788 On Wed, Aug 17, 2011 at 5:08 PM, Romil ... vamosro...@gmail.com wrote: @Priya: A mistake from my side. The answer should be 1-0.212 i.e. 0.788 Sorry for this mistake. @Kumar: Yours is wrong. Check it

Re: [algogeeks] What is the reason??

2011-08-17 Thread Nitin Nizhawan
I think this happens because EOF on stream is set when fscanf actually tries to read beyond EOF but reads 0 characters and therefore printf prints the previous value in s. On Wed, Aug 17, 2011 at 5:11 PM, kumar raja rajkumar.cs...@gmail.comwrote: while(!feof(fp)) {

Re: [algogeeks] What is the reason??

2011-08-17 Thread Nitin Nizhawan
from it?? On 17 August 2011 17:19, Nitin Nizhawan nitin.nizha...@gmail.com wrote: I think this happens because EOF on stream is set when fscanf actually tries to read beyond EOF but reads 0 characters and therefore printf prints the previous value in s. On Wed, Aug 17, 2011 at 5:11 PM, kumar

Re: [algogeeks] De shaw ques!

2011-08-17 Thread Nitin Nizhawan
N = 935*q + 69 N%38 = 31, 16, 1, 24, 9, 32, 17, 2 for { q = 0,1,2,3,4,5,6,7. } On Wed, Aug 17, 2011 at 5:54 PM, aditya kumar aditya.kumar130...@gmail.comwrote: @priya . i have shown you my method . write your method and we shall discuss it . On Wed, Aug 17, 2011 at 5:52 PM, sukran

Re: [algogeeks] Re: Algorithms For Interviews

2011-08-16 Thread Nitin Nizhawan
http://www.fileflyer.com/view/XyBZGA8 On Tue, Aug 16, 2011 at 8:07 PM, Yasir yasir@gmail.com wrote: Typo: achieves -- archives -- 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] Re: Algorithms For Interviews

2011-08-16 Thread Nitin Nizhawan
sent to you ravi On Tue, Aug 16, 2011 at 8:16 PM, ravi kumar ravikumar...@gmail.com wrote: heyy nitin.. it says da file izz locked .. can u mail me da buk.. thanx in advance -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to

Re: [algogeeks] Number theory

2011-08-16 Thread Nitin Nizhawan
I think 2^(n-1) - 1 On Tue, Aug 16, 2011 at 8:36 PM, sameer gupta gupta.sameer...@gmail.comwrote: no. of ways you can write a no. as sum of other non-zero positive integers like 3 can be written in 3 ways: 1+1+1, 1+2 2+1 imp. 2+1 and 1+2 are different find the answer and give and

Re: [algogeeks] Prime numbers

2011-08-16 Thread Nitin Nizhawan
Can someone pls explain what dod's algorithm is doing? Dod, from where did you get this recursive algo? On Wed, Aug 17, 2011 at 8:45 AM, Dipankar Patro dip10c...@gmail.com wrote: Sieve's is the fastest in generating prime numbers. +1 to Sandeep and Sanjay On 17 August 2011 08:21, Sanjay

Re: [algogeeks] an array question

2011-08-12 Thread Nitin Nizhawan
radix sort the digits wrong way (left most digit first), and then concatenate On Fri, Aug 12, 2011 at 6:12 PM, Yasir yasir@gmail.com wrote: Kindly check it with both the examples. It won't work. -- You received this message because you are subscribed to the Google Groups Algorithm

[algogeeks] Factorial Algorithms

2011-08-12 Thread Nitin Nizhawan
http://www.luschny.de/math/factorial/FastFactorialFunctions.htm Does anyone know of resource for good/detailed explanation of factorial algorithms on this site? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email

Re: [algogeeks] Trees

2011-08-11 Thread Nitin Nizhawan
i guess answer is c. 4 n*i+1 On Thu, Aug 11, 2011 at 8:01 PM, rShetty rajeevr...@gmail.com wrote: A complete n- array tree in which each node has n children or no children, let i be the number of internal nodes and L be the number of leaves in a complete n- array tree. If L=41 and i=10 what

Re: [algogeeks] Re: Trees

2011-08-11 Thread Nitin Nizhawan
I am also getting , 5 as answer now. here is what I did. In any n-ary tree we can add one internal node by adding n-children to any one of its leaf nodes. This operation creates one internal node and at the cost one leaf node and adds n new leaf nodes. L(i) be leaf nodes in a tree with i internal

Re: [algogeeks] Design .. how to attack ???

2011-08-11 Thread Nitin Nizhawan
I feel such questions are asked to test OO skills so try to identify all the entities and verbs in the system. Also describing key interfaces in detail should help. On Fri, Aug 12, 2011 at 11:20 AM, MAC macatad...@gmail.com wrote: Hi guys , Can anyone help me in understanding what is expected

Re: [algogeeks] Re: SPOJ CENCRY

2011-08-10 Thread Nitin Nizhawan
3 eee cjpvbhntzgm aeiouaeiouae vfghjklwerf eouaeioicou On Wed, Aug 10, 2011 at 12:06 PM, kartik sachan kartik.sac...@gmail.comwrote: any body tell the test cases?? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To

Re: [algogeeks] Re: SPOJ CENCRY

2011-08-10 Thread Nitin Nizhawan
inp: 3 eee vfghjklwerf out: cjpvbhntzgm aeiouaeiouae eouaeioicou On Wed, Aug 10, 2011 at 12:40 PM, Nitin Nizhawan nitin.nizha...@gmail.comwrote: 3 eee cjpvbhntzgm aeiouaeiouae vfghjklwerf eouaeioicou On Wed, Aug 10, 2011 at 12:06 PM, kartik

Re: [algogeeks] STL sort

2011-08-10 Thread Nitin Nizhawan
what is comp in your code? On Wed, Aug 10, 2011 at 6:19 PM, aanchal goyal goyal.aanch...@gmail.comwrote: I have a vector of stuct, how to sort this vector? problem is I can't overload the '' operator in struct definition, as i want to sort by 'x' one time, and then by 'y'. I tried to write

Re: [algogeeks] STL sort

2011-08-10 Thread Nitin Nizhawan
10, 2011 at 6:24 PM, Nitin Nizhawan nitin.nizha...@gmail.comwrote: what is comp in your code? On Wed, Aug 10, 2011 at 6:19 PM, aanchal goyal goyal.aanch...@gmail.comwrote: I have a vector of stuct, how to sort this vector? problem is I can't overload the '' operator in struct definition

Re: [algogeeks] m'th max element

2011-08-08 Thread Nitin Nizhawan
Selection algorithm, http://en.wikipedia.org/wiki/Selection_algorithm On Mon, Aug 8, 2011 at 3:59 PM, nick tarunguptaa...@gmail.com wrote: how will you find the m'th maximum element in an unsorted array of integers? -- You received this message because you are subscribed to the Google

Re: [algogeeks] Random number

2011-08-08 Thread Nitin Nizhawan
following solution should work but it uses an array so its ST is O(N) #include stdio.h #include time.h #define MAX 500 /** copied from wikipedia * */ unsigned m_w = time(NULL);/* must not be zero */ unsigned m_z = 300;/* must not be zero */ unsigned long get_random() { m_z =

Re: [algogeeks] suggest simple code for

2011-08-08 Thread Nitin Nizhawan
I think this should work void finddepth(Node *node,int depth){ if(node!=NULL){ depth = max( finddepth(node-left,depth+1), finddepth(node-right,depth+1) ); } return depth; } On Mon, Aug 8, 2011 at 6:33 PM, jagrati verma jagrativermamn...@gmail.comwrote: finding the depth or height

Re: [algogeeks] Re: nlogn, in-place, iterative mergesort?

2011-08-07 Thread Nitin Nizhawan
Thanks everyone, Achieving nlogn, interative, and in-place separately is easy. But I did not know of algo that achieves all these simultaneously for merge sort. Thanks DK for pointing to that paper I wonder if algorithm presented in paper is also stable. --Nitin On Sun, Aug 7, 2011 at 5:10

Re: [algogeeks] Re: nlogn, in-place, iterative mergesort?

2011-08-07 Thread Nitin Nizhawan
good Joke :) On Mon, Aug 8, 2011 at 1:43 AM, DK divyekap...@gmail.com wrote: @Nitin: In-place merge sorts are not stable (atleast I haven't come across a stable one - you might want to create one as research? ;) ). -- DK http://twitter.com/divyekapoor http://gplus.to/divyekapoor

Re: [algogeeks] Re: adobe

2011-08-06 Thread Nitin Nizhawan
http://trickofmind.com/?p=1080 i think this will help, we need to find Carmichael number or somthing related to ETF for the input number. On Sat, Aug 6, 2011 at 12:24 PM, Nikhil Gupta nikhilgupta2...@gmail.comwrote: @sumit, these numbers containing all ones are not in binary representation.

Re: [algogeeks] nlogn, in-place, iterative mergesort?

2011-08-06 Thread Nitin Nizhawan
inplace? On Sat, Aug 6, 2011 at 10:27 PM, immanuel kingston kingston.imman...@gmail.com wrote: Yes. just remove the recursive part using 2 stacks. Thanks, Immanuel On Fri, Aug 5, 2011 at 6:51 PM, Nitin Nizhawan nitin.nizha...@gmail.comwrote: does anyone know of any in-place

Re: [algogeeks] pls help

2011-08-05 Thread Nitin Nizhawan
Or one could just simulate a counting from 0 to (numchars^N)-1 in base numchars. ... code: void printit(int N,char chars[],int index[]){ for(int i=0;iN;i++){ printf(%c,chars[index[i]]); } printf(\n); } void generate(int numchars,char chars[],int N){ int index[100]={0};

Re: [algogeeks] pls help

2011-08-05 Thread Nitin Nizhawan
of nested loops. On Fri, Aug 5, 2011 at 2:44 PM, Nitin Nizhawan nitin.nizha...@gmail.com wrote: @Varun I think it can be done using bits, if input character set has only two elements. Or could u plz explain? On Fri, Aug 5, 2011 at 2:29 PM, Varun Jakhoria varunjakho...@gmail.com wrote

Re: [algogeeks] probabilty

2011-08-05 Thread Nitin Nizhawan
1/8 On Fri, Aug 5, 2011 at 4:19 PM, nethaji guru nethaji.1...@gmail.com wrote: 3 /4 -- With regards, Nethaji Guru -- 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] probabilty

2011-08-05 Thread Nitin Nizhawan
yes it cant be 1/8 I was wrong. On Fri, Aug 5, 2011 at 4:23 PM, coder dumca coder.du...@gmail.com wrote: i think it should be 3/4 On Fri, Aug 5, 2011 at 4:20 PM, aditi garg aditi.garg.6...@gmail.comwrote: 1/8 On Fri, Aug 5, 2011 at 4:14 PM, coder dumca coder.du...@gmail.comwrote: A

Re: [algogeeks] probabilty

2011-08-05 Thread Nitin Nizhawan
A dice is 6 B reports 6 P(A) = 1/6 P(!A) = 5/6 P(B|!A) =(1/4)*(1/5) P(B|A) = (3/4) P(A|B) = P(B|A)*P(A)/( P(B|A)*P(A) + P(B|!A)*P(!A)) =((3/4)*(1/6))/( (3/4)*(1/6) + (1/4)*(1/5)*(5/6)) = 3/4 On Fri, Aug 5, 2011 at 4:50 PM, tarang dawer tarrang1...@gmail.com wrote: 1/2 -- You

Re: [algogeeks] Reverse Bits

2011-08-05 Thread Nitin Nizhawan
x = x16 | (0xx)16 this line exchanges ls 16bits with ms 16bits, i.e. 1 pair of 16bit this logic of exchanging bits is the used for 2 pairs of 8bits each, then for 4 pairs of 4bit, then for 8 pairs of 2 bit and finally 16 pairs of 1bit. On Fri, Aug 5, 2011 at 6:04 PM, rShetty

Re: [algogeeks] My senior's Interview Experience at Microsoft who got selected and offered a 16lacks package

2011-08-05 Thread Nitin Nizhawan
if input starts with one or more characters from the string A telephone girl then it will give SEG FAULT because it scanf will try to write to CS, else initial value junk will be printed On Fri, Aug 5, 2011 at 6:28 PM, Lakshmi Prasad prasadlakshmi...@gmail.comwrote: for some inputs its giving

[algogeeks] nlogn, in-place, iterative mergesort?

2011-08-05 Thread Nitin Nizhawan
does anyone know of any in-place, iterative mergesort algorithm with nlogN worst case complexity? It would be good if it is stable also. TIA Nitin -- 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] Re: remove duplicate words in a string

2011-08-05 Thread Nitin Nizhawan
@deepika this is a different question, your solution is great for removing duplicate characters. original question is about removing duplicate words. On Fri, Aug 5, 2011 at 7:06 PM, deepikaanand swinyanand...@gmail.comwrote: ya an array of 256 is surely a wastage of space but this was i couls

Re: [algogeeks] Circle

2011-08-05 Thread Nitin Nizhawan
I think this will do. http://en.wikipedia.org/wiki/Midpoint_circle_algorithm On Fri, Aug 5, 2011 at 7:08 PM, rShetty rajeevr...@gmail.com wrote: Write a routine to draw a circle (x ** 2 + y ** 2 = r ** 2) without making use of any floating point computations at all. -- You received this

Re: [algogeeks] My senior's Interview Experience at Microsoft who got selected and offered a 16lacks package

2011-08-04 Thread Nitin Nizhawan
its a regex. scanf will only accept characters in square brackets. On Thu, Aug 4, 2011 at 12:45 PM, muthu raj muthura...@gmail.com wrote: Can any one explain the working of %[A telephonnic girl] *Muthuraj R IV th Year , ISE PESIT , Bangalore* On Thu, Aug 4, 2011 at 12:25 PM, Nitish

Re: [algogeeks] Re: Amazon Aptitude questions

2011-08-04 Thread Nitin Nizhawan
find ./ -name *.java On Thu, Aug 4, 2011 at 8:17 PM, kashish jain kashish.jain.n...@gmail.comwrote: answer to shell command is grep -r *.java i wanted to ask , am i right ? On Thu, Aug 4, 2011 at 2:16 PM, Shashank Jain shashan...@gmail.comwrote: whats the priority of ^ symbol?

Re: [algogeeks] Amazon Question

2011-08-03 Thread Nitin Nizhawan
why not first sort the lists first? (we could if we do not want to modify original list) it will give O(nLogn) solution -Nitin On Wed, Aug 3, 2011 at 4:44 PM, veera reddy veeracool...@gmail.com wrote: sry... misunderstood the question On Wed, Aug 3, 2011 at 4:43 PM, veera reddy

Re: [algogeeks] Amazon Question

2011-08-03 Thread Nitin Nizhawan
EDIT: why not first sort the lists first? (we can create copy if we do not want to modify original list) it will give O(nLogn) solution -Nitin On Wed, Aug 3, 2011 at 4:59 PM, Nitin Nizhawan nitin.nizha...@gmail.comwrote: why not first sort the lists first? (we could if we do not want

Re: [algogeeks] Complexity Help..

2011-08-02 Thread Nitin Nizhawan
Running time can be found by solving this recursion. T(sz,target) = SUM {1=i=sz} T(i,target-1) T(sz,0) = c I think it is around O(sz^target) Thanks Nitin On Wed, Aug 3, 2011 at 10:40 AM, aanchal goyal goyal.aanch...@gmail.comwrote: sorry, *target=45*, not sum. sum=0 when we call the function

Re: [algogeeks] sorting in O(n) time

2011-08-02 Thread Nitin Nizhawan
counting sort http://en.wikipedia.org/wiki/Counting_sort Thanks NItin On Wed, Aug 3, 2011 at 10:58 AM, AMAN AGARWAL mnnit.a...@gmail.com wrote: Hi, How can we sort one unsorted int array with O(n). Unsorted : {4,2,6,1,5,5,1,2,45,444,44,45,4,1} Sorted : {1,1,1,2,2,4,4,5,5,6,44,45,45,444}