Largest Online Community of VU Students

Similar documents
Largest Online Community of VU Students

Largest Online Community of VU Students

Data Structure (CS301)

CS301- Data Structures LATEST SOLVED MCQS & SUBJECTIVE FROM MIDTERM PAPERS. 18 December 2014

MIDTERM EXAMINATION Spring 2010 CS301- Data Structures

CIS Fall Data Structures Midterm exam 10/16/2012

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

University of Palestine. Final Exam 2 nd semester 2014/2015 Total Grade: 50

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

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)

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

double d0, d1, d2, d3; double * dp = new double[4]; double da[4];

First Semester - Question Bank Department of Computer Science Advanced Data Structures and Algorithms...

Lecture No.04. Data Structures

CS 216 Exam 1 Fall SOLUTION

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

Lecture Data Structure Stack

Wentworth Institute of Technology COMP201 Computer Science II Spring 2015 Derbinsky. Stacks and Queues. Lecture 11.

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

DEEPIKA KAMBOJ UNIT 2. What is Stack?

Review for Test 1 (Chapter 1-5)

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

Sample Question Paper

1. Stack overflow & underflow 2. Implementation: partially filled array & linked list 3. Applications: reverse string, backtracking

IV. Stacks. A. Introduction 1. Consider the 4 problems on pp (1) Model the discard pile in a card game. (2) Model a railroad switching yard

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

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

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

CSCE 2014 Final Exam Spring Version A

Computer Science CS221 Test 2 Name. 1. Give a definition of the following terms, and include a brief example. a) Big Oh

Computer Science 302 Spring 2007 Practice Final Examination: Part I

STACKS AND QUEUES. Problem Solving with Computers-II

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

Programming. Lists, Stacks, Queues

CS-301 Data Structure. Tariq Hanif

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

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

DNHI Homework 3 Solutions List, Stacs and Queues

Abstract Data Types 1

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

MIDTERM EXAMINATION Douglas Wilhelm Harder EIT 4018 x T09:30:00P1H20M Rooms: RCH-103 and RCH-302

Programming Abstractions

CS 10, Fall 2015, Professor Prasad Jayanti

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

Abstract Data Types. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University

17CS33:Data Structures Using C QUESTION BANK

COS 226 Algorithms and Data Structures Fall Midterm

Section 1: True / False (2 points each, 30 pts total)

NATIONAL UNIVERSITY OF SINGAPORE

Abstract Data Types 1

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

PA3 Design Specification

Ch. 18: ADTs: Stacks and Queues. Abstract Data Type

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

1) What is the primary purpose of template functions? 2) Suppose bag is a template class, what is the syntax for declaring a bag b of integers?

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

CS171 Midterm Exam. October 29, Name:

Top of the Stack. Stack ADT

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

Dynamic Data Structures

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

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

SYSC 2006 CD. Come to the PASS workshop with your mock exam complete. During the workshop you can work with other students to review your work.

Data Structure using C++ Lecture 04. Data Structures and algorithm analysis in C++ Chapter , 3.2, 3.2.1

CSCE 110 PROGRAMMING FUNDAMENTALS

CSE143 Exam with answers Problem numbering may differ from the test as given. Midterm #2 February 16, 2001

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

! A data type for which: ! In fact, an ADT may be implemented by various. ! Examples:

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

PESIT Bangalore South Campus Department of MCA Course Information for

12 Abstract Data Types

CS Data Structure Spring Answer Key- Assignment #4

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

Introduction to Computing II (ITI 1121) Final Examination

The Stack ADT. Stacks. The Stack ADT. The Stack ADT. Set of objects in which the location an item is inserted and deleted is prespecified.

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

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

1 P age DS & OOPS / UNIT II

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

Lists, Stacks, and Queues. (Lists, Stacks, and Queues ) Data Structures and Programming Spring / 50

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

CS350 - Exam 1 (100 Points)

An Introduction to Queues With Examples in C++

Part I: Short Answer (12 questions, 65 points total)

CSE 230 Intermediate Programming in C and C++

Arrays and Linked Lists

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305

Queues Fall 2018 Margaret Reid-Miller

Data Abstraction and Specification of ADTs

Top of the Stack. Stack ADT

Linked Structures. See Section 3.2 of the text.

Total No. of Questions :09] [Total No. of Pages : 02. II/IV B.Tech. DEGREE EXAMINATIONS, NOV/DEC First Semester CSE/IT DATA STRUCTURES USING C

CS302 Data Structures using C++

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

SOLUTIONS (INCOMPLETE, UNCHECKED)

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

2015 Academic Challenge

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

! Determine if a number is odd or even. ! Determine if a number/character is in a range. ! Assign a category based on ranges (wind speed)

Midterm Exam (REGULAR SECTION)

Transcription:

WWW.VUPages.com WWW.VUTUBE.EDU.PK http://forum.vupages.com Largest Online Community of VU Students MIDTERM EXAMINATION SEMESTER FALL 2003 CS301-DATA STRUCTURE Total Marks:86 Duration: 60min Instructions Please read the following instructions carefully before attempting any question: 1. The duration of this examination is 60 Mins. 2. This examination is closed book, closed notes, closed neighbors; any one found cheating will get no grade. 3. Unless stated otherwise, all questions carry a single mark. 4. Do not ask any questions about the contents of this examination from anyone. a. If you think that there is something wrong with any of the questions, attempt it to the best of your understanding. b. If you believe that some essential piece of information is missing, make an appropriate assumption and use it to solve the problem. 5. Most, but not all, of the examination consists of multiple-choice questions. Choose only one choice as your answer. a. If you believe that two (or more) of the choices are the correct ones for a particular question, choose the best one. b. On the other hand, if you believe that all of the choices provided for a particular question are the wrong ones, select the one that appears to you as being the least wrong. 7. You are allowed to use any development environment like Dev C++ etc.

Question No: 1 Marks: 2 Given the class declaration class MyClass public:... void Func(); private: int n; ; what notation does the body of Func use to assign the value 3 to n? n = 3; MyClass.n = 3; MyClass::n = 3; someobject.n = 3; It can t be done n is private. Question No: 2 Marks: 2 Suppose that the class declaration of SomeClass includes the following function prototype. bool LessThan( SomeClass anotherobject ); Which of the following tests in the client code correctly compares two class objects alpha and beta? (e) if (alpha < beta) if (alpha.lessthan(beta)) if (LessThan(alpha, beta)) if (alpha.lessthan.beta) if (LessThan(alpha).beta) Question No: 3 Marks: 2 When should you use a const reference parameter? Whenever the data type might be many bytes. Whenever the data type might be many bytes, the function changes the parameter within its body, and you do NOT want these changes to alter the actual argument. Whenever the data type might be many bytes, the function changes the parameter within its body, and you DO want these changes to alter the actual argument. Whenever the data type might be many bytes, and the function does not change the parameter within its body. Question No: 4 Marks: 2

The Bag ADT is like the List ADT. The Bag ADT does not store items in any particular order and it allows duplicates. Suppose that the Bag class is efficiently implemented with a fixed array with a capacity of 4000. Insert appends the new item at the end of the array. Choose the best description of b s member variables size (count of items in the bag) and data (the array that holds the actual items) after we execute these statements: Bag b; b.insert(5); b.insert(4); b.insert(6); What will be the values of b.size and b.data after the statements? b.size is 3, b.data[0] is 4, b.data[1] is 5, b.data[2] is 6 b.size is 3, b.data[0] is 5, b.data[1] is 4, b.data[2] is 6 b.size is 3, b.data[0] is 6, b.data[1] is 4, b.data[2] is 5 b.size is 3, b.data[0] is 6, b.data[1] is 5, b.data[2] is 4 Question No: 5 Marks: 2 The operation for removing an entry from a stack is traditionally called: delete peek pop remove Question No: 6 Marks: 2 Which of the following stack operations could result in stack underflow? is empty pop push Two or more of the above answers Question No: 7 Marks: 5 Consider the following pseudo code: declare a stack of characters while ( there are more characters in the word to read ) read a character push the character on the stack while ( the stack is not empty ) pop a character off the stack write the character to the screen

What is written to the screen for the input carpets? serc carpets steprac ccaarrppeettss Question No: 8 Marks: 2 In the linked list implementation of the stack class, where does the push member function place the new entry on the linked list? At the head At the tail After all other entries that are greater than the new entry. After all other entries that are smaller than the new entry. Question No: 9 Marks: 2 Given a stack of n items, how many POP and PUSH operations need to be performed to remove the item at its bottom? (e) 0 POP operation and 0 PUSH operation 1 POP operation and 1 PUSH operation n POP operations and n PUSH operations n POP operations and n-1 PUSH operations Unknown Question No: 10 Marks: 2 In the linked list implementation of the queue class, where does the insert member function place the new entry on the linked list? At the head At the tail After all other entries that are greater than the new entry. After all other entries that are smaller than the new entry. Question No: 11 Marks: 2

I have implemented the queue with a linked list, keeping track of a front pointer and a rear pointer. Which of these pointers will change during an insertion into a NONEMPTY queue? Neither changes Only front pointer changes. Only rear pointer changes. Both change. Question No: 12 Marks: 2 I have implemented the queue with a linked list, keeping track of a front pointer and a rear pointer. Which of these pointers will change during an insertion into an EMPTY queue? Neither changes Only front pointer changes. Only rear pointer changes. Both change. Question No: 13 Marks: 6 For public part of the Throttle declaration below, mark each function member header as follows: Mark C for any constructor; mark X for any function that is forbidden from changing the throttles data fields. class Throttle public: Throttle( ); Throttle(int size); void shut_off( ); void shift(int amount); double flow( ) const; bool is_on( ) const;... class Throttle public: Throttle( ); C Throttle(int size); C void shut_off( ); void shift(int amount); double flow( ) const; bool is_on( ) const;... X X Question No: 14 Marks: 5

I am going to execute this code with THREE pushes and ONE pop: Stack s; s.push(1); s.push(2); s.push(3); cout << s.pop( ); Suppose that the stack s is represented by a singly linked list. Draw the linked list after the above operations and show where the top element is in the list. head --> head 2 1 Question No: 15 Marks: 10 Complete the body of this function. Use a Queue of characters to store the input line as it is being read. int counter( ) // Precondition: // There is a line of input waiting to be read from cin. // Postcondition: // A line of input has been read from cin, up to but not // including the newline character. The return value of // the function is the number of times that the LAST // character of the line appeared somewhere in this line. // EXAMPLE // Input: PQQYDYYTY // The value returned by the function counter would // be 4 for this input since there are 4 Y s in // the input line. int answer = 0; Queue q; int counter() char a[100]; int i=0; int answer=0; Queue q; cin.getline(a,98,'\n'); for(i=0;i<strlen;i++) q.enqueue(a[i]); i--; while(!q.isempty())

if(a[i]==q.dequeue()) answer++; return answer; Question No: 16 Marks: 5. I am going to execute this code with THREE inserts (enqueue) and ONE remove ( dequeue ): Queue s; s.insert(1); s.insert(2); s.insert(3); cout << s.remove( ); Suppose that queue s is represented by a circular array. Draw the state of the private member variables data and front of s after the above code: 0 1 2 3 4 5 6 7 8 9 2 3 Front 1 Question No: 17 Marks: 10

Consider CList and Node classes defined as follows: class Node public: Node *next; Node *prev; int data; ; class CList public: void inserthead(int); void inserttail(int); void removehead(); void removetail(); bool isempty(); bool find(int); private: Node *head; Node *tail; ; A. write the body of the member function inserthead which inserts a new element at the head of the list. void Clist::insertHead( int x ) B. write the body of the member function removetail which removes the element at the tail of the list. void Clist::removeTail( int x ) Solution for Question 17 option void CList::insertHead(int x) Node *newnode=new Node(); newnode->data=x; newnode->next=null; newnode->prev=null; if(isempty()) head=tail=newnode; else newnode->next=head; newnode->prev=null; head->prev=newnode; head=newnode; Solution for Question 17 option void CList::removeTail(int &x) if(isempty())

return; else Node *p=tail; if(head==tail) head=tail=null; else tail=tail->prev; tail->next=null; x=p->data; delete p; return; Question No: 18 Marks: 10 Trace the running of the infix to postfix conversion algorithm on the infix expression A * (B C)/D A * ( B C ) / D Symbol Postfix Stack A A * A * ( A *( B AB *( - AB *(- C ABC *(- ) ABC- ABC- *( *

/ ABC-* / D ABC-*D ABC-*D/ Question No: 19 Marks: 13 Here is a small binary tree: A. What are all the leaves? (2pts) C. What are the ancestors of the node 30?(2pts) D. What are the descendants of the node 11? (2pts) E. Is the tree a binary search tree (BST) (true/false)? (2pts) F. Print the tree when visited in in-order manner? (5pts) A) Leaves of the Tree = 1,3,7,40 B) Ancestors of the node 30 = 11,14 C) Descendants of the node 11= 10,30,7,40 D) Is the three a binary search tree (BST) (True/False) False E) In-order Traversal = 1,2,3,14,7,10,11,30,40