CS 240 Data Structure Spring 2018 Exam I 03/01/2018

Similar documents
CS 240 Data Structure Spring 2018 Exam III 04/25/2018

CSE 333 Midterm Exam Cinco de Mayo, 2017 (May 5) Name UW ID#

CS 161 Exam II Winter 2018 FORM 1

Jordan University of Science & Technology Department of Computer Science CS 211 Exam #1 (23/10/2010) -- Form A

Review Questions for Final Exam

Midterm Exam. Sample Solutions

Control Structure: Loop

The American University in Cairo Department of Computer Science & Engineering CSCI &09 Dr. KHALIL Exam-I Fall 2011

CS 455 Final Exam Spring 2015 [Bono] May 13, 2015

CS 455 Final Exam Fall 2012 [Bono] Dec. 17, 2012

ENJOY! Problem 2 What does the following code do, in a brief English sentence? int mystery(int k) { int i = 0; if (k < 0) return -1;

CS Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015

Introducing C++ to Java Programmers

Unit 7. 'while' Loops

CSE 303 Final Exam. March 16, 2009

CS16 Exam #1 7/17/ Minutes 100 Points total

Practice test for midterm 1

FORM 1 (Please put your name and section number (001/10am or 002/2pm) on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each):

Exercise 1.1 Hello world

CSE 333 Autumn 2013 Midterm

CSE413 Midterm. Question Max Points Total 100

CSC 126 FINAL EXAMINATION Spring Total Possible TOTAL 100

CSE030 Fall 2012 Final Exam Friday, December 14, PM

The American University in Cairo Computer Science & Engineering Department CSCE Dr. KHALIL Exam II Spring 2010

CSE 333 Midterm Exam 7/25/16. Name UW ID#

CSE 333 Midterm Exam July 24, Name UW ID#

Exam 2. CSI 201: Computer Science 1 Fall 2016 Professors: Shaun Ramsey and Kyle Wilson. Question Points Score Total: 80

Lecture 7. Log into Linux New documents posted to course webpage

CS31 Discussion 1E. Jie(Jay) Wang Week1 Sept. 30

Exercises with Linked Lists CS 16: Solving Problems with Computers I Lecture #15

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

Midterm Practice Exam

Midterm Practice TA: Brian Choi Section Webpage:

[CSE10200] Programming Basis ( 프로그래밍기초 ) Chapter 9. Seungkyu Lee. Assistant Professor, Dept. of Computer Engineering Kyung Hee University

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

Lecture on pointers, references, and arrays and vectors

Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Designing Loops and General Debug Pre-Defined Functions in C++ CS 16: Solving Problems with Computers I Lecture #6

1 Unit 8 'for' Loops

CSCE 206: Structured Programming in C++

Programming in C/C Lecture 2

Exceptions, Case Study-Exception handling in C++.

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

CS31 Discussion 1E Spring 17 : week 05

CSCS 261 Programming Concepts Exam 2 Fall EXAM 2 VERSION 1 Fall Points. Absolutely no electronic devices may be used during this exam.

Non-numeric types, boolean types, arithmetic. operators. Comp Sci 1570 Introduction to C++ Non-numeric types. const. Reserved words.

FORM 2 (Please put your name and form # on the scantron!!!!)

Linked Lists CS 16: Solving Problems with Computers I Lecture #16

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

Local and Global Variables

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

Lesson 13 - Vectors Dynamic Data Storage

CS302 Midterm Exam Answers & Grading James S. Plank September 30, 2010

pointers + memory double x; string a; int x; main overhead int y; main overhead

C++ for Java Programmers

CSE 374 Programming Concepts & Tools. Hal Perkins Spring 2010

Pointers and References

Linked List using a Sentinel

The American University in Cairo Department of Computer Science & Engineeringt CSCI &09 Dr. KHALIL Exam-I Fall 2009

CS32 Final Exam. E03, F15, Phill Conrad, UC Santa Barbara

CS380 Algorithm Design & Analysis Assignment 2: Disk Scheduling

CS 61B Summer 2005 (Porter) Midterm 2 July 21, SOLUTIONS. Do not open until told to begin

Chapter 1 INTRODUCTION

FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam II:

Computer Programming. Basic Control Flow - Loops. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons

CSC 126 FINAL EXAMINATION FINAL Spring 2012 B. Name (last, First) Instructor. Total Possible. Received

To become familiar with array manipulation, searching, and sorting.

! A data structure representing a list. ! A series of nodes chained together in sequence. ! A separate pointer (the head) points to the first

1. a) What #include statement do you put at the top of a program that does uses cin, cout or endl?

CS171 Midterm Exam. October 29, Name:

CS 1713 Introduction to Programming II

CS 117 Programming II, Spring 2018 Dr. Ghriga. Midterm Exam Estimated Time: 2 hours. March 21, DUE DATE: March 28, 2018 at 12:00 PM

Program Organization and Comments

Lab 2: ADT Design & Implementation

Output of sample program: Size of a short is 2 Size of a int is 4 Size of a double is 8

CS 103: Introduction to Programming Fall Written Final Exam 12/11/16, 4:30PM 6:30PM

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

Midterm Review. Short Answer. Short Answer. Practice material from the Winter 2014 midterm. Will cover some (but not all) of the questions.

CS 103 Unit 15. Doubly-Linked Lists and Deques. Mark Redekopp

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

Agenda' Data Structures and Algorithms. Floa+ng'Point'Numbers' Floa+ng'Point'Numbers'

CSE 333 Midterm Exam 7/25/16 Sample Solution. Question 1. (10 points) Preprocessor. Suppose we have the following two files:

Review Questions for Final Exam KEY

Chapter 1: Object-Oriented Programming Using C++

CS 104 (Spring 2014) Final Exam 05/09/2014

REFERENCES, POINTERS AND STRUCTS

Review Questions II KEY

Total 100. The American University in Cairo Computer Science & Engineering Department CSCE Instructor: Final Exam Fall 2014

CSE 333 Final Exam 3/19/14

Name SECTION: 12:45 2:20. True or False (12 Points)

EECE.2160: ECE Application Programming

QUIZ. What are 3 differences between C and C++ const variables?

a. a * c - 10 = b. a % b + (a * d) + 7 =

CS2255 HOMEWORK #1 Fall 2012

CS113: Lecture 5. Topics: Pointers. Pointers and Activation Records

Algorithms for Programming Contests - Week 1

CSE 250 Final Exam. Fall 2013 Time: 3 hours. Dec 11, No electronic devices of any kind. You can open your textbook and notes

CSC 1300 Exam 4 Comprehensive-ish and Structs

DELHI PUBLIC SCHOOL TAPI

Transcription:

CS 240 Data Structure Spring 2018 Exam I 03/01/2018 This exam contains three section A) Code: (basic data type, pointer, ADT) a. Reading: Trace the code to predict the output of the code b. Filling: Fill in the missing code to guarantee the shown output c. Quick short answer telling the difference of the implementation d. If the program won t compile, simply say so. B) Algorithm: (critical thinking and analysis ability) a. You are given a sorting problem and you are supposed to design strategies to solve this problem b. Briefly talk about how efficient it is. For instance, if the major computation is 2 for loops and each loop contains N iterations, then the complexity is approximately N^2. c. You are provided enough space to write out your solution. C) Implementation: (application of ideas along with learned skills) a. Based on your solutions in B, please write up your code. Your code will be judged by the correctness of your interpretation of your solution, not the correctness of your solution because you might have come up with a wrong solution (but that solution be penalized in section B already) b. TA will code your program and run it. Based on the correctness of the code (faithful translation of solution and correct execution of the code). D) Concept a. Breaking a long cpp file into main cpp, header file and implementation cpp. Good luck and do your best. When you are lost in pointers and addresses, the best way to attack that is simply drawing the diagram with respect to address of the variable that the pointer points to, and the pointer s its own address and the dereferencing operator *. Name: Score: /80 + 20

