ProgrammingVery hardGATE CS · Product company OA
With the tree below, what does in(0) print?
With the tree below, what does in(0) print?
char key[] = "ABCDE";
int L[] = {1, 3, -1, -1, -1}, R[] = {2, 4, -1, -1, -1};
void in(int n) {
if (n < 0) return;
in(L[n]);
putchar(key[n]);
in(R[n]);
}- A. DBAEC
- B. DBEAC
- C. ABDEC
- D. DEBCA
Correct answer: B. DBEAC
A is the root with left child B and right child C; B has children D and E. In-order visits left subtree, node, right subtree: D B E, then A, then C. ABDEC is pre-order and DEBCA post-order.
More C Programming questions
- What is wrong with this code? c char s = malloc(5); strcpy(s, "hello");
- With 4-byte int, what is printed? c int a[3] = {7, 8, 9}; int (p)[3] = &a; printf("%d %d %zu", (p)[1], p + 1, sizeof p);
- What is printed? c int c = 0, calls = 0; void comb(int start, int n, int k) { calls++; if (k == 0) { c++; return; } for (int i = start; i…
- What is printed? c int x = 3, y = 1; printf("%d %d", !x == y, !(x == y));
- For ints a and b with b != 0 and no overflow, which statement is always true in C99 and later?
- Why should a header file shared by several .c files not contain the line int counter = 0;?