Re: [algogeeks] MS Question

2013-01-22 Thread Amitesh Singh
you can't implement in O(log n). It can be done in O(log n) in case of Ranked BS Tree. -- Amitesh On Sun, Jan 20, 2013 at 6:23 PM, Praveen praveensonare...@gmail.com wrote: If for all the nodes in BST we also store the size of subtree, then it is possible to find nth smallest element in

Re: [algogeeks] MS Question

2013-01-20 Thread Guneesh Paul Singh
not possible unless u use augmented bst..which itself takes o(n) to built --

Re: [algogeeks] MS Question

2013-01-20 Thread Mohanabalan D B
http://stackoverflow.com/questions/2329171/find-kth-smallest-element-in-a-binary-search-tree-in-optimum-way On Sun, Jan 20, 2013 at 4:57 PM, Guneesh Paul Singh gunees...@gmail.comwrote: not possible unless u use augmented bst..which itself takes o(n) to built -- --

Re: [algogeeks] MS Question

2013-01-20 Thread Praveen
If for all the nodes in BST we also store the size of subtree, then it is possible to find nth smallest element in O(logN). On Sun, Jan 20, 2013 at 4:57 PM, Guneesh Paul Singh gunees...@gmail.comwrote: not possible unless u use augmented bst..which itself takes o(n) to built -- --

[algogeeks] MS Question

2013-01-19 Thread Umer Farooq
Given a BST, how would you return the nth smallest element. The code had to cover all the edge cases and was expected to write a logn solution. -- Umer --

[algogeeks] MS QUESTION

2012-08-24 Thread sulekha metta
Hi all, This was asked in microsoft, question is write a program to reverse a linked list.and write it's test cases. i got very few test cases 1) check if the node is null 2) check if there is only one node 3) check if there is any loop in the linked list. can any one tell how to

Re: [algogeeks] MS QUESTION

2012-08-24 Thread Navin Kumar
Reversing a linked list if loop exists: 1. Find the node from which loop start by any loop finding algorithm in linked list and keep the position of that node. 2. Unroll the loop i.e. set the last node's(last unrepeating node) next pointer to NULL. 3. Reverse this singly linked list. 4. Change

Re: [algogeeks] MS QUESTION

