by zig-zag order means level order traversal ???
On Sun, Dec 11, 2011 at 6:22 AM, AMAN AGARWAL mnnit.a...@gmail.com wrote:
Hi,
Given a tree, in addition to the left and right pointer, it has a third
pointer, that is set to NULL.
Set the third pointer to a node, which will be the successor
1) Get the count of nodes in the given DLL. Say its, n.
2) Call convert(0, n-1, headPtrToDLL);
node* convert(int start, int end, node **head)
{
node * root = NULL;
if (start end)
return NULL;
int mid = (start + end) / 2;
node * left = convert(
@Dheeraj
The ans for 14532 should be 15234..
I am calculating using the above given algo to get to the ans:
1) 4 is the value where A[i] A[i+1] when scanned from the end.
2) The closest element grater than equal to 4 in the subarray 532 is
5.
3) Swap (4,5) : 14532 - 15432
4) Now, as we have
@atul zig-zag mean spiral traversal of tree e.g. alternate the level while
traversing , if previous traversal is left to right , then next level will
be right to left .
@aman .quest has little ambiguity its says successor but ebvery nodes can
have we can ore-order , inorder ,postorder
You can do a zig-zag traversal of a tree by using 2 stacks in place of
the 2 queues you'd use for level order traversal. As you do the zig-
zag traversal, just keep track of the current and previous node
visited and set previous-zznext = current at each visit.
On Dec 11, 1:52 am, AMAN AGARWAL
This is nice. There is also an article on how to do this iteratively
with a stack:
http://groups.google.com/group/comp.programming/msg/41f46b2801c4f84e
This solution actually traverses a BST of any shape, tears it apart,
and reassembles it as a perfectly balanced tree. However, it will
also
We talked about the problem of removing as many parentheses as
possible:
http://groups.google.com/group/algogeeks/browse_thread/thread/26ce36ad34dce9dc/e8fb40ab2ba0ecc0
You didn't define duplicate. For (a*b)+c, the parens don't add any
information. Should they be removed? The algorithm given
Hi,
Suppose we have a binary search tree as 15,12,18,17,21,11,14
then O/P will be 15 12 18 21 17 14 11.
so the successor of 15 is 12 the successor of 12 is 18 and so on.
I hope now its clear.
Regards,
Aman.
On Sun, Dec 11, 2011 at 6:26 PM, WgpShashank shashank7andr...@gmail.comwrote:
@atul
for linked we always have only head
On Thu, Dec 8, 2011 at 11:40 PM, sayan nayak sayanna...@gmail.com wrote:
@Himanshu: If I follow ur algo..then I have to remove the loop..Otherwise
there will not be any head for the reversed linked-list.
If u wanna say..First remove the loop,make it a
@Gene : if i am not wrong , level order traversal can be done using only 1
queuewhy 2 queue???
On Sun, Dec 11, 2011 at 9:53 PM, AMAN AGARWAL mnnit.a...@gmail.com wrote:
Hi,
Suppose we have a binary search tree as 15,12,18,17,21,11,14
then O/P will be 15 12 18 21 17 14 11.
so the
we have to traverse in zig zaz or spirally. so we need two stack or two
queus.
On Mon, Dec 12, 2011 at 12:23 AM, atul anand atul.87fri...@gmail.comwrote:
@Gene : if i am not wrong , level order traversal can be done using only 1
queuewhy 2 queue???
On Sun, Dec 11, 2011 at 9:53 PM, AMAN
One queue certainly suffices. Sometimes two are very nice. E.g. if you
have the task of printing all nodes at level N and you don't have
level numbers in the nodes. With two queues, all the nodes in a queue
at a given time are on the same level, so this problem is elegantly
solved. WIth one it's
Hi,
Yes.
Regards,
Aman.
On Sun, Dec 11, 2011 at 12:54 PM, atul anand atul.87fri...@gmail.comwrote:
by zig-zag order means level order traversal ???
On Sun, Dec 11, 2011 at 6:22 AM, AMAN AGARWAL mnnit.a...@gmail.comwrote:
Hi,
Given a tree, in addition to the left and right pointer, it
Hey group,
This is kind of a cliched question but given a file with billion numbers
and the task is to compute 'k' largest numbers from this file, what
approach is preferred?
1) Using heaps
2) Using Median-of-median algorithm.
Have read few links which prefer heaps but clearly median of median
so algo for zig-zag using two stack would be like this :-
let* two stack s1,s2;*
toggle = -1;
push(root,s1);
while ( !isEmpty(s1) || ! isEmpty(s2))
{
while( ! isEmtpy(s1))
{
print : val=pop(s1);
if(toggle == -1)
{
if(val-right)
Using Median-of-median algorithm is not a practical approch bcozz as you
have mentioned it has billion of data.
so even if we ignore constant but when we implement is practically then
constant matters and value of constant would be very large to make it work
for O(n).
so heap would me much better
hey here how will you find the median over the billions of numbers when all
data doesnt fit at the same time in memory??
On Mon, Dec 12, 2011 at 6:41 AM, bharath sriram bharath.sri...@gmail.comwrote:
Hey group,
This is kind of a cliched question but given a file with billion numbers
and the
yeah..u r rite..i got it
On Sun, Dec 11, 2011 at 5:08 PM, Lucifer sourabhd2...@gmail.com wrote:
@Dheeraj
The ans for 14532 should be 15234..
I am calculating using the above given algo to get to the ans:
1) 4 is the value where A[i] A[i+1] when scanned from the end.
2) The closest
18 matches
Mail list logo