Last active
June 17, 2018 21:51
-
-
Save sazid/a1ef67c680c33347da1be56511a48302 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define MX 6 | |
int arr[MX]; | |
int tree[MX*4]; | |
void build(int node, int b, int e) { | |
if (b == e) { | |
tree[node] = arr[b]; | |
return; | |
} | |
int left = 2*node; | |
int right = 2*node + 1; | |
int mid = (b + e)/2; | |
// left child node | |
build(left, b, mid); | |
// right child node | |
build(right, mid + 1, e); | |
// merge the child nodes | |
tree[node] = tree[left] + tree[right]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment