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

Similar documents
Computer Science Foundation Exam. May 6, Computer Science. Section 1A. No Calculators! KEY. Score: 50

Computer Science. Section 1B

Q1 Q2 Q3 Q4 Q5 Q6 Total

Computer Science Foundation Exam

Computer Science Foundation Exam

R10 SET - 1. Code No: R II B. Tech I Semester, Supplementary Examinations, May

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

R13. II B. Tech I Semester Supplementary Examinations, May/June DATA STRUCTURES (Com. to ECE, CSE, EIE, IT, ECC)

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

CSE 373 Spring Midterm. Friday April 21st

Section I B COMPUTER SCIENCE SOLUTION

Basic Data Structures (Version 7) Name:

MIDTERM EXAMINATION Spring 2010 CS301- Data Structures

Computer Science Foundation Exam

Computer Science Foundation Exam

Computer Science Foundation Exam

R10 SET - 1. Code No: R II B. Tech I Semester, Supplementary Examinations, May

INSTITUTE OF AERONAUTICAL ENGINEERING

CS 216 Exam 1 Fall SOLUTION

Data Structures Question Bank Multiple Choice

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

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

MLR Institute of Technology

Largest Online Community of VU Students

Computer Science Foundation Exam. March 3, Section I A. No Calculators! Name: SSN: In this section of the exam, there are three (3) problems.

Computer Science Foundation Exam

Computer Science Foundation Exam. May 3, Section I A. No Calculators! Name: SSN: In this section of the exam, there are three (3) problems.

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

Sample Question Paper

Computer Science Foundation Exam

Delhi Noida Bhopal Hyderabad Jaipur Lucknow Indore Pune Bhubaneswar Kolkata Patna Web: Ph:

Computer Science Foundation Exam

Bachelor Level/ First Year/ Second Semester/ Science Full Marks: 60 Computer Science and Information Technology (CSc. 154) Pass Marks: 24

MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct.

End-Term Examination Second Semester [MCA] MAY-JUNE 2006

Computer Science Foundation Exam

ECE 250 Data Structures and Algorithms MID-TERM EXAMINATION /5:30-7:00

CMPSCI 187: Programming With Data Structures. Review for Final Exam David Mix Barrington 10 December 2012

CP2 Revision. theme: dynamic datatypes & data structures

Tribhuvan University Institute of Science and Technology Computer Science and Information Technology (CSC. 154) Section A Attempt any Two questions:

Computer Science Foundation Exam

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

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

Computer Science Foundation Exam

Ashish Gupta, Data JUET, Guna

Computer Science Foundation Exam

CSE 332 Spring 2014: Midterm Exam (closed book, closed notes, no calculators)

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

! 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)

Section 05: Solutions

S.E. (Computer) (First Semester) EXAMINATION, 2011 DATA STRUCTURES AND ALGORITHM (2008 PATTERN) Time : Three Hours Maximum Marks : 100

Where does the insert method place the new entry in the array? Assume array indexing starts from 0(zero).

An Introduction to Trees

Computer Science Foundation Exam. December 15, Section I A. No Calculators! Name: SSN:

Computing Science 115 Final Examination April 23, 2002 Section: B2 BASU. Please put student id on last page. Instructions:

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

Abstract Data Structures IB Computer Science. Content developed by Dartford Grammar School Computer Science Department

CS302 Data Structures using C++

Tree: non-recursive definition. Trees, Binary Search Trees, and Heaps. Tree: recursive definition. Tree: example.

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

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

ECE 250 Data Structures and Algorithms MID-TERM EXAMINATION B /13:30-14:50 MC-4021/RCH-211

CSE 332 Winter 2015: Midterm Exam (closed book, closed notes, no calculators)

Summer Final Exam Review Session August 5, 2009

Draw a diagram of an empty circular queue and describe it to the reader.

CS 151 Quiz 4. Instructions: Student ID. (Last Name) (First Name) Signature

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

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)

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

Final Exam. Name: Student ID: Section: Signature:

University of Toronto Department of Electrical and Computer Engineering. Midterm Examination. ECE 345 Algorithms and Data Structures Fall 2012

ECE 250 Data Structures and Algorithms MIDTERM EXAMINATION /5:30-7:00

Computer Science Foundation Exam

Data Structure and Algorithm, Spring 2013 Midterm Examination 120 points Time: 2:20pm-5:20pm (180 minutes), Tuesday, April 16, 2013

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

CSL 201 Data Structures Mid-Semester Exam minutes

Points off Total off Net Score. CS 314 Final Exam Spring 2016

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

UNIT 5B Binary Search

CS210 (161) with Dr. Basit Qureshi Final Exam Weight 40%

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

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305

Solution printed. Do not start the test until instructed to do so! CS 2604 Data Structures Midterm Spring Instructions:

APJ ABDUL KALAM TECHNOLOGICAL UNIVERSITY THIRD SEMESTER B.TECH DEGREE EXAMINATION, JULY 2017 CS205: DATA STRUCTURES (CS, IT)

We've tried to include the common errors and grading standard for every question.

Reg. No. : Question Paper Code : 27157

MCS 360 Exam 2 11 November In order to get full credit, you need to show your work.

COS 226 Algorithms and Data Structures Fall Midterm

CS 445: Data Structures Final Examination: Study Guide

CS 314 Exam 2 Fall 2017

CSE wi: Practice Midterm

Spring 2002: Fundamental Structures of Computer Science

Name: After line 1: After line 3: After line 5: After line 8: After line 11:

CMPT 225. Lecture 6 linked list

ECE 250 Data Structures and Algorithms MID-TERM EXAMINATION /08:30-9:50 RCH 105, RCH 110

Computer Science Foundation Exam

Computer Science Foundation Exam

Section 05: Midterm Review

: Advanced Programming Final Exam Summer 2008 June 27, 2008

Transcription:

Computer Science Foundation Exam Dec. 19, 2003 COMPUTER SCIENCE I Section I A No Calculators! Name: KEY SSN: Score: 50 In this section of the exam, there are Three (3) problems You must do all of them. The weight of each problem in this section is indicated with the problem. The algorithms in this exam are written in C programming language notation. Partial credit cannot be given unless all work is shown. As always, be complete, yet concise, and above all be neat. Credit cannot be given when your results are unreadable.

1. a)convert the following infix expression to postfix, showing the values in the operator stack at each indicated point in the infix string (points 1, 2, 3 and 4), in the boxes below. You may add more boxes for each position if necessary to do so. [ 10 ] A / B / 1 ( C R J 2 * M + N ) L 3 / D * E 4 * F GRADING SCHEME: Box 1 : [ 1 point ] Box 2, 3, 4 [ 2 points each] Resultant expression [ 3 points ] ( * / / 1 2 3 4 Resulting Expression : A B / C R J M * N + / L D / E * F * b) A circular queue is implemented on an array of size N. Let tail represent the index of the last element added to the queue, and head represent the index of the element to be deleted from the queue. To start with, the queue is empty, and both tail and head equal 1. How many more elements can the queue hold when [ 10 ] i) head = 30 tail = 33 N 4 [ 3 points ] ii) head = 3 tail = 3 N 1 [ 3 points ] iii) head = 1 tail = N 1 1 [ 2 points ] iv) tail = 1 head = 1 N [ 2 points ] 2

2. Trace the effect of executing the code segment shown below on the linked list structure, also shown below, by drawing the linked list as it would look after the code has been executed [ 10 ] struct list{ int data; struct list *next; }; p = head; while (p!= NULL) { if (p->data <= 6) { newp = (struct list *) malloc(sizeof(struct list)); newp->data = p->data + 8; newp->next = p->next; p->next = newp; p = newp; } else p = p->next; } head 1 8 7 6 3 9 5-1 - null The new list has the elements 1, 9, 8, 7, 6, 14, 3, 11, 9, 5, 13, -1, 7 Give [ 2 points ] for each new node created 3

3. Consider the following circular list, where head points to the FIRST node of the list. [20] head Assume the following declaration for nodes struct node{ int data; struct node *next; }; Complete the following incomplete function to extend the circular linked list being pointed by p ( the first node) by appending a singly linked list (pointed by q ) to the end of the circular list. The singly linked list has got twice as many elements as the circular list. The resulting list will be one big circular list.. It is specified that * Circular list is NOT empty i.e. p cannot be NULL, but q may be NULL. Desired: the first node of the original circular list will be the first node of the newly created big circular list again. 4

void extend(struct node *p, struct node * q) { struct node *t; /* t is used to traverse the lists */ if ( q == NULL ) /* if standard linked list is [ 2 points ] empty */ return; t = p; /* Assume p cannot be NULL */ while ( t->next!= p ) /*traverse the circular list */ [ 4 points ] t = t ->next ; [ 2 points ] t->next = q ; /* append the standard list */ [ 2 points ] while ( t->next!= NULL ) /* traverse the std. list */ [ 2 points ] t = t->next ; [ 2 points ] t->next = p ; [ 2 points ] /*here you may insert a statement to take care of the fact that singly linked list contains twice as many nodes as circular list. You may insert this statement anywhere else too */ [ 4 points if they leave this space blank ] } 5

Computer Science Foundation Exam Dec. 19, 2003 COMPUTER SCIENCE I Section I B No Calculators! Name: KEY SSN: Score: 50 In this section of the exam, there are four (4) problems You must do all of them. The weight of each problem in this section is indicated with the problem. The algorithms in this exam are written in C programming language notation. Partial credit cannot be given unless all work is shown. As always, be complete, yet concise, and above all be neat. Credit cannot be given when your results are unreadable. 6

1a) An array contains a list of 1500 words arranged alphabetically. What is the minimum number of words that must be examined to establish that a particular word is not present in the list. [ 3 ] Ans: Since it is alphabetically arranged, binary search can be applied which needs to examine the list log 2 n times, i.e. log 2 1500. Now 2 10 = 1024 and 2 11 = 2048 Since 1500 is more than 1024, it would require searching of 11 words. 1b) An array contains a sequence of n integers arranged in ascending order. Indicate a method to organize this data so that searching for an integer, deleting an integer or adding a new integer takes O(log n) operations. You may suggest a different data structure to hold the data, if you think it is necessary. In that case indicate how the data movement is to take place. [ 10 ] Ans: The Binary search tree BST, is a data structure, where searching, deletion and insertion operations can be done in O(log n ) operations. The data is in ascending order so if the elements are stored in that order in the BST tree, it will result in a skewed tree of height n. To get a balanced binary search tree, the root of the tree should be so chosen that the left half of the tree and the right half of the tree contain almost equal number of nodes. The subsequent nodes should also be chosen keeping this in mind. Data Movement : Let root be the integer at the middle of the array,i.e. at the (n/2) th position. This will divide the array in two equal parts. The left child should be the middle element of the left part of the array, and the right child should be the middle element of the right part of the array. Keep on dividing the array at each stage and pick up the remaining elements in same manner. Example: Let the array be 4 8 9 12 24 30 36 40 47 52 60 66 75 82 88 92 96 Root node: 47 47 4 8 9 12 24 30 36 40 52 60 66 75 82 88 92 96 7

left child: 12 right child : 75 47 12 75 4 8 9 24 30 36 40 52 60 66 82 88 92 96 The process continues with nodes at next level being 8, 30, 60 and 88 Final Binary search tree takes the following form: 47 12 75 8 30 60 88 4 9 24 36 52 66 82 92 40 96 ---------------------------------------------------------------------------------------------------------- 8

2. Carry out the following summations: [ 15 ] 40 S ( 2 i 4 ) i = 1 = 2 [(40) ( 41)/2] - 4 [40] = 40 (41 4 ) = 1480 S i 2 j = 3 + 5 j 14 = i 2 ( 14 3 + 1) + 5 [ 14(15)/2 2 (3)/2 ] = 5 [ 105 3 ] +12 i 2 = 12 i 2 + 510 - n m k S S S 22 i = 1 k= 1 j = 1 n m S S 22 k i = 1 k= 1 n S 22 m(m+1)/2 i = 1 = 11 n m ( m+1) 9

3. Study the following algorithm for generating Fibonacci numbers, where the problem of generating the nth number is broken down into two parts, one trying to solve for (n 1 )th number and the other trying to solve for (n-2)th number. [ 10 ] int fib( n ) { if ( n < 2 ) return n ; else return ( fib (n 2 ) + fib ( n 1 ) ; } What would be the complexity of this algorithm: a) log n b) n c) n 2 d) n 3 e) more than n 3 Justify your answer. Let T(n) be running time for calling the fib. Function. For n =0 or 1 it takes constant time T(0) = T(1) = 1 At any other stage, it involves calling fib function with running time T(n-1) and again with running time T(n-2). In addition, there is a if operation and one addition operation. Thus, T(n) = T(n-1) + T(n-2) + 2 Since fib (n) = fib (n-1) + fib (n-2) it is easy to see that T(n) > fib(n), as at every stage T(n) is more than sum of T(n-1) and T(n-2). It is known that fibonacci numbers grow very fast fib(n) > ( 3/2) n Thus, T(n) > ( 3/2) n Which grows much faster than n 3. 10

4. a)what will be the out put of the following algorithm, if it is used on the binary search tree shown in the figure. In the algorithm p points to the root node of the tree, and Q represents a queue. If ( p! = NULL) { Q.enqueue (p) ; while (Q is not empty) { p = Q.dequeue ; print ( contents of p ) ; if ( p -> left!= NULL ) Q.enqueue( p -> left) ; if ( P -> right!= NULL) Q.enqueue ( p ->right); } } 4b) Write down the pre-order traversal of the tree [ 12 ] 45 26 72 15 35 83 20 30 65 79 90 11

Ans. 4a) 45, 26, 72, 15, 35, 65, 83, 20, 30, 79, 90 4b) 45, 26, 15, 20, 35, 30, 72, 65, 83, 79, 90 12