Midterm Exam (REGULAR SECTION)

Size: px
Start display at page:

Download "Midterm Exam (REGULAR SECTION)"

Transcription

1 Data Structures (CS 102), Professor Yap Fall 2014 Midterm Exam (REGULAR SECTION) October 28, 2014 Midterm Exam Instructions MY NAME:... MY NYU ID:... MY ... Please read carefully: 0. Do all questions. 1. Write answers in the provided spaces. Write Programs on the reverse of the Question Sheet. 2. Show your working in the margins. 3. This is a closed book exam (no calculators). You may refer to a cheat sheet (8 by 11, 2-sided). 4. Unless otherwise indicated, you must show some working or reasoning for your answers. 5. Please allocate your time wisely. 6. This exam is worth 85 Points. 7. Good Luck! MY SCORES: (for official use only) TOTAL 1

2 Q1. SHORT QUESTIONS (5 Points Each). No credit is given if you do not provide a justification. (a) Say whether the following two programs are equivalent. void aa( Node u) { if (u == null u.next == null u.next.next == null) return; dosomething(u); void bb( Node u) { if (u!= null && u.next!= null && u.next.next!= null) dosomething(u); SOLUTION: Yes, they are equivalent. Why? The first program will dosomething(u) if (X Y Z) is false, where X is u== null, and similarly for Y and Z. It will do nothing otherwise. By DeMorgan s law, the negation of (X Y Z) is equivalent to (!X &&!Y &&!Z). But you see that second program will do dosomething(u) if (!X &&!Y &&!Z) is true, and do nothing otherwise. So it is exactly equivalent to the first program. Comments: We discussed De Morgan s law in one of our class lectures. Understanding De Morgan s law will speed up your ability to analyze algorithms such as this. (b) Write a method called isvowel(char cc) that returns true iff cc is a vowel. You must use string patterns available in the Java String class. SOLUTION: If vowels is a String containing all the vowels, you just return this: vowels.matches(".*" + c + ".*"); Comments: Recall that this question is straight from hw3. How could you go wrong in this question? Well, you have to remember that in the syntax ss.matches(pp), ss represents a string (literal) and although pp is also a string, it is not literally representing itself! Rather, pp is to be interpreted as a pattern (which has its own logic and interpretation. (c) Here is a stack interface from the textbook: public interface StackInterface<T> { void pop() throws StackUnderflowException; T top() throws StackUnderflowException; boolean isempty(); Did the textbook forget about the push operation? SOLUTION: No. They left the push operation to another interface that extends this interface. There are two ways to implement push, one that throws a StackOverflowException (if the stack size is bounded), and one that does not (if the stack size is unbounded). So there are two possible extensions, called BoundedStackInterface and UnboundedStackInterface. Comments: Of course the question does not make sense unless you know that a stack ADT should have a push operation. (d) Explain this statement: if there were no class inheritance, we would not need protected variables as private variables will do. 2

3 SOLUTION: The difference between private and protected variables only shows up if we have subclasses. A protected variable is seen as a public variable from the subclass, but other classes sees it a private variable. If there is no class inheritance, then there are no subclasses, and so you can replace every protected modifier by private. (e) What is the bug in the following attempt to overload a function ff? public class Overload { public int ff( int n) {... protected double ff( int a) {... SOLUTION: The bug is that the two methods called ff here have the same signature. Although they have different return types, different modifiers and different parameter names, these are not part of the signature. Comments: Key word here is "signature". See our solution to homework 2. Some students say that the bug is because the two definitions of ff have different return types. But this does not cause any compiler error. (f) Give the big-oh of the running time of this code as a function of its input arguments: void fun( int n, int m) { int s = 0; for (int i = 0; i< n+m; i++){ //careful! s = s + i; for (int j = 0; j<n; j++){ s = s+j; SOLUTION: The outer loop has n + m iterations, the inner loop has n iterations. So total time is O((n+m)n) = O(n 2 +mn). Comments: Some students conclude that the runningtime is O(n 2 ). That is false because we cannot make this conclude unless you were told that m = O(n). We have no restrictions on m and n. Some students say that the running is O(N 2 ) but the did not say how N is related to the input n,m. You should say that N = n + m. NOTE: the O(N 2 ) answer is inferior to O((n+m)n) answer, although we take off no points for this. Q2. Circular Array Queue (25 Points) Recall our poorqueue which implements a queue using an array of Strings: 3

4 public class poorqueue { static int MAX = 100; String[] q = new String[MAX]; int front = 0; int back = 0; // Invariant: front <= back // Size of queue is (back - front) String dequeue(){ return q[front++]; // remove from the front of queue boolean isempty(){ return (front == back); void enqueue(string item){... omitted.. boolean isfull(){ return back == MAX; //poorqueue Rewrite each of the methods so that the queue is circular: i.e., if front=max, you must reset it to 0 again. Similarly, if back=max, you reset it to 0. PLEASE IGNORE POSSIBLE UNDERFLOW or OVERFLOW EXCEPTIONS. SOLUTION: To understand the poorqueue, you need to remember that back is pointing at the next empty slot in the array. Underflow is ignored because we do not check that the queue is empty before we dequeue. Overflow is ignored because we do not check that the queue is full before we enqueue. All these are reasonable as long as we we warn the user about these possibilities ( Caveat Emptor ). The main changes to enqueue and dequeue is to reset the points to 0 when they hit MAX value: String dequeue(){ int tmp = front++; // remember the old value of front if (front==max) front=0; return q[tmp]; void enqueue(string s){ q[back++] = s; if (back==max) back=0; boolean isfull() { // NEW!!! if (front<=back) return(front==0 && back==max-1); return(back+1 == front); boolean isempty(){ return (front == back); The code for isempty() is unchanged but isfull() is new. This requires some explanation. 4

5 For circular queues, the front-back invariant front <= back no longer holds. This has consequences for isempty and isfull: we cannot tell the difference between full and empty! Indeed, we have front=back in both cases. The simplest solution to this is to say that the maximum number of items allowed in the queue is MAX-1, not MAX. Then there is no change in the isempty() code. But the isfull() code is more complicated as shown above. COMMENTS:Theabovesolutionwastesoneslotofthearray. Supposeyouwanttoallowup to MAX items in queue. Then you can introduce a boolean variable, call it inverted, that is true iff the front-back invariant is true. Initially, inverted=false and each time you reset the back pointer to 0 or reset the front pointer to 0, you must change the value of inverted. Then, the queue is full iff (front==back && inverted); it is empty iff (front==back &&!inverted). Do you agree that this solution is slightly less simple that our other solution? Q3. Programming Question (30 Points) In this question, you are to write an interface, implement it with a class, and include a main method to do accomplish a simple task. To get full credit, you must ensure correct Java syntax (not forgetting your semi-colons, etc). (a) Write an interface called PoorListInterface. Each node in our list has a value of type String. The interface has four methods with these signatures: append(string), prepend(string), print(), isempty(). They return void except the last one returns a boolean. The meaning is clear: append(s) adds a node with value s as the tail of the list; prepend(s) is similar except the new node is at the head of the list. Print will print the strings in the list, from head to tail. (b) Write a class called PoorList to implement your above PoorListInterface. Define an inner class called Node in PoorList. You must use a singly-linked list that is circular. Your PoorList should only have one member that refers to the tail of the list (you do not need another member to refer to the head). Your program should be in our usual poor style. (c) Write a main method in your PoorList class that that accepts a command line argument which is an integer n. If no argument is given, n defaults to 3. The main method will instantiate an empty list, and then alternately append and prepend the string representations of the numbers from 0 to 2n-1. E.g., if n=3, it will append 0, prepend 1, append 2, prepend 3, append 4, prepend 5. When we print the list, we should see the output: SOLUTION: Our code for this problem is uploaded in NYU Classes, and compare to your own solution. Please study this well. Comments: There is no setters or getters in poor designs. You are supposed to use a circular list, not just any linked list (certainly not arrays). 5

l Determine if a number is odd or even l Determine if a number/character is in a range - 1 to 10 (inclusive) - between a and z (inclusive)

l Determine if a number is odd or even l Determine if a number/character is in a range - 1 to 10 (inclusive) - between a and z (inclusive) Final Exam Exercises Chapters 1-7 + 11 Write C++ code to: l Determine if a number is odd or even CS 2308 Fall 2016 Jill Seaman l Determine if a number/character is in a range - 1 to 10 (inclusive) - between

More information

Computer Science 62. Bruce/Mawhorter Fall 16. Midterm Examination. October 5, Question Points Score TOTAL 52 SOLUTIONS. Your name (Please print)

Computer Science 62. Bruce/Mawhorter Fall 16. Midterm Examination. October 5, Question Points Score TOTAL 52 SOLUTIONS. Your name (Please print) Computer Science 62 Bruce/Mawhorter Fall 16 Midterm Examination October 5, 2016 Question Points Score 1 15 2 10 3 10 4 8 5 9 TOTAL 52 SOLUTIONS Your name (Please print) 1. Suppose you are given a singly-linked

More information

Discussion 2C Notes (Week 3, January 21) TA: Brian Choi Section Webpage:

Discussion 2C Notes (Week 3, January 21) TA: Brian Choi Section Webpage: Discussion 2C Notes (Week 3, January 21) TA: Brian Choi (schoi@cs.ucla.edu) Section Webpage: http://www.cs.ucla.edu/~schoi/cs32 Abstraction In Homework 1, you were asked to build a class called Bag. Let

More information

CS171 Midterm Exam. October 29, Name:

CS171 Midterm Exam. October 29, Name: CS171 Midterm Exam October 29, 2012 Name: You are to honor the Emory Honor Code. This is a closed-book and closed-notes exam. You have 50 minutes to complete this exam. Read each problem carefully, and

More information

CS 216 Exam 1 Fall SOLUTION

CS 216 Exam 1 Fall SOLUTION CS 216 Exam 1 Fall 2004 - SOLUTION Name: Lab Section: Email Address: Student ID # This exam is closed note, closed book. You will have an hour and fifty minutes total to complete the exam. You may NOT

More information

Data Structures (CS 102), Professor Yap Spring 2015 MIDTERM. April 19, 2015

Data Structures (CS 102), Professor Yap Spring 2015 MIDTERM. April 19, 2015 Data Structures (CS 102), Professor Yap Spring 2015 MIDTERM April 19, 2015 QUESTION 1. SHORT QUESTIONS (5 Points each part = 50 Points). (a) (5 Points for each error) This Java program has two errors.

More information

Computer Science 62. Midterm Examination

Computer Science 62. Midterm Examination Computer Science 62 Bruce/Mawhorter Fall 16 Midterm Examination October 5, 2016 Question Points Score 1 15 2 10 3 10 4 8 5 9 TOTAL 52 Your name (Please print) 1. Suppose you are given a singly-linked list

More information

Lecture 3: Stacks & Queues

Lecture 3: Stacks & Queues Lecture 3: Stacks & Queues Prakash Gautam https://prakashgautam.com.np/dipit02/ info@prakashgautam.com.np 22 March, 2018 Objectives Definition: Stacks & Queues Operations of Stack & Queues Implementation

More information

CSE 331 Midterm Exam 2/13/12

CSE 331 Midterm Exam 2/13/12 Name There are 10 questions worth a total of 100 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. The exam is closed book, closed notes, closed

More information

COS 226 Algorithms and Data Structures Fall Midterm

COS 226 Algorithms and Data Structures Fall Midterm COS 226 Algorithms and Data Structures Fall 2017 Midterm This exam has 10 questions (including question 0) worth a total of 55 points. You have 0 minutes. This exam is preprocessed by a computer, so please

More information

You must include this cover sheet. Either type up the assignment using theory3.tex, or print out this PDF.

You must include this cover sheet. Either type up the assignment using theory3.tex, or print out this PDF. 15-122 Assignment 3 Page 1 of 12 15-122 : Principles of Imperative Computation Fall 2012 Assignment 3 (Theory Part) Due: Thursday, October 4 at the beginning of lecture. Name: Andrew ID: Recitation: The

More information

Please note that if you write the mid term in pencil, you will not be allowed to submit a remark request.

Please note that if you write the mid term in pencil, you will not be allowed to submit a remark request. University of Toronto CSC148 Introduction to Computer Science Fall 2001 Mid Term Test Section L5101 Duration: 50 minutes Aids allowed: none Make sure that your examination booklet has 8 pages (including

More information

CMPSCI 187: Programming With Data Structures. Lecture #11: Implementing Stacks With Arrays David Mix Barrington 28 September 2012

CMPSCI 187: Programming With Data Structures. Lecture #11: Implementing Stacks With Arrays David Mix Barrington 28 September 2012 CMPSCI 187: Programming With Data Structures Lecture #11: Implementing Stacks With Arrays David Mix Barrington 28 September 2012 Implementing Stacks With Arrays The Idea of the Implementation Data Fields

More information

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University CS 11 Introduction to Computing II Wayne Snyder Department Boston University Today Object-Oriented Programming Concluded Stacks, Queues, and Priority Queues as Abstract Data Types Reference types: Basic

More information

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

University of Illinois at Urbana-Champaign Department of Computer Science. First Examination University of Illinois at Urbana-Champaign Department of Computer Science First Examination CS 225 Data Structures and Software Principles Spring 2007 7p-9p, Thursday, March 1 Name: NetID: Lab Section

More information

Midterm Exam 2 CS 455, Spring 2011

Midterm Exam 2 CS 455, Spring 2011 Name: USC loginid (e.g., ttrojan): Midterm Exam 2 CS 455, Spring 2011 March 31, 2011 There are 6 problems on the exam, with 50 points total available. There are 7 pages to the exam, including this one;

More information

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University CS 112 Introduction to Computing II Wayne Snyder Department Boston University Today Introduction to Linked Lists Stacks and Queues using Linked Lists Next Time Iterative Algorithms on Linked Lists Reading:

More information

MIDTERM EXAM (HONORS SECTION)

MIDTERM EXAM (HONORS SECTION) Data Structures Course (V22.0102.00X) Professor Yap Fall 2010 MIDTERM EXAM (HONORS SECTION) October 19, 2010 SOLUTIONS Problem 1 TRUE OR FALSE QUESTIONS (4 Points each) Brief justification is required

More information

Queues. CITS2200 Data Structures and Algorithms. Topic 5

Queues. CITS2200 Data Structures and Algorithms. Topic 5 CITS2200 Data Structures and Algorithms Topic 5 Queues Implementations of the Queue ADT Queue specification Queue interface Block (array) representations of queues Recursive (linked) representations of

More information

Code Reuse: Inheritance

Code Reuse: Inheritance Object-Oriented Design Lecture 14 CSU 370 Fall 2008 (Pucella) Tuesday, Nov 4, 2008 Code Reuse: Inheritance Recall the Point ADT we talked about in Lecture 8: The Point ADT: public static Point make (int,

More information

Interfaces & Generics

Interfaces & Generics Interfaces & Generics CSC207 Winter 2018 The Programming Interface The "user" for almost all code is a programmer. That user wants to know:... what kinds of object your class represents... what actions

More information

UNIVERSITY OF WATERLOO DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING E&CE 250 ALGORITHMS AND DATA STRUCTURES

UNIVERSITY OF WATERLOO DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING E&CE 250 ALGORITHMS AND DATA STRUCTURES UNIVERSITY OF WATERLOO DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING E&CE 250 ALGORITHMS AND DATA STRUCTURES Midterm Examination Douglas Wilhelm Harder 1.5 hrs, 2005/02/17 11 pages Name (last, first):

More information

CSC 1052 Algorithms & Data Structures II: Linked Queues

CSC 1052 Algorithms & Data Structures II: Linked Queues CSC 1052 Algorithms & Data Structures II: Linked Queues Professor Henry Carter Spring 2018 Recap A queue simulates a waiting line, where objects are removed in the same order they are added The primary

More information

Today s lecture. CS 314 fall 01 C++ 1, page 1

Today s lecture. CS 314 fall 01 C++ 1, page 1 Today s lecture Midterm Thursday, October 25, 6:10-7:30pm general information, conflicts Object oriented programming Abstract data types (ADT) Object oriented design C++ classes CS 314 fall 01 C++ 1, page

More information

Insertions and removals follow the Fist-In First-Out rule: Insertions: at the rear of the queue Removals: at the front of the queue

Insertions and removals follow the Fist-In First-Out rule: Insertions: at the rear of the queue Removals: at the front of the queue Queues CSE 2011 Fall 2009 9/28/2009 7:56 AM 1 Queues: FIFO Insertions and removals follow the Fist-In First-Out rule: Insertions: at the rear of the queue Removals: at the front of the queue Applications,

More information

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

University of Illinois at Urbana-Champaign Department of Computer Science. First Examination University of Illinois at Urbana-Champaign Department of Computer Science First Examination CS 225 Data Structures and Software Principles Spring 2007 7p-9p, Thursday, March 1 Name: NetID: Lab Section

More information

! Determine if a number is odd or even. ! Determine if a number/character is in a range. - 1 to 10 (inclusive) - between a and z (inclusive)

! Determine if a number is odd or even. ! Determine if a number/character is in a range. - 1 to 10 (inclusive) - between a and z (inclusive) Final Exam Exercises Chapters 1-7 + 11 Write C++ code to:! Determine if a number is odd or even CS 2308 Fall 2018 Jill Seaman! Determine if a number/character is in a range - 1 to 10 (inclusive) - between

More information

CSE P 501 Exam 8/5/04

CSE P 501 Exam 8/5/04 Name There are 7 questions worth a total of 65 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. You may refer to the following references: Course

More information

CSC 1052 Algorithms & Data Structures II: Stacks

CSC 1052 Algorithms & Data Structures II: Stacks CSC 1052 Algorithms & Data Structures II: Stacks Professor Henry Carter Spring 2018 Recap Abstraction allows for information to be compartmentalized and simplifies modular use Interfaces are the Java construction

More information

CPSC 221: Algorithms and Data Structures Lecture #1: Stacks and Queues

CPSC 221: Algorithms and Data Structures Lecture #1: Stacks and Queues CPSC 221: Algorithms and Data Structures Lecture #1: Stacks and Queues Alan J. Hu (Slides borrowed from Steve Wolfman) Be sure to check course webpage! http://www.ugrad.cs.ubc.ca/~cs221 1 Lab 1 is available.

More information

CSE 373 Data Structures and Algorithms. Lecture 2: Queues

CSE 373 Data Structures and Algorithms. Lecture 2: Queues CSE 373 Data Structures and Algorithms Lecture 2: Queues Queue ADT queue: A list with the restriction that insertions are done at one end and deletions are done at the other First-In, First-Out ("FIFO

More information

CS 2150 Exam 1, Spring 2018 Page 1 of 6 UVa userid:

CS 2150 Exam 1, Spring 2018 Page 1 of 6 UVa userid: CS 2150 Exam 1, Spring 2018 Page 1 of 6 UVa userid: CS 2150 Exam 1 Name You MUST write your e-mail ID on EACH page and put your name on the top of this page, too. If you are still writing when pens down

More information

Prelim 1. CS 2110, October 1, 2015, 5:30 PM Total Question Name True Short Testing Strings Recursion

Prelim 1. CS 2110, October 1, 2015, 5:30 PM Total Question Name True Short Testing Strings Recursion Prelim 1 CS 2110, October 1, 2015, 5:30 PM 0 1 2 3 4 5 Total Question Name True Short Testing Strings Recursion False Answer Max 1 20 36 16 15 12 100 Score Grader The exam is closed book and closed notes.

More information

Week 6. Data structures

Week 6. Data structures 1 2 3 4 5 n Week 6 Data structures 6 7 n 8 General remarks We start considering Part III Data Structures from CLRS. As a first example we consider two special of buffers, namely stacks and queues. Reading

More information

CS/ENGRD 2110 SPRING 2018

CS/ENGRD 2110 SPRING 2018 CS/ENGRD 2110 SPRING 2018 Lecture 7: Interfaces and http://courses.cs.cornell.edu/cs2110 1 2 St Valentine s Day! It's Valentines Day, and so fine! Good wishes to you I consign.* But since you're my students,

More information

CMSC 341. Linked Lists, Stacks and Queues. CMSC 341 Lists, Stacks &Queues 1

CMSC 341. Linked Lists, Stacks and Queues. CMSC 341 Lists, Stacks &Queues 1 CMSC 341 Linked Lists, Stacks and Queues CMSC 341 Lists, Stacks &Queues 1 Goal of the Lecture To complete iterator implementation for ArrayList Briefly talk about implementing a LinkedList Introduce special

More information

csci 210: Data Structures Stacks and Queues

csci 210: Data Structures Stacks and Queues csci 210: Data Structures Stacks and Queues 1 Summary Topics Stacks and Queues as abstract data types ( ADT) Implementations arrays linked lists Analysis and comparison Applications: searching with stacks

More information

Fun facts about recursion

Fun facts about recursion Outline examples of recursion principles of recursion review: recursive linked list methods binary search more examples of recursion problem solving using recursion 1 Fun facts about recursion every loop

More information

SOLUTIONS (INCOMPLETE, UNCHECKED)

SOLUTIONS (INCOMPLETE, UNCHECKED) UNIVERSITY OF WATERLOO DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING E&CE 250 ALGORITHMS AND DATA STRUCTURES Midterm Examination Instructor: R.E.Seviora 1.5 hrs, Oct 27, 2000 SOLUTIONS (INCOMPLETE,

More information

University of Waterloo Department of Electrical and Computer Engineering ECE250 Algorithms and Data Structures Fall 2014

University of Waterloo Department of Electrical and Computer Engineering ECE250 Algorithms and Data Structures Fall 2014 University of Waterloo Department of Electrical and Computer Engineering ECE250 Algorithms and Data Structures Fall 2014 Midterm Examination Instructor: Ladan Tahvildari, PhD, PEng, SMIEEE Date: Tuesday,

More information

CS 367: Introduction to Data Structures Midterm Sample Questions

CS 367: Introduction to Data Structures Midterm Sample Questions LAST NAME (PRINT): FIRST NAME (PRINT): CS 367: Introduction to Data Structures Midterm Sample Questions Friday, July 14 th 2017. 100 points (26% of final grade) Instructor: Meena Syamkumar 1. Fill in these

More information

CS61BL: Data Structures & Programming Methodology Summer 2014

CS61BL: Data Structures & Programming Methodology Summer 2014 CS61BL: Data Structures & Programming Methodology Summer 2014 Instructor: Edwin Liao Final Exam August 13, 2014 Name: Student ID Number: Section Time: TA: Course Login: cs61bl-?? Person on Left: Possibly

More information

First Examination. CS 225 Data Structures and Software Principles Spring p-9p, Tuesday, February 19

First Examination. CS 225 Data Structures and Software Principles Spring p-9p, Tuesday, February 19 Department of Computer Science First Examination CS 225 Data Structures and Software Principles Spring 2008 7p-9p, Tuesday, February 19 Name: NetID: Lab Section (Day/Time): This is a closed book and closed

More information

Lecture Notes on Memory Layout

Lecture Notes on Memory Layout Lecture Notes on Memory Layout 15-122: Principles of Imperative Computation Frank Pfenning André Platzer Lecture 11 1 Introduction In order to understand how programs work, we can consider the functions,

More information

CS 10, Fall 2015, Professor Prasad Jayanti

CS 10, Fall 2015, Professor Prasad Jayanti Problem Solving and Data Structures CS 10, Fall 2015, Professor Prasad Jayanti Midterm Practice Problems We will have a review session on Monday, when I will solve as many of these problems as possible.

More information

Lecture Data Structure Stack

Lecture Data Structure Stack Lecture Data Structure Stack 1.A stack :-is an abstract Data Type (ADT), commonly used in most programming languages. It is named stack as it behaves like a real-world stack, for example a deck of cards

More information

CS2012 Programming Techniques II

CS2012 Programming Techniques II 27 January 14 Lecture 6 (continuing from 5) CS2012 Programming Techniques II Vasileios Koutavas 1 27 January 14 Lecture 6 (continuing from 5) 2 Previous Lecture Amortized running time cost of algorithms

More information

UNIVERSITY REGULATIONS

UNIVERSITY REGULATIONS CPSC 221: Algorithms and Data Structures Midterm Exam, 2013 February 15 Name: Student ID: Signature: Section (circle one): MWF(201) TTh(202) You have 60 minutes to solve the 5 problems on this exam. A

More information

Prelim 2. CS 2110, November 20, 2014, 7:30 PM Extra Total Question True/False Short Answer

Prelim 2. CS 2110, November 20, 2014, 7:30 PM Extra Total Question True/False Short Answer Prelim 2 CS 2110, November 20, 2014, 7:30 PM 1 2 3 4 5 Extra Total Question True/False Short Answer Complexity Induction Trees Graphs Extra Credit Max 20 10 15 25 30 5 100 Score Grader The exam is closed

More information

CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators)

CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators) Name: Email address: Quiz Section: CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators) Instructions: Read the directions for each question carefully before answering. We will

More information

Faculty of Science FINAL EXAMINATION COMP-250 A Introduction to Computer Science School of Computer Science, McGill University

Faculty of Science FINAL EXAMINATION COMP-250 A Introduction to Computer Science School of Computer Science, McGill University NAME: STUDENT NUMBER:. Faculty of Science FINAL EXAMINATION COMP-250 A Introduction to Computer Science School of Computer Science, McGill University Examimer: Prof. Mathieu Blanchette December 8 th 2005,

More information

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

! Mon, May 5, 2:00PM to 4:30PM. ! Closed book, closed notes, clean desk. ! Comprehensive (covers entire course) ! 30% of your final grade Final Exam Review Final Exam Mon, May 5, 2:00PM to 4:30PM CS 2308 Spring 2014 Jill Seaman Closed book, closed notes, clean desk Comprehensive (covers entire course) 30% of your final grade I recommend

More information

Name Section Number. CS210 Exam #2 *** PLEASE TURN OFF ALL CELL PHONES*** Practice

Name Section Number. CS210 Exam #2 *** PLEASE TURN OFF ALL CELL PHONES*** Practice Name Section Number CS210 Exam #2 *** PLEASE TURN OFF ALL CELL PHONES*** Practice All Sections Bob Wilson OPEN BOOK / OPEN NOTES You will have all 90 minutes until the start of the next class period. Spend

More information

COMP 213 Advanced Object-oriented Programming Lecture 8 The Queue ADT (cont.)

COMP 213 Advanced Object-oriented Programming Lecture 8 The Queue ADT (cont.) COMP 213 Advanced Object-oriented Programming Lecture 8 The Queue ADT (cont.) Recall: The Queue ADT A data structure in which elements enter at one end and are removed from the opposite end is called a

More information

Data Structure (CS301)

Data Structure (CS301) WWW.VUPages.com http://forum.vupages.com WWW.VUTUBE.EDU.PK Largest Online Community of VU Students Virtual University Government of Pakistan Midterm Examination Spring 2003 Data Structure (CS301) StudentID/LoginID

More information

Multiple choice questions. Answer on Scantron Form. 4 points each (100 points) Which is NOT a reasonable conclusion to this sentence:

Multiple choice questions. Answer on Scantron Form. 4 points each (100 points) Which is NOT a reasonable conclusion to this sentence: Multiple choice questions Answer on Scantron Form 4 points each (100 points) 1. Which is NOT a reasonable conclusion to this sentence: Multiple constructors for a class... A. are distinguished by the number

More information

CS/ENGRD 2110 FALL Lecture 7: Interfaces and Abstract Classes

CS/ENGRD 2110 FALL Lecture 7: Interfaces and Abstract Classes CS/ENGRD 2110 FALL 2017 Lecture 7: Interfaces and Abstract Classes http://courses.cs.cornell.edu/cs2110 1 Announcements 2 A2 is due tomorrow night (17 February) Get started on A3 a method every other day.

More information

Data Abstraction and Specification of ADTs

Data Abstraction and Specification of ADTs CITS2200 Data Structures and Algorithms Topic 4 Data Abstraction and Specification of ADTs Example The Reversal Problem and a non-adt solution Data abstraction Specifying ADTs Interfaces javadoc documentation

More information

CSC 1052 Algorithms & Data Structures II: Queues

CSC 1052 Algorithms & Data Structures II: Queues CSC 1052 Algorithms & Data Structures II: Queues Professor Henry Carter Spring 2018 Recap Recursion solves problems by solving smaller version of the same problem Three components Applicable in a range

More information

CS 231 Data Structures and Algorithms Fall DDL & Queue Lecture 20 October 22, Prof. Zadia Codabux

CS 231 Data Structures and Algorithms Fall DDL & Queue Lecture 20 October 22, Prof. Zadia Codabux CS 231 Data Structures and Algorithms Fall 2018 DDL & Queue Lecture 20 October 22, 2018 Prof. Zadia Codabux 1 Agenda Mid Semester Analysis Doubly Linked List Queue 2 Administrative None 3 Doubly Linked

More information

CSCI 102L - Data Structures Midterm Exam #1 Fall 2011

CSCI 102L - Data Structures Midterm Exam #1 Fall 2011 Print Your Name: Page 1 of 8 Signature: Aludra Loginname: CSCI 102L - Data Structures Midterm Exam #1 Fall 2011 (10:00am - 11:12am, Wednesday, October 5) Instructor: Bill Cheng Problems Problem #1 (24

More information

CSE 373 Autumn 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

CSE 373 Autumn 2010: Midterm #1 (closed book, closed notes, NO calculators allowed) Name: Email address: CSE 373 Autumn 2010: Midterm #1 (closed book, closed notes, NO calculators allowed) Instructions: Read the directions for each question carefully before answering. We may give partial

More information

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

Cpt S 122 Data Structures. Course Review Midterm Exam # 1 Cpt S 122 Data Structures Course Review Midterm Exam # 1 Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Midterm Exam 1 When: Friday (09/28) 12:10-1pm Where:

More information

CSCI 102L - Data Structures Midterm Exam #2 Spring 2011

CSCI 102L - Data Structures Midterm Exam #2 Spring 2011 CSCI 102L - Data Structures Midterm Exam #2 Spring 2011 (12:30pm - 1:50pm, Thursday, March 24) Instructor: Bill Cheng ( This exam is closed book, closed notes, closed everything. No cheat sheet allowed.

More information

Keeping Order:! Stacks, Queues, & Deques. Travis W. Peters Dartmouth College - CS 10

Keeping Order:! Stacks, Queues, & Deques. Travis W. Peters Dartmouth College - CS 10 Keeping Order:! Stacks, Queues, & Deques 1 Stacks 2 Stacks A stack is a last in, first out (LIFO) data structure Primary Operations: push() add item to top pop() return the top item and remove it peek()

More information

CPSC 221: Algorithms and Data Structures ADTs, Stacks, and Queues

CPSC 221: Algorithms and Data Structures ADTs, Stacks, and Queues CPSC 221: Algorithms and Data Structures ADTs, Stacks, and Queues Alan J. Hu (Slides borrowed from Steve Wolfman) Be sure to check course webpage! http://www.ugrad.cs.ubc.ca/~cs221 1 Lab 1 available very

More information

! A data type for which: ! An ADT may be implemented using various. ! Examples:

! A data type for which: ! An ADT may be implemented using various. ! Examples: Stacks and Queues Unit 6 Chapter 19.1-2,4-5 CS 2308 Fall 2018 Jill Seaman 1 Abstract Data Type A data type for which: - only the properties of the data and the operations to be performed on the data are

More information

CMPSCI 187: Programming With Data Structures. Lecture 12: Implementing Stacks With Linked Lists 5 October 2011

CMPSCI 187: Programming With Data Structures. Lecture 12: Implementing Stacks With Linked Lists 5 October 2011 CMPSCI 187: Programming With Data Structures Lecture 12: Implementing Stacks With Linked Lists 5 October 2011 Implementing Stacks With Linked Lists Overview: The LinkedStack Class from L&C The Fields and

More information

FINAL EXAMINATION. COMP-250: Introduction to Computer Science - Fall 2011

FINAL EXAMINATION. COMP-250: Introduction to Computer Science - Fall 2011 STUDENT NAME: STUDENT ID: McGill University Faculty of Science School of Computer Science FINAL EXAMINATION COMP-250: Introduction to Computer Science - Fall 2011 December 13, 2011 2:00-5:00 Examiner:

More information

CSL 201 Data Structures Mid-Semester Exam minutes

CSL 201 Data Structures Mid-Semester Exam minutes CL 201 Data tructures Mid-emester Exam - 120 minutes Name: Roll Number: Please read the following instructions carefully This is a closed book, closed notes exam. Calculators are allowed. However laptops

More information

8. Fundamental Data Structures

8. Fundamental Data Structures 172 8. Fundamental Data Structures Abstract data types stack, queue, implementation variants for linked lists, [Ottman/Widmayer, Kap. 1.5.1-1.5.2, Cormen et al, Kap. 10.1.-10.2] Abstract Data Types 173

More information

CIS 110 Introduction to Computer Programming. 7 May 2012 Final Exam

CIS 110 Introduction to Computer Programming. 7 May 2012 Final Exam CIS 110 Introduction to Computer Programming 7 May 2012 Final Exam Name: Recitation # (e.g. 201): Pennkey (e.g. bjbrown): My signature below certifies that I have complied with the University of Pennsylvania

More information

Declarations and Access Control SCJP tips

Declarations and Access Control  SCJP tips Declarations and Access Control www.techfaq360.com SCJP tips Write code that declares, constructs, and initializes arrays of any base type using any of the permitted forms both for declaration and for

More information

Matriculation number:

Matriculation number: Department of Informatics Prof. Dr. Michael Böhlen Binzmühlestrasse 14 8050 Zurich Phone: +41 44 635 4333 Email: boehlen@ifi.uzh.ch AlgoDat Repetition Exam Spring 2018 18.05.2018 Name: Matriculation number:

More information

Subclassing for ADTs Implementation

Subclassing for ADTs Implementation Object-Oriented Design Lecture 8 CS 3500 Fall 2009 (Pucella) Tuesday, Oct 6, 2009 Subclassing for ADTs Implementation An interesting use of subclassing is to implement some forms of ADTs more cleanly,

More information

UNIVERSITY REGULATIONS

UNIVERSITY REGULATIONS CPSC 221: Algorithms and Data Structures Midterm Exam, 2015 October 21 Name: Student ID: Signature: Section (circle one): MWF(101) TTh(102) You have 90 minutes to solve the 8 problems on this exam. A total

More information

CS 61B Discussion 5: Inheritance II Fall 2014

CS 61B Discussion 5: Inheritance II Fall 2014 CS 61B Discussion 5: Inheritance II Fall 2014 1 WeirdList Below is a partial solution to the WeirdList problem from homework 3 showing only the most important lines. Part A. Complete the implementation

More information

Stacks (5.1) Abstract Data Types (ADTs) CSE 2011 Winter 2011

Stacks (5.1) Abstract Data Types (ADTs) CSE 2011 Winter 2011 Stacks (5.1) CSE 2011 Winter 2011 26 January 2011 1 Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data structure An ADT specifies: Data stored Operations on the data Error

More information

Standard ADTs. Lecture 19 CS2110 Summer 2009

Standard ADTs. Lecture 19 CS2110 Summer 2009 Standard ADTs Lecture 19 CS2110 Summer 2009 Past Java Collections Framework How to use a few interfaces and implementations of abstract data types: Collection List Set Iterator Comparable Comparator 2

More information

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University 9/5/6 CS Introduction to Computing II Wayne Snyder Department Boston University Today: Arrays (D and D) Methods Program structure Fields vs local variables Next time: Program structure continued: Classes

More information

This examination has 11 pages. Check that you have a complete paper.

This examination has 11 pages. Check that you have a complete paper. MARKING KEY The University of British Columbia MARKING KEY Computer Science 252 2nd Midterm Exam 6:30 PM, Monday, November 8, 2004 Instructors: K. Booth & N. Hutchinson Time: 90 minutes Total marks: 90

More information

LIFO : Last In First Out

LIFO : Last In First Out Introduction Stack is an ordered list in which all insertions and deletions are made at one end, called the top. Stack is a data structure that is particularly useful in applications involving reversing.

More information

CS18000: Programming I

CS18000: Programming I CS18000: Programming I Data Abstraction January 25, 2010 Prof. Chris Clifton Announcements Book is available (Draft 2.0) Syllabus updated with readings corresponding to new edition Lab consulting hours

More information

CIS 120 Midterm II November 16, 2012 SOLUTIONS

CIS 120 Midterm II November 16, 2012 SOLUTIONS CIS 120 Midterm II November 16, 2012 SOLUTIONS 1 1. Java vs. OCaml (22 points) a. In OCaml, the proper way to check whether two string values s and t are structurally equal is: s == t s = t s.equals(t)

More information

CS61BL: Data Structures & Programming Methodology Summer 2014

CS61BL: Data Structures & Programming Methodology Summer 2014 CS61BL: Data Structures & Programming Methodology Summer 2014 Instructor: Edwin Liao Midterm 2 July 30, 2014 Name: Student ID Number: Section Time: TA: Course Login: cs61bl-?? Person on Left: Possibly

More information

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

University of Illinois at Urbana-Champaign Department of Computer Science. Second Examination University of Illinois at Urbana-Champaign Department of Computer Science Second Examination CS 225 Data Structures and Software Principles Spring 2014 7-10p, Tuesday, April 8 Name: NetID: Lab Section

More information

CSE 373 Winter 2009: Midterm #1 (closed book, closed notes, NO calculators allowed)

CSE 373 Winter 2009: Midterm #1 (closed book, closed notes, NO calculators allowed) Name: Email address: CSE 373 Winter 2009: Midterm #1 (closed book, closed notes, NO calculators allowed) Instructions: Read the directions for each question carefully before answering. We may give partial

More information

Data Structure. Recitation VII

Data Structure. Recitation VII Data Structure Recitation VII Recursion: Stack trace Queue Topic animation Trace Recursive factorial Executes factorial(4) Step 9: return 24 Step 8: return 6 factorial(4) Step 0: executes factorial(4)

More information

CSE 326 Team. Today s Outline. Course Information. Instructor: Steve Seitz. Winter Lecture 1. Introductions. Web page:

CSE 326 Team. Today s Outline. Course Information. Instructor: Steve Seitz. Winter Lecture 1. Introductions. Web page: CSE 326 Team CSE 326: Data Structures Instructor: Steve Seitz TAs: Winter 2009 Steve Seitz Lecture 1 Eric McCambridge Brent Sandona Soyoung Shin Josh Barr 2 Today s Outline Introductions Administrative

More information

CPSC 211, Sections : Data Structures and Implementations, Honors Final Exam May 4, 2001

CPSC 211, Sections : Data Structures and Implementations, Honors Final Exam May 4, 2001 CPSC 211, Sections 201 203: Data Structures and Implementations, Honors Final Exam May 4, 2001 Name: Section: Instructions: 1. This is a closed book exam. Do not use any notes or books. Do not confer with

More information

COE 312 Data Structures. Welcome to Exam II Monday November 23, Instructor: Dr. Wissam F. Fawaz

COE 312 Data Structures. Welcome to Exam II Monday November 23, Instructor: Dr. Wissam F. Fawaz 1 COE 312 Data Structures Welcome to Exam II Monday November 23, 2016 Instructor: Dr. Wissam F. Fawaz Name: Student ID: Instructions: 1. This exam is Closed Book. Please do not forget to write your name

More information

You must include this cover sheet. Either type up the assignment using theory4.tex, or print out this PDF.

You must include this cover sheet. Either type up the assignment using theory4.tex, or print out this PDF. 15-122 Assignment 4 Page 1 of 12 15-122 : Principles of Imperative Computation Fall 2012 Assignment 4 (Theory Part) Due: Thursday, October 18, 2012 at the beginning of lecture Name: Andrew ID: Recitation:

More information

CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0)

CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0) CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0) An interesting definition for stack element The stack element could be of any data type struct stackelement int etype; union int ival;

More information

Midterm I Exam Principles of Imperative Computation Frank Pfenning, Tom Cortina, William Lovas. September 30, 2010

Midterm I Exam Principles of Imperative Computation Frank Pfenning, Tom Cortina, William Lovas. September 30, 2010 Midterm I Exam 15-122 Principles of Imperative Computation Frank Pfenning, Tom Cortina, William Lovas September 30, 2010 Name: Andrew ID: Instructions This exam is closed-book with one sheet of notes permitted.

More information

Introduction to Computing II (ITI 1121) Midterm Examination

Introduction to Computing II (ITI 1121) Midterm Examination Introduction to Computing II (ITI 1121) Midterm Examination Instructor: Marcel Turcotte March 2014, duration: 2 hours Identification Surname: Given name: Student number: Instructions 1. This is a closed

More information

CS61BL Summer 2013 Midterm 2

CS61BL Summer 2013 Midterm 2 CS61BL Summer 2013 Midterm 2 Sample Solutions + Common Mistakes Question 0: Each of the following cost you.5 on this problem: you earned some credit on a problem and did not put your five digit on the

More information

Data Structures and Algorithms Winter Semester

Data Structures and Algorithms Winter Semester Page 0 German University in Cairo October 24, 2018 Media Engineering and Technology Faculty Prof. Dr. Slim Abdennadher Dr. Wael Abouelsadaat Data Structures and Algorithms Winter Semester 2018-2019 Midterm

More information

+ Abstract Data Types

+ Abstract Data Types Linked Lists Abstract Data Types An Abstract Data Type (ADT) is: a set of values a set of operations Sounds familiar, right? I gave a similar definition for a data structure. Abstract Data Types Abstract

More information

1 Inheritance (8 minutes, 9 points)

1 Inheritance (8 minutes, 9 points) Name: Career Account ID: Recitation#: 1 CS180 Spring 2011 Exam 2, 6 April, 2011 Prof. Chris Clifton Turn Off Your Cell Phone. Use of any electronic device during the test is prohibited. Time will be tight.

More information

Computer Science First Exams Pseudocode Standard Data Structures Examples of Pseudocode

Computer Science First Exams Pseudocode Standard Data Structures Examples of Pseudocode Computer Science First Exams 2014 Pseudocode Standard Data Structures Examples of Pseudocode Candidates are NOT permitted to bring copies of this document to their examinations. 1 Introduction The purpose

More information