Re: [algogeeks] confusion

2010-07-29 Thread harit agarwal
printf returns the number of character it prints so output is ok it is 111 see this o/p you will understand #includestdio.hint main(){int i=1;printf(%d\n,printf(%d\n,printf(%d,i))); return 0;} http://codepad.org/gLGMDdoU -- You received this message because you are subscribed to the Google

Re: [algogeeks] Amazon Placement Question

2010-07-29 Thread harit agarwal
are the nodes having an extra pointer for sibling?? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to

Re: [algogeeks] Google Interview Question

2010-07-15 Thread harit agarwal
@varun c should also be in the array -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com.

Re: [algogeeks] Re: AMAZON Interview Question

2010-07-14 Thread harit agarwal
this is O(n) solution and using O(n) space... #includeiostream #includevector #includestack using namespace std; void leader_count(vectorint v,int *ar) { stackint s; int n=v.size(); int i=n-1; while(i=0) { if(s.empty()) { ar[--n]=0; s.push(i); i--; } else { if(v[i] = v[s.top()]) {

Re: [algogeeks] recursive

2010-07-11 Thread harit agarwal
here is the recursion http://geeksforgeeks.org/?p=2686 execution: http://codepad.org/pMszw4Y8 was it difficult to google it -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com.

Re: [algogeeks] Re: cycle in Linked List generalised

2010-07-07 Thread harit agarwal
m!=n -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at

Re: [algogeeks] ipc

2010-07-06 Thread harit agarwal
shared memory processing is fast but it is not a IPC mechanism... -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to

Re: [algogeeks] ipc

2010-07-06 Thread harit agarwal
pipes -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at

Re: [algogeeks] isr

2010-07-06 Thread harit agarwal
when the system is interrupted then before running ISR set a flag and then run ISR and when it returns from ISR unset the flag after 20ms when system is interrupted again check the flag if(flag is set) means ISR is running else ISR run 20ms -- You received this message because you are

Re: [algogeeks] Re: amazon

2010-07-05 Thread harit agarwal
@ashgoel check the output of your code here: http://codepad.org/7BSTedh5 and i don't think this idea will work -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe

Re: [algogeeks] cops n robber

2010-07-04 Thread harit agarwal
yes if one having speed greater than other then at some point of time he will catch the robber -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group,

Re: [algogeeks] shift operators

2010-07-04 Thread harit agarwal
bitwise are ony applicable to unsignedtheir behaviour is undefined on negative numbers... -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send

Re: [algogeeks] amazon question

2010-07-04 Thread harit agarwal
in my approach a( b,c)- this implies that nodes within parenthesis are child of a where b is left child and c is right child if there is no left child then we can use a(,c) and if there is no right child then use a(b) and if there is no child use only a -- You received this message because you

Re: [algogeeks] cops n robber

2010-07-03 Thread harit agarwal
i don't think sorobber always have 3 ways to go..so he wouldn't get caught... -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to

Re: [algogeeks] Diameter of a set of points

2010-06-28 Thread harit agarwal
If the points are already sorted by one of the coordinates or by the angle to a fixed vector, then the algorithm takes O(*n*) time. -- 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: microsoft

2010-06-27 Thread harit agarwal
i think the question is not just about sorting non-zero values... it is asking for a stable sort...so just swapping will not work in this case -- 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: common

2010-06-27 Thread harit agarwal
@sharad i don't think there is better solution then trie.. it is space as well as time efficient... -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this

Re: [algogeeks] c

2010-06-26 Thread harit agarwal
replace x++ with x it is const so you can't change it. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to

Re: [algogeeks] 23 candies among 7 kids

2010-06-26 Thread harit agarwal
ok.. i got it.. it is 29! / 23! 6! -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more

Re: [algogeeks] common

2010-06-26 Thread harit agarwal
in linux use comm -12 log1 log2 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more

Re: [algogeeks] OS problems

2010-06-25 Thread harit agarwal
1. the virtual memory size depends on the page size that the system is using... 2. logical address=5+10=15 bits + (some modifying bits if they are present like modified,copied etc..) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to

Re: [algogeeks] 23 candies among 7 kids

2010-06-25 Thread harit agarwal
look at this approach: a1+a2+a3+a4+a5+a6+a7=23 now it means there are 23 choclates and 6 partitions(+ symbol) and arrange these 23+6=29 items so it is 29! now 23 choclates are identical so divide by 23! so number of ways=29! / 23 ! -- You received this message because you are subscribed to the

Re: [algogeeks] 23 candies among 7 kids

2010-06-23 Thread harit agarwal
it is 29! / 23! -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit

Re: [algogeeks] OS problems

2010-06-19 Thread harit agarwal
yes you can allocate 1gb using malloc but it also depends on how much heap size is available to you.. if you try 2gb then more chances are it won't allocate because of heap is exhausted.. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post

Re: [algogeeks] OS problems

2010-06-19 Thread harit agarwal
@amit i think your query is answered by varun..as each process do system call to allocate memory so it is exhausting the memory for all the processesas all processes are having the same interface... @sharad 1.i don't think priviliges affect the user address spaceit tells that in which

Re: [algogeeks] Width of the tree

2010-06-18 Thread harit agarwal
do a bfs traversal and insert a null marker after each traversal keep a variable max for maximum nodes at any level.. O(n) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To

Re: [algogeeks] OS problems