2012-08-24 Thread Navin Kumar
Few more Test cases : Check for 10 node. Check for 1 million node Check for even number of nodes Check for odd number of nodes... etc etc... On Fri, Aug 24, 2012 at 6:25 PM, Navin Kumar algorithm.i...@gmail.comwrote: Reversing a linked list if loop exists: 1. Find the node from which loop

Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-07-02 Thread atul anand
peacelover1987...@yahoo.co.in wrote: This is a variant of that one -- *From:* saurabh singh saurab...@gmail.com *To:* algogeeks@googlegroups.com *Sent:* Friday, 29 June 2012 3:05 PM *Subject:* Re: [algogeeks] MS Question: Segregrate positive and negative nos

Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-07-02 Thread Hassan Monfared
-- *From:* saurabh singh saurab...@gmail.com *To:* algogeeks@googlegroups.com *Sent:* Friday, 29 June 2012 3:05 PM *Subject:* Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order duplicate of a previous post.Kindly refer

Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-07-02 Thread Amol Sharma
; } On Fri, Jun 29, 2012 at 3:37 PM, raghavan M peacelover1987...@yahoo.co.in wrote: This is a variant of that one -- *From:* saurabh singh saurab...@gmail.com *To:* algogeeks@googlegroups.com *Sent:* Friday, 29 June 2012 3:05 PM *Subject:* Re: [algogeeks] MS Question

Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-07-02 Thread atul anand
@amol : #includestdio.h int main() { int arr[]={5,0,1,2,6,7,8,3,4,9}; int i,j,n,temp; n=sizeof(arr)/sizeof(arr[0]); for(j=0;j=1;j++) { for(i=0;in;i++) { if(arr[i]!=i){ temp=arr[i]; arr[i]=arr[arr[i]];

Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-07-02 Thread Amol Sharma
i don't see any change in the code you posted...other than expanding swap function i believe in discussing the idea/algonot the code.. -- Amol Sharma Final Year Student Computer Science and Engineering MNNIT Allahabad http://gplus.to/amolsharma99

Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-07-02 Thread atul anand
yes it is same and it not working . Apart for this you had provided code for sorting O(n) time and not the idea/algo. please explain the algorithm , how you are sorting it within O(n) time and O(1) space complexity. On Mon, Jul 2, 2012 at 3:18 PM, Amol Sharma amolsharm...@gmail.com wrote: i

Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-07-02 Thread atul anand
opssyeah dat was the bug... now got it :) On Mon, Jul 2, 2012 at 4:08 PM, Amol Sharma amolsharm...@gmail.com wrote: @atul: the logic for the O(n) counting is same as for the count sort. you haven't write the swap function correctly, here is correct code for swap function --

Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-07-01 Thread Amol Sharma
: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order duplicate of a previous post.Kindly refer to that post. Saurabh Singh B.Tech (Computer Science) MNNIT blog:geekinessthecoolway.blogspot.com On Fri, Jun 29, 2012 at 10:41 AM, raghavan M peacelover1987

Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-07-01 Thread Darpan Baweja
PM, raghavan M peacelover1987...@yahoo.co.in wrote: This is a variant of that one -- *From:* saurabh singh saurab...@gmail.com *To:* algogeeks@googlegroups.com *Sent:* Friday, 29 June 2012 3:05 PM *Subject:* Re: [algogeeks] MS Question: Segregrate positive

Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-07-01 Thread Bhaskar Kushwaha
saurab...@gmail.com *To:* algogeeks@googlegroups.com *Sent:* Friday, 29 June 2012 3:05 PM *Subject:* Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order duplicate of a previous post.Kindly refer to that post. Saurabh Singh B.Tech (Computer Science

Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-07-01 Thread shiva@Algo
: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order duplicate of a previous post.Kindly refer to that post. Saurabh Singh B.Tech (Computer Science) MNNIT blog:geekinessthecoolway.blogspot.com On Fri, Jun 29, 2012 at 10:41 AM, raghavan M

Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-07-01 Thread shiva@Algo
-- *From:* saurabh singh saurab...@gmail.com *To:* algogeeks@googlegroups.com *Sent:* Friday, 29 June 2012 3:05 PM *Subject:* Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order duplicate of a previous post.Kindly

Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-07-01 Thread Amol Sharma
-- *From:* saurabh singh saurab...@gmail.com *To:* algogeeks@googlegroups.com *Sent:* Friday, 29 June 2012 3:05 PM *Subject:* Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order duplicate of a previous post.Kindly refer to that post

[algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-06-29 Thread raghavan M
Hi Question as in subject *No extra spaceĀ (can use one extra space)-O(1) max *No order change allowed example: input : 1,-5,2,10,-100,-2 output: -5,-10,-100,1,2 input : -1,-5,10,11,15,-500,200,-10 output : -1,-5,-10,-500,-10,10,11,15 Thanks Raghavn -- You received this message because you

Re: [algogeeks] MS Question :implement read write lock class

2012-06-29 Thread Mithun Kumar
This link should help http://stackoverflow.com/questions/5667793/how-does-a-read-write-mutex-lock-work?rq=1 -mithun On Fri, Jun 29, 2012 at 7:30 AM, bharat b bagana.bharatku...@gmail.comwrote: class lock { enum{read, write,free}status; }; By default, make status value as free. Based

Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-06-29 Thread saurabh singh
duplicate of a previous post.Kindly refer to that post. Saurabh Singh B.Tech (Computer Science) MNNIT blog:geekinessthecoolway.blogspot.com On Fri, Jun 29, 2012 at 10:41 AM, raghavan M peacelover1987...@yahoo.co.inwrote: Hi Question as in subject *No extra space (can use one extra

Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-06-29 Thread Ravi Ranjan
one can modify dutch national flag algo for two colors(2 types positive n negative) -- 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] MS Question: Segregrate positive and negative nos in array without changing order

2012-06-29 Thread adarsh kumar
Quick sort partition routine variation. On Fri, Jun 29, 2012 at 3:06 PM, Ravi Ranjan ravi.cool2...@gmail.comwrote: one can modify dutch national flag algo for two colors(2 types positive n negative) -- You received this message because you are subscribed to the Google Groups Algorithm

Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-06-29 Thread raghavan M
To: algogeeks@googlegroups.com Sent: Friday, 29 June 2012 3:06 PM Subject: Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order one can modify dutch national flag algo for two colors(2 types positive n negative) -- You received this message because you

Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-06-29 Thread raghavan M
This is a variant of that one From: saurabh singh saurab...@gmail.com To: algogeeks@googlegroups.com Sent: Friday, 29 June 2012 3:05 PM Subject: Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order duplicate

Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-06-29 Thread Bhaskar Kushwaha
of that one -- *From:* saurabh singh saurab...@gmail.com *To:* algogeeks@googlegroups.com *Sent:* Friday, 29 June 2012 3:05 PM *Subject:* Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order duplicate of a previous

Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-06-29 Thread Bhaskar Kushwaha
:* Friday, 29 June 2012 3:05 PM *Subject:* Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order duplicate of a previous post.Kindly refer to that post. Saurabh Singh B.Tech (Computer Science) MNNIT blog:geekinessthecoolway.blogspot.com On Fri, Jun

Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-06-29 Thread utsav sharma
*Subject:* Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order duplicate of a previous post.Kindly refer to that post. Saurabh Singh B.Tech (Computer Science) MNNIT blog:geekinessthecoolway.blogspot.com On Fri, Jun 29, 2012 at 10:41 AM

Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-06-29 Thread Hassan Monfared
:05 PM *Subject:* Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order duplicate of a previous post.Kindly refer to that post. Saurabh Singh B.Tech (Computer Science) MNNIT blog:geekinessthecoolway.blogspot.com On Fri, Jun 29, 2012 at 10:41

Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order

2012-06-29 Thread Bhaskar Kushwaha
*Subject:* Re: [algogeeks] MS Question: Segregrate positive and negative nos in array without changing order duplicate of a previous post.Kindly refer to that post. Saurabh Singh B.Tech (Computer Science) MNNIT blog:geekinessthecoolway.blogspot.com On Fri, Jun 29, 2012 at 10:41 AM, raghavan M

Re: [algogeeks] MS Question: Add two large numbers where the numbers are stored in an array format

2012-06-28 Thread Lomash Goyal
we can create linked list for the number where each node will store some k digits (say 5) in the reverse order.then we just perform a normal addition of the data of the nodes with the help of carry. note that if the numbers are not positive then we need to maintain a sign bit node also.if any of

[algogeeks] MS Question :implement read write lock class

2012-06-28 Thread Ashish Goel
Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 -- 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

Re: [algogeeks] MS Question :implement read write lock class

2012-06-28 Thread bharat b
class lock { enum{read, write,free}status; }; By default, make status value as free. Based on the request, status value will be changed... Based on the value of the status, we should decide whether another read/write lock can be given. Any suggestions ? On Thu, Jun 28, 2012 at 4:46 PM, Ashish

[algogeeks] MS Question: Add two large numbers where the numbers are stored in an array format

2012-06-26 Thread Ashish Goel
Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 -- 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

Re: [algogeeks] MS Question: Add two large numbers where the numbers are stored in an array format

2012-06-26 Thread Navin Kumar
whether it is in character array or integer array?? On Tue, Jun 26, 2012 at 3:40 PM, Ashish Goel ashg...@gmail.com wrote: Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 -- You received this message because you are subscribed to the Google

Re: [algogeeks] MS Question: Add two large numbers where the numbers are stored in an array format

2012-06-26 Thread saurabh singh
^ Does it make any difference? Saurabh Singh B.Tech (Computer Science) MNNIT blog:geekinessthecoolway.blogspot.com On Tue, Jun 26, 2012 at 5:32 PM, Navin Kumar algorithm.i...@gmail.comwrote: whether it is in character array or integer array?? On Tue, Jun 26, 2012 at 3:40 PM, Ashish Goel

Re: [algogeeks] MS Question: Add two large numbers where the numbers are stored in an array format

2012-06-26 Thread Kumar Vishal
MSB is at end or at the last of the array .. ?? On Tue, Jun 26, 2012 at 5:43 PM, saurabh singh saurab...@gmail.com wrote: ^ Does it make any difference? Saurabh Singh B.Tech (Computer Science) MNNIT blog:geekinessthecoolway.blogspot.com On Tue, Jun 26, 2012 at 5:32 PM, Navin Kumar

Re: [algogeeks] MS Question: Add two large numbers where the numbers are stored in an array format

2012-06-26 Thread Kumar Vishal
I mean 123 is store as 1,2,3 or 3,2,1 On Tue, Jun 26, 2012 at 6:01 PM, Kumar Vishal kumar...@gmail.com wrote: MSB is at end or at the last of the array .. ?? On Tue, Jun 26, 2012 at 5:43 PM, saurabh singh saurab...@gmail.comwrote: ^ Does it make any difference? Saurabh Singh

Re: [algogeeks] MS Question: Add two large numbers where the numbers are stored in an array format

2012-06-26 Thread Ashish Goel
the base is not given, so 10 can't be assumed Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Tue, Jun 26, 2012 at 4:38 PM, amrit harry dabbcomput...@gmail.comwrote: make size of both array by adding '0' in front of smaller array then int

Re: [algogeeks] MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-17 Thread algogeek
This solution works perfectly :) On Friday, June 15, 2012 10:59:22 AM UTC+5:30, Navin Kumar wrote: I corrected in function InsertAtBottom :In my code isntead of (!IsEmptyStack) use IsEmptyStack On Fri, Jun 15, 2012 at 10:49 AM, Navin Kumar algorithm.i...@gmail.comwrote: @all: In my

[algogeeks] MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-14 Thread Ashish Goel
Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 -- 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

Re: [algogeeks] MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-14 Thread rahul patil
to store items in stack you will need some DS. Do they mean you cant use any auxillary DS than stack ? On Thu, Jun 14, 2012 at 2:24 PM, Ashish Goel ashg...@gmail.com wrote: Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 -- You received this

Re: [algogeeks] MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-14 Thread Navin Kumar
void Reverse(struct Stack *S) { int data; if(IsEmptyStack(S)) return; data=pop(s); ReverseStack(S); InsertAtBottom(S, data); } void InsertAtBottom(struct stack *S, int data) { int temp; if(!IsEmptyStack(S)){ push(S,data); return; } temp=pop(S);

Re: [algogeeks] MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-14 Thread Sourabh Singh
@ Navin Kumar Nice . Solution. But your function also make a stack only. so you are using a stack[internal] here. but may be this one is allowed:-) On Thu, Jun 14, 2012 at 5:23 AM, Navin Kumar algorithm.i...@gmail.comwrote: void Reverse(struct Stack *S) { int data;

Re: [algogeeks] MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-14 Thread Ashish Goel
Navin: copy pastes not encouraged till the logic is also clarified ;) Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Thu, Jun 14, 2012 at 7:25 PM, Sourabh Singh singhsourab...@gmail.comwrote: @ Navin Kumar Nice . Solution. But your

Re: [algogeeks] MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-14 Thread Hassan Monfared
how can you pop from empty stack ? temp=pop(S); Regards, Hassan On Thu, Jun 14, 2012 at 8:25 PM, Ashish Goel ashg...@gmail.com wrote: Navin: copy pastes not encouraged till the logic is also clarified ;) Best Regards Ashish Goel Think positive and find fuel in failure +919985813081

Re: [algogeeks] MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-14 Thread Lomash Goyal
void pushreverse(int data) { int temp; if(top==0) { push(data); return; } else temp=pop(); pushreverse(data); push(temp); } int reversestack() { //static int arr[50]; int top2=0; int i; if(top==0) { return top2; } top2=pop(); reversestack(); pushreverse(top2); } On Thu, Jun 14, 2012 at 2:44

Re: [algogeeks] MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-14 Thread Karthikeyan V.B
Hi all, Generate combinations (taken k out of n) of a given string Eg: Input : abcd Output: abc acd abd bcd -- 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

Re: [algogeeks] MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-14 Thread Nishant Pandey
the steps would be like this : if i say stack is like this 1,2,3,4 then 1) pop each and every item from the stack till stack is empty the nodes will be ther in function call stack stil not pushed 2) now now take elements from function call stack like 4 and push it 3) when 3 comes next time first

Re: [algogeeks] MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-14 Thread Nishant Pandey
stack means inbuild stack we cant use any DS from our program explicitly. On Thu, Jun 14, 2012 at 2:44 PM, rahul patil rahul.deshmukhpa...@gmail.comwrote: to store items in stack you will need some DS. Do they mean you cant use any auxillary DS than stack ? On Thu, Jun 14, 2012 at 2:24 PM,

