Spring 2014, CS288 Test 2, 2:30-3:45 pm, Fri, 4/4/2014, GITC 1400

Similar documents
Spring 2013 CS288 Final exam, 6 pm - 8:30 pm, Thur, 5/16/2013, GITC

CSC Execution Environment. Program Execution Environment

ECE 264 Exam 2. 6:30-7:30PM, March 9, You must sign here. Otherwise you will receive a 1-point penalty.

ECE264 Fall 2013 Exam 1, September 24, 2013

Pointer Arithmetic and Lexical Scoping. CS449 Spring 2016

Intermediate Programming, Spring 2017*

CS 1713 Introduction to Programming II

ECE264 Spring 2013 Final Exam, April 30, 2013

C strings. (Reek, Ch. 9) 1 CS 3090: Safety Critical Programming in C

CS 223: Data Structures and Programming Techniques. Exam 2. April 19th, 2012

CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community

CS 216 Fall 2007 Midterm 1 Page 1 of 10 Name: ID:

COMP 2001/2401 Test #1 [out of 80 marks]

Wawrzynek & Weaver CS 61C. Sp 2018 Great Ideas in Computer Architecture MT 1. Print your name:,

CS 220: Introduction to Parallel Computing. Input/Output. Lecture 7

CSC 2405: Computer Systems II

CS 111X - Fall Test 1 - KEY KEY KEY KEY KEY KEY KEY

COS 126 Midterm 1 Written Exam, Fall 2009

ECE264 Fall 2013 Exam 3, November 20, 2013

Wawrzynek & Weaver CS 61C. Sp 2018 Great Ideas in Computer Architecture MT 1. Print your name:,

Each line will contain a string ("even" or "odd"), followed by one or more spaces, followed by a nonnegative integer.

COMP 2355 Introduction to Systems Programming

Week 2 Intro to the Shell with Fork, Exec, Wait. Sarah Diesburg Operating Systems CS 3430

Problem 2 Add the two 2 s complement signed 8-bit values given below, and express your answer in decimal.

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

Computer Organization & Systems Exam I Example Questions

Review of the C Programming Language for Principles of Operating Systems

CS 0449 Sample Midterm

CSC209S Midterm (L0101) Spring 1999 University of Toronto Department of Computer Science

CS 111X - Fall Test 1

ECE264 Spring 2013 Exam 1, February 14, 2013

C programming for beginners

ECE 2035 Programming HW/SW Systems Fall problems, 5 pages Exam Three 19 November 2014

ECE 2035 A Programming HW/SW Systems Spring problems, 5 pages Exam Three 13 April Your Name (please print clearly)

Do not start the test until instructed to do so!

Midterm Exam Nov 8th, COMS W3157 Advanced Programming Columbia University Fall Instructor: Jae Woo Lee.

CS-220 Spring 2018 Test 1 Version A Feb. 28, Name:

CS Operating system Summer Midterm I -- July 11, 2017 You have 115 min (10:00am-11:55pm). Good Luck!

On my honor I affirm that I have neither given nor received inappropriate aid in the completion of this exercise.

CS 223: Data Structures and Programming Techniques. Exam 2

Variables and literals

Introduction to Languages for Scientific Computing, winter semester 14/15: Final Exam

In the case of the dynamic array, the space must be deallocated when the program is finished with it. free(x);

CS 610: Intermediate Programming: C/C++ Making Programs General An Introduction to Linked Lists

United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring AY2017

CS 101 Fall 2006 Midterm 1 Name: ID:

CS 101 Spring 2007 Midterm 2 Name: ID:

CS 1713 Introduction to Programming II

Programming in C. What is C?... What is C?

Midterm Exam Review Slides

Programming in C UVic SEng 265

On my honor I affirm that I have neither given nor received inappropriate aid in the completion of this exercise.

Midterm Examination # 2 Wednesday, March 18, Duration of examination: 75 minutes STUDENT NAME: STUDENT ID NUMBER:

Programming in C. What is C?... What is C?

COS 126 General Computer Science Fall Midterm 1

The New C Standard (Excerpted material)

CS Operating system

CS 360 Exam 1 Fall 2014 Name. 1. Answer the following questions about each code fragment below. [8 points]

