FE-Jan19.pdf-Page 1 of 4 Computer Scienc...
FE-Jan19.pdf-Page 1 of 4 Computer Science
Showing 4-7 out of 16
FE-Jan19.pdf-Page 1 of 4 Computer Science
FE-Jan19.pdf-Page 1 of 4 Computer Science
FE-Jan19.pdf-Page 1 of 4 Computer S...
FE-Jan19.pdf-Page 1 of 4 Computer Science
Page 4
Spring 2019
Data Structures Exam, Part A
Page
4
of
4
3)
(5 pts) ALG (Stacks and Queues)
Consider the following function:
void doTheThing(void)
{
int i, n = 9;
// Note: There are 9 elements in the following array.
int array[] = {3, 18, 58, 23, 12, 31, 19, 26, 3};
Stack *s1 = createStack();
Stack *s2 = createStack();
Queue *q = createQueue();
for (i = 0; i < n; i++)
push(s1, array[i]);
while (!isEmptyStack(s1))
{
while (!isEmptyStack(s1))
enqueue(q, pop(s1));
// pop element from s1 and enqueue it in q
while (!isEmptyQueue(q))
push(s2, dequeue(q));
// dequeue from q and push onto s2
printf("%d ", pop(s2));
// pop from s2 and print element
while (!isEmptyStack(s2))
push(s1, pop(s2));
// pop from s2 and push onto s1
}
printf("Tada!\n");
freeStack(s1);
freeStack(s2);
freeQueue(q);
}
What will be the exact output of the function above? (You may assume the existence of all functions
written in the code, such as
createStack()
,
createQueue()
,
push()
,
pop()
, and so on.)


Page 5
Page
1
of
4
Computer Science Foundation Exam
January 12, 2019
Section I B
DATA STRUCTURES
NO books, notes, or calculators may be used,
and you must work entirely on your own.
Name:
___________________________________________
UCFID:
___________________________________________
NID:
___________________________________________
Question #
Max Pts
Category
Passing
Score
1
5
DSN
3
2
10
ALG
7
3
10
ALG
7
TOTAL
25
17
You must do all 3 problems in this section of the exam.
Problems will be graded based on the completeness of the solution steps and not
graded based on the answer alone.
Credit cannot be given unless all work is shown
and is readable. Be complete, yet concise, and above all
be neat
. For each coding
question, assume that all of the necessary includes (stdlib, stdio, math, string) for
that particular question have been made.


Page 6
Spring 2019
Data Structures Exam, Part B
Page
2
of
4
1)
(5 pts) DSN (Binary Trees)
Write a
recursive
function to print a postorder traversal of all the integers in a binary tree. The node
struct and function signature are as follows:
typedef struct node
{
struct node *left;
struct node *right;
int data;
} node;
void print_postorder(node *root)
{


Page 7
Spring 2019
Data Structures Exam, Part B
Page
3
of
4
2)
(10 pts) ALG (Minheaps)
a)
Show the result of inserting the value 24 into the following minheap.
33
/
\
41
89
/
\
/
77
50 92
b)
Show the result of deleting the root of the following minheap.
33
/
\
41
89
/
\
/
77
50
92
c)
Using big-oh notation, what is the
worst-case
runtime for deleting the minimum element from a
minheap that has
n
nodes?


Ace your assessments! Get Better Grades
Browse thousands of Study Materials & Solutions from your Favorite Schools
University of Pune
University_of_Pune
School:
Computer_Science_I
Course:
Great resource for chem class. Had all the past labs and assignments
Leland P.
Santa Clara University
Introducing Study Plan
Using AI Tools to Help you understand and remember your course concepts better and faster than any other resource.
Find the best videos to learn every concept in that course from Youtube and Tiktok without searching.
Save All Relavent Videos & Materials and access anytime and anywhere
Prepare Smart and Guarantee better grades

Students also viewed documents