Skip to content

Instantly share code, notes, and snippets.

@sazid
Last active June 17, 2018 21:51
Show Gist options
  • Save sazid/a1ef67c680c33347da1be56511a48302 to your computer and use it in GitHub Desktop.
Save sazid/a1ef67c680c33347da1be56511a48302 to your computer and use it in GitHub Desktop.
#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