A) Basic Data Type, Pointers and ADT: Problem 1: 10pts #include <iostream> using namespace std; void changethis(int* p) { for(int i = 0; i < 15; i++) { What to fill in here? Answer 1: (5pts) p++; } } int main () { int numbers[5]; int * p; p = numbers; *p = 10; p++; *p = 20; p = &numbers[2]; *p = 30; p = numbers + 3; *p = 40; p = numbers; *(p+4) = 50; p++ ; cout<<*(p+4)<<endl; // What will be printed out here?? Answer 2: (5pts) int s[15]; int *t; t = s; changethis(t); for(int i = 0; i < 15; i++) { cout<<s[i]<<endl; } //Here we prints out 1, 3, 5, 7,, 29, What should you do in Answer 1 return 0; }

A) Basic Data Type, Pointers and ADT: Problem 2: 10 points #include <iostream> #include <string> using namespace std; void prntarray(int *k, int size); int main() { int thesize = 10; int myarray[thesize]; int *p = myarray; for(int i = 0; i<thesize; i++) { myarray[i] = i; } prntarray(p, thesize); return 0; } Please write out the function prnarray that will print out the elements inside the myarray array Void prnarray(int* p, int t) { Line 1: Line 2: Line 3: Line 4: Line 5: Line 6: Line 7: }

