top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Write an algorithm for Copying a Binary Tree in dfs (data file structure).

0 votes
417 views
Write an algorithm for Copying a Binary Tree in dfs (data file structure).
posted Jan 27, 2016 by Latha

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

PROCEDURE COPY(ROOT)
[Given a binary tree whose root node address is given by the pointer value ROOT and this algorithm generates a copy of the tree and returns the address of its root node. NEW is a temporary pointer variable].

1 [Cheching for empty tree]

If ROOT = NULL
then return (NULL).

2 [Creating a new node]

NEW <-- NODE.

3 [Copy information field]

DATA(NEW) <-- DATA(ROOT).

4 [Set the structural links]

LPTR(NEW) <-- COPY(LPTR(ROOT))
RPTR(NEW) <-- COPY(RPTR(ROOT))

5 [FINISH]
return(NEW).

answer Jan 27, 2016 by Shivaranjini
Similar Questions
+3 votes

What data structure would you mostly likely see in a non recursive implementation of a recursive algorithm?

+1 vote

How do you shuffle a binary tree without using any external data structures.
Note: With equal probability to every node.

0 votes

Give program time complexity as well as.

...