2010-06-18 Thread harit agarwal
@amit 1. calloc gives contiguos allocated space and it is not necessary that it can find 1gb in a row that's why it failed after allocating some memory... it is not necessary that it will always allocate 800mb of space as in this case... 2. whenever a process is executed in critical

Re: [algogeeks] op

2010-06-16 Thread harit agarwal
it is returning the address of last operation done in the accumulator. as the last operation is copying to s to it is returning s you will understand try running this,,... #includemalloc.h char *f() {char *s=malloc(8); strcpy(s,goodbye); } main() {

Re: [algogeeks] Mirroring Binary Tree Pattern Problem

2010-06-12 Thread harit agarwal
just send the inorder and preorder traversal of binary tree to other process and recontruct it. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this

Re: [algogeeks] Explain the output

2010-06-08 Thread harit agarwal
@jitendra u got it right but parent and child are using the same text region that's why control is transferring back and forth.. try running this code and see that line numbers are repeating...because of same text region it is working like a loop... #includestdio.h int main() { int id,i;

Re: [algogeeks]

2010-06-05 Thread harit agarwal
if the array contains only numbers 1 to n then it can be done in O(n) inplace otherwise only way is hashing or sorting.which is trivial solution... -- 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] Find the number with maximum frequency in an array. Better than O(nlogn + n) time complexity

2010-06-01 Thread harit agarwal
see this .vote majority algorithm.. http://userweb.cs.utexas.edu/~moore/best-ideas/mjrty/index.html -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this

Re: [algogeeks] Where does OS scheduling run??

2010-05-02 Thread harit agarwal
although CPU is busy in exexcution...it check's its registers values for the pending interrupts .. if any interrupt is pending at the end of the current CPU cycle...it shedules the interrupt handler to further execute the interrupt subroutine... -- You received this message because you are

Re: [algogeeks] Implement a Queue using a stack

2010-02-11 Thread harit agarwal
but logic remains the same here...instead of own stack.system stack is being usedso wat's d difference. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To

Re: [algogeeks] Dijkstra For Longest Path?

2010-01-15 Thread harit agarwal
dijkstra can be applied for longest pathif there is no cycle.. now assuming that it is directed acyclic graph(DAG) if u multiply all weights by -1...means all weights are negative..then apply dijkstra for shortest path and u will get your answer -- You received this message because you

Re: [algogeeks] Linear time sieve

2009-11-29 Thread harit agarwal
read this http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to

Re: [algogeeks] Horse race

2009-11-06 Thread harit agarwal
why the 7th race is doneand also it might be the case that E group contains the fastest three then how it is done?? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. For more

Re: [algogeeks] Re: aai + bj + ck =0

2009-11-03 Thread harit agarwal
@anilkumarmylayr second step is n^2 logn so yr algo is O(n^2logn) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. For more options, visit this group at

[algogeeks] Re: find the index of a number in a sorted array

2009-10-25 Thread harit agarwal
the only other way can be the jump exponentially during search as in binary search a[mid] is checked so if a[mid]!=x then make low=highest index of a[mid]!=x this will reduce the comparisionsin binary search ex-1,1,1,2,2,2,3,3,3,4,4,5,5(13 elements) let's search for 4 modify binary search

[algogeeks] Re: How to find number of Cycles in a Graph...

2009-10-21 Thread harit agarwal
number of back egdes in DFS=number of cycles --~--~-~--~~~---~--~~ 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

[algogeeks] Re: 100!

2009-10-15 Thread harit agarwal
no use of all these logics.u have 2 calculate whole value of 100! for summation... use link list to store final value...after ever product... --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Algorithm Geeks group.

[algogeeks] Re: Interesting array multiplication problem

2009-10-11 Thread harit agarwal
@Debanjan really nice solution --~--~-~--~~~---~--~~ 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: Interesting array multiplication problem

2009-10-10 Thread harit agarwal
traverse the array once and ge product of all elements , this is dividend now again traverse for each a[i] do division(divisor,a[i]) code for division without using / #includestdio.h int dividend, divisor, remainder; /* Division function Computes the quotient and remainder of two numbers using

[algogeeks] Re: Design a stack to perform push(), pop() and retrieve minimum in constant time.

2009-10-07 Thread harit agarwal
question is just to retrieve minimum element and not to do any operation like push pop on it so do one thing push the element on stack with one more data member that contains minimum number seen till now...that will be enough[?] --~--~-~--~~~---~--~~ You

[algogeeks] Re: Traversing a binary tree from bottom to top

2009-10-03 Thread harit agarwal
try this do the DFS analogous traversal on the tree.means 1.set level=1,push root 2.pop root 3.push both children on stack and set increment level . 4.now pop top and recursively do the same thing every time u pop an element enque it in a max priority queue according to level when

[algogeeks] Re: second highest elemt in an aary

2009-09-29 Thread harit agarwal
in my codei am doing the same thing the winner is compared to the new player and saved as winner and previous winner is also stored in another variable...so comparisions r same. --~--~-~--~~~---~--~~ You received this message because you are subscribed

[algogeeks] Re: second highest elemt in an aary

2009-09-28 Thread harit agarwal
It will take n comparisons.observe this code #includeiostream using namespace std; int sec_largest(int ar[],int n) { int i,max=-32767,sec_max=0; for(i=0;in;i++) { if(ar[i]max) { sec_max=max;