FOA Practice Exam Attempt 1
FOA Practice Exam Attempt 1
Instructions
This Practice Exam is an accurate reflection of the content, style, and difficulty of the main exam.
employ grok or a gcc/compilation environment to write and test functions, before you paste
them into the answer boxes;
make use of the textbook and lecture slides in soft- or hard-copy form.
make any use of communications devices or channels, such as mobile phones, text messages,
WeChat or WhatsApp, email, or other messaging technologies, while undertaking this
assessment;
make use of any world-wide web or internet based resources, including google and other
search services, wikipedia, and stackoverfow;
make use any soft- or hard-copy documents or resources except for the textbook and lecture
slides;
discuss the questions or their answers with any other person, both during the Exam and after
the completion of the Exam;
engage in any actions that would encourage, permit, or support other enrolled students to
violate the Academic Honesty expectations that apply to this assessment, even if they are
completing this assessment at a different time to you.
In the real Exam you will have 15 minutes of reading time, and then 120 minutes of writing time.
This Practice Quiz will allow you 135 minutes of access.
Attempt History
Attempt Time Score
LATEST Attempt 1 128 minutes 11.67 out of 40 *
* Some questions not yet graded
Question 1 1 / 1 pts
Correct!
calculation, selection, iteration, and abstraction
Question 2 0 / 1 pts
*c
c->c->c->c
(*c).a.b.c
Question 3 1 / 1 pts
Correct!
Struct variables can only be passed to functions via a pointer
Question 4 0 / 1 pts
What is size_t in C?
Correct Answer
A data type for storing the non-negative integers used for memory
management.
You Answered
A data type that Alistair invented and used in one of the example
programs shown in the subject.
Question 5 0 / 1 pts
-38
+93
+38
You Answered +221
Question 6 1 / 1 pts
In the 32-bit floating point system (for float variables) that was
explored using the floatbits.c program the following bit patterns are
observed for the three given values, expressed as four 8-bit bytes:
Question 7 1 / 1 pts
Which of the following is not a valid file access mode to use with a
call to fopen():
"w+", to create a new file that will be both written to and also read
Correct!
"rw", to both read from and write to an existing file
Question 8 1 / 1 pts
Stacks and queues are two abstract data types that both support
insert and remove operations. One way of implementing these data
types is via linked lists. In regard to a linked list implementation of
stacks and queues, which is the most correct statement:
Correct!
void
mystery(int n) {
int i, j, k;
int sum1=0, sum2=0, sum3=0;
for (i=0; i<n; i++) {
sum1++;
for (j=0; j<i; j++) {
sum2++;
for (k=i*j; k>0; k=k/2) {
sum3++;
}
}
}
return;
}
Each of the three variables sum1, sum2, and sum3 ends up with a value
that is a function of n. Match those variables on the left with the
possible big-Oh expressions on the right.
Question 10 0 / 2 pts
now#or#never
0 0 1 1 2 2 3
01234567890123456789012345678901234
not#now#not#never#not#now#nor#never
Trace the KMP algorithm as it operates from then on, and indicate
the character offsets in T (using the numbers above the string as a
guide) of the third, fifth, and seventh alignments of the pattern.
Correct Answer 3
You Answered The offset associated 4
with the fifth alignment
is
Correct Answer 8
Correct Answer 11
Question 11 2 / 2 pts
Question 12 2 / 2 pts
The following declarations are exactly the same as the ones used in
the file lists.h that was discussed in class.
struct node {
data_t data;
node_t *next;
};
typedef struct {
node_t *head;
node_t *foot;
} list_t;
list_t
*reverse(list_t *list) {
node_t *curr, *prev, *next;
assert(list);
prev = NULL;
curr = list->head;
while (curr) {
// line A
// line B
// line C
curr = next;
}
list->foot = list->head;
// line D
return list;
}
Match the line locations on the left with the correct assignment
statements on the right.
Question 13 2 / 2 pts
The first phase of heapsort converts the input array to an initial heap.
Match the initial heap array locations on the left with the elements
that they contain on the right.
Be sure to select "Preformatted" for the LMS text box before you
enter each answer, and (if necessary) again after you have pasted
text into it. If you choose to develop your function using grok or
another external tool, be sure to paste your answer regularly into the
text box, so your progress is recorded; and be sure to use spaces to
indent your code, and not tabs. Tabs cannot be typed into the LMS
text box.
Your Answer:
#define MAX_CHAR 40;
#define MAX_BOOK 100000;
#define MAX_RECENT_BORROW 10;
typedef struct {
int book_num;
char title[MAX_CHAR+1];
char author[MAX_CHAR+1];
char publisher[MAX_CHAR+1];
int year;
int borrow_times;
int library_cards[MAX_RECENT_BORROW+1];
} book_t;
typedef struct {
book_t library[MAX_BOOK];
} library_t;
{1,1,1,2,2,2,2,2,5,4,4,4,1,1,1,1,1,1,3,3,3,0}
The last value in the array is always zero, and provides a sentinel,
meaning that a buddy variable is not required.
A student notices that there are often repeated values straight after
each other, and suggests that the data could be restructured into a
packed form, with negative numbers introduced to indicate repetitions
of the previous (positive) value. For example, the same data would
be represented in this packed form as:
{1,-2,2,-4,5,4,-2,1,-5,3,-2,0}
Write a function
You may assume that A[] is large enough to contain the fully
unpacked sequence. You may not declare any arrays within your
function.
Be sure to select "Preformatted" for the LMS text box before you
enter each answer, and (if necessary) again after you have pasted
text into it. If you choose to develop your function using grok or
another external tool, be sure to paste your answer regularly into the
text box, so your progress is recorded; and be sure to use spaces to
indent your code, and not tabs. Tabs cannot be typed into the LMS
text box.
Your Answer:
void
unpack(int A[]) {
int i = 0, j;
while (A[i]!=0) {
if (A[i] < 0) {
for (j=i+1; j!=0; j++) {
A[j]
}
}
i++
}
struct tree {
data_t data; // the data stored at this node
tree_t *left; // left subtree of node
tree_t *rght; // right subtree of node
};
would be:
fat
/ \
cat fat
/ \ \
bat eat rat
/ /
cat fat
You only need to submit the required function, but may include other
functions too if you decide to break the process into smaller parts. Do
not submit a main program.
to each data item stored in the tree, and returns the sum of those
integer values, added up over all of the data_t elements stored in the
tree. If t is empty then sum_tree(t) should return zero. You do not
need to write get_int(), and may call it without knowing anything
about its operation.
Be sure to select "Preformatted" for the LMS text box before you
enter each answer, and (if necessary) again after you have pasted
text into it. If you choose to develop your function using grok or
another external tool, be sure to paste your answer regularly into the
text box, so your progress is recorded; and be sure to use spaces to
indent your code, and not tabs. Tabs cannot be typed into the LMS
text box.
Your Answer:
int
sum_trees(tree_t *t) {
int right_side, left_side, sum=0;
if (t!= NULL) {
right_side = sum_trees(t -> right);
left_side = sum_trees(t -> left);
sum = (t -> data) + right_side + left_side;
}
}
Unanswered
Question 17 Not yet graded / 3 pts
that creates a new tree node that stores the data value indicated by
*d, and inserts it into the correct place in t, returning the new address
of the root of the tree.
For example, a typical calling sequence for this function might be:
tree_t *t=NULL;
data_t d;
while (get_value(&d)) {
// now insert d into t
t = bst_insert(t, &d);
}
// t now contains all of the data
Before starting to answer this question, you should read the next
question too. You may find it convenient to develop a single helper
function that can assist with both bst_insert() and the bst_merge()
function required by the next question.
Be sure to select "Preformatted" for the LMS text box before you
enter each answer, and (if necessary) again after you have pasted
text into it. If you choose to develop your function using grok or
another external tool, be sure to paste your answer regularly into the
text box, so your progress is recorded; and be sure to use spaces to
indent your code, and not tabs. Tabs cannot be typed into the LMS
text box.
Your Answer:
Unanswered
Question 18 Not yet graded / 2 pts
that constructs and returns a single tree containing the union (the
merge) of the elements in t1 and t2, by combining them and at the
same time destroying the original trees.
For example, a typical calling sequence for this function might be:
Be sure to select "Preformatted" for the LMS text box before you
enter each answer, and (if necessary) again after you have pasted
text into it. If you choose to develop your function using grok or
another external tool, be sure to paste your answer regularly into the
text box, so your progress is recorded; and be sure to use spaces to
indent your code, and not tabs. Tabs cannot be typed into the LMS
text box.
Your Answer:
Section 4 -- Algorithms (8 marks in
total)
The next several questions relate to the following problem
description. Read it carefully, and then move on to the questions.
then when k=2, the value required is 17, because if A[] was sorted,
then A[2] would be 17.
Use the answer box below to describe in English the approach that
Student A is thinking of.
You must give enough detail in your answer that the marker can be
sure that the approach you are describing will (a) solve the problem,
and (b) have the stated analysis.
Your Answer:
Use the answer box below to describe in English the approach that
Student B is thinking of.
You must give enough detail in your answer that the marker can be
sure that the approach you are describing will (a) solve the problem,
and (b) have the stated analysis.
Your Answer:
Use the answer box below to describe in English the approach that
Student C is thinking of.
You must give enough detail in your answer that the marker can be
sure that the approach you are describing will (a) solve the problem,
and (b) have the stated analysis.
Your Answer:
Use the answer box below to describe in English the approach that
Student D is thinking of.
You must give enough detail in your answer that the marker can be
sure that the approach you are describing will (a) solve the problem,
and (b) have the stated analysis.
Your Answer: