carleton.ca · Web viewCourse: SYSC 2006 ABC Facilitator: Alec Bales D’Cruze Mock Final (for...

18
Course: SYSC 2006 ABC Facilitator: Alec Bales D’Cruze Mock Final (for practice only) Welcome to PASS, a safe and collaborative learning environment where no answers are judged! For times in your local time zone try using this calculator . It is most beneficial to you to write this mock midterm UNDER EXAM CONDITIONS. This means: 1. • Complete the midterm in 2 hours. 2. • Work on your own and attempt every question. 3. • Keep your notes and textbook closed. After the time limit, go back over your work with a different colour or on a separate piece of paper and try to do the questions you are unsure of. Record your ideas in the margins to remind yourself of what you were thinking when you take it up at PASS. The purpose of this mock exam is to give you practice answering questions in a timed setting and to help you to gauge which aspects of the course content you know well, and which are in need of further development and review. Use this mock exam as a learning tool in preparing for the actual exam. Please note: Complete the mock exam before attending the take-up session. During the session you can work with other students to review your work. Often, there is not enough time to review the entire exam in the PASS workshop. Decide which questions you most want to review – the Facilitator may ask students to vote on which questions they want to discuss in detail. Facilitators will not distribute an answer key for mock exams . The Facilitator’s role is to help students work together to compare and assess the answers they have. If you are not able to attend the PASS workshop, you can work alone or with others in the class. PASS worksheets are designed as a study aid only for use in PASS workshops. Worksheets may contain errors, intentional or Mock Take-Up #1: Monday, December 14 th , 6:05 pm – 7:55 pm Mock Take-Up #2: Thursday, December 17 th , 1:05 pm – 2:55 pm Office Hour: Thursday, December 17 th , 4:05 pm – 5:55 pm Email: [email protected]

Transcript of carleton.ca · Web viewCourse: SYSC 2006 ABC Facilitator: Alec Bales D’Cruze Mock Final (for...

Page 1: carleton.ca · Web viewCourse: SYSC 2006 ABC Facilitator: Alec Bales D’Cruze Mock Final (for practice only) Mock Take-Up #1: Monday, December 14th, 6:05 pm – 7:55 pm Mock Take-Up

Course: SYSC 2006 ABCFacilitator: Alec Bales D’CruzeMock Final (for practice only)

Welcome to PASS, a safe and collaborative learning environment where no answers are judged!

For times in your local time zone try using this calculator.

It is most beneficial to you to write this mock midterm UNDER EXAM CONDITIONS. This means: 1. • Complete the midterm in 2 hours. 2. • Work on your own and attempt every question. 3. • Keep your notes and textbook closed.

After the time limit, go back over your work with a different colour or on a separate piece of paper and try to do the questions you are unsure of. Record your ideas in the margins to remind yourself of what you were thinking when you take it up at PASS. The purpose of this mock exam is to give you practice answering questions in a timed setting and to help you to gauge which aspects of the course content you know well, and which are in need of further development and review. Use this mock exam as a learning tool in preparing for the actual exam. Please note:

Complete the mock exam before attending the take-up session. During the session you can work with other students to review your work.

Often, there is not enough time to review the entire exam in the PASS workshop. Decide which questions you most want to review – the Facilitator may ask students to vote on which questions they want to discuss in detail.

Facilitators will not distribute an answer key for mock exams . The Facilitator’s role is to help students work together to compare and assess the answers they have. If you are not able to attend the PASS workshop, you can work alone or with others in the class.

PASS worksheets are designed as a study aid only for use in PASS workshops. Worksheets may contain errors, intentional or otherwise. It is up to the student to verify the information contained within by attending the PASS workshop.

 Good Luck writing the Mock Exam!!

Take-up Session #1: Monday, December 14th, 6:05 pm – 7:55 pm

Take-up Session #2: Thursday, December 17th, 1:05 pm – 2:55 pm

Office Hour: Thursday, December 17th, 4:05 pm – 5:55 pmZoom Meeting Information: Use this link at the appropriate times!

Contact Information: [email protected]

Mock Take-Up #1: Monday, December 14th, 6:05 pm – 7:55 pm Mock Take-Up #2: Thursday, December 17th, 1:05 pm – 2:55 pm

Office Hour: Thursday, December 17th, 4:05 pm – 5:55 pmEmail: [email protected]

Page 2: carleton.ca · Web viewCourse: SYSC 2006 ABC Facilitator: Alec Bales D’Cruze Mock Final (for practice only) Mock Take-Up #1: Monday, December 14th, 6:05 pm – 7:55 pm Mock Take-Up

Course: SYSC 2006 ABCFacilitator: Alec Bales D’CruzeMock Final (for practice only)

Part 1: Short Answer

This is the short answer section of the mock midterm. For all questions make sure to pick best answer unless otherwise specified. A easy way to pick your answer is by highlighing it!

The following figure will be used for the first four questions. This figure shows the time a function takes to run as it's data inputs increase, each line represents a different order of complexity or O-notation.

Question 1: What order of complexity would represent L1?

A) O(1-n)

B) O(2)

C) O(n^2)

D) O(n^n)

Question 2: What order of complexity would represent L2?

A) O(n^(-1))

B) O((1+n)/2)

C) O(n)

D) O(log(n))

Question 3: What order of complexity would represent L3?

A) O(log(n))

B) O(n+1)

C) O(n/2)

D) O(n^0)

Mock Take-Up #1: Monday, December 14th, 6:05 pm – 7:55 pm Mock Take-Up #2: Thursday, December 17th, 1:05 pm – 2:55 pm

Office Hour: Thursday, December 17th, 4:05 pm – 5:55 pmEmail: [email protected]

Page 3: carleton.ca · Web viewCourse: SYSC 2006 ABC Facilitator: Alec Bales D’Cruze Mock Final (for practice only) Mock Take-Up #1: Monday, December 14th, 6:05 pm – 7:55 pm Mock Take-Up

Course: SYSC 2006 ABCFacilitator: Alec Bales D’CruzeMock Final (for practice only)

Question 4: What order of complexity would represent L4?

A) O(1/n)

B) O(1)

C) O(2/n)

D) O(n^1.5)

The next four questions will focus on the following operations: adding at end, adding at beginning, removing from end, removing from beginning, deleting all elements and adding in order.

Question 5: Which operation is of O(n) complexity for all following data structures? (singly linked list, array, ring array)

A) Delete all

B) Add in order

C) Remove from the end

D) None of the above

Question 6: What data structure has the most operations that are of complexty O(1)?

A) Singly linked list tail pointer

B) Ring Array

C) Array

D) Singly linked lists

Question 7: What operation is of complexity O(n) for a regular array?

A) Adding at beginning

B) Delete All

C) Add at end

D) Both B) and C)

Question 8: What operation are NOT of complexty O(1) for a singly linked list with a tail pointer?

A) Add at beginning,

B) Add at end

C) Delete at beginning

D) Delete at endMock Take-Up #1: Monday, December 14th, 6:05 pm – 7:55 pm

Mock Take-Up #2: Thursday, December 17th, 1:05 pm – 2:55 pmOffice Hour: Thursday, December 17th, 4:05 pm – 5:55 pm

Email: [email protected]

Page 4: carleton.ca · Web viewCourse: SYSC 2006 ABC Facilitator: Alec Bales D’Cruze Mock Final (for practice only) Mock Take-Up #1: Monday, December 14th, 6:05 pm – 7:55 pm Mock Take-Up

Course: SYSC 2006 ABCFacilitator: Alec Bales D’CruzeMock Final (for practice only)

The following figure will be used for the next two questions:

Question 9: What will the function in the code above do?

A) Calculate the sum of an array

B) Calculate the median of an array

C) Calculated the average of an array

D) Create an array on the heap

Question 10: What is the function in code above an example of?