CS251-SE1. Midterm 2. Tuesday 11/1 8:00pm 9:00pm. There are 16 multiple-choice questions and 6 essay questions.

CS323: Data Structures and Algorithms Midterm Exam (October 17, 2016) Name:

CS16 Midterm Exam 2 E02, 10W, Phill Conrad, UC Santa Barbara Tuesday, 03/02/2010

CpSc 1010, Fall 2014 Lab 10: Command-Line Parameters (Week of 10/27/2014)

Quiz 0 Answer Key. Answers other than the below may be possible. Multiple Choice. 0. a 1. a 2. b 3. c 4. b 5. d. True or False.

C0MP1911 Final Exam 1337 Computing 1

EE 472 Embedded Systems. Name solutions. Instructions:

Dynamic memory allocation

C PROGRAMMING QUESTIONS AND

CS 1301 Exam 3 Spring 2014

Arithmetic Operators. Portability: Printing Numbers

Lecture 4: Outline. Arrays. I. Pointers II. III. Pointer arithmetic IV. Strings

Programming and Data Structure Solved. MCQs- Part 2

Final CSE 131B Spring 2005

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

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

COS 126 General Computer Science Spring Midterm 1

CS 101 Fall 2005 Midterm 2 Name: ID:

ECE264 Spring 2014 Exam 2, March 11, 2014

CSE 351: The Hardware/Software Interface. Section 2 Integer representations, two s complement, and bitwise operators

INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR Stamp / Signature of the Invigilator

FINAL TERM EXAMINATION SPRING 2010 CS304- OBJECT ORIENTED PROGRAMMING

A506 / C201 Computer Programming II Placement Exam Sample Questions. For each of the following, choose the most appropriate answer (2pts each).

ECE264 Summer 2013 Exam 1, June 20, 2013

Binghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program

Outline. Lecture 1 C primer What we will cover. If-statements and blocks in Python and C. Operators in Python and C

Arrays and Pointers in C. Alan L. Cox

CS 101 Spring 2006 Final Exam Name: ID:

CS16 Midterm Exam 2 E02, 09F, Phill Conrad, UC Santa Barbara Wednesday, 11/18/2009

Midterm Exam 2 Solutions C Programming Dr. Beeson, Spring 2009

CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011. MIDTERM EXAMINATION Spring 2010

Midterm Examination # 2 Wednesday, March 19, Duration of examination: 75 minutes STUDENT NAME: STUDENT ID NUMBER:

EL2310 Scientific Programming

Main Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University

Secure Software Programming and Vulnerability Analysis

Time: 8:30-10:00 pm (Arrive at 8:15 pm) Location What to bring:

Contents. A Review of C language. Visual C Visual C++ 6.0

CS 370 Operating Systems

Pointers and Lexical Scoping. CS449 Fall 2017

CS Sorting Terms & Definitions. Comparing Sorting Algorithms. Bubble Sort. Bubble Sort: Graphical Trace

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

Type Checking. Prof. James L. Frankel Harvard University

Transcription:

Spring 2014, CS288 Test 2, 2:30-3:45 pm, Fri, 4/4/2014, GITC 1400 Name: The exam has 5 pages. Do not take any page(s) with you. Any missing page(s) will result in failure in the exam. This exam is closed book close notes. Do not exchange anything during the exam. No questions will be answered during the exam. If you are in doubt, state your assumptions below, including typos if any. I have read and understood all of the instructions above. On my honor, I pledge that I have not violated the provisions of the NJIT Academic Honor Code. Signature: Date: Answers to Questions 1 to 13 (3 points each) = 39 points + 1 1 2 3 4 5 6 7 8 9 10 11 12 13 Questions 1-3: Assume radix sorting of 1024 floats on a 32-bit machine with 8 passes (rounds). The floats are initially stored in lst[1024] and the sorted floats will be available in lst at the end of sorting. float buf[1024] is available as working space. 1. What is the number of buckets? 2. The bit mask in hexadecimal is? 3. Find the number of data assignments for correcting the result when completed. For example, moving lst[i] to buf[j], or buf[j]=lst[i]; is a data assignment. 4. Given float f; which of the C statements would allow you to access the binary equivalent of f: a) &f b) *f c) (unsigned long *) (&f) d) (unsigned long *) (*f) e) * (unsigned long *) (&f) CS288 Spring 2014 1/5 Test 2, 4/4/2014

