Question 1:  (7 points)

Top of Form

Declare a record data type in C named qwack that can simultaneously hold

a real number named fox, a character named bingo, and an integer named

age, in that order.

Bottom of Form

 

Question 2:  (7 points)

Top of Form

What is wrong with the following sequence of C statements?

char * p1;

char * p2;

char * tmp;

p1=(char *) malloc(sizeof(char));

p2=(char *) malloc(sizeof(char));

*p1='A';

*p2='B';

tmp=p1;

p2=tmp;

Bottom of Form

 

Question 3:  (7 points)

Top of Form

Given the following list of numbers, how many passes must radix sort make in

order to sort the list?

 

123, 432, 543, 3567, 89765, 4321, 7865, 423

Bottom of Form

 

Question 4:  (8 points)

Top of Form

You encounter the following list of numbers from left to right and put them into a

binary search tree.  23 18 41 11 15 26 19 28 7 10

Next you encounter the number 25 and insert it into the tree.

a.

25 becomes the right child of 23

b.

25 becomes the left child of 28

c.

25 becomes the left child of 26

d.

none of the above

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Bottom of Form

Question 5:  (7 points)

Top of Form

Big-O refers to a worst-case performance statistic for algorithms based on

the size of the input.  Which of the following is the best performer in terms of

this statistic for a large amount of data that still fits into memory?

a.

quick sort

b.

merge sort

c.

selection sort

Question 6:  (8 points)

Top of Form

You are going to encounter a widly variable amount of data from users who

are running your program.  The data must be processed using a stack. 

Which implementation will you choose?

a.

An array-counter based implementation because it has less

metadata.

b.

A linked list based implementation because it can adapt to the

amount of data the user inputs.

c.

neither of the above is acceptable for this problem.

Question 7:  (8 points)

Top of Form

Data must be processed in the same order in which it is encountered - i.e.

the first item entered is the first item processed.  Which data structure will

best enable you to do this?

a.

a simple linked list

b.

a stack

c.

a queue  

d.

a tree

e.

none of the above

 

 

 

 

 

 

 

 

 

Question 8:  (8 points)

Top of Form

Given the following declarations:

char c;

char cs[20];

Why doesn't the second scanf below have an & in front of the cs while the

first one has an & in front of the c?

scanf("%c", &c);

scanf("%s", cs);

a.

It is an error to omit the & in front of cs

b.

it is an error to include the & in front of c

c.

cs is an array

d.

none of the above

 

Question 9:  (8 points)

Top of Form

Assume that you have obtained the name of a file from the user and it is

stroed in the string variable fname.  You have a variable declared as

FILE * ifile;

What is the C command that will open this file for reading and associate it

with the variable ifile?  Answer format:  no spaces in your answer.

Answer

Question 10:  (8 points)

Top of Form

Given the binary tree in figure 1 (downloaded word document), list the node

numbers in the order they would be visited during a preorder traversal - separate

the numbers by single spaces.

Answer

Question 11:  (8 points)

Top of Form

What is the philosophy behind insertion sort?

a.

Given a value, find its position and put it there

b.

Given a position, find the proper value and put it there

c.

neither of the above

 

 

 

 

 

Question 12:  (8 points)

Top of Form

What is the philosophy behind selection sort?

a.

Given a value, find its position and put it there.

b.

Given a position, find the proper value and put it there.

c.

neither of the above  

Question 13:  (8 points)

Top of Form

Show the output of the function fun when called on the string s="AbEfIjOpUv";

 

void fun(char * str)

{

  if (str[0]==NULL) return;

  if(islower(str[0])

    printf("%c", toupper(str[0]));

  else

    printf("%c", tolower(str[0]));

  fun(str+1);

}

 

Call is fun(s);

Answer

Bottom of Form

Bottom of Form

Bottom of Form

Bottom of Form

Bottom of Form

Bottom of Form

Bottom of Form

Bottom of Form

Bottom of Form