PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Electronics and Communication

Similar documents
PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Electronics and Communication

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Electronics and Communication

Data Structures. data object. set or collection of instances. integer = {0, +1, -1, +2, -2, +3, -3, } daysofweek = {S,M,T,W,Th,F,Sa}

Data Structures and Programming 資料結構與程式設計. Topic 3 Linear Lists Array. AbstractDataType linearlist. Linear List - Array Representation

Computer Science & Engineering 150A Problem Solving Using Computers

Ch6. Linear Lists Linked Representation

High Institute of Computer Science & Information Technology Term : 1 st. El-Shorouk Academy Acad. Year : 2013 / Year : 2 nd

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Computer Science and Engineering

Before we start - Announcements: There will be a LAB TONIGHT from 5:30 6:30 in CAMP 172. In compensation, no class on Friday, Jan. 31.

Introduction to Arrays

Data Structures (CS301) LAB

Comp 311: Sample Midterm Examination

Introduction to Computer Science Midterm 3 Fall, Points

15. Arrays and Methods. Java. Summer 2008 Instructor: Dr. Masoud Yaghini

Types of Data Structures

SCJ2013 Data Structure & Algorithms. Bubble Sort. Nor Bahiah Hj Ahmad & Dayang Norhayati A. Jawawi

Spring 2008 Data Structures (CS301) LAB

PESIT Bangalore South Campus

PESIT Bangalore South Campus

Decaf Language Reference Manual

COP3530 DATA STRUC/ALGORITHMS

Pointer Basics. Lecture 13 COP 3014 Spring March 28, 2018

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard

egrapher Language Reference Manual

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of MCA

Arrays. CS10001: Programming & Data Structures. Pallab Dasgupta Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur

class Polynomial { public: Polynomial(const string& N = "no name", const vector<int>& C = vector<int>());... };

CSCE 110 PROGRAMMING FUNDAMENTALS. Prof. Amr Goneid AUC Part 7. 1-D & 2-D Arrays

calling a function - function-name(argument list); y = square ( z ); include parentheses even if parameter list is empty!

[0569] p 0318 garbage

Data types. CISC 1600/1610 Computer Science I. Array syntax. Memory allocation. Zero-indexing 4/4/2016. Arrays

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

Algorithm Analysis. Performance Factors

Searching. 11. Searching

Here we will only consider the problem of searching among the elements of an array. Intro Programming in C++

2. List Implementations (a) Class Templates (b) Contiguous (c) Simply Linked (d) Simply Linked with Position Pointer (e) Doubly Linked

Darshan Institute of Engineering & Technology for Diploma studies Unit 4

Instantiation of Template class

Data Structures and Programming 資料結構與程式設計. Topic 6 Stacks. Stacks. Stack of Cups. Stacks. top. top. bottom. bottom

Programming II (CS300)

Data abstractions: ADTs Invariants, Abstraction function. Lecture 4: OOP, autumn 2003

Java Classes and Objects

MIDTERM EXAMINATION Spring 2010 CS301- Data Structures

CE204 Data Structures and Algorithms Part 2

Lists. CITS2200 Data Structures and Algorithms. Topic 9

Data Structures CSci 1200 Test 2 Questions

Arrays and ArrayLists. Ananda Gunawardena

8/2/10. Looking for something COMP 10 EXPLORING COMPUTER SCIENCE. Where is the book Modern Interiors? Lecture 7 Searching and Sorting TODAY'S OUTLINE

Lecture 10 March 4. Goals: hashing. hash functions. closed hashing. application of hashing

FACULTY OF SCIENCE ACADEMY OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING ADVANCED DATA STRUCTURES AND ALGORITHMS EXAM EXAMINATION JUNE 2014

Exercise 1.1 Hello world

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

Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru Department of Electronics and Communication Engineering

Arrays and functions Multidimensional arrays Sorting and algorithm efficiency

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

CSE 373 Spring Midterm. Friday April 21st

Programming Languages and Compilers Qualifying Examination. Answer 4 of 6 questions.1

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

Introduction to Linked Data Structures

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

CS201 Some Important Definitions

DOWNLOAD PDF LINKED LIST PROGRAMS IN DATA STRUCTURE

Outline and Reading. The Stack ADT ( 4.2.1) Applications of Stacks ( 4.2.3) Array-based implementation ( 4.2.2) Growable array-based stack.

Procedural programming with C

Chapter 6: User-Defined Functions. Objectives (cont d.) Objectives. Introduction. Predefined Functions 12/2/2016

Topic 11 Linked Lists

About this exam review

Bangalore South Campus

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Data Structures and Algorithms. Final Examination

The format for declaring function templates with type parameters

14. Pointers, Algorithms, Iterators and Containers II

Page. No. 1/15 CS201 Introduction to Programmming Solved Subjective Questions From spring 2010 Final Term Papers By vuzs Team

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

SYSC 2006 C Winter 2012

15. Pointers, Algorithms, Iterators and Containers II

Function Pointers. Function Pointers

CSCI-1200 Data Structures Spring 2018 Lecture 7 Order Notation & Basic Recursion

Structured programming

Sorting. Weiss chapter , 8.6

G Programming Languages - Fall 2012

Programming II (CS300)

Introduction to C++ Systems Programming

CS 2505 Computer Organization I

Prof. Sushant S Sundikar 1

C++ PROGRAMMING LANGUAGE: CLASSES. CAAM 519, CHAPTER 13

Introduction to Core C++

UNIVERSITY OF WATERLOO DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING E&CE 250 ALGORITHMS AND DATA STRUCTURES

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)

CHAPTER 4 LINKED LISTS

Pointers as Arguments

Chapter 10 - Notes Applications of Arrays

CSCI-1200 Data Structures Fall 2017 Lecture 7 Order Notation & Basic Recursion

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Data Structures and Algorithms. Final Examination

BBM 201 DATA STRUCTURES

DATA STRUCTURES AND ALGORITHMS

Dynamic Data Structures

6. Pointers, Structs, and Arrays. March 14 & 15, 2011

Tokens, Expressions and Control Structures

1 Lexical Considerations

Transcription:

USN 1 P E PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -0 Department of Electronics and Communication INTERNAL ASSESSMENT TEST 1 Date : 30/8/2017 Marks: 0 Subject & Code : Data Structures using C++ (EC761) Sec : 7 th Sem A/B/C Name of faculty : Ms. Sai Prasanna M S Time : 11:30am -1:00 pm Note: Answer FIVE full questions. Marks Q.No 1 a. What are Data Structures? Justify their need with an illustrative example. b. Explain the need of Template Function and Template Class. 2 Explain the operators used for Dynamic Memory Allocation. Illustrate with a program - expanding the dynamic array. 3 What are the two types of representations of a linear list? Explain and distinguish them. Mention their relative Advantages and disadvantages. 4 What is linear list? Write the abstract class specification of a linear list. Using Formula based representation illustrate with a C++ program insertion of the element as the index-i th element using the template class for linear list. 6 a. In the following code, explain why the swap method fails to swap actual parameters. Change this code so that it swaps actual parameters, 4 void swap (int x, int y) int t = x ; x =y; y = t; b. Write a C++ function template for Bubble Sort. 7 Explain linked representation of singly linked list. Write a program using function templatei) to return the index of the first occurrence of the element ii) to insert an element in the index position. 8 Explain testing and debugging of a C++ code. Explain the different methods of testing. 6

SOLUTION MANUAL FOR INTERNAL ASSESSMENT TEST 1 Date : 30/8/2017 Marks: 0 Subject & Code : Data Structures using C++ (EC761) Sec : 7 th Sem A/B/C Name of faculty : Ms. Sai Prasanna M S Time : 11:30am -1:00 pm Note: Answer FIVE full questions. Marks Q.No 1 a. What are Data Structures? Justify their need with an illustrative example. b. Explain the need of Template Function and Template Class. Function templates are special functions that can operate with generic types. This allows us to create a function template whose functionality can be adapted to more than one type or class without repeating the entire code for each type. Class templates class can have members that use template parameters as types. For example: template <class T> class mypair T values [2]; public: mypair (T first, T second) values[0]=first; values[1]=second; ; 2 Explain the operators used for Dynamic Memory Allocation. Illustrate with a program - expanding the dynamic array. Dynamic memory In the programs seen in previous chapters, all memory needs were determined before program execution by defining the variables needed. But there may be cases where the memory needs of a program can only be determined during runtime. For example, when the memory needed depends on user input. On these cases, programs need to dynamically allocate memory, for which the C++ language integrates the operators new and delete. Operators new and new[] Dynamic memory is allocated using operator new. new is followed by a data type specifier and, if a sequence of more than one element is required, the number of these within brackets []. It returns a pointer to the beginning of the new block of memory allocated. Its syntax is:

pointer = new type pointer = new type [number_of_elements] The first expression is used to allocate memory to contain one single element of type type. The second one is used to allocate a block (an array) of elements of type type, where number_of_elements is an integer value representing the amount of these. For example: i nt * foo; foo=new int []; once it is no longer needed, it can be freed so that the memory becomes available again for other requests of dynamic memory. This is the purpose of operator delete, whose syntax is: 1 delete pointer; 2 delete[] pointer; The first statement releases the memory of a single element allocated using new, and the second one releases the memory allocated for arrays of elements using new and a size in brackets ([]). The value passed as argument to delete shall be either a pointer to a memory block previously allocated with new, or a null pointer (in the case of a null pointer, delete produces no effect). 3 What are the two types of representations of a linear list? Explain and distinguish them. Mention their relative Advantages and disadvantages. A formula-based representation uses an array to represent the instances of an object. Each position of the array, called a cell or a node, holds one element that makes up an instance of that object. Individual elements of an instance are located in the array, based on a mathematical formula, e.g., a simple and often used formula is Location(i) = i 1,which says the ith element of the list is in position i 1. We also need two more variables, length and MaxSize, to completely characterize the list type. One way to overcome the inefficiency problem of the previous approach is to assign space on a need-only base. No space will be assigned if there is no need; and whenever there is a need, another piece of space will be assigned to an element. Since, we can t guarantee all the pieces of spaces assigned at different times will be physically adjacent, besides the space assigned for the elements, we also have to keep track of the location information of previously assigned pieces.

Hence, in a linked representation, each element of an instance is presented in a cell or node, which also contains a pointer that keeps information about the location of another node. 4 What is linear list? Write the abstract class specification of a linear list. L = (e0, e1, e2, e3,, en-1) Relationships: e0 is the zero th (or front) element en-1 is the last element ei immediately precedes ei+1 class linearlist public: virtual ~linearlist() ; virtual bool empty() const = 0; virtual int size() const = 0; virtual T& get(int theindex) const = 0; virtual int indexof(const T& theelement)const = 0; virtual void erase(int theindex) = 0; virtual void insert(int theindex, const T& theelement) = 0; virtual void output(ostream& out) const = 0; ; Using Formula based representation illustrate with a C++ program insertion of the element as the index-i th element using the template class for linear list. void arraylist<t>::insert(int theindex, const T& theelement) // Insert theelement. checkindex(theindex) ; // valid index, make sure we have space if (listsize == arraylength) // no space, double capacity changelength1d(element, arraylength, 2 * arraylength); arraylength *= 2; // shift elements right one position copy_backward(element + theindex, element + listsize, element + listsize + 1);

element[theindex] = theelement; listsize++; 6 a. In the following code, explain why the swap method fails to swap actual parameters. Change this code so that it swaps actual parameters, 4 void swap (int x, int y) int t = x ; x =y; y = t; Concept of actual parameter and formal parameter. Problem can be overcome using pointers. void swap (int *x, int *y) int t = x ; *x =*y; *y = *t; b. Write a C++ function template for Bubble Sort. 6 template< typename T > void sort( T a[], int n ) for( int i=0 ; i<n ; ++i ) for( int j=i+1 ; j<n ; ++j ) if( a[j] < a[i] ) int temp = a[i] ; a[i] = a[j] ; a[j] = temp ; 7 Explain linked representation of singly linked list. Write a program using function templatei) to return the index of the first occurrence of the element

ii) to insert an element in the index position. list elements are stored, in memory, in an arbitrary order explicit information (called a link) is used to go from one element to the next int chain<t>::indexof(const T& theelement) const // search the chain for theelement chainnode<t>* currentnode = firstnode; int index = 0; // index of currentnode while (currentnode!= NULL && currentnode->element!= theelement) // move to next node currentnode = currentnode->next; index++; if (currentnode == NULL) return -1; else return index; void chain<t>::insert(int theindex, const T& theelement) if (theindex < 0 theindex > listsize) // Throw illegalindex exception if (theindex == 0) // insert at front firstnode = new chainnode<t>

(theelement, firstnode); else // find predecessor of new element chainnode<t>* p = firstnode; for (int i = 0; i < theindex - 1; i++) p = p->next; // insert after p p->next = new chainnode<t> (theelement, p->next); listsize++; 8 Explain testing and debugging of a C++ code. Explain the different methods of testing. Black box testing: when the tester has no idea of the internal working of the system which he is testing, that approach is called black box testing. In this case, the system under test is viewed as a black box. Requirements Document or Functional Specification Document forms the basis of this testing, which requires the user to understand the processes within the software. White box testing: The tester has the knowledge of the internals of a system and knows how the system is implemented. The tester uses this knowledge to develop test cases that will examine the control flow, information flow, data flow, exception and error handling as well as coding practices of the system. Debugging Techniques: Incremental testing Sanity checks Boolean constants for turning debugging code on or off Error variables for controlling program behavior after errors