Rotate image (square matrix) by 90 deg
Tue, 06 May 2025

Input: 5 Output: 10 Input: 40 Output: 30 10 Input: 1 Output: 4 5 10
If Node of the binary tree is defined as below:
struct Node
{
int data;
Node *left;
Node *right;
};
Algorithm:
To print the ancestors, the logic is as below:
At any point true means the node is an ancestor of the given node. A false means that the given node is neither in the left nor in the right-sub-tree of this node, hence this node is not the ancestor.
Code: bool printAncestors(Node *r, int d)
{
if(r == NULL)
return false;
if(r->data == d )
return true;
if( printAncestors(root->left, d) || printAncestors(root->right, d) )
{
cout << root->data << " ";
return true;
}
else
{
return false;
}
}
Tue, 06 May 2025
Tue, 06 May 2025
Tue, 06 May 2025
Leave a comment