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 Q

2012-05-22 Thread Ashish Goel
// countIslands.cpp : Defines the entry point for the console application. // #include "stdafx.h" const int rows = 5; const int cols = 6; bool visited[rows][cols] = {0}; int arr[rows][cols] = { 0,0,0,0,1,1, 0,1,0,0,0,1, 1,1,0,0,0,0, 1,0,0,0,1,1, 0,0,1,0,1,0}; void initialize() { for (int i=0; i

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

2012-03-26 Thread Harjot singh
@atul anand: the question simply says that in each node the second should point to the next larger no. which means in your case 7 3 5 1 5 9 the output should be 7->9 5->7 3->5 1->3 On Mon, Mar 26, 2012 at 10:37 AM, Dheeraj Sharma < dheerajsharma1...@gmail.com> wrote: > Correct me if am wrong.. i

Re: [algogeeks] MS QUESTION_LINKED LIST

2012-03-25 Thread Dheeraj Sharma
Correct me if am wrong.. i think we can use Stack as follows node * minFun(node *head) { stack st; return fun(head,st); } node * fun(node *ptr,stack &st) { if(ptr) { node *x=fun(ptr->next,st); while(!st.empty() && (ptr->data)>(st.top()->data))

Re: [algogeeks] MS QUESTION_LINKED LIST

2012-03-24 Thread atul anand
after push(&s,next) move head also head=head->next; On Sun, Mar 25, 2012 at 12:10 AM, atul anand wrote: > @all : i am getting this right , i guess given a linked list ...you need > to point to next larger element. > so if input linked list is 7 3 5 1 5 9 > then nextLarger of each node will point

Re: [algogeeks] MS QUESTION_LINKED LIST

2012-03-24 Thread atul anand
@all : i am getting this right , i guess given a linked list ...you need to point to next larger element. so if input linked list is 7 3 5 1 5 9 then nextLarger of each node will point as follows:- 3->5 1->5 5->9 7->9 9->NULL; i have no idea why the linked list is modified using merge sort... any

Re: [algogeeks] MS QUESTION_LINKED LIST

2012-03-23 Thread Ashish Goel
actually, multimap can be avoided, each element of heap is key,value where key is the element and value is address and build heap on key. Best Regards Ashish Goel "Think positive and find fuel in failure" +919985813081 +919966006652 On Sat, Mar 24, 2012 at 1:40 AM, Ashish Goel wrote: > don't kn

Re: [algogeeks] MS QUESTION_LINKED LIST

2012-03-23 Thread Ashish Goel
don't know if i am complicating..assumption, build a multimap of values and the corresponding node address as well as a heap from the given nodes in first pass. now from minheap pick one by one and set the second pointer of previous picked min element to this element using multimap(remove from mu

Re: [algogeeks] MS QUESTION_LINKED LIST

2012-03-23 Thread Abhishek Sharma
It is basically sorting the linked list. Do not change the first pointer of nodes and use the second pointer for sorting. return the pointer to the smallest element. That's it. On Sat, Mar 24, 2012 at 12:50 AM, Atul Singh wrote: > Given a linked list with each node having two pointers : one point

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

Re: [algogeeks] MS Q

2012-01-10 Thread atul anand
@ Ashish : abt the solution given by reference. well sometimes it depends , interviewer may take it +vely as he can see you are keen to learn abt different algorithm dats why you knw it... On Tue, Jan 10, 2012 at 7:28 PM, Ashish Goel wrote: > i liked the solution given by the reference i have p

Re: [algogeeks] MS Q

2012-01-10 Thread atul anand
@ Ramakant : yupwont work. On Tue, Jan 10, 2012 at 7:28 PM, Ramakant Sharma wrote: > > @atul: > > > 0 0 0 0 0 0 > -->0 1 0 0 1 0 count=2 > 0 1 1 1 1 1 > > > > 0 0 0 0 0 0 > 0 1 0 0 1 0 > -->0 1 1 1 1 1 count=2 (will not change) > > but there is only one islandso

Re: [algogeeks] MS Q

2012-01-10 Thread Ramakant Sharma
@atul: 0 0 0 0 0 0 -->0 1 0 0 1 0 count=2 0 1 1 1 1 1 0 0 0 0 0 0 0 1 0 0 1 0 -->0 1 1 1 1 1 count=2 (will not change) but there is only one islandso it wouldnt work... am i right? -- You received this message because you are subscribed to the Google Groups "Al

Re: [algogeeks] MS Q

2012-01-10 Thread Ashish Goel
i liked the solution given by the reference i have provided. The thought process is similar to mazing problem given in horowitz sahani. nice question, however, how can this be an interview question? If you give this solution, the interviewer would understand that you knew the problem and hence wou

Re: [algogeeks] MS Q

2012-01-10 Thread Ramakant Sharma
0 0 0 0 0 0 0 1 0 0 1 0 0 1 1 1 1 1 -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For mo

Re: [algogeeks] MS Q

2012-01-10 Thread atul anand
@Ramakan: for j=0 to col arr[0][j]=0; for i=0 to rows arr[i][0]=0; assuming that given matrix is surrounded by 0 i.e indexs (i,j) for arr[][] will start from i=1 <= row and j=1 <= col. i guess your approach will work. -- You received this message because you are subscribed to the Google Group

Re: [algogeeks] MS Q

2012-01-10 Thread atul anand
@Ramakant : for which test case your code would fail?? On Tue, Jan 10, 2012 at 1:04 PM, Ramakant Sharma wrote: > @atul: > no..my approach was wrongwe have to check recursively...as sravan said > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm

Re: [algogeeks] MS Q

2012-01-09 Thread Ashish Goel
http://www.janaganamana.net/onedefault.aspx?bid=276 did not get it Best Regards Ashish Goel "Think positive and find fuel in failure" +919985813081 +919966006652 On Tue, Jan 10, 2012 at 1:15 PM, Ashish Goel wrote: > this is a single island, sorry for that > > Best Regards > Ashish Goel > "Th

Re: [algogeeks] MS Q

2012-01-09 Thread Ashish Goel
this is a single island, sorry for that Best Regards Ashish Goel "Think positive and find fuel in failure" +919985813081 +919966006652 On Tue, Jan 10, 2012 at 9:24 AM, atul anand wrote: > @Ashish Goel : didnt get it :( > > > 1 1 0 0 > 1 1 0 0 > 0 0 1 1 > > > 1-1-1 diagonal is one island ...wher

Re: [algogeeks] MS Q

2012-01-09 Thread Ramakant Sharma
@atul: no..my approach was wrongwe have to check recursively...as sravan said -- 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 Q

2012-01-09 Thread atul anand
@Ramakant : i guess you shud include diagonal case also for each arr[i][j] if(arr[i][j]==1) { if (!(arr[i-1][j]==1 || arr[i][j-1]==1 || arr[i-1][j-1])) count++; } On Tue, Jan 10, 2012 at 9:33 AM, Ramakant Sharma wrote: > Scan the matrix row wise left to right > for each arr[i][j]

Re: [algogeeks] MS Q

2012-01-09 Thread Ramakant Sharma
Scan the matrix row wise left to right for each arr[i][j] if(arr[i][j]==1) { if (!(arr[i-1][j]==1||arr[i][j-1]==1)) count++; } ///also chk for baundary values accordingly 1 1 0 0 1 1 0 0 0 0 1 1 i think it should work.. -- You received this message because you are subscribed to the Go

Re: [algogeeks] MS Q

2012-01-09 Thread atul anand
@sravanreddy001 : got it ..thanks :) On Tue, Jan 10, 2012 at 9:33 AM, sravanreddy001 wrote: > @atul: given a matrix just like above, (usually an image) the pixel values > with similar can be searched for around the current pixel, and they all can > be marked in one go, > > think of an algorithm,

Re: [algogeeks] MS Q

2012-01-09 Thread sravanreddy001
@atul: given a matrix just like above, (usually an image) the pixel values with similar can be searched for around the current pixel, and they all can be marked in one go, think of an algorithm, which does the following 1) when a one is replaced by '2' manually, then algorithm changes every '1'

Re: [algogeeks] MS Q

2012-01-09 Thread atul anand
@Ashish Goel : didnt get it :( 1 1 0 0 1 1 0 0 0 0 1 1 1-1-1 diagonal is one island ...where is another?? 1 1 0 0 1 1 0 0 0 0 1 1 these 1 will be considered one island of 2 island.?? On Tue, Jan 10, 2012 at 7:36 AM, Ashish Goel wrote: > row, col, diag all > > 1-1-1 is a single island :) >

Re: [algogeeks] MS Q

2012-01-09 Thread atul anand
@sravanreddy001 : Pixel fill algorithm ..what is the exact name of that algo ??? -- 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 t

Re: [algogeeks] MS Q

2012-01-09 Thread sravanreddy001
this is similar to the Pixel fill algorithm usually used in photo editing softwares (photoshop or paint ) BFS would be best approach to start with ( and check 4-adjacent or 8-includeing diagonal elements for a '1' and include that to queue. When the queue becomes empty, increase the count by 1.

Re: [algogeeks] MS Q

2012-01-09 Thread Ashish Goel
row, col, diag all 1-1-1 is a single island :) 1 1 0 0 1 1 0 0 0 0 1 1 this has only 2 islands Best Regards Ashish Goel "Think positive and find fuel in failure" +919985813081 +919966006652 On Tue, Jan 10, 2012 at 7:29 AM, Ankur Garg wrote: > Can you give an example > > Say matrix is > >

Re: [algogeeks] MS Q

2012-01-09 Thread Ankur Garg
Can you give an example Say matrix is 1 1 0 0 1 1 0 0 0 0 1 1 Has it got 3 islands i.e 1-1 be in same row or they can be column wise also i.e. 5 On Tue, Jan 10, 2012 at 7:09 AM, Ashish Goel wrote: > there is a matrix of 1 and 0 > 1 is a island and 0 is water > 1-1 together makes one island

[algogeeks] MS Q

2012-01-09 Thread Ashish Goel
there is a matrix of 1 and 0 1 is a island and 0 is water 1-1 together makes one island calculate total no of islands Best Regards Ashish Goel "Think positive and find fuel in failure" -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post

[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 WRITTEN TEST FOR INTERNS

2011-10-02 Thread rahul sharma
hey from which college r u??? On Sun, Oct 2, 2011 at 10:51 PM, gaurav kumar wrote: > there were 10 objective questions covering c,c++ and ds > questions were on mainly memory allocation > stack and heap ,etc > output/error ; > > subjective part > 1. compress the given string > eg. aaabbcccaadee

[algogeeks] MS WRITTEN TEST FOR INTERNS

2011-10-02 Thread gaurav kumar
there were 10 objective questions covering c,c++ and ds questions were on mainly memory allocation stack and heap ,etc output/error ; subjective part 1. compress the given string eg. aaabbcccaadee o/p = a3b2c3de2 2. u have to give the various test case and fault cases for a USB device such that

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

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

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

[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 algogeeks@googl

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

[algogeeks] MS-IT

2011-09-21 Thread ankit arun
hi!! MS-IT is visiting our college. could anyone plz help me in knowing what kind of questions(interview) they asked/asking. Thanks in advance. Ankit Arun NIT Durgapur -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To view this discussio

Re: [algogeeks] MS interview

2011-09-17 Thread Abhishek Yadav
What should be the answer to above questions...? On Sat, Sep 17, 2011 at 5:01 AM, bharatkumar bagana < bagana.bharatku...@gmail.com> wrote: > Memory management has following things.. > 1.Relocation > To maintain the free pages and when a page is to be swapped, we have to add > that page into free

Re: [algogeeks] MS interview

2011-09-17 Thread bharatkumar bagana
Memory management has following things.. 1.Relocation To maintain the free pages and when a page is to be swapped, we have to add that page into free page list .. For this ,if we maintain a bool array which is equal to # pages in RAM,it gives whether it is free or not .. 2.Protection If ours is st

[algogeeks] MS interview

2011-09-15 Thread teja bala
13. Propose an algo/data struct for memory manager. 14. Propose and algo/data struct for timer manager. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this

Re: [algogeeks] ms question

2011-09-14 Thread Akash Mukherjee
thanx...it was very helpful :) On Mon, Sep 12, 2011 at 8:46 PM, Piyush Grover wrote: > A can remain same in following cases: > -> If m, n are equal in all the N iterations > -> if m, n are equal in N-2 iterations but in 1 iteration m and n both are > different in that case there should be one ite

Re: [algogeeks] MS test cases type Questions

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

Re: [algogeeks] MS written

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

Re: [algogeeks] MS written

2011-09-12 Thread bharatkumar bagana
ya from the 2nd quest, we can infer some more ... like the way we represent the date of birth is different than other countries...PIN code,6 digits in INDIA, but may not be same in other countries ... On Mon, Sep 12, 2011 at 7:06 PM, teja bala wrote: > 1-Write test cases for a new student reg

Re: [algogeeks] ms question

2011-09-12 Thread Piyush Grover
A can remain same in following cases: -> If m, n are equal in all the N iterations -> if m, n are equal in N-2 iterations but in 1 iteration m and n both are different in that case there should be one iteration where m and n should be same as the previous iteration so that they are swapped again to

Re: [algogeeks] ms question

2011-09-12 Thread payal gupta
@piyush.. cud u plzz..xplain...n elaborate Regards, Payal Gupta On Mon, Sep 12, 2011 at 10:15 PM, Piyush Grover wrote: > Sry i was little wrong: > > nC0*(1/n)^n + nC2 *2*(1/n)^n + nC4*2^2*(1/n)^n++nCn*2^(n/2)*(1/n)^n > when n is even > > nC0*(1/n)^n + nC2 *2*(1/n)^n + > nC4*2^2*(1/n)^n+

Re: [algogeeks] ms question

2011-09-12 Thread Piyush Grover
Sry i was little wrong: nC0*(1/n)^n + nC2 *2*(1/n)^n + nC4*2^2*(1/n)^n++nCn*2^(n/2)*(1/n)^n when n is even nC0*(1/n)^n + nC2 *2*(1/n)^n + nC4*2^2*(1/n)^n++nCn-1*2^(n-1/2)*(1/n)^n when n is odd On Mon, Sep 12, 2011 at 10:08 PM, Piyush Grover wrote: > it should be: > > (1/n)^n * (1 + 2

Re: [algogeeks] ms question

2011-09-12 Thread Piyush Grover
it should be: (1/n)^n * (1 + 2 + 2^2 + 2^3 +(n/2)+1 terms) = {2^(1 + n/2) - 1}*(1/n)^n when n even (1/n)^n * (1 + 2 + 2^2 + 2^3 +(n-1/2)+1 terms) = {2^(1 + (n-1)/2) - 1}*(1/n)^n when n is odd -Piyush On Mon, Sep 12, 2011 at 8:01 PM, sandeep nagamalli wrote: > I think it is 1 / (2

[algogeeks] MS test cases type Questions

2011-09-12 Thread pg@manit
Cud some 1 suggest me 4m how 2 practise test cases type of questions which usually cum in MS written Papers? thanx..in advance Regards, PAYAL GUPTA -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogee

Re: [algogeeks] ms question

2011-09-12 Thread sandeep nagamalli
I think it is 1 / (2N) (1/N) * (1/N)*(N/2) = 1/(2N) On Mon, Sep 12, 2011 at 6:33 PM, Akash Mukherjee wrote: > this is a case, but isnt der a case of circular permutation 2?? > what say abt dis > 0,1 > 2,3 > 4,5 > 0,1 > 2,3 > 4,5 > > it wrks i gues?? > > > On Mon, Sep 12, 2011 at 12:56 PM, teja

[algogeeks] MS written

2011-09-12 Thread teja bala
1-Write test cases for a new student registration form. The registration form captures Student name, email address, Address, Date of birth, Password. It also asks the student to confirm the password. 2-Consider that this application is being deployed as Web application and Desktop application and

Re: [algogeeks] ms question

2011-09-12 Thread Akash Mukherjee
this is a case, but isnt der a case of circular permutation 2?? what say abt dis 0,1 2,3 4,5 0,1 2,3 4,5 it wrks i gues?? On Mon, Sep 12, 2011 at 12:56 PM, teja bala wrote: > > > I think it is 1/N > > let N=6 that means rand(6)= takes values 0-5 i.e 6 values. > rand(m)=6 values > rand(n)=6 value

Re: [algogeeks] ms question

2011-09-12 Thread teja bala
I think it is 1/N let N=6 that means rand(6)= takes values 0-5 i.e 6 values. rand(m)=6 values rand(n)=6 values total combinations 6*6=36 values set but among dem array will change only for (0,0)(1,1)(2,2)(3,3)(4,4)(5,5)(6,6)=6values of N So 6/36=1/6 If we generalize it 1/N correct me if i'm wro

[algogeeks] ms question

2011-09-12 Thread Akash Mukherjee
given a rand(N) a random generator 0 - N-1. now //assume N is defined somewhere int A[N] for(i = 0; i < N; i++){ int m = rand(N); int n = rand(N); swap(A[m],A[n]); } what is the probability that array A remains the same? p.s. rand n swap are o(1) in case it makes any diff -- You received this m

Re: [algogeeks] MS written test

2011-09-07 Thread sukran dhawan
which is the best site where in can find backtracking and branch and bound programs ? On Wed, Sep 7, 2011 at 8:58 PM, gmagog...@gmail.com wrote: > 0xa == 0x 1010, which stands for all the even bits > 0x5 == 0x 0101, which stands for all the odd bits > > >>1 and <<1 means shifting odd to even and

Re: [algogeeks] MS written test

2011-09-07 Thread gmagog...@gmail.com
0xa == 0x 1010, which stands for all the even bits 0x5 == 0x 0101, which stands for all the odd bits >>1 and <<1 means shifting odd to even and even to odd then | means putting new even bits and odd bits together Yanan Cao On Wed, Sep 7, 2011 at 10:23 AM, teja bala wrote: > > Can anyone plzz

[algogeeks] MS written test

2011-09-07 Thread teja bala
Can anyone plzz xplain the code? public static int swapOddEvenBits(int x) { return ( ((x & 0x) >> 1) | ((x & 0x) << 1) ); } -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@goo

Re: [algogeeks] MS question

2011-09-06 Thread ravinder s
haha lol f o On Tue, Sep 6, 2011 at 8:51 AM, Yogesh Yadav wrote: > @all : > Thanks for correcting me. > > > On Tue, Sep 6, 2011 at 3:41 AM, Piyush Grover > wrote: > >> Here's the pseudo code. I hope it should work. >> >> >> d = (d[0]d[1]) >> m = (m[0]m[1]) >> y = (y[0]y[1]y[2]y[3]) >> dd =

Re: [algogeeks] MS question

2011-09-05 Thread Yogesh Yadav
@all : Thanks for correcting me. On Tue, Sep 6, 2011 at 3:41 AM, Piyush Grover wrote: > Here's the pseudo code. I hope it should work. > > > d = (d[0]d[1]) > m = (m[0]m[1]) > y = (y[0]y[1]y[2]y[3]) > dd = d; > mm = m; > yy = y; > > while(1){ > if (strcmp(concat(dd,mm), reverse(yy)) >

Re: [algogeeks] MS question

2011-09-05 Thread Piyush Grover
Here's the pseudo code. I hope it should work. d = (d[0]d[1]) m = (m[0]m[1]) y = (y[0]y[1]y[2]y[3]) dd = d; mm = m; yy = y; while(1){ if (strcmp(concat(dd,mm), reverse(yy)) return(dd,mm,yy) else if(isValidDateMonth(yy[3]yy[2], yy[1]yy[0] ,yy){ if(yy[3]yy[2] > d && yy[1]

Re: [algogeeks] MS question

2011-09-05 Thread Anshul Khandelwal
@yogesh: u r incrementing num1 and decrementing num2 without considering there are 12 months and 30/31 days On Tue, Sep 6, 2011 at 12:07 AM, Neha Singh wrote: > @piyush : > 01/02/2011 > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. >

Re: [algogeeks] MS question

2011-09-05 Thread Neha Singh
@piyush : 01/02/2011 -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, vis

Re: [algogeeks] MS question

2011-09-05 Thread Piyush Grover
One thing i would like to know is 01/02/2011 needs to be considered or 1/02/2011. thnx On Mon, Sep 5, 2011 at 11:48 PM, Neha Singh wrote: > @yogesh: its stiil not correct. There r many test cases where ur solution > will fail > > -- > You received this message because you are subscribed to the

Re: [algogeeks] MS question

2011-09-05 Thread Neha Singh
@yogesh: its stiil not correct. There r many test cases where ur solution will fail -- 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

2011-09-05 Thread shady
not correct. On Mon, Sep 5, 2011 at 11:01 PM, Yogesh Yadav wrote: > //Num is our given number obtained from date > > 1.divide num into 2 parts last 4 and first 4 > ex: num=96548765 > num1=9765,num2=Reverse(8765) > 2.if(num1>num2) >add(num1-num2) in num2 > 3. num3=reverse(num2) >

Re: [algogeeks] MS question

2011-09-05 Thread sukran dhawan
hmmm ok thanks for correcting me :) On Mon, Sep 5, 2011 at 11:01 PM, Yogesh Yadav wrote: > //Num is our given number obtained from date > > 1.divide num into 2 parts last 4 and first 4 > ex: num=96548765 > num1=9765,num2=Reverse(8765) > 2.if(num1>num2) >add(num1-num2) in num2 > 3.

Re: [algogeeks] MS question

2011-09-05 Thread ravinder s
balls to u guys !! On Mon, Sep 5, 2011 at 11:01 PM, Yogesh Yadav wrote: > //Num is our given number obtained from date > > 1.divide num into 2 parts last 4 and first 4 > ex: num=96548765 > num1=9765,num2=Reverse(8765) > 2.if(num1>num2) >add(num1-num2) in num2 > 3. num3=reverse(

<    1   2   3   4   5   >