[algogeeks] Single linked list questions.

2011-01-06 Thread dinesh bansal
Hi Guys, There are some questions asked to me: 1. How do you print the SLL in reverse order. List should not be changed. 2. Two SLLs are merging at one point, how can you find out efficiently. Thanks -- Dinesh Bansal The Law of Win says, Let's not do it your way or my way; let's do it the best

[algogeeks] Re: Single linked list questions.

2011-01-06 Thread anurag.singh
Hi, I'm new here and looking to learn more on algos and participate in discussions. @juver++, Recursion solution to the 1st problem implicitly using stack. No? print (list l) { if(i-next) print(l-next); print l; } On Jan 6, 4:55 pm, juver++ avpostni...@gmail.com wrote: 1. Recursive

Re: [algogeeks] Re: Single linked list questions.

2011-01-06 Thread dinesh bansal
On Thu, Jan 6, 2011 at 5:25 PM, juver++ avpostni...@gmail.com wrote: 1. Recursive function. Print node's element after processing next link of the current node. Also this can be achieved using stack. 2. Please clarify the question. -- You received this message because you are subscribed to

[algogeeks] Re: Single linked list questions.

2011-01-06 Thread juver++
Yes, but recursion stack's size is limited instead of iterative version. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to

Re: [algogeeks] Re: Single linked list questions.

2011-01-06 Thread vishal raja
@sourabh, In addition to your solution, If there is any cycle(loop) exist in the link list your algo will fail. To solve this problem first detect this cycle if there is any and count the element in the cycle, and then you can do the mathematics. On Thu, Jan 6, 2011 at 6:51 PM, sourabh jakhar

Re: [algogeeks] Re: Single linked list questions.

2011-01-06 Thread vishal raja
@aditya, Who said it's a Y shaped structure, It can very well has a cycle. Assume the case when the last node is not pointing to NULL but to a node in the list. On Thu, Jan 6, 2011 at 7:45 PM, ADITYA KUMAR aditya...@gmail.com wrote: @vishal saurabh is right its merging at only one point its

Re: [algogeeks] Re: Single linked list questions.

2011-01-06 Thread Naveen Kumar
@ Vishal, I think question says that its merging at a point. But anyway can you tell me how to detect cycle in this case. On Thu, Jan 6, 2011 at 7:57 PM, vishal raja vishal.ge...@gmail.com wrote: @aditya, Who said it's a Y shaped structure, It can very well has a cycle. Assume the case when

[algogeeks] Re: Google Interview Question

2011-01-06 Thread soundar
Maybe the code has lot of dynamic updations..So for each kind of i/ p there can be different places where the updated value is used. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

Re: [algogeeks] Re: Single linked list questions.

2011-01-06 Thread mahesh.jnumc...@gmail.com
Hii @ Question 2 - 1. Just count the no of nodes in each link list lets say N1 and N2 are the number of the nodes in first and second linklist respectively. 2. Now calculate the difference of the Nodes like as p = {N1~N2) 3. Now take 2 pointers say P1 and P2. 4. a. If N1 N2 then put

[algogeeks] How to search for the presence of a file in Linux?

2011-01-06 Thread janani thiru
I have written a program to search for a file in C in UNIX. But it doesn't loop recursively if the starting path is / Could it be because of permissions? But I am the root while executing the program and I have also changed the permissions of all the files in the folder correspondingly. Please

Re: [algogeeks] quick sort

2011-01-06 Thread Wladimir Tavares
You can use some techniques to improve quicksort: - randomized pivot - use insertion sort for small vector ~10 - use non recursive approach - median of some element chosed randomized - when you have many duplicate keys, you can use 3-way

Re: [algogeeks] Single linked list questions.

2011-01-06 Thread Prashant Kulkarni
hi, for 1 question, use stack to display elements in reverse order. can you elaborate your 2nd question ? -- Prashant Kulkarni On Thu, Jan 6, 2011 at 4:56 PM, dinesh bansal bansal...@gmail.com wrote: Hi Guys, There are some questions asked to me: 1. How do you print the SLL in reverse

[algogeeks] How to search for the presence of a file in Linux?

2011-01-06 Thread janani thiru
I have written a program to search for a file in C in UNIX. But it doesn't loop recursively if the starting path is / Could it be because of permissions? But I am the root while executing the program and I have also changed the permissions of all the files in the folder correspondingly. Please

Re: [algogeeks] Re: Single linked list questions.

2011-01-06 Thread Aditya
There are two aspects here for second question. 1. to find if the common node exist (ie the lists are merging) with out the limitation of length available. 2. To find the merging node. On 1/6/2011 8:49 PM, Naveen Kumar wrote: @ Vishal, I think question says that its merging at a point. But

Re: [algogeeks] Re: Single linked list questions.

2011-01-06 Thread Tushar Bindal
Is it necessary that the two lists are merging at their ends?? Do we have to find whether they merge at the end into same lists or wheter they are just intersecting?? On Thu, Jan 6, 2011 at 10:04 PM, Aditya adit.sh...@gmail.com wrote: There are two aspects here for second question. 1. to

Re: [algogeeks] Re: Single linked list questions.

2011-01-06 Thread Naveen Kumar
How can two list just intersect, each node can have one pointer to the next. So, if they intersect they will definitely be merging. On Thu, Jan 6, 2011 at 11:01 PM, Tushar Bindal tushicom...@gmail.comwrote: Is it necessary that the two lists are merging at their ends?? Do we have to find

