Skip to content

Instantly share code, notes, and snippets.

@manosriram
Created July 1, 2019 16:54
Show Gist options
  • Save manosriram/9a7616d9f091c447300fdc6d94d3739b to your computer and use it in GitHub Desktop.
Save manosriram/9a7616d9f091c447300fdc6d94d3739b to your computer and use it in GitHub Desktop.
void buildTreeMinSum(int *a, int *tree, int start, int end, int treeNode)
{
if (start == end)
{
tree[treeNode] = a[start];
return;
}
int mid = (start + end) / 2;
buildTreeMinSum(a, tree, start, mid, 2 * treeNode);
buildTreeMinSum(a, tree, mid + 1, end, (2 * treeNode) + 1);
tree[treeNode] = min(tree[2 * treeNode], tree[(2 * treeNode) + 1]);
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment