What Must Be The Missing Logic In Place Of Missing Lines For #490
What must be the missing logic in place of missing lines for finding sum of nodes of binary tree in alternate levels?</p> <pre><code class="language-java"> //e.g:-consider -complete binary tree:-height-3, [1,2,3,4,5,6,7]-answer must be 23 n=power(2,height)-1; //assume input is height and a[i] contains tree elements for(i=1;i<=n;) { //present level is initialized to 1 and sum is initialized to 0 for(j=1;j<=pow(2,currentlevel-1);j++) { sum=sum+a[i]; i=i+1; } //missing logic } </code></pre>
This multiple choice question (MCQ) is related to the book/course gs gs121 Data Structures and Algorithms. It can also be found in gs gs121 Binary Trees - Binary Trees using Array - Quiz No.1.
What must be the missing logic in place of missing lines for finding sum of nodes of binary tree in alternate levels?
//e.g:-consider -complete binary tree:-height-3, [1,2,3,4,5,6,7]-answer must be 23 n=power(2,height)-1; //assume input is height and a[i] contains tree elements for(i=1;i<=n;) { //present level is initialized to 1 and sum is initialized to 0 for(j=1;j<=pow(2,currentlevel-1);j++) { sum=sum+a[i]; i=i+1; } //missing logic }
i=i+pow(2,currentlevel); currentlevel=currentlevel+2; j=1;
i=i+pow(2,currentlevel); currentlevel=currentlevel+2; j=0;
i=i-pow(2,currentlevel); currentlevel=currentlevel+2; j=1;
i=i+pow(2,currentlevel); currentlevel=currentlevel+1; j=1;
Similar question(s) are as followings:
Online Quizzes of gs121 Data Structures and Algorithms
Binary Trees - Binary Search Tree - Quiz No.1
gs gs121 Data Structures and Algorithms
Online Quizzes
Binary Trees - Binary Search Tree - Quiz No.2
gs gs121 Data Structures and Algorithms
Online Quizzes
Binary Trees - Preorder Traversal - Quiz No.1
gs gs121 Data Structures and Algorithms
Online Quizzes