A) Basic Data Type, Pointers and ADT: Problem 3: Pass by reference, pointer and variables // passing parameters by reference #include <iostream> using namespace std; void duplicate (int& a, int& b, int& c) { a=2; b=2; c=2;} void duplicate1 (int a, int b, int c) { a=5; b=6; c=7;} void duplicate2 (int* a, int* b, int* c) { *a = 3; *b = 3; *c = 3; } int main () { int x=1, y=3, z=7; int *d, *e, *f; d=&x; e=&y; f=&z; duplicate (x, y, z); // Please predict the output cout << "x=" << x << ", y=" << y << ", z=" << z << endl; Answer 3: 5pts duplicate1 (x, y, z); cout << "x=" << x << ", y=" << y << ", z=" << z<<endl; Answer 4: 5pts duplicate2 (d,e,f ); cout << "x=" << x << ", y=" << y << ", z=" << z<<endl; Answer 5: 5pts return 0; } A) Basic Data Type, Pointers and ADT: Problem 4: Address of an array, int myarray[thesize]; int *p = myarray; Answer 6: True / False: &p = &myarray[0] and myarray = &myarray[0] (5pts)

B) Algorithm: Problem 1: Sorting (10 pts + 10 bonus pts) In PS1, we talked about LinkedList and we tried to sort a given array of integer. In that exercise, we are given an array as the following: int test[] ={4, 8, 2, 1, 5, 6, 66, -11, 34, 7, 3, 21, 17, 7}; Please describe how you would sort this array of integers Answer 6: (10pts) Step 1: Your idea

Step 2: What is the complexity of your solution and why? Bonus Answer 6: (5 pts) Bonus (5 pts): If the given array is only given by the users at runtime (i.e., you do not know the size during the compiling time), how would you handle this problem since now it is not a fixed size 14? (various solutions here, they can range from correct data structure to some size computation function) Answer 8:

C) Implementation: Please write out the complete implementation of your solution from section B. Answer 9: 20pts #include <iostream> using namespace std; 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12 13. 14. 15. 16. 17. 18. 19 20. 21. 22. 23. 24.

D) (10pts) We learned about how to break a long cpp file into multiple files. By doing so, it would be easier to read and debug. Given the old_main.cpp example below, please fill up the new_main.cpp, linkedlist.h and linkedlist.cpp via using those blocks and maybe additional couple lines Block A #include <iostream> #include <stdio.h> /* printf, scanf, NULL */ using namespace std; Block B struct node { int value; node *nxt;}; node* Insert(node *p, int k); void printlinkedlist(node *p); void addnode(node *p, int k); Block C int main() {Some operations; Calling node objects; Operating on node objects and call Insert, printlinkedlist functions. } BLOCK D node* Insert(node *p, int k) { some implementation; } Block E void printlinkedlist(node *p) { some implementation; }

new_main.cpp linkedlist.h linkedlist.cpp

Bonus: Write an one line code to convert military time into standard time. (10pts) Eg. Military time 1523 will become 3:23 PM; military time 1604 will become 4:04 PM. Answer: