COP 3502 Section 2 Exam #2 Version A Spring /23/2017

Similar documents
COP 3502 (Computer Science I) Test #3: Data Structures Date: 11/1/2013 VERSION A

C Data Structures Stacks. Stack. push Adds a new node to the top of the stack

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

Computer Science Foundation Exam

Data Structure Advanced

Cpt S 122 Data Structures. Course Review Midterm Exam # 1

Stacks, Queues and Hierarchical Collections. 2501ICT Logan

Stacks, Queues and Hierarchical Collections

CP2 Revision. theme: dynamic datatypes & data structures

Stack Applications. Lecture 27 Sections Robb T. Koether. Hampden-Sydney College. Wed, Mar 29, 2017

DC104 DATA STRUCTURE JUNE Q.2 a. If you are using C language to implement the heterogeneous linked list, what pointer type will you use?

ECE264 Fall 2013 Exam 3, November 20, 2013

Prepared By: Ms. Nidhi Solanki (Assist. Prof.) Page 1

ECE264 Spring 2013 Final Exam, April 30, 2013

Name CPTR246 Spring '17 (100 total points) Exam 3

3137 Data Structures and Algorithms in C++

CS24 Week 8 Lecture 1

Computer Science Foundation Exam

Computer Science Foundation Exam

PA3 Design Specification

DNHI Homework 3 Solutions List, Stacs and Queues

1 P a g e A r y a n C o l l e g e \ B S c _ I T \ C \

Trees! Ellen Walker! CPSC 201 Data Structures! Hiram College!

University of Illinois at Urbana-Champaign Department of Computer Science. Second Examination

Postfix (and prefix) notation

S.E. Sem. III [CMPN] Data Structures. Primitive Linear Non Linear

Computer Science Foundation Exam

12 Abstract Data Types

CSL 201 Data Structures Mid-Semester Exam minutes

Computer Science E-22 Practice Final Exam

CSE 333 Midterm Exam 2/14/14

2016 Spring COP 3502 Final Exam. Date: 4/28/2016. Name:

An Introduction to Trees

Computer Science Foundation Exam. Dec. 19, 2003 COMPUTER SCIENCE I. Section I A. No Calculators! KEY

1 Binary trees. 1 Binary search trees. 1 Traversal. 1 Insertion. 1 An empty structure is an empty tree.

Formal Languages and Automata Theory, SS Project (due Week 14)

Solution for Data Structure

TREES. Trees - Introduction

JTSK Programming in C II C-Lab II. Lecture 3 & 4

Linear Data Structure

CS 241 Data Organization Binary Trees

Revision Statement while return growth rate asymptotic notation complexity Compare algorithms Linear search Binary search Preconditions: sorted,

ESC101N: Fundamentals of Computing End-sem st semester

Tree. A path is a connected sequence of edges. A tree topology is acyclic there is no loop.

Objective Questions for Online Practical Exams under CBCS Scheme Subject: Data Structure-I (CS-113)

S.E. Sem. III [INFT] Data Structures & Analysis. Primitive Linear Non Linear

University of Illinois at Urbana-Champaign Department of Computer Science. Second Examination

ECE264 Spring 2014 Exam 2, March 11, 2014

return return else return

Linked List. April 2, 2007 Programming and Data Structure 1

Computer Science 1 Study Union Practice Problems. What are the arguments to malloc? calloc? realloc? What do they do?

Data Structures, Algorithms & Data Science Platforms

Data Structures Question Bank Multiple Choice

CS61B Lecture #20: Trees. Last modified: Wed Oct 12 12:49: CS61B: Lecture #20 1

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

Computer Science Foundation Exam

MIDTERM EXAMINATION Spring 2010 CS301- Data Structures

Section I B COMPUTER SCIENCE SOLUTION

Data Structure (CS301)

Recursive Data Structures and Grammars

Computer Science Foundation Exam

NET/JRF-COMPUTER SCIENCE & APPLICATIONS. Time: 01 : 00 Hour Date : M.M. : 50

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- OCTOBER, 2012 DATA STRUCTURE

INSTITUTE OF AERONAUTICAL ENGINEERING

COMP 250 Midterm #2 March 11 th 2013

The combination of pointers, structs, and dynamic memory allocation allow for creation of data structures

Largest Online Community of VU Students

Linked-List Basic Examples. A linked-list is Linear collection of self-referential class objects, called nodes Connected by pointer links

COP Programming Concepts Spring 1999 CLOSED BOOK Exam #1 100 Points NAME

Chapter 20: Binary Trees

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard

Data Structures & Algorithm Analysis. Lecturer: Souad Alonazi

Trees. Eric McCreath

A. Year / Module Semester Subject Topic 2016 / V 2 PCD Pointers, Preprocessors, DS