Re: [algogeeks] MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-14 Thread Nishant Pandey
i think i already explained the logic initially :) On Thu, Jun 14, 2012 at 9:30 PM, Hassan Monfared hmonfa...@gmail.comwrote: how can you pop from empty stack ? temp=pop(S); Regards, Hassan On Thu, Jun 14, 2012 at 8:25 PM, Ashish Goel ashg...@gmail.com wrote: Navin: copy pastes not

Re: [algogeeks] MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-14 Thread Navin Kumar
@all: In my code isntead of (!IsEmptyStack) use IsEmptyStack Logic : First pop the all element and then start putting element at bottom in reverse order i.e. the element which is fetched last is put at the bottom and so on. ex: let our stack is: 1 2 3 4 (1 is at bottom). function Call is will

Re: [algogeeks] MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-14 Thread Navin Kumar
I corrected in function InsertAtBottom :In my code isntead of (!IsEmptyStack) use IsEmptyStack On Fri, Jun 15, 2012 at 10:49 AM, Navin Kumar algorithm.i...@gmail.comwrote: @all: In my code isntead of (!IsEmptyStack) use IsEmptyStack Logic : First pop the all element and then start putting

Re: [algogeeks] MS Question : find word in 2D array

2012-06-09 Thread Bhaskar Kushwaha
@utsav u haven't initialized match anywhere so ur algo fails On Thu, Jun 7, 2012 at 2:50 AM, utsav sharma utsav.sharm...@gmail.comwrote: i think it can be solved using DP word=bcdf take hash of word h[b]=1 h[c]=2 h[d]=3 h[f]=4 given 2d matrix m[][]= {b c b e f g h b c d f p o u d f d