Re: [algogeeks] Re: Single linked list questions.

2011-01-06 Thread Tushar Bindal
I agree But my doubt is that whether we have to find that they just have their last node as common or they can have many nodes common(which I was calling intersecting) On Thu, Jan 6, 2011 at 11:07 PM, Naveen Kumar naveenkumarve...@gmail.comwrote: How can two list just intersect, each node can

[algogeeks] double and int

2011-01-06 Thread Ankur Khurana
in a C++ program , when we have something like this double p=37.0; int k; k=(int)p; why is k!=p ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this

Re: [algogeeks] Re: Single linked list questions.

2011-01-06 Thread nishaanth
for 2nd question. Let m1,m2 be the length of sll1 and sll2.. now we know that after the merge no of nodes are same in both the slls. So take the difference , k= m1 - m2 skip k nodes frm the longer lists, then increment both sll1 and sll2 till you find a match. The matched node is the

Re: [algogeeks] Re: Single linked list questions.

2011-01-06 Thread sanchit mittal
Problem hav been solved u all giving same answers..! On Thu, Jan 6, 2011 at 11:30 PM, nishaanth nishaant...@gmail.com wrote: for 2nd question. Let m1,m2 be the length of sll1 and sll2.. now we know that after the merge no of nodes are same in both the slls. So take the difference , k=

Re: [algogeeks] Re: Single linked list questions.

2011-01-06 Thread nishaanth
@Sanchit..sorry i didnt see the replies :P On Thu, Jan 6, 2011 at 11:32 PM, sanchit mittal sm14it...@gmail.com wrote: Problem hav been solved u all giving same answers..! On Thu, Jan 6, 2011 at 11:30 PM, nishaanth nishaant...@gmail.com wrote: for 2nd question. Let m1,m2 be the length

[algogeeks] Re: double and int

2011-01-06 Thread juver++
On my computer k == p. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options,

[algogeeks] Re: Dynamic Programming

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

[algogeeks] Amazon Intrerview

2011-01-06 Thread Decipher
There is a binary tree(Not a BST) in which you are given three nodes x,y,z .Write a function which finds whether y lies in the path b/w x and z. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

[algogeeks] Re: Dynamic Programming

2011-01-06 Thread Decipher
I meant any test cases you think I haven't covered in my solution. Although I have run this solution and checked answer manually . -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com.

[algogeeks] Re: Amazon Intrerview

2011-01-06 Thread juver++
Find node A = LCA(x, z). If y lies on the path x-z (or reverse), then A should be either on the path A-x, or A-z. Also this can be find while searching LCA, it depends on the used algorithm for this. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks

[algogeeks] Re: Dynamic Programming

2011-01-06 Thread juver++
You may check the exact solution found here: http://users.eecs.northwestern.edu/~dda902/336/hw6-sol.pdf -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this

[algogeeks] Re: Dynamic Programming

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

Re: [algogeeks] Re: double and int

2011-01-06 Thread Ankur Khurana
not always. well , i got some problem using that approachwhen the output is coming out of some library function , this doesn't qualify always i wlll find an example by tomorrow. On Thu, Jan 6, 2011 at 11:48 PM, juver++ avpostni...@gmail.com wrote: On my computer k == p. -- You received this

[algogeeks] Re: Amazon Intrerview

2011-01-06 Thread Decipher
Good solution but what would be the time complexity ?? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to

Re: [algogeeks] Re: double and int

2011-01-06 Thread juver++
Numbers without fractional parts are represented exactly (in a range supported by double). -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send

Re: [algogeeks] How to search for the presence of a file in Linux?

2011-01-06 Thread Avi Dullu
Hey, Remembered of my OS assignment and wanted to fix it :). Though do not appreciate the design of the program :D, and not having the enthu to redesign it, I have fixed the program with minimal possible changes. Please reply in case of any issues. Thnx for posting :) #include iostream #include

Re: [algogeeks] Re: double and int

2011-01-06 Thread Avi Dullu
Just to mention, floating point numbers r always compared *for equality* like double d1 = 90.0; double d2 = 90.0; assert(d1 == d2); // might fail, and Wrong way to do !! assert(d1 - d2 1e-5); // given u assume precision of 1e-5, is the correct and recommended way. Programmers should realize

[algogeeks] Re: double and int

2011-01-06 Thread Dave
I don't think your example with == would ever fail. According to the IEEE floating point standard, integers within the dynamic range of the number type must be represented exactly and must compare as equal. Furthermore, the four basic operations on integers within the dynamic range of the

[algogeeks] Re: Adobe Interview

2011-01-06 Thread Decipher
Please write the recursive DP formula for this question . -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to

[algogeeks] Dynamic Programming - Series

2011-01-06 Thread Decipher
Given an array of integers, each element represents the max number of jumps can make forward. What is the minimum number of element selections to reach the end of the array (starting from the first element). Example: arr = 1, 3, 5, 8, 9, 2, 6, 7, 6, 8, 9 Here the min # of selections is : 3 with

[algogeeks] Amazon Interview - Algorithms

2011-01-06 Thread Decipher
Given an array of integers, each element represents the max number of jumps can make forward. What is the minimum number of element selections to reach the end of the array (starting from the first element). Example: arr = 1, 3, 5, 8, 9, 2, 6, 7, 6, 8, 9 Here the min # of selections is : 3 with