ESC101 : Fundamental of Computing

Similar documents
University of Palestine. Mid Exam Total Grade: 100

CSCI 135 Exam #0 Fundamentals of Computer Science I Fall 2012

Fall 2005 CS 11 Final exam Answers

ESC101N: Fundamentals of Computing End-sem st semester

CSCI 135 Exam #0 Fundamentals of Computer Science I Fall 2013

1.00 Introduction to Computers and Engineering Problem Solving Quiz 1 March 4, 2005

COS 126 General Computer Science Spring Written Exam 1

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003

ESC101: Fundamentals of Computing End-Semester Exam

Computer Science 1 Ah

ESc101 : Fundamental of Computing

CSEN 202: Introduction to Computer Programming Spring term Final Exam

ESc101 : Fundamental of Computing

Introduction to Computer Science I Spring 2010 Sample mid-term exam Answer key

Instructions. This exam has 7 questions, worth 10 points each. You have 50 minutes.

CSCI 135 Exam #1 Fundamentals of Computer Science I Fall 2014

ESc101 : Fundamental of Computing

Computer Science II Data Structures

Midterm Examination (MTA)

1. What is the difference between a compiler and an interpreter? Also, discuss Java s method.

Lecture 2. Two-Dimensional Arrays

CS2141 Software Development using C/C++ C++ Basics

CSL 201 Data Structures Mid-Semester Exam minutes

10/30/2010. Introduction to Control Statements. The if and if-else Statements (cont.) Principal forms: JAVA CONTROL STATEMENTS SELECTION STATEMENTS

Selected Questions from by Nageshwara Rao

COS 126 General Computer Science Fall Written Exam 1

AP Computer Science Unit 1. Writing Programs Using BlueJ

CSE 11 Midterm Fall 2008

Unit 10: Sorting/Searching/Recursion

CIS 110 Introduction to Computer Programming Summer 2014 Midterm. Name:

Birkbeck (University of London) Software and Programming 1 In-class Test Mar 2018

CS/ENGRD 2110 Object-Oriented Programming and Data Structures Spring 2012 Thorsten Joachims. Lecture 10: Asymptotic Complexity and

APCS Semester #1 Final Exam Practice Problems

Getting started with Java

Array. Prepared By - Rifat Shahriyar

COMPUTER APPLICATIONS

( &% class MyClass { }

ESC 101N: Fundmentals of Computing ( IInd Semester) Mid Sem II Examination PM, Monday 7th March, 2011

CMPS 12A - Winter 2002 Final Exam A March 16, Name: ID:

COS 126 Exam Review. Exams overview Example programming exam Example written exam questions (part 1)

PROGRAMMING FUNDAMENTALS

Jump Statements. The keyword break and continue are often used in repetition structures to provide additional controls.

CSCI 135 Exam #2 Fundamentals of Computer Science I Fall 2013

Give one example where you might wish to use a three dimensional array

COS 126 General Computer Science Fall Exam 1

Computer Programming, I. Laboratory Manual. Final Exam Solution

CSCI 135 Midterm Fundamentals of Computer Science I Fall 2011

Esc101 Mid Semester Exam - II

CMPS 12A Winter 2006 Prof. Scott A. Brandt Final Exam, March 21, Name:

CONTENTS: Array Usage Multi-Dimensional Arrays Reference Types. COMP-202 Unit 6: Arrays

Jump Statements. The keyword break and continue are often used in repetition structures to provide additional controls.

CS180. Exam 1 Review

CS13002 Programming and Data Structures, Spring 2005

CMPS 12A Introduction to Programming Midterm 2 Review Problems

Complexity, General. Standard approach: count the number of primitive operations executed.

CSCI 135 Exam #2 Fundamentals of Computer Science I Fall 2013

CMSC 150 LECTURE 7 RECURSION

Nested Loops. A loop can be nested inside another loop.

Arrays in Java Using Arrays

Object-Oriented Programming and Software Engineering CITS1001 MID-SEMESTER TEST

Introduction to the Java Basics: Control Flow Statements

Lecture Set 4: More About Methods and More About Operators

Lecture 2 Tao Wang 1

ANSWERS. Birkbeck (University of London) Software and Programming 1 In-class Test Feb Student Name Student Number. Answer all questions

CMPT 125: Lecture 4 Conditionals and Loops

ANSWERS. Birkbeck (University of London) Software and Programming 1 In-class Test Feb Student Name Student Number. Answer all questions

Prelim 2 Solution. CS 2110, November 19, 2015, 5:30 PM Total. Sorting Invariants Max Score Grader

Recursion. EECS2030: Advanced Object Oriented Programming Fall 2017 CHEN-WEI WANG

University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ June Exam

Solutions to Sample JAC444 Midterm Test

CSC 1051 Arrays - Review questions

Indian Institute of Technology Kharagpur Programming and Data Structures (CS10001) Autumn : Mid-Semester Examination

Object Oriented Programming 2013/14. Final Exam June 20, 2014

Data Structures CSCI C343, Fall 2016 [B]

Fundamentals of Programming Data Types & Methods

Computer Applications Answer Key Class IX December 2017

Recursion. Tracing Method Calls via a Stack. Beyond this lecture...

Running Time. Analytic Engine. Charles Babbage (1864) how many times do you have to turn the crank?

Computação I. Exercises. Leonardo Vanneschi NOVA IMS, Universidade Nova de Lisboa. Leonardo Vanneschi Computação I NOVA IMS

Code Analysis Sample Questions

Lab Assignment Three

CS 177 Spring 2009 Exam I

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger.

COS 126 Midterm 1 Written Exam Fall 2012

1 Short Answer (15 Points Each)

Recursion: Factorial (1) Recursion. Recursion: Principle. Recursion: Factorial (2) Recall the formal definition of calculating the n factorial:

CIS 110 Introduction To Computer Programming. February 29, 2012 Midterm

Class definition. complete definition. public public class abstract no instance can be created final class cannot be extended

Loops. CSE 114, Computer Science 1 Stony Brook University

C212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below.

Prelim 2. CS 2110, November 19, 2015, 7:30 PM Total. Sorting Invariants Max Score Grader

QUIZ 2 Introduction to Computer Science (COMP 250) Mon. March 2, 2009 Professor Michael Langer

Prelim 2 Solution. CS 2110, November 19, 2015, 7:30 PM Total. Sorting Invariants Max Score Grader

2. [20] Suppose we start declaring a Rectangle class as follows:

CMPS 11 Intermediate Programming Midterm 2 Review Problems

Unit 7. Arrays and matrices

Introduction to Java Unit 1. Using BlueJ to Write Programs

CSCE 145 Exam 1 Review. This exam totals to 100 points. Follow the instructions. Good luck!

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

CONDITIONAL EXECUTION: PART 2

Transcription:

ESC101 : Fundamental of Computing End Semester Exam 19 November 2008 Name : Roll No. : Section : Note : Read the instructions carefully 1. You will lose 3 marks if you forget to write your name, roll number, and section. 2. There are EIGHT questions in this paper distributed among total five sheets of the answer sheet. 3. You have to write in the space provided. Please avoid over writing. 4. You will be given rough sheets. Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Marks 1

1. (marks = 5) What is the value of d at the end of each of the following code fragments? If you feel that there will be any compilation error, then mention that the cause of compilation error. (a) double d; d = 2+11/9*4.5; (b) int i=10; byte b=12; float d = b+i+1.3; (c) long d; d = 1234567898765; (d) double A=11; byte b=2; float d = (float)(a/b/2*4); (e) int d; d = (int)3.4/1.1; Answer : (a) (b) (c) (d) (e) 2

2. (marks = 8) Given two arrays A and B of size m and n respectively and m n. The arrays are storing characters. We say that B appears in A if there exists a non-negative integer i such that for all j with 0 j < n, A[i + j] = B[j]. For example if A=s, t, a, x, n, b, y, and B=a, x, n, then B appears in A. Write a method Appears which takes two character arrays A and B as parameters and returns true if B appears in A and false otherwise. You may assume that A.length B.length is ensured by the method which calls the method Appears. Answer : 3

3. (marks = 8) The following method computes product of two matrices M and N and returns the reference to the final product matrix. Fill in the blanks appropriately. // this method assumes that M and N are matrices // and that columns of M = rows of N. // It returns reference to the matrix which corresponds to M*N public static multiply(int[ ][ ] M, int[ ][ ] N) int rows = ; int columns = ; int[][] R = new int[rows][columns]; for(int r=0; ; r = r+1) for(int c=0; ; c=c+1) int product = ; for(int i=0; ;i=i+1) product = + ; R[r][c]= ; return R; 4

4. (marks=6) Recall the class Triangle which was described in details during some lecture. For your assistance, the following was the skeleton of the Triangle class. class Triangle private Point P; private Point Q; Private Point R; public Triangle()... public Triangle(Point A, Point B, Point C)... public double Area()... public double Perimeter()... We want to add one more non-static method Encloses() to this class. This method takes a point as parameter and returns true if the point is enclosed by the triangle and false otherwise. Note that a point lying on one of the sides of the triangle is also said to be enclosed by the triangle. Please fill in the blanks of the following skeleton of the method. You may write at most one statement/expression in a blank. You can t use && or in the expression of if statement. public boolean Encloses(Point O) ; ; ; if( ) return true; return false; 5

5. (Marks = 3,5) Draw the recursion tree for the following method when invoked with arguments n = 10, and S =. Also print the output of the method. public static f(int n, String S) if(n<=2) System.out.println(S); f(n-3, S+"-"+n); if(n>=4) f(n/2,s+"-"+(n/2)); 6

6. (7 marks) There is a function G defined for positive integers as follows. G(n) = 4 if 1 n 4 G(n 1) + G(n 2) + 2G(n 3) - 2 if n > 4 Write a method for computing G(n) which performs at most c n instructions for some constant c. public static int G(int n) 7

7. (Marks = 1,3,3,1) Given a grid with height n and width 2n, We want to enumerate all those shortest paths from origin (0, 0) to (2n, n) which satisfy the constraint : Each point of the path is either on or below the diagonal. See figure given below for better understanding. The program enumerates a path so that it prints -up for a step in upward direction and prints -right for a step in right direction. For example for n = 2, the output should be -right-right-up-right-right-up -right-right-right-up-right-up -right-right-right-right-up-up (8,4) Diagonal (0,0) 8 by 2 grid (8,4) (8,4) (0,0) Valid shortest path (0,0) Invalid shortest path Figure 1: The grid, an example of valid path and an example of invalid path Please fill in the blanks of the following program carefully. The program reads the value of n from command line. class special_paths public static void PathS(int r, int u, String S) if( ) System.out.println(S); ; ; public static void main(string args[]) int n = Integer.parseInt(args[0]); if(n<1) System.out.println("Invalid input"); PathS( ); 8

8. (10) The idea underlying binary search is a very useful idea and can be used for a variety of problems. We showed that we can use it for the following problem. Given an array A which stores 0 s and 1 s such that all 0 s precede all 1 s, find the smallest index of the array which stores 1. We are going to use similar idea for the following problem. There is an array A storing n distinct integers. The numbers are arranged such that there is a nonnegative integer p< n such that A[0],...A[p] is a strictly increasing sequence and A[p],..., A[n 1] is a strictly decreasing sequence of numbers. The following code prints the value of p. Fill in the blanks accordingly. public static void Largest_value(int[] A) int n = A.length; int mid = 0; if( ) System.out.println( The value of p = 0 ); if( ) System.out.println( The value of p = + ); boolean p_is_found = false; int left = ; int right = n-2; while( ) mid = (left+right)/2; if(a[mid]> ) if( ) ; ; System.out.println("The value of p is "+mid); 9. 9