Questions 61–70 of 106. Imported answers require independent review unless marked reviewed.

Topic practice 106 questionsPage 7 of 11

Question 23

Open question
CSNAT1 markNeeds review
Consider the following ANSI C function:
int SomeFunction(int x, int y)
{
if ((x == 1) || (y == 1)) return 1;
if (x == y) return x;
if (x > y) return SomeFunction(x - y, y);
if (y > x) return SomeFunction(x, y - x);
}
The value returned by SomeFunction(15, 255) is ________.

Log in to check the answer

You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answer

Question 35

Open question
CSMCQ2 marksNeeds review
Consider the following ANSI C program:
#include <stdio.h>
#include <stdlib.h>
struct Node{
int value;
struct Node *next;};
int main(){
struct Node *box, *head, *boxN; int index = 0;
box = head = (struct Node *) malloc(sizeof(struct Node));
head->value = index;
for (index = 1; index <= 3; index++){
boxN = (struct Node *) malloc(sizeof(struct Node));
box->next = boxN;
boxN->value = index;
box = boxN; }
for (index = 0; index <= 3; index++) {
printf("Value at index %d is %d\n", index, head->value);
head = head->next;
printf("Value at index %d is %d\n", index+1, head->value); } }
Which one of the statements below is correct about the program?
Your answerChoose one option.

Log in to check the answer

You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answer

Question 36

Open question
CSMCQ2 marksNeeds review
Let

be an undirected unweighted connected graph. The diameter of

is defined as:

Let

be the adjacency matrix of

. Define graph

on the same set of vertices with adjacency matrix

, where

Which one of the following statements is true?
Your answerChoose one option.

Log in to check the answer

You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answer

Question 37

Open question
CSMCQ2 marksNeeds review
Consider the following ANSI C program.
#include <stdio.h>
int main()
{
int i, j, count;
count = 0;
i = 0;
for (j = -3; j <= 3; j++)
{
if ((j >= 0) && (i++))
count = count + j;
}
count = count + i;
printf("%d", count);
return 0;
}
Which one of the following options is correct?
Your answerChoose one option.

Log in to check the answer

You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answer

Question 48

Open question
CSNAT2 marksNeeds review
Consider the following ANSI C function:
int SimpleFunction(int Y[], int n, int x)
{
int total = Y[0], loopIndex;
for (loopIndex = 1; loopIndex <= n - 1; loopIndex++)
total = x * total + Y[loopIndex];
return total;
}
Let

be an array of 10 elements with

, for all

such that

. The value returned by SimpleFunction(Z, 10, 2) is __________.

Log in to check the answer

You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answer

Question 49

Open question
CSNAT2 marksNeeds review
Consider the following ANSI C program.
#include <stdio.h>

int foo(int x, int y, int q)
{
if ((x <= 0) && (y <= 0))
return q;
if (x <= 0)
return foo(x, y-q, q);
if (y <= 0)
return foo(x-q, y, q);
return foo(x, y-q, q) + foo(x-q, y, q);
}

int main()
{
int r = foo(15,15,10);
printf("%d", r);
return 0;
}
The output of the program upon execution is ______.

Log in to check the answer

You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answer

Question 5

Open question
CSMCQ1 markNeeds review
The preorder traversal of a binary search tree is 15, 10, 12, 11, 20, 18, 16, 19.
Which one of the following is the postorder traversal of the tree?
Your answerChoose one option.

Log in to check the answer

You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answer

Question 16

Open question
CSMCQ1 markNeeds review
What is the worst case time complexity of inserting

elements into an empty linked list, if the linked list needs to be maintained in sorted order?
Your answerChoose one option.

Log in to check the answer

You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answer

Question 22

Open question
CSNAT1 markNeeds review
Consider the following C program.
#include <stdio.h>
int main() {
int a[4][5]={{1, 2, 3, 4, 5},
{6, 7, 8, 9, 10},
{11, 12, 13, 14, 15},
{16, 17, 18, 19, 20}};
printf("%d\n", *(*(a+*a+2)+3));
return(0);
}
The output of the program is ________.

Log in to check the answer

You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answer

Question 46

Open question
CSNAT2 marksNeeds review
Consider the following C functions.
int fun1(int n) {
static int i = 0;
if (n > 0) {
++i;
fun1(n-1);
}
return (i);
}

int fun2(int n) {
static int i = 0;
if (n > 0) {
i = i + fun1(n);
fun2(n-1);
}
return (i);
}
The return value of fun2(5) is ______.

Log in to check the answer

You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answer