A) A pass by value array

B) A O(1) operation

C) Dynamically allocated memory

D) A walking pointer

Mock Take-Up #1: Monday, December 14th, 6:05 pm – 7:55 pm Mock Take-Up #2: Thursday, December 17th, 1:05 pm – 2:55 pm

Office Hour: Thursday, December 17th, 4:05 pm – 5:55 pmEmail: [email protected]

Page 5: carleton.ca · Web viewCourse: SYSC 2006 ABC Facilitator: Alec Bales D’Cruze Mock Final (for practice only) Mock Take-Up #1: Monday, December 14th, 6:05 pm – 7:55 pm Mock Take-Up

Course: SYSC 2006 ABCFacilitator: Alec Bales D’CruzeMock Final (for practice only)

The following code will be used for the next two questions:

Question 11: What values will slice “t” contain?

A) [10 20 30 40]

B) [20 30 40 50]

C) [10 20 30]

D) [20 30 40]

Question 12: What will the values of len(t) and cap(t) be repectively?

A) len = 4 cap = 6

B) len = 3 cap = 7

C) len = 3 cap = 6

D) len = 3 cap = 3

What data structure would best represent the following situations?

Question 13: Removing shipping containers from a conatiner ship

A) Queue

B) Stack

C) Ring Array

D) Array

Question 14: Traffic in a traffic jam

A) Queue

B) Stack

C) Doubly Linked List

D) Array

Mock Take-Up #1: Monday, December 14th, 6:05 pm – 7:55 pm Mock Take-Up #2: Thursday, December 17th, 1:05 pm – 2:55 pm

Office Hour: Thursday, December 17th, 4:05 pm – 5:55 pmEmail: [email protected]

Page 6: carleton.ca · Web viewCourse: SYSC 2006 ABC Facilitator: Alec Bales D’Cruze Mock Final (for practice only) Mock Take-Up #1: Monday, December 14th, 6:05 pm – 7:55 pm Mock Take-Up

Course: SYSC 2006 ABCFacilitator: Alec Bales D’CruzeMock Final (for practice only)

Question 15: 16 eggs in a carton

A) Ring Array

B) Stack

C) Linked List

D) Array

Question 16: Storing the undo and redo operations of a text editor

A) Queue

B) Slack

C) Doubly Linked List

D) Array

Question 17: What will the values in this program be once it has reached line 12?

A) y1 = 3 y2 = 4 y3 = -1 x1 = 3 x2 = 4 x3 = -1

B) y1 = 1 y2 = 3 y3 = 1 x1 = 3 x2 = 3 x3 = -1

C) y1 = 2 y2 = 4 y3 = 0 x1 = 3 x2 = 4 x3 = -1

D) y1 = 3 y2 = 3 y3 = -1 x1 = 3 x2 = 4 x3 = -1

Mock Take-Up #1: Monday, December 14th, 6:05 pm – 7:55 pm Mock Take-Up #2: Thursday, December 17th, 1:05 pm – 2:55 pm

Office Hour: Thursday, December 17th, 4:05 pm – 5:55 pmEmail: [email protected]

Page 7: carleton.ca · Web viewCourse: SYSC 2006 ABC Facilitator: Alec Bales D’Cruze Mock Final (for practice only) Mock Take-Up #1: Monday, December 14th, 6:05 pm – 7:55 pm Mock Take-Up

Course: SYSC 2006 ABCFacilitator: Alec Bales D’CruzeMock Final (for practice only)

Question 18: The fibonacci squence is calculated by adding together the two values that came before the desired order of the sequence. What will be the base and recursive case for a recursive function that calculates the fibonacci sequence? The function header will look as follows:

int fib(int n){} (Assume all input values will be greater than 0)

A) Base: if(n < 3) return 1; Recusive: return fib(n-1) – fib(n-2);

B) Base: if(n == 2) return 1; Recusive: return fib(n-1) + fib(n-2);

C) Base: if(n =< 2) return 1; Recusive: return fib(n + fib(n-2));

D) Base: if(n < 3) return 1; Recusive: return fib(n-1) + fib(n-2);

The following figure will will be used for the next 5 questions:

Question 19: What will be the value stored in a?

A) 18

B) 17

C) 16

D) 15

Question 20: What will be the value stored in b?

A) 0

B) positive interger

C) negative interger

D) none of the above

Mock Take-Up #1: Monday, December 14th, 6:05 pm – 7:55 pm Mock Take-Up #2: Thursday, December 17th, 1:05 pm – 2:55 pm

Office Hour: Thursday, December 17th, 4:05 pm – 5:55 pmEmail: [email protected]

Page 8: carleton.ca · Web viewCourse: SYSC 2006 ABC Facilitator: Alec Bales D’Cruze Mock Final (for practice only) Mock Take-Up #1: Monday, December 14th, 6:05 pm – 7:55 pm Mock Take-Up

Course: SYSC 2006 ABCFacilitator: Alec Bales D’CruzeMock Final (for practice only)

Question 21: What will be the value stored in c?

A) 0

B) positive interger

C) negative interger

D) none of the above

Question 22: What will be the value stored in d?

A) 0

B) positive interger

C) negative interger

D) none of the above

Question 23: What will be the value stored in e?

A) 17

B) 18

C) 40

D) 41

Question 24: What will be the value stored in f?

A) 40

B) 41

C) 32

D) 33

Mock Take-Up #1: Monday, December 14th, 6:05 pm – 7:55 pm Mock Take-Up #2: Thursday, December 17th, 1:05 pm – 2:55 pm

Office Hour: Thursday, December 17th, 4:05 pm – 5:55 pmEmail: [email protected]

Page 9: carleton.ca · Web viewCourse: SYSC 2006 ABC Facilitator: Alec Bales D’Cruze Mock Final (for practice only) Mock Take-Up #1: Monday, December 14th, 6:05 pm – 7:55 pm Mock Take-Up

Course: SYSC 2006 ABCFacilitator: Alec Bales D’CruzeMock Final (for practice only)

Question 25: Following pop function for a stack will produce and error, where does this occur?

A) 48 and 49

B) 55 and 56

C) 56 and 57

D) 58

Question 26: Which of the following lines in this queues enqueue function is not an error?

A) 36

B) 41

C) 44

D) 45

Mock Take-Up #1: Monday, December 14th, 6:05 pm – 7:55 pm Mock Take-Up #2: Thursday, December 17th, 1:05 pm – 2:55 pm

Office Hour: Thursday, December 17th, 4:05 pm – 5:55 pmEmail: [email protected]

Page 10: carleton.ca · Web viewCourse: SYSC 2006 ABC Facilitator: Alec Bales D’Cruze Mock Final (for practice only) Mock Take-Up #1: Monday, December 14th, 6:05 pm – 7:55 pm Mock Take-Up

Course: SYSC 2006 ABCFacilitator: Alec Bales D’CruzeMock Final (for practice only)

Question 27: What is the following code an example of?

A) Obfuscated C Code

B) Clearly a flight simulator

C) Your guess is as good as mine

D) The winner of the 1998 International Obfuscated C Code Contest

Mock Take-Up #1: Monday, December 14th, 6:05 pm – 7:55 pm Mock Take-Up #2: Thursday, December 17th, 1:05 pm – 2:55 pm

Office Hour: Thursday, December 17th, 4:05 pm – 5:55 pmEmail: [email protected]

Page 11: carleton.ca · Web viewCourse: SYSC 2006 ABC Facilitator: Alec Bales D’Cruze Mock Final (for practice only) Mock Take-Up #1: Monday, December 14th, 6:05 pm – 7:55 pm Mock Take-Up

Course: SYSC 2006 ABCFacilitator: Alec Bales D’CruzeMock Final (for practice only)

Part 2: Long Answer

In this section wiritng your own code will be required, answer all questions to the best of your ability!

