answersLogoWhite

0

/*

Given two trees, return true if they are

structurally identical.

*/

int sameTree(struct node* a, struct node* b) {

// 1. both empty -> true

if (a==NULL && b==NULL) return(true);

// 2. both non-empty -> compare them

else if (a!=NULL && b!=NULL) {

return(sameTree(a->left, b->left) &&

sameTree(a->right, b->right)

);

}

// 3. one empty, one not -> false

else return(false);

}

User Avatar

Wiki User

15y ago

What else can I help you with?

Continue Learning about Engineering

Which search algorithm requires that the arrays contents be sorted?

Binary Search Algorithm


How do you do binary search in file?

A binary search on a random-access file is performed much in the same way as a binary search in memory is performed, with the exception that instead of pointers to items in memory file seek operations are used to locate individual items within the file, then load into memory for further examination. The key aspects of the binary search algorithm do not depend on the specifics of the set of searchable items: the set is expected to be sorted, and it must be possible to determine an order between any two items A and B. Finally, the binary search algorithm requires that the set of searchable items is finite in size, and of a known size.


Which are the searching algorithm always compare the middle element with the searching elements in the given array?

binary search system


How do you print all data in a Binary Search Tree?

By using Depth First Search or Breadth First search Tree traversal algorithm we can print data in Binary search tree.


Algorithm to determine if a binary tree is complete binary?

There are many ways of checking for a complete binary tree. Here is one method:1. Do a level order traversal of the tree and store the data in an array2. If you encounter a nullnode, store a special flag value.3. Keep track of the last non-null node data stored in the array - lastvalue4. Now after the level order traversal, traverse this array up to the index lastvalue and check whether the flag value is encountered. If yes, then it is not a complete binary tree, otherwise it is a complete binary tree.

Related Questions

Which search algorithm requires that the arrays contents be sorted?

Binary Search Algorithm


What is the best search algorithm to use for a sorted array?

The best search algorithm to use for a sorted array is the binary search algorithm.


What is the running time of binary search algorithm?

The running time of the binary search algorithm is O(log n), where n is the number of elements in the sorted array being searched.


What is the time complexity of a binary search algorithm?

The time complexity of a binary search algorithm is O(log n), where n is the number of elements in the sorted array being searched.


What is the number of nodes in a strictly binary tree which has n leaves?

IF EVERY NON-LEAF NODE IN A BINARY TREE HAS HAS NONEMPTY LEFT AND RIGHT SUBTREES, THE TREE IS TERMED AS A STRICTLY BINARY TREE. SUCH A TREE WITH n LEAVES ALWAYS CONTAINS 2n-1 NODES.


Algorithm to determine if a binary tree is strictly binary?

// Author : SAGAR T.U, PESIT #define TRUE 1 #define FALSE 0 int isStrictBinaryTree (struct tree * n) { if( n NULL ) return TRUE; return FALSE; }


Give you the algorithm of creating a new binary search tree using c?

i want to know how to give the algorithm password in a computer ?


What is the time complexity of a binary search algorithm in computer science?

The time complexity of a binary search algorithm in computer science is O(log n), where n is the number of elements in the sorted array being searched.


How is a pso program in matlab..how is it created from algorithm..please help?

The PSO or Particle Swarm Optimization Program algorithm in MatLab is created by first creating a binary genetic algorithm.


The order of binary search algorithm is?

n log n - G.Parthiban, SRM


What is the time complexity of an algorithm that uses a binary search to find an element in a sorted array in logn time?

The time complexity of an algorithm that uses binary search to find an element in a sorted array in logn time is O(log n).


The truncated binary exponential back off algorithm?

This is the Algorithm use by CSMA/CD as a wait period to allow other devices on the network to access the media.