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 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 O(logN). > > On Sun, Jan 2

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 wrote: > not possible unless u use augmented bst..which itself takes o(n) to built > > -- > > > -- Praveen Sonare +91

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 wrote: > not possible unless u use augmented bst..which itself takes o(n) to built > > -- > > > --

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 --

[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 --

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 wrote: > Reversing a linked list if loop exists: > > 1. Find the node from which loop start by any loop findi

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

[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 reverse

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

2012-07-02 Thread atul anand
@amol : algo seems to work but will fail if size of arr increases. int arr[]={21,2,7,9,20,15,3,5,0,17,11,12,13,14,1,8,10,4,19,6,18,16}; it will fail for above case. if we u run outer loop one more time then it will work fine. So there should be some relation b/w number of elements and minimum numbe

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 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-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 wrote: > i don't see any change in t

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

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

2012-07-02 Thread atul anand
@amol : #include 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;ihttp://groups.google.com/group/algogeeks?hl=en.

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

2012-07-02 Thread Amol Sharma
zeof(a)/sizeof(int)); >>>>> >>>>> copy(a,a+sizeof(a)/sizeof(int),ostream_iterator(cout,","));cout<>>>> >>>>> } >>>>> >>>>> >>>>> Regards >>>>> >>>>> On F

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

2012-07-01 Thread Hassan Monfared
On Fri, Jun 29, 2012 at 7:52 PM, utsav sharma >>> > wrote: >>>> >>>>> @bhaskar:- please explain stable sorting algorithm you would use(as >>>>> mainly all of them require extra space) >>>>> @sourabh:- that previous post discussion does't lead to

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

2012-07-01 Thread atul anand
>>>> On Fri, Jun 29, 2012 at 8:39 PM, Bhaskar Kushwaha < >>>> bhaskar.kushwaha2...@gmail.com> wrote: >>>> >>>>> @saurabh please provide the link to the post you are mentioning >>>>> >>>>> On Fri, Jun 29, 2012 at

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

2012-07-01 Thread Amol Sharma
>> for(int i=1;i>> >>>> if(pdata[i-1]>0 && pdata[i]<0) >>> >>>> { >>> >>>> swap(pdata[i-1], pdata[i]); >>> >>>> changed=true; >>> >>>> } >>> >>>> }while(changed)

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

2012-07-01 Thread shiva@Algo
;>> } >> >>>> }while(changed); >> >>>> } >> >>>> >> >>>> void test_inplace_pos_neg() >> >>>> { >> >>>> int a[]={-1,-5,10,11,15,-500,200,-10}; >> >>>> >> >>>

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

2012-07-01 Thread shiva@Algo
; > >>>> > >>>> > copy(a,a+sizeof(a)/sizeof(int),ostream_iterator(cout,","));cout< >>>> > >>>> } > >>>> > >>>> > >>>> Regards > >>>> > >>>> On Fri, Jun 29,

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

2012-07-01 Thread Bhaskar Kushwaha
utsav sharma >>>> wrote: >>>> >>>>> @bhaskar:- please explain stable sorting algorithm you would use(as >>>>> mainly all of them require extra space) >>>>> @sourabh:- that previous post discussion does't lead to any correct >>&

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

2012-07-01 Thread Darpan Baweja
>>>> >>>> On Fri, Jun 29, 2012 at 8:39 PM, Bhaskar Kushwaha < >>>> bhaskar.kushwaha2...@gmail.com> wrote: >>>> >>>>> @saurabh please provide the link to the post you are mentioning >>>>> >>>>> On F

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

2012-07-01 Thread Amol Sharma
gt;>>>> If the order is important then I think we can use any stable sorting >>>>> algorithm with the following comparison function >>>>> >>>>> int compare (int a ,int b) >>>>> { >>>>> if((a>0&&b>0)

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

2012-06-29 Thread Bhaskar Kushwaha
t;>>> if((a>0&&b>0)||(a<0&&b<0)) return 0; >>>> else return a>>> } >>>> On Fri, Jun 29, 2012 at 3:37 PM, raghavan M < >>>> peacelover1987...@yahoo.co.in> wrote: >>>> >>>>> This is a v

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

2012-06-29 Thread Hassan Monfared
&&b>0)||(a<0&&b<0)) return 0; >>> else return a>> } >>> On Fri, Jun 29, 2012 at 3:37 PM, raghavan M < >>> peacelover1987...@yahoo.co.in> wrote: >>> >>>> This is a variant of that one >>>> >>&g

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

2012-06-29 Thread utsav sharma
gt; This is a variant of that one >>> >>> ------ >>> *From:* saurabh singh >>> *To:* algogeeks@googlegroups.com >>> *Sent:* Friday, 29 June 2012 3:05 PM >>> >>> *Subject:* Re: [algogeeks] MS Que

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

2012-06-29 Thread Bhaskar Kushwaha
m:* saurabh singh >> *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 refe

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

2012-06-29 Thread Bhaskar Kushwaha
--- > *From:* saurabh singh > *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 r

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 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 raghavan M
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 are subscrib

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 wrote: > 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 p

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 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 wrote: > Hi > Question as in subject > > *No extra space (can use one extra space)-O(1) max > *No order change