5. From problem 4, you now have the floating point number f converted to x. Assuming char s[32]; int i,n=32; which of the following C statements would store the binary equivalent of x in the string s, where s[0] holds the sign bit (the most significant bit) of the original number f while s[31] holds the least significant bit of the original number f: a) for (i=0;i<n;i++) { s[n-1-i] = "01"[x 1]; x = x + 1; b) for (i=0;i<n;i++) { s[n-1-i] = "10"[x&1]; x = x + 1; c) for (i=0;i<n;i++) { s[n-1-i] = "01"[x&1]; x = x >> 1; d) for (i=0;i<n;i++) { s[n-1-i] = "10"[x&1]; x = x >> 1; e) none of the above 6. Given char *str = "a?,?b,,??c#,,"; what would strtok(str, "?"); return? 7. Continuing Problem 6 write fill in the blank such that strtok() will return b. strtok( ); 8. Continuing Problem 7, what would strtok(null, "?#,"); return? For 9-13 on the 15-puzzle state-space search consider succ has three nodes (p,q,r) while open has two nodes (x,y). 9. What search strategy would result in open=(p,q,r,x,y) after merging succ and open? a)depth b)breadth c)best d)branch-bound e)a* 10. What search strategy would result in open=(x,y,p,q,r) after merging succ and open? a)depth b)breadth c)best d)branch-bound e)a* 11. Depth first search relies solely on a)g b)h c)f=func(g,h) d)any 2 of f,g,h e)can t determine 12. Intelligent heuristic search such as A* relies on a)g b)h c)f=func(g,h) d)any 2 of f,g,h e)can t determine 13. What is the branching factor for the 15-Puzzle problem? a)2 b)3 c)4 d)5 e)can t determine CS288 Spring 2014 2/5 Test 2, 4/4/2014

Problem 14 (splitting string - 20 points): Write a C function that splits a string line separated by commas and stores the values in an array of strings fields. The number of commas is unknown and your function must be able to handle any number of commas in the string. Use the following builtin functions: strtok(line, delim); strtok(null, delim); malloc(strlen(token)); strcpy(fields[i],token); /* at the end of this function, fields will have n strings stored */ void split_line(char **fields,char *line) { int i=0; char *token, *delim; CS288 Spring 2014 3/5 Test 2, 4/4/2014

Problem 15 (Linked list - 20 points): Write a C function () which creates a struct clip, sets an integer passed as parameter to views, and inserts the newly created struct in descending order of views to the list. head points to the first clip in the list. Your function must be able to handle any number of clips, including none in the beginning. #include <stdio.h> void insert(); struct clip { int views; struct clip *next; *head; void main() { struct clip *head; int n; append(&head,1); n = length(head); void insert( ) { struct clip *cp,*tp; CS288 Spring 2014 4/5 Test 2, 4/4/2014

Problem 16 (Signed integer radix sort - 20 points): Write a C program for sorting 32-bit signed integers using radix sort with a group of 8 bits. Use the variables listed below. Assume lst is initialized with n numbers. #define N 1048576 #define BIN 256 #define MAXBIT 32 #define LST 1 #define BUF 0 int n,group,bin; int flag; /* to show which one holds numbers: lst or buf */ int lst[n],buf[n]; int count[bin], map[bin], tmap[bin]; int main(int argc, char **argv){ int i; flag = LST; initialize(); /* initialize lst with n random floats */ for (i=0;i<maxbit;i=i+group) radix_sort(i); /* move lst to buf or buf to lst depending on the iteration number */ correct(); /* sorted numbers must be in lst */ void radix_sort(int idx) { int i,j,k,mask; /* initialize mask for lifting the 4 least significant bits. */ int *src_p,*dst_p; /* cast lst and buf to int pointers to treat lst/buf as int s */ /* set src_p and dst_p*/ /* count */ /* map */ /* move */ void correct() { CS288 Spring 2014 5/5 Test 2, 4/4/2014