forked from purushottamnawale/geeksforgeeks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntroduction to Trees.cpp
More file actions
45 lines (37 loc) · 814 Bytes
/
Introduction to Trees.cpp
File metadata and controls
45 lines (37 loc) · 814 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//{ Driver Code Starts
// Initial Template for C++
//{ Driver Code Starts
#include <bits/stdc++.h>
using namespace std;
// } Driver Code Ends
// } Driver Code Ends
// User function Template for C++
/*
The maximum number of nodes at level ‘l’ of a binary tree is 2^l:
Note: Here, level is the number of nodes on the path from the root to the node (including root and node).
The level of the root is 0.
*/
class Solution
{
public:
int countNodes(int i)
{
return pow(2, i - 1); // This Question considers root as level 1, hence i-1.
}
};
//{ Driver Code Starts.
int main()
{
int t;
cin >> t;
while (t--)
{
int i;
cin >> i;
Solution ob;
int res = ob.countNodes(i);
cout << res;
cout << "\n";
}
}
// } Driver Code Ends