[algogeeks] Re: Time Complexity

2011-11-19 Thread Ankuj Gupta
I guess its NlogN for balanced tree as it is traversing N nodes for H times ie the height of tree which is logN for balanced and N for skewed tree. So it should be Nlogn and N^2 On Nov 20, 9:27 am, tech coder wrote: > @ sravanreddy001 > complexity is O(N^2) whether tree is balanced or not doesn't

[algogeeks] regarding start of loop in linked list

2011-11-19 Thread rahul sharma
when a loop is found then slow=fast //pointers; then to find start we move one of any pointer at start and other at same palce and move both @ speed of 1...then where they meet is startr,,, can nyone xplain the logic behind this in simple words that how they meet at startthnx in advance -

[algogeeks] Re: Problem

2011-11-19 Thread Zyro
@all : Thanks :) On Nov 19, 3:55 pm, Amol Sharma wrote: > that's what i was saying :) > -- > > Amol Sharma > Third Year Student > Computer Science and Engineering > MNNIT Allahabad >   >

Re: [algogeeks] Time Complexity

2011-11-19 Thread Jagannath Prasad Das
I think any traversal has o(n) complexity as we traverse all the nodes.There is no skipping of nodes.Very simple logic:) On Sun, Nov 20, 2011 at 9:57 AM, tech coder wrote: > @ sravanreddy001 > complexity is O(N^2) whether tree is balanced or not doesn't matter > For each level it's visiting elem

[algogeeks] Given a int N, write a function to return the closest Fibonacci Number

2011-11-19 Thread Ankuj Gupta
O(N) method is trivial. Can we do better than this ? Using matrix f= { {1,1},{1,0}}. -- 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] Time Complexity

2011-11-19 Thread tech coder
@ sravanreddy001 complexity is O(N^2) whether tree is balanced or not doesn't matter For each level it's visiting elements. all elements upto n-1 level . i dont know from where u got the concept of logn , the code is not making any decision to go in left or right , it is going in left and right

[algogeeks] Time Complexity

2011-11-19 Thread sravanreddy001
Its NlogN if balanced.. Else N^2 For each element it's visiting at most log N elements.(assuming balanced) -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/

Re: [algogeeks] Time Complexity

2011-11-19 Thread atul anand
void printLevelOrder(BinaryTree *root) { node *temp; enqueue(root); while((temp=dequeue()) != NULL) { printf("%d ",temp->data); if (temp->left) { enqueue(temp->left); } if ( temp->right) { enqueue(temp->right); } } } i guess this approach is much

Re: [algogeeks] Time Complexity

2011-11-19 Thread atul anand
@shady : i guess code is fineit will print the node only when level=1 , and level is in loop so for level = 1 it will print root when level=2 then it will print all nodes at level 2 and so on... i guess we can optimize this code.. On Sat, Nov 19, 2011 at 3:28 PM, shady wrote: > this do

Re: [algogeeks] Re: Problem

2011-11-19 Thread Amol Sharma
that's what i was saying :) -- Amol Sharma Third Year Student Computer Science and Engineering MNNIT Allahabad On Sat, Nov 19, 2011 at 2:10 PM

[algogeeks] Re: Time Complexity

2011-11-19 Thread ((** VICKY **))
Its level order traversal but its O(n^2) u search entire tree to check if the nodes level is i (say 0<= i <= height). i guess can use stack or queue to get O(n) complexity On Nov 19, 2:58 pm, shady wrote: > this doesn't seem like level order printing, because you are simply > printing the tree st

[algogeeks] Re: COA Question

2011-11-19 Thread ((** VICKY **))
I guess it could be. b) position independent code Keeping relative addressing facilates address independent code as its always relative. correct me if am wrong.! On Nov 18, 4:07 pm, Vijay Khandar wrote: > Relative mode of addressing is most relevant to writing > a)coroutines > b)position

Re: [algogeeks] COA Question

2011-11-19 Thread Manish Patidar
Need Help to prepare for SYNTEL interview. plzz send me topics to cover. Thank you in advance, Have a great day !! * With Regards, * * Manish Patidar.* -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group,

Re: [algogeeks] Time Complexity

2011-11-19 Thread tech coder
the complexity is N^2 for each level you are traversing all the nodes below that level. for nth level , you have to traverse all n-1 nodes. so O(N^2) better to use queue , we can traverse level order in O(n). On Sat, Nov 19, 2011 at 4:58 PM, shady wrote: > this doesn't seem like level order prin

[algogeeks] Re: Time Complexity

2011-11-19 Thread Ankuj Gupta
Try it once. It is for level order only in dfs way On Nov 19, 2:58 pm, shady wrote: > this doesn't seem like level order printing, because you are simply > printing the tree starting with the children as the root node. > > > > > > > > On Sat, Nov 19, 2011 at 12:57 PM, Ankuj Gupta wrote: > > What

Re: [algogeeks] Time Complexity

2011-11-19 Thread shady
this doesn't seem like level order printing, because you are simply printing the tree starting with the children as the root node. On Sat, Nov 19, 2011 at 12:57 PM, Ankuj Gupta wrote: > What is the time complexity of this code for Level Order Traversal. > > void printLevel(BinaryTree *p, int lev

[algogeeks] Re: Problem

2011-11-19 Thread shady
sorry, we don't need to do so much computation minimizing the difference of the maximum and minimum array in the selected array is the solution. difference will always be = largest element - smallest element On Nov 19, 1:20 pm, shady wrote: > aim : minimize the sum of elements of a sorted set of

[algogeeks] Re: Problem

2011-11-19 Thread shady
@amol how ? we are not minimizing the difference between the greatest and smallest element in the set, but the difference of the sum of the consecutive elements in the sorted selected array of size k... and complexity O(logn) ? On Nov 19, 1:25 pm, Amol Sharma wrote: > agree with mehdi's solution.

Re: [algogeeks] Re: Problem

2011-11-19 Thread Amol Sharma
agree with mehdi's solution.minimizing sum of differences will be equivalent to minimizing the difference between the largest and smallest number in the setO(logn) solution.. -- Amol Sharma Third Year Student Computer Science and Engineering MNNIT Allahabad

[algogeeks] Re: Problem

2011-11-19 Thread shady
aim : minimize the sum of elements of a sorted set of size k. mehdi's solution is correct, 1. sort the whole array, 2. and then as you add new element to the set a. delete the oldest element added along with its difference b. add the difference of the newly added element. O(nlogn) On Nov 19