CS61B Lecture #20: Trees. Last modified: Mon Oct 8 21:21: CS61B: Lecture #20 1

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305

Data Structures. Outline. Introduction Linked Lists Stacks Queues Trees Deitel & Associates, Inc. All rights reserved.

(Section : Computer Science)

3137 Data Structures and Algorithms in C++

Table of Contents. Chapter 1: Introduction to Data Structures... 1

Procedural Programming & Fundamentals of Programming

Recursion, Trees and Tree Traversal. Module CE System Programming & Computer Control Systems

University of Illinois at Urbana-Champaign Department of Computer Science. Second Examination

Computer Science Foundation Exam

COP 3223 Section 4 Exam #2 Form A Multiple Choice Fall /1/2014

8. Write an example for expression tree. [A/M 10] (A+B)*((C-D)/(E^F))

! Mon, May 5, 2:00PM to 4:30PM. ! Closed book, closed notes, clean desk. ! Comprehensive (covers entire course) ! 30% of your final grade

ENEE 150: Intermediate Programming Concepts for Engineers Spring 2018 Handout #27. Midterm #2 Review

COP 3223 Section 4 Exam #2 Form A Multiple Choice Spring /4/2015

Frequently asked Data Structures Interview Questions

! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge

There are many other applications like constructing the expression tree from the postorder expression. I leave you with an idea as how to do it.

Binary Trees

CS 314 Exam 2 Spring

Data Structure - Stack and Queue-

Binary Trees. Height 1

Summer Final Exam Review Session August 5, 2009

ESc101: (Linear, Circular, Doubly) Linked Lists, Stacks, Queues, Trees. Introduction to Linked Lists

Binary Search Tree 1.0. Generated by Doxygen Mon Jun :12:39

Stacks and their Applications

Transcription:

COP 3502 Section 2 Exam #2 Version A Spring 2017 3/23/2017 Lecturer: Arup Guha Directions: Answer all multiple choice questions on the scantron. Each question has a single correct answer. In case of ambiguities, choose the most accurate answer. Each of these questions is worth 4 points for a correct answer. Incorrect answers and questions left blank are worth 0 points. When you finish this exam, double check that you have bubbled in your UCFID and Exam Version on the scantron and then hand in the scantron ONLY.

Consider storing a string in a linked list where each node stores a single character. The following code implements functions similar to strlen and strcmp, as well as a function to convert a regular string to its equivalent linked list representation. Several lines of the implementation have been omitted. Questions 1-6 will be about these missing lines. #include <string.h> #include <stdlib.h> #include <stdio.h> typedef struct chtype { char c; struct chtype* next; chtype; chtype* convert(char* word); int len(chtype* word); int compare(chtype* left, chtype* right); chtype* convert(char* word) { chtype* front = NULL; int i; for (i=strlen(word)-1; i>=0; i--) { chtype* tmp = malloc(sizeof(chtype)); tmp->c = word[i]; tmp->next = /*** Q1 ***/; front = /*** Q2 ***/; return front; int len(chtype* word) { if (word == NULL) return 0; return /*** Q3 ***/; int compare(chtype* left, chtype* right) { if (left == NULL && right == NULL) return /*** Q4 ***/; if (left == NULL) return -1; if (right == NULL) return 1; if (left->c!= right->c) return /*** Q5 ***/; return /*** Q6 ***/;

1) What expression should replace /*** Q1 ***/? a) front b) front->next c) tmp->next d) tmp e) None of the Above 2) What expression should replace /*** Q2 ***/? a) front b) front->next c) tmp->next d) tmp e) None of the Above 3) What expression should replace /*** Q3 ***/? a) len(word->next) b) 2*len(word->next) c) len(word) + 1 d) len(word->next) + 1 e) None of the Above 4) What expression should replace /*** Q4 ***/? a) -1 b) 0 c) 1 d) left->c - right->c e) None of the Above 5) What expression should replace /*** Q5 ***/? a) -1 b) 0 c) 1 d) left->c - right->c e) None of the Above 6) What expression should replace /*** Q6 ***/? a) -1 b) 0 c) 1 d) left->c - right->c e) None of the Above 7) Which of the following could represent the inorder traversal of a binary search tree? A) 9 7 3 6 8 15 12 99 B) 3 6 7 8 9 12 15 99 C) 99 12 15 9 8 7 6 3 D) All of the Above (A, B and C) E) None of the Above 8) What is the run time of an insert inorder function on a sorted doubly linked list of n integers? A) O(1) B) O(lg n) C) O(n) D) O(2 n ) E) None of the Above 9) How many structurally different binary search trees can be created which have three nodes, storing the values 1, 2 and 3? A) 1 B) 2 C) 3 D) 4 E) None of the Above

The following code implements an insert function for a binary search tree of integers, where the height of each node is stored (distance from node to furthest leaf node in its subtree). Several lines of the implementation have been omitted. Questions 10-15 will be about these missing lines. #include <stdio.h> #include <stdlib.h> #include <time.h> typedef struct bintreenode { int data; int height; struct bintreenode* left; struct bintreenode* right; bintreenode; bintreenode* insert(bintreenode* root, int value); void preorder(bintreenode* root); void freetree(bintreenode* root); bintreenode* insert(bintreenode* root, int value) { if (root == NULL) { bintreenode* tmp = /*** Q10 ***/; tmp->data = value; tmp->left = NULL; tmp->right = NULL; tmp->height = /*** Q11 ***/; return tmp; if (value <= root->data) { root->left = insert(root->left, value); if (/*** Q12 ***/ >= root->height) root->height = /*** Q13 ***/; else { root->right = insert(root->right, value); if (/*** Q14 ***/ >= root->height) root->height = /*** Q15 ***/; return root; 10) What expression should replace /*** Q10 ***/? a) root b) malloc(sizeof(bintreenode*)) c) malloc(4) d) new bintreenode() e) None of the Above 11) What expression should replace /*** Q11 ***/? a) -1 b) 0 c) 1 d) root->height e) None of the Above

12) What expression should replace /*** Q12 ***/? a) 0 b) root->height c) root->left->height d) root->right->height e) None of the Above 13) What expression should replace /*** Q13 ***/? a) root->left->height b) root->right->height c) root->left->height + 1 d) root->right->height+1 e) None of the Above 14) What expression should replace /*** Q14 ***/? a) 0 b) root->height c) root->left->height d) root->right->height e) None of the Above 15) What expression should replace /*** Q15 ***/? a) root->left->height b) root->right->height c) root->left->height + 1 d) root->right->height+1 e) None of the Above 16) What is the value of the following postfix expression? 3 4 5 + * 3-1 1 + 2 * / a) 2 b) 3 c) 4 d) 5 e) None of the Above 17) What is the value of the following postfix expression? 6 3 / 2 2 + * - a) -2 b) 2 c) 24 d) Invalid Postfix Expression e) None of the Above 18) Let the sequence A of operations on a stack involve 3 pushes followed by 2 pops. Consider repeating the sequence A 20 times. If the stack was implemented using an array, what is the minimum size of the array necessary to ensure that these instructions are executed properly? a) 20 b) 21 c) 22 d) 23 e) None of the Above 19) Which of the following class examples roughly implemented a linked list of linked lists? A) binary tree B) stack C) queue D) Books E) Artists+CDs

Questions 20-22 involve converting the following infix expression to postfix using a stack of operators and parentheses: ( 3 + 7 ) * ( ( 1 + 8 ) - 2 * ( 16 / ( 4-2 ) - 5 ) ) - 26 20) Right before the value 16 gets inserted into the expression, how many items are on the stack of operators and parentheses? a) 3 b) 4 c) 5 d) 6 e) None of the Above 21) When the last close parenthesis gets processed, how many items are popped off the stack of operators and parentheses? a) 3 b) 4 c) 5 d) 6 e) None of the Above 22) Which of the following is the equivalent postfix expression to the infix expression given above? a) 3 7 + 1 8 + 2 16 4 2-5 / - * - 26 * - b) 3 7 1 8 + + 2 16 4 2 - / 5 - * - 26 * - c) 3 7 1 8 + + 2 16 4 2 - / 5 - * - * 26 - d) 3 7 + 1 8 + 2 16 4 2 - / 5 - * - 26 * - e) None of the Above 23) In class we implemented a queue using a linked list and one using an array. We tested both implementations with successive enqueues until the enqueue failed. The array implementation failed with fewer elements in the queue than the linked list version. What was our hypothesis as to why? A) Arrays are stored inefficiently in C, compared to linked list and a single array slot takes up twice the space of the corresponding linked list node. B) I had different programs running on my computer in the background during the two separate program runs. The programs running on my computer while I ran the array code just happened to be using more memory. C) I ran the linked list version with a special command line flag that specified a larger allocation of memory for the execution of the program. D) We were doubling our array size when it filled up so even though our code failed to find enough room for the doubling, there would have been room for quite a few more than one extra element. With the linked list implementation, we only added one node at a time. It only failed after nearly all the available memory was filled. E) None of the Above 24) A short video was shown in class to introduce the breadth first search. What was the video about? A) Trees B) Corn Mazes C) Shopping Lines D) Rubix Cubes E) None of the Above 25) Where do seahorses live? A) the sea B) mountaintops C) mars D) 7-11s E) igloos