[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 a

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 wrote: > class lock > { > enum{"read", "write","free"}status; > }; > By default, make status value as "free". > Based on the request,

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, As

[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, se

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

2012-06-27 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 th

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 wrote: > make size of both array by adding '0' in front of smaller array > then > int carry=0; > for(i=array.

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 wrote: > MSB is at end or at the last of the array .. ?? > > On Tue, Jun 26, 2012 at 5:43 PM, saurabh singh wrote: > >> ^ Does it make any difference? >> Saurabh Singh >> B.Tech (Computer Science) >> MN

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 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 wrote: > >>

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

2012-06-26 Thread amrit harry
make size of both array by adding '0' in front of smaller array then int carry=0; for(i=array.size();i>=0;i--) { sum[i]=carry+arrayA[i]+arrayB[i]; carry=sum[i]/10; sum[i]=sum[i]%10; } then reverse and print sum On Tue, Jun 26, 2012 at 3:40 PM, Ashish Goel wrote: > > Best Regards > Ashish Goel > "

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 wrote: > whether it is in character array or integer array?? > > > On Tue, Jun 26, 2012 at 3:40 PM, Ashish Goel wrote: > >> >> Best Re

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 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 Groups >

[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, se

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 wrote: > >> @all: >> >> In my code isntea

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 wrote: > @all: > > In my code isntead of (!IsEmptyStack) use IsEmptyStack > > Logic : > > First pop the all element and then start putting element at bott

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 Nishant Pandey
i think i already explained the logic initially :) On Thu, Jun 14, 2012 at 9:30 PM, Hassan Monfared wrote: > how can you pop from empty stack ? > " temp=pop(S); " > > Regards, > Hassan > > On Thu, Jun 14, 2012 at 8:25 PM, Ashish Goel wrote: > >> Navin: copy pastes not encouraged till the logic

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 wrote: > 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 wrote: > >>

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 P

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 wrote: > Navin: copy pastes not encouraged till the logic is also clarified ;) > > Best Regards > Ashish Goel > "Think positive and find fuel in failure" > +919985813081 > +919966006

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 wrote: > @ Navin Kumar > > Nice . Solution. > But > your function also make a stac

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 wrote: > void Reverse(struct Stack *S) { > int data; > if(IsEmptyStack(S)) return; > d

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); Ins

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 wrote: > > Best Regards > Ashish Goel > "Think positive and find fuel in failure" > +919985813081 > +919966006652 > > -- > You received this messag

[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, se

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 wrote: > 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 } > > ta

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-

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 wrote: > WAP to find a word in a 2D array. The word can be formed on > row/col/diagnal/reverse diagnal > > Best Regar

[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 pos

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 wrote: > here is the question ans solution with p

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

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

2012-06-02 Thread Ashish Goel
[algogeeks] 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 wrote: > ls-r implemen

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 wrote: > > > #include > #include > #include > #include > #include > #include > #include > > void dirfun(char *); > > > int main() > { > > char *home="/home/nav

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

2012-06-02 Thread Navin Kumar
#include #include #include #include #include #include #include void dirfun(char *); int main() { char *home="/home/navin/temp/"; dirfun(home); return 0; } void dirfun(char *path) { struct dirent *dir; DIR *dp= opendir(path); if(dp!=NULL)

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 wrote: > ls-r implementation needed... > > > Best Regards > Ashish Goel > "Think positive and find fuel in

[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: 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 wrote: > @navin : +1 > > On 5/31/12, Navin Kuma

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 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 wrote: > >> that is what i have done by using recursion<=>stack.

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 wrote: > that is what i have done by using recursion<=>stack. > > my code has problem, after free(pCurr);, i shoul

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 wrote: > that is what i have done by using recursion<=>stack. > > my code has problem, after free(pCurr);, i should

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 wrote: > then i guess ...it can

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 pop

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 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 3 4 7 12 > > del

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 wrote: > the LL is unsorted, is there a

[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; i

[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

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 memor

[algogeeks] MS Question

2012-03-30 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}. Suppos

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

2012-01-23 Thread Dhaval Patel
NODEPTR krev(NODEPTR head,int k) { NODEPTR current=head; NODEPTR prev=NULL; NODEPTR next; int cnt=0; while(current!=NULL&&cntnext; current->next=prev; prev=current; current=next; cnt++; } if(head!=NULL) head->next=krev(current,k); return prev; } here k=2 -- You received this message because y

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 th

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 wrote: > node *ptr =head; > > //function call is reverse(head,NULL) > > void reverse(node *ptr, node *follow) > {

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; } ptr->ne

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 wrote: > 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 wrote: > >> Say LL is >> >> 1->2->3->4->5->6->7->8 >> >>

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

2012-01-23 Thread atul anand
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 wrote: > 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

[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@googleg

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. fo

[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 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 wrote: > @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>

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

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 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 wrote: > Is there anything called in-place reversal ?? > UTF-8 is only encoding similar to ASCII but with a huge charecter set. > So normal string revers

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 wrote: > How to do this > > Write a function to reverse a UTF-8 encoded string in-place ??

[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 alg

[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 == a[i][

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 wrote: > 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 >

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 Go

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 wrote: > do the inorder traversal as s

  1   2   >