[algogeeks] MS Question : find word in 2D array

2012-06-06 Thread Ashish Goel
WAP to find a word in a 2D array. The word can be formed on row/col/diagnal/reverse diagnal Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post

Re: [algogeeks] MS Question : find word in 2D array

2012-06-06 Thread atul anand
i did this question long time back well simple brute force check can be doneyou can keep one flag matrix of same size to avoid necessary recursion. On 6/6/12, Ashish Goel ashg...@gmail.com wrote: WAP to find a word in a 2D array. The word can be formed on row/col/diagnal/reverse

Re: [algogeeks] MS Question : find word in 2D array

2012-06-06 Thread utsav sharma
i think it can be solved using DP word=bcdf take hash of word h[b]=1 h[c]=2 h[d]=3 h[f]=4 given 2d matrix m[][]= {b c b e f g h b c d f p o u d f d f g k p } take another matrix match[][] if( h[ m[i][j] ] 0 ) //if this char is in word then {a=h[ m[i][j] ]; if (match[i-1][j] ==a-1

Re: [algogeeks] MS Question: Delete a node in single linked list if it is less than any of the successor nodes

2012-06-04 Thread Amol Sharma
here is the question ans solution with proper explanation http://www.geeksforgeeks.org/archives/11604 -- Amol Sharma Third Year Student Computer Science and Engineering MNNIT Allahabad http://gplus.to/amolsharma99

Re: [algogeeks] MS Question: Delete a node in single linked list if it is less than any of the successor nodes

2012-06-04 Thread atul anand
whats problem with the approch provided by navin http://k2code.blogspot.in/2011/09/deleting-node-in-singly-linked-list-if.html it seems much simpler ...is there any test case for which it wont work ?? On Mon, Jun 4, 2012 at 3:25 PM, Amol Sharma amolsharm...@gmail.com wrote: here is the

RE: [algogeeks] MS Question: WAP to find files in a

2012-06-03 Thread Ashish Goel
] MS Question: WAP to find files in a directory/subdirectories i wrote this program in college labbut used shell script to simulate ls -r functionality. now to do in c or java .. we only need to knw about the libraries to use. On 6/3/12, Ashish Goel ashg...@gmail.com wrote: ls-r implementation

[algogeeks] MS Question: WAP to find files in a directory/subdirectories

2012-06-02 Thread Ashish Goel
ls-r implementation needed... Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 -- 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] MS Question: WAP to find files in a directory/subdirectories

2012-06-02 Thread atul anand
i wrote this program in college labbut used shell script to simulate ls -r functionality. now to do in c or java .. we only need to knw about the libraries to use. On 6/3/12, Ashish Goel ashg...@gmail.com wrote: ls-r implementation needed... Best Regards Ashish Goel Think positive and

Re: [algogeeks] MS Question: WAP to find files in a directory/subdirectories

2012-06-02 Thread Navin Kumar
#include stdio.h #include stdlib.h #include sys/types.h #include dirent.h #include unistd.h #include ctype.h #include string.h void dirfun(char *); int main() { char *home=/home/navin/temp/; dirfun(home); return 0; } void dirfun(char *path) { struct dirent

Re: [algogeeks] MS Question: WAP to find files in a directory/subdirectories

2012-06-02 Thread Navin Kumar
you can set your directory path in this line char *home=/home/navin/temp/; On Sun, Jun 3, 2012 at 11:26 AM, Navin Kumar algorithm.i...@gmail.comwrote: #include stdio.h #include stdlib.h #include sys/types.h #include dirent.h #include unistd.h #include ctype.h #include string.h void

Re: [algogeeks] MS Question: Delete a node in single linked list if it is less than any of the successor nodes

2012-06-01 Thread Hassan Monfared
1- read all elements of list into stack 2- max = stak.pop() 3- if stack.empty() goto 7 4- next=stack.pop() 5- if next max then max=next else delete next from list 6- repeat from 3 7- end! Regards, On Thu, May 31, 2012 at 9:45 PM, atul anand atul.87fri...@gmail.com wrote: @navin : +1 On

[algogeeks] MS Question: Delete a node in single linked list if it is less than any of the successor nodes

2012-05-31 Thread Ashish Goel
the LL is unsorted, is there any better solution that this? struct node* deleteNodes(struct node *pHead, struct node *pPrev) { struct node *pLL = *pHead; if (!pLL) return NULL; struct node *pCurr = pLL; struct node *pRest = deleteNodes(pCurr-next, pCurr); if (!pRest) return pCurr;

Re: [algogeeks] MS Question: Delete a node in single linked list if it is less than any of the successor nodes

2012-05-31 Thread atul anand
@Ashish : please clarify this ques... delete a node in SLL if it is less than *any* of the succesor node .. 1 2 8 10 3 4 7 12 delete 1,2,8,10,3,4,7 ouput will be single node i.e 12 dats what question asks? On Thu, May 31, 2012 at 2:16 PM, Ashish Goel ashg...@gmail.com wrote: the LL is

Re: [algogeeks] MS Question: Delete a node in single linked list if it is less than any of the successor nodes

2012-05-31 Thread Ashish Goel
yes Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Thu, May 31, 2012 at 2:34 PM, atul anand atul.87fri...@gmail.com wrote: @Ashish : please clarify this ques... delete a node in SLL if it is less than *any* of the succesor node .. 1 2 8 10

Re: [algogeeks] MS Question: Delete a node in single linked list if it is less than any of the successor nodes

2012-05-31 Thread atul anand
then i guess ...it can be done using stack..with O(n) complexity.. it is similar to finding next greater element http://www.geeksforgeeks.org/archives/8405 element in the stack at the end of the algo...are the element which will remain in the linked list . if stack is not empty then keep

Re: [algogeeks] MS Question: Delete a node in single linked list if it is less than any of the successor nodes

2012-05-31 Thread Ashish Goel
that is what i have done by using recursion=stack. my code has problem, after free(pCurr);, i should have return pRest; Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Thu, May 31, 2012 at 4:37 PM, atul anand atul.87fri...@gmail.com wrote: then

Re: [algogeeks] MS Question: Delete a node in single linked list if it is less than any of the successor nodes

2012-05-31 Thread Navin Kumar
I think the easiest method to do this problem is this: http://k2code.blogspot.in/2011/09/deleting-node-in-singly-linked-list-if.html On Thu, May 31, 2012 at 5:58 PM, Ashish Goel ashg...@gmail.com wrote: that is what i have done by using recursion=stack. my code has problem, after

Re: [algogeeks] MS Question: Delete a node in single linked list if it is less than any of the successor nodes

2012-05-31 Thread Nishant Pandey
if i am getting this questions correctly then we have to delete the element till its next is not null ?? please comment if i am wrong ? On Thu, May 31, 2012 at 5:58 PM, Ashish Goel ashg...@gmail.com wrote: that is what i have done by using recursion=stack. my code has problem, after

Re: [algogeeks] MS Question: Delete a node in single linked list if it is less than any of the successor nodes

2012-05-31 Thread atul anand
@navin : +1 On 5/31/12, Navin Kumar algorithm.i...@gmail.com wrote: I think the easiest method to do this problem is this: http://k2code.blogspot.in/2011/09/deleting-node-in-singly-linked-list-if.html On Thu, May 31, 2012 at 5:58 PM, Ashish Goel ashg...@gmail.com wrote: that is what i have

[algogeeks] MS question : string compression

2012-05-25 Thread utsav sharma
Implement a method to perform basic string compression using the counts of repeated characters.(inplace) eg:- input: aaabcdef output:3a5b1c1d1e1f. what should be my approach to this problem if i calculate the size of array required to store the output string and start from the last of

Re: [algogeeks] MS Question

2012-04-01 Thread bharat b
First we divide the large memory into some chunks and we hash them. For each chunk, we need hash function. If a thread accesses a memory location, we find which chunk of address it is accessing, then we hash based on memory location. We can easily identify what are all threads are accessing a

[algogeeks] MS Question

2012-03-31 Thread Dheeraj Sharma
MS IDC interview question: Given a memory location say from 0 - 1023. Now there are many threads that are reading and writing in this memory locations at any time 0t 1t 2t ... and so on. For ex a thread no.4 is writing to memory location 512 at time 3t. So we get a quadruple {4,512,W,3t}.

[algogeeks] MS Question -Reverse a Linked List in size of 2

2012-01-23 Thread Ankur Garg
Say LL is 1-2-3-4-5-6-7-8 Then u need to return 7-8-5-6-3-4-1-2 U cant swap the values U have to rearrange the ptr... -- 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] MS Question -Reverse a Linked List in size of 2

