Bottom view of a binary tree

I wrote this code on geeks fir geeks this code’s time complexity is o(n)?
Why this error is in being shown.
ERROR: Abort signal from abort(3) (SIGABRT)
Problem link:-
https://practice.geeksforgeeks.org/problems/bottom-view-of-binary-tree/1

submitted code:-

Node** printBottomView(Node* root,int n,Node arr[])
{
// static Node
arr[1000]={0};

if(root==nullptr)
{
   return arr; 
}
else
{
    arr[n]=root;
    printBottomView(root->left,n-1,arr);
    printBottomView(root->right,n+1,arr);
    return arr;
}

}
int findNoOfNodes(Node* root,int *n)
{
// static int n=0;
if(root)
{
n+=1;
// cout<< n<<" ";
findNoOfNodes(root->left,n);
findNoOfNodes(root->right,n);
return n;
}
return 0;
}
// Method that prints the bottom view.
void bottomView(Node root)
{
// Your Code Here//
int n=0;
findNoOfNodes(root,&n);
// cout<<n<<endl;
Node
arr=new Node
[1000000];
printBottomView(root,n,arr);
for(int i=0;i<=2
n;i++)
{
if(arr[i])
{
cout<<arr[i]->data<<" ";
}
}
delete *arr;
}

Hello @gaurav19063,

SIGABRT errors are caused by your program aborting due to a fatal error. In C++, this is normally due to an assert statement in C++ not returning true, but some STL elements can generate this if they try to store too much memory.

Following could be a possible reason:
Node arr=new Node [1000000];

You must have gone through this video if not go through it once.

Let me know if you still have any doubt.

10^6 size for an array is normal .i don’t think that error is occuring because of this reason just run this code over the given gfg link.

Sure @gaurav19063,

The very first mistake i noticed there:
Code segment provided by them:
// Method that returns the bottom view.
vector <int> bottomView(Node *root)
{
// Your Code Here
}

It has a return type.

Now, look at the function you have written:
// Method that prints the bottom view.
void bottomView(Node root)
{
// Your Code Here//

}

The return type is void.

So, this might be the possible reason of the error you are getting.