Question 1: Write a strlen function below using a walking pointer implementation. The main and the function header have been provided.

Main: Your Code Here:int main(){

char string[] = “This is an array of chars.”;

int a = strlen(string)

return 0;}

size_t strlen(const char *s) {

}(size_t is a data type in C that essential means an unsigned interger)

Mock Take-Up #1: Monday, December 14th, 6:05 pm – 7:55 pm Mock Take-Up #2: Thursday, December 17th, 1:05 pm – 2:55 pm

Office Hour: Thursday, December 17th, 4:05 pm – 5:55 pmEmail: [email protected]

Page 12: carleton.ca · Web viewCourse: SYSC 2006 ABC Facilitator: Alec Bales D’Cruze Mock Final (for practice only) Mock Take-Up #1: Monday, December 14th, 6:05 pm – 7:55 pm Mock Take-Up

Course: SYSC 2006 ABCFacilitator: Alec Bales D’CruzeMock Final (for practice only)

Question 2: Convert the recursive code on the left from regular recusion to tail recursion, assume the user will not enter a invalid input. Tail recursion means there is no operations being preformed in the recursive return statement only in the function call.

Recusive Code: Your Tail Recursive Code:

Mock Take-Up #1: Monday, December 14th, 6:05 pm – 7:55 pm Mock Take-Up #2: Thursday, December 17th, 1:05 pm – 2:55 pm

Office Hour: Thursday, December 17th, 4:05 pm – 5:55 pmEmail: [email protected]

Page 13: carleton.ca · Web viewCourse: SYSC 2006 ABC Facilitator: Alec Bales D’Cruze Mock Final (for practice only) Mock Take-Up #1: Monday, December 14th, 6:05 pm – 7:55 pm Mock Take-Up

Course: SYSC 2006 ABCFacilitator: Alec Bales D’CruzeMock Final (for practice only)

Question 3: Convert the following Go code to the same program in C. You can be as creative as you like as long as the program accomplishes the same task and prints the same data.

Go Code: Your C Program here:

Mock Take-Up #1: Monday, December 14th, 6:05 pm – 7:55 pm Mock Take-Up #2: Thursday, December 17th, 1:05 pm – 2:55 pm

Office Hour: Thursday, December 17th, 4:05 pm – 5:55 pmEmail: [email protected]

Page 14: carleton.ca · Web viewCourse: SYSC 2006 ABC Facilitator: Alec Bales D’Cruze Mock Final (for practice only) Mock Take-Up #1: Monday, December 14th, 6:05 pm – 7:55 pm Mock Take-Up

Course: SYSC 2006 ABCFacilitator: Alec Bales D’CruzeMock Final (for practice only)

Question 3: Write code to preform the following tasks: Add in decending order to a linked list and delete the entire linked list in one pass through. The main of the code will be provided along with some helpful functions, strucutures and the headers of the functions to be written

Main: Provided Structures and Functionsint main(void) { intnode_t *head = NULL; head = decendingOrder(head, 20); head = decendingOrder(head, 40); head = decendingOrder(head, 10); head = decendingOrder(head, 30);

deleteList(head); head = NULL; return 0;}

#include <stdlib.h>#include <assert.h>

typedef struct intnode { int value; struct intnode *next;} intnode_t;

intnode_t *intnode_construct(int value, intnode_t *next){ intnode_t *ptr; ptr = malloc(sizeof(intnode_t)); assert(ptr != NULL); ptr->value = value; ptr->next = next; return ptr;}

Add in decending order:intnode_t* decendingOrder(intnode_t* head, int value){

}Delete entire list in one pass through:void *deleteList(intnode_t *head){

}

Mock Take-Up #1: Monday, December 14th, 6:05 pm – 7:55 pm Mock Take-Up #2: Thursday, December 17th, 1:05 pm – 2:55 pm

Office Hour: Thursday, December 17th, 4:05 pm – 5:55 pmEmail: [email protected]