2012-01-23 Thread Ankur Garg
wat if u have odd no of nodes On Tue, Jan 24, 2012 at 12:00 AM, atul anand atul.87fri...@gmail.comwrote: one simple way would be using stacks. push node,node-next; then pop() , and reversing the pointers. On Mon, Jan 23, 2012 at 11:46 PM, Ankur Garg ankurga...@gmail.com wrote: Say LL is

Re: [algogeeks] MS Question -Reverse a Linked List in size of 2

2012-01-23 Thread Arun Vishwanathan
node *ptr =head; //function call is reverse(head,NULL) void reverse(node *ptr, node *follow) { if(ptr-next!=NULL ptr-next-next!=NULL) reverse(ptr-next-next,ptr); else if(ptr-next!=NULL ptr-next-next==NULL) { ptr-next-next=follow; head=ptr; }

Re: [algogeeks] MS Question -Reverse a Linked List in size of 2

2012-01-23 Thread Ankur Garg
Well for odd cases its lile this 1 -2-3-4-5 4-5-2-3-1 Also u have to do this in single pass..U can use recursion though On Tue, Jan 24, 2012 at 12:18 AM, Arun Vishwanathan aaron.nar...@gmail.comwrote: node *ptr =head; //function call is reverse(head,NULL) void reverse(node *ptr, node

Re: [algogeeks] MS Question -Reverse a Linked List in size of 2

2012-01-23 Thread Dhaval Patel
struct node* revll(struct node* root) { return reverse(root,NULL); } struct node* reverse(struct node* head,struct node* prev) { struct node* temp1; if(head-next==NULL) { head-next=prev; return head; } else { temp1=reverse(head-next,head); head-next=prev; return temp1; } } -- You received this

Re: [algogeeks] MS question

2012-01-19 Thread bharat b
Assumption here is that we can use 4K memory other than considering the actual elements storage memory. we were given the range of elements.. we can use count sort. for first case, all elements are unique -- we can use 27000 bits to represent the corresponding numbers== takes 3375 Bytes 4KB. for

[algogeeks] MS question

2012-01-18 Thread Arun Vishwanathan
Given large number of elements. All elements belong to range 1 to 27000. First case no elements repeated and second case elements are repeated. memory capacity is 4k. How to sort efficiently? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To

Re: [algogeeks] MS Question

2012-01-14 Thread payal gupta
@himanshu thnx..:) Regards, PAYAL GUPTA, 3rd YR ,CSE, NIT-BHOPAL. On Fri, Jan 13, 2012 at 9:42 PM, Himanshu Neema potential.himansh...@gmail.com wrote: Let a color below represent a single character in UTF-8 encoding , which means that each color can span multiple bytes , In example below I

Re: [algogeeks] MS Question

2012-01-14 Thread Ankur Garg
@Himanshu Nice idea..that shud do..but how do we code that ? regards Ankur On Sat, Jan 14, 2012 at 2:23 PM, payal gupta gpt.pa...@gmail.com wrote: @himanshu thnx..:) Regards, PAYAL GUPTA, 3rd YR ,CSE, NIT-BHOPAL. On Fri, Jan 13, 2012 at 9:42 PM, Himanshu Neema

Re: [algogeeks] MS Question

2012-01-13 Thread Himanshu Neema
Let a color below represent a single character in UTF-8 encoding , which means that each color can span multiple bytes , In example below I denote one byte by one english character . i.e. 'a' or 'b' or 'c' ,etc. below takes one byte : Let the string is : x abc def gh ij klmn now to reverse this

Re: [algogeeks] MS Question

2012-01-12 Thread b.kisha...@gmail.com
Is there anything called in-place reversal ?? UTF-8 is only encoding similar to ASCII but with a huge charecter set. So normal string reversal would work fine.. On Thu, Jan 12, 2012 at 2:02 AM, Ankur Garg ankurga...@gmail.com wrote: How to do this Write a function to reverse a UTF-8 encoded

Re: [algogeeks] MS Question

2012-01-12 Thread Supraja Jayakumar
Hi Normal string will not work I think. Because it is avriable length encoding scheme. On Fri, Jan 13, 2012 at 11:11 AM, b.kisha...@gmail.com b.kisha...@gmail.com wrote: Is there anything called in-place reversal ?? UTF-8 is only encoding similar to ASCII but with a huge charecter set. So

[algogeeks] MS Question

2012-01-11 Thread Ankur Garg
How to do this Write a function to reverse a UTF-8 encoded string in-place ?? -- 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] MS question

2011-10-02 Thread rahul sharma
if element is 0 in matrix then entire row and column should be set to 0 i got this from sumwhr void makeRowColZero(int (*a)[COL]) { int i, j, k; k = 0; for(i = 0; i ROW; i++) for(j = k; j COL; j++) { if(0 ==

Re: [algogeeks] MS Question - Median of a BST without using extra space and in O(n)

2011-09-28 Thread praneethn
convert bst to doubly linked list inorder and find middle element using slow and fast pointer concept On Tue, Sep 27, 2011 at 2:18 PM, Ankur Garg ankurga...@gmail.com wrote: I was thinking of making the tree balanced with equal no of nodes in left and right subtree Median will be

[algogeeks] MS Question - Median of a BST without using extra space and in O(n)

2011-09-27 Thread Ankur Garg
I was thinking of making the tree balanced with equal no of nodes in left and right subtree Median will be root in this case Regards Ankur -- 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] MS Question - Median of a BST without using extra space and in O(n)

2011-09-27 Thread anshu mishra
do the inorder traversal as soon as reached at n/2th element that will be median. -- 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] MS Question - Median of a BST without using extra space and in O(n)

2011-09-27 Thread Ankur Garg
@Anshu Will u be using extra space to store ur nodes in traversal ? On Tue, Sep 27, 2011 at 2:22 PM, anshu mishra anshumishra6...@gmail.comwrote: do the inorder traversal as soon as reached at n/2th element that will be median. -- You received this message because you are subscribed to

Re: [algogeeks] MS Question - Median of a BST without using extra space and in O(n)

2011-09-27 Thread Dheeraj Sharma
keep a global pointer and a global variable check=0 do inorder traversal..instead of printing the value do if(check==0) save pointer check==1 else check==0; correct me if m wrong On Tue, Sep 27, 2011 at 2:22 PM, anshu mishra anshumishra6...@gmail.comwrote: do the

Re: [algogeeks] MS Question - Median of a BST without using extra space and in O(n)

2011-09-27 Thread anshu mishra
int bstMedian(node *root, int n, int x) { if (node-left) return bstMedian(root-left, n, x); x++; if (x == n/2) return node-val; if (node-right) return bstMedian(root-right, n, x); } call bstMedian(root, n, 0); -- You received this message because you are subscribed to the Google

[algogeeks] MS question

2011-09-26 Thread Ankur Garg
Saw this question in one of the algo communities. Amazon telephonic interview question on Matrix Input is a matrix of size n x m of 0's and 1's. eg: 1 0 0 1 0 0 1 0 0 0 0 0 If a location has 1; make all the elements of that row and column = 1. eg 1 1 1 1 1 1 1 1 1 0 1 1 Solution should be with

  1   2   >