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

Size: px
Start display at page:

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

Transcription

1 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

2 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:

3 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.

4 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);

5 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

6 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>

7 (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

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 INTERNAL ASSESSMENT TEST 1 Date : 28.2.2018 Marks: 40 Subject & Code : DataStructures Using C++ (15EC661) Sem : VI A,B,C Name of faculty : Vandana M L Time : 11:30-1:00 PM Note: Answer FIVE full questions,

More information

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 USN 1 P E PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -0 Department of Electronics and Communication INTERNAL ASSESSMENT TEST 2 Date : 4//2017 Marks: 50 Subject & Code

More information

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. 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 data object set or collection of instances integer = {0, +1, -1, +2, -2, +3, -3, } daysofweek = {S,M,T,W,Th,F,Sa} Data Object instances may or may not be related mydataobject = {apple,

More information

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

Data Structures and Programming 資料結構與程式設計. Topic 3 Linear Lists Array. AbstractDataType linearlist. Linear List - Array Representation Data Structures and Programming 資料結構與程式設計 Topic 3 Linear Lists Array 課程編號 :901 31900 EE 3011 科目名稱 : 資料結構與程式設計授課教師 : 黃鼎偉時間地點 : 一 678 電機二館 229 Abstract Data Type linearlist Abstract Data Type (ADT) AbstractDataType

More information

Computer Science & Engineering 150A Problem Solving Using Computers

Computer Science & Engineering 150A Problem Solving Using Computers Computer Science & Engineering 150A Problem Solving Using Computers Lecture 06 - Stephen Scott Adapted from Christopher M. Bourke 1 / 30 Fall 2009 Chapter 8 8.1 Declaring and 8.2 Array Subscripts 8.3 Using

More information

Ch6. Linear Lists Linked Representation

Ch6. Linear Lists Linked Representation Ch6. Linear Lists Linked Representation copyright 2006 Bird s-eye View Ch.5 ~ Ch.7: Linear List Ch. 5 array representation Ch. 6 linked representation Singly Linked Lists and Chains Circular Lists and

More information

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

High Institute of Computer Science & Information Technology Term : 1 st. El-Shorouk Academy Acad. Year : 2013 / Year : 2 nd El-Shorouk Academy Acad. Year : 2013 / 2014 High Institute of Computer Science & Information Technology Term : 1 st Year : 2 nd Computer Science Department Object Oriented Programming Section (1) Arrays

More information

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

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Computer Science and Engineering USN 1 P E PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Computer Science and Engineering SOLUTION FOR INTERNAL ASSESSMENT TEST 2 Date : 6/10/2017 Marks:

More information

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.

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. Before we start - Announcements: There will be a LAB TONIGHT from 5:30 6:30 in CAMP 172 The lab will be on pointers In compensation, no class on Friday, Jan. 31. 1 Consider the bubble function one more

More information

Introduction to Arrays

Introduction to Arrays Introduction to Arrays One Dimensional Array. Two Dimensional Array. Inserting Elements in Array. Reading Elements from an Array. Searching in Array. Sorting of an Array. Merging of 2 Arrays. What is an

More information

Data Structures (CS301) LAB

Data Structures (CS301) LAB Data Structures (CS301) LAB Objectives The objectives of this LAB are, o Enabling students to implement Doubly Linked List practically using c++ and adding more functionality in it. Introduction to Singly

More information

Comp 311: Sample Midterm Examination

Comp 311: Sample Midterm Examination Comp 311: Sample Midterm Examination October 29, 2007 Name: Id #: Instructions 1. The examination is closed book. If you forget the name for a Scheme operation, make up a name for it and write a brief

More information

Introduction to Computer Science Midterm 3 Fall, Points

Introduction to Computer Science Midterm 3 Fall, Points Introduction to Computer Science Fall, 2001 100 Points Notes 1. Tear off this sheet and use it to keep your answers covered at all times. 2. Turn the exam over and write your name next to the staple. Do

More information

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

15. Arrays and Methods. Java. Summer 2008 Instructor: Dr. Masoud Yaghini 15. Java Summer 2008 Instructor: Dr. Masoud Yaghini Outline Passing Arrays to Methods Returning an Array from a Method Variable-Length Argument Lists References Passing Arrays to Methods Passing Arrays

More information

Types of Data Structures

Types of Data Structures DATA STRUCTURES material prepared by: MUKESH BOHRA Follow me on FB : http://www.facebook.com/mukesh.sirji4u The logical or mathematical model of data is called a data structure. In other words, a data

More information

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

SCJ2013 Data Structure & Algorithms. Bubble Sort. Nor Bahiah Hj Ahmad & Dayang Norhayati A. Jawawi SCJ2013 Data Structure & Algorithms Bubble Sort Nor Bahiah Hj Ahmad & Dayang Norhayati A. Jawawi 1 Bubble Sort Sorting activities for Bubble: Go through multiple passes over the array. In every pass: Compare

More information

Spring 2008 Data Structures (CS301) LAB

Spring 2008 Data Structures (CS301) LAB Spring 2008 Data Structures (CS301) LAB Objectives The objectives of this LAB are, o Enabling students to implement Singly Linked List practically using c++ and adding more functionality in it. o Enabling

More information

PESIT Bangalore South Campus

PESIT Bangalore South Campus USN 1 P E PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Information Science & Engineering INTERNAL ASSESSMENT TEST 1 Date : 23/02/2016 Max Marks: 50

More information

PESIT Bangalore South Campus

PESIT Bangalore South Campus USN 1 P E PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of ECE INTERNAL ASSESSMENT TEST 2 Date : 03/10/2017 Marks: 40 Subject & Code : Object Oriented Programming

More information

Decaf Language Reference Manual

Decaf Language Reference Manual Decaf Language Reference Manual C. R. Ramakrishnan Department of Computer Science SUNY at Stony Brook Stony Brook, NY 11794-4400 cram@cs.stonybrook.edu February 12, 2012 Decaf is a small object oriented

More information

COP3530 DATA STRUC/ALGORITHMS

COP3530 DATA STRUC/ALGORITHMS COP3530 DATA STRUC/ALGORITHMS Spring 2013 Lecture 9 Fun with Chains Bin Sort Bin Sort Code (first take) 1. void binsort(chain& thechain, int range) 2. {// Sort by score. 3. 4. // initialize

More information

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

Pointer Basics. Lecture 13 COP 3014 Spring March 28, 2018 Pointer Basics Lecture 13 COP 3014 Spring 2018 March 28, 2018 What is a Pointer? A pointer is a variable that stores a memory address. Pointers are used to store the addresses of other variables or memory

More information

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

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 FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 The data of the problem is of 2GB and the hard disk is of 1GB capacity, to solve this problem we should Use better data structures

More information

egrapher Language Reference Manual

egrapher Language Reference Manual egrapher Language Reference Manual Long Long: ll3078@columbia.edu Xinli Jia: xj2191@columbia.edu Jiefu Ying: jy2799@columbia.edu Linnan Wang: lw2645@columbia.edu Darren Chen: dsc2155@columbia.edu 1. Introduction

More information

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

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of MCA USN 1 P E PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of MCA INTERNAL ASSESSMENT TEST 2 (Scheme and Solution) Data Structures Using C (16MCA11) 1) A.

More information

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

Arrays. CS10001: Programming & Data Structures. Pallab Dasgupta Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur Arrays CS10001: Programming & Data Structures Pallab Dasgupta Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur Array Many applications require multiple data items that have common

More information

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

class Polynomial { public: Polynomial(const string& N = no name, const vector<int>& C = vector<int>());... }; Default Arguments 1 When declaring a C++ function, you may optionally specify a default value for function parameters by listing initializations for them in the declaration: class Polynomial { public:

More information

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

CSCE 110 PROGRAMMING FUNDAMENTALS. Prof. Amr Goneid AUC Part 7. 1-D & 2-D Arrays CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 7. 1-D & 2-D Arrays Prof. Amr Goneid, AUC 1 Arrays Prof. Amr Goneid, AUC 2 1-D Arrays Data Structures The Array Data Type How to Declare

More information

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

calling a function - function-name(argument list); y = square ( z ); include parentheses even if parameter list is empty! Chapter 6 - Functions return type void or a valid data type ( int, double, char, etc) name parameter list void or a list of parameters separated by commas body return keyword required if function returns

More information

[0569] p 0318 garbage

[0569] p 0318 garbage A Pointer is a variable which contains the address of another variable. Declaration syntax: Pointer_type *pointer_name; This declaration will create a pointer of the pointer_name which will point to the

More information

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

Data types. CISC 1600/1610 Computer Science I. Array syntax. Memory allocation. Zero-indexing 4/4/2016. Arrays 4/4/6 CISC 6/6 Computer Science I rrays Professor Daniel Leeds dleeds@fordham.edu JMH 38 Data types Single pieces of information one integer int one symbol char one truth value bool Multiple pieces of

More information

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

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours TED (10)-3071 Reg. No.. (REVISION-2010) (Maximum marks: 100) Signature. FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours PART

More information

Algorithm Analysis. Performance Factors

Algorithm Analysis. Performance Factors Algorithm Analysis How can we demonstrate that one algorithm is superior to another without being misled by any of the following problems: Special cases Every algorithm has certain inputs that allow it

More information

Searching. 11. Searching

Searching. 11. Searching Searching In many applications it is necessary to search a list of data elements for one (or more) that matches some specific criterion. For example: - find the largest integer in a list of test scores

More information

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

Here we will only consider the problem of searching among the elements of an array. Intro Programming in C++ S 10 Fall 00 May 1, 006 Searching In many applications it is necessary to search a list of data elements for one (or more) that matches some specific criterion. For example: - find the largest integer

More information

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

2. List Implementations (a) Class Templates (b) Contiguous (c) Simply Linked (d) Simply Linked with Position Pointer (e) Doubly Linked Chapter 6 LISTS AND STRINGS 1. List Specifications 2. List Implementations (a) Class Templates (b) Contiguous (c) Simply Linked (d) Simply Linked with Position Pointer (e) Doubly Linked 3. Strings 4. Application:

More information

Darshan Institute of Engineering & Technology for Diploma studies Unit 4

Darshan Institute of Engineering & Technology for Diploma studies Unit 4 Pointer A pointer is a variable that contains address or location of another variable. Pointer is a derived data type in C. Pointers contain memory address as their values, so they can also be used to

More information

Instantiation of Template class

Instantiation of Template class Class Templates Templates are like advanced macros. They are useful for building new classes that depend on already existing user defined classes or built-in types. Example: stack of int or stack of double

More information

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

Data Structures and Programming 資料結構與程式設計. Topic 6 Stacks. Stacks. Stack of Cups. Stacks. top. top. bottom. bottom Data Structures and Programming 資料結構與程式設計 Topic 6 Stacks 課程編號 :90 3900 EE 30 科目名稱 : 資料結構與程式設計授課教師 : 黃鼎偉時間地點 : 一 678 電機二館 229 Stacks Linear list. One end is called top. Other end is called bottom. Additions

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 07: Linked Lists MOUNA KACEM mouna@cs.wisc.edu Spring 2019 Linked Lists 2 Introduction Linked List Abstract Data Type SinglyLinkedList ArrayList Keep in Mind Introduction:

More information

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

Data abstractions: ADTs Invariants, Abstraction function. Lecture 4: OOP, autumn 2003 Data abstractions: ADTs Invariants, Abstraction function Lecture 4: OOP, autumn 2003 Limits of procedural abstractions Isolate implementation from specification Dependency on the types of parameters representation

More information

Java Classes and Objects

Java Classes and Objects Table of contents 1 Introduction Case Study - Stack 2 3 Integer String Case Study - Stack Introduction Case Study - Stack Classes Template for creating objects Definition of State (What it knows) Definition

More information

MIDTERM EXAMINATION Spring 2010 CS301- Data Structures

MIDTERM EXAMINATION Spring 2010 CS301- Data Structures MIDTERM EXAMINATION Spring 2010 CS301- Data Structures Question No: 1 Which one of the following statement is NOT correct. In linked list the elements are necessarily to be contiguous In linked list the

More information

CE204 Data Structures and Algorithms Part 2

CE204 Data Structures and Algorithms Part 2 CE204 Data Structures and Algorithms Part 2 14/01/2018 CE204 Part 2 1 Abstract Data Types 1 An abstract data type is a type that may be specified completely without the use of any programming language.

More information

Lists. CITS2200 Data Structures and Algorithms. Topic 9

Lists. CITS2200 Data Structures and Algorithms. Topic 9 CITS2200 Data Structures and Algorithms Topic 9 Lists Why lists? List windows Specification Block representation Singly linked representation Performance comparisons Reading: Lambert and Osborne, Sections

More information

Data Structures CSci 1200 Test 2 Questions

Data Structures CSci 1200 Test 2 Questions Overview Data Structures CSci 1200 Test 2 Questions Test 2 will be held Thursday, March 10, 2010, 12:00-1:30pm, Darrin 308. No make-ups will be given except for emergency situations, and even then a written

More information

Arrays and ArrayLists. Ananda Gunawardena

Arrays and ArrayLists. Ananda Gunawardena Arrays and ArrayLists Ananda Gunawardena Introduction Array is a useful and powerful aggregate data structure presence in modern programming languages Arrays allow us to store arbitrary sized sequences

More information

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

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 Looking for something COMP 10 EXPLORING COMPUTER SCIENCE Where is the book Modern Interiors? Lecture 7 Searching and Sorting TODAY'S OUTLINE Searching algorithms Linear search Complexity Sorting algorithms

More information

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

Lecture 10 March 4. Goals: hashing. hash functions. closed hashing. application of hashing Lecture 10 March 4 Goals: hashing hash functions chaining closed hashing application of hashing Computing hash function for a string Horner s rule: (( (a 0 x + a 1 ) x + a 2 ) x + + a n-2 )x + a n-1 )

More information

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

FACULTY OF SCIENCE ACADEMY OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING ADVANCED DATA STRUCTURES AND ALGORITHMS EXAM EXAMINATION JUNE 2014 FACULTY OF SCIENCE ACADEMY OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING MODULE CSC3A10 ADVANCED DATA STRUCTURES AND ALGORITHMS CAMPUS APK EXAM EXAMINATION JUNE 2014 DATE 2014-06-03 SESSION 12:30 15:30

More information

Exercise 1.1 Hello world

Exercise 1.1 Hello world Exercise 1.1 Hello world The goal of this exercise is to verify that computer and compiler setup are functioning correctly. To verify that your setup runs fine, compile and run the hello world example

More information

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

! 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) Final Exam Exercises CS 2308 Spring 2014 Jill Seaman Chapters 1-7 + 11 Write C++ code to: Determine if a number is odd or even Determine if a number/character is in a range - 1 to 10 (inclusive) - between

More information

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

Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100 Code: DC-05 Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100 NOTE: There are 11 Questions in all. Question 1 is compulsory and carries 16 marks. Answer to Q. 1. must be written in the space

More information

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

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru Department of Electronics and Communication Engineering PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -560100 Department of Electronics and Communication Engineering Faculty: Richa Sharma Subject: Operating System SCHEME & SOLUTION

More information

Arrays and functions Multidimensional arrays Sorting and algorithm efficiency

Arrays and functions Multidimensional arrays Sorting and algorithm efficiency Introduction Fundamentals Declaring arrays Indexing arrays Initializing arrays Arrays and functions Multidimensional arrays Sorting and algorithm efficiency An array is a sequence of values of the same

More information

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

Insertions and removals follow the Fist-In First-Out rule: Insertions: at the rear of the queue Removals: at the front of the queue Queues CSE 2011 Fall 2009 9/28/2009 7:56 AM 1 Queues: FIFO Insertions and removals follow the Fist-In First-Out rule: Insertions: at the rear of the queue Removals: at the front of the queue Applications,

More information

CSE 373 Spring Midterm. Friday April 21st

CSE 373 Spring Midterm. Friday April 21st CSE 373 Spring 2006 Data Structures and Algorithms Midterm Friday April 21st NAME : Do all your work on these pages. Do not add any pages. Use back pages if necessary. Show your work to get partial credit.

More information

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

Programming Languages and Compilers Qualifying Examination. Answer 4 of 6 questions.1 Programming Languages and Compilers Qualifying Examination Monday, September 19, 2016 Answer 4 of 6 questions.1 GENERAL INSTRUCTIONS 1. Answer each question in a separate book. 2. Indicate on the cover

More information

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

Solution printed. Do not start the test until instructed to do so! CS 2604 Data Structures Midterm Spring Instructions: VIRG INIA POLYTECHNIC INSTITUTE AND STATE U T PROSI M UNI VERSI TY Instructions: Print your name in the space provided below. This examination is closed book and closed notes, aside from the permitted

More information

Introduction to Linked Data Structures

Introduction to Linked Data Structures Introduction to Linked Data Structures A linked data structure consists of capsules of data known as nodes that are connected via links Links can be viewed as arrows and thought of as one way passages

More information

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

First Examination. CS 225 Data Structures and Software Principles Spring p-9p, Tuesday, February 19 Department of Computer Science First Examination CS 225 Data Structures and Software Principles Spring 2008 7p-9p, Tuesday, February 19 Name: NetID: Lab Section (Day/Time): This is a closed book and closed

More information

CS201 Some Important Definitions

CS201 Some Important Definitions CS201 Some Important Definitions For Viva Preparation 1. What is a program? A program is a precise sequence of steps to solve a particular problem. 2. What is a class? We write a C++ program using data

More information

DOWNLOAD PDF LINKED LIST PROGRAMS IN DATA STRUCTURE

DOWNLOAD PDF LINKED LIST PROGRAMS IN DATA STRUCTURE Chapter 1 : What is an application of linear linked list data structures? - Quora A linked list is a linear data structure, in which the elements are not stored at contiguous memory locations. The elements

More information

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.

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. Stacks 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 Stacks 2 Abstract Data Types (ADTs) An abstract data type

More information

Procedural programming with C

Procedural programming with C Procedural programming with C Dr. C. Constantinides Department of Computer Science and Software Engineering Concordia University Montreal, Canada August 11, 2016 1 / 77 Functions Similarly to its mathematical

More information

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

Chapter 6: User-Defined Functions. Objectives (cont d.) Objectives. Introduction. Predefined Functions 12/2/2016 Chapter 6: User-Defined Functions Objectives In this chapter, you will: Learn about standard (predefined) functions Learn about user-defined functions Examine value-returning functions Construct and use

More information

Topic 11 Linked Lists

Topic 11 Linked Lists Topic 11 "All the kids who did great in high school writing pong games in BASIC for their Apple II would get to college, take CompSci 101, a data structures course, and when they hit the pointers business

More information

About this exam review

About this exam review Final Exam Review About this exam review I ve prepared an outline of the material covered in class May not be totally complete! Exam may ask about things that were covered in class but not in this review

More information

Bangalore South Campus

Bangalore South Campus USN: 1 P E PESIT Bangalore South Campus Hosur road, 1km before ElectronicCity, Bengaluru -100 Department of Basic Science and Humanities INTERNAL ASSESSMENT TEST 3 Date: 22/11/2017 Time:11:30am- 1.00 pm

More information

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

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Data Structures and Algorithms. Final Examination University of Waterloo Department of Electrical and Computer Engineering ECE 250 Data Structures and Algorithms Instructor: Douglas Wilhelm Harder Time: 2.5 hours Aides: none 14 pages Final Examination

More information

The format for declaring function templates with type parameters

The format for declaring function templates with type parameters UNIT 3 Function and class templates - Exception handling try-catch-throw paradigm exception specification terminate and Unexpected functions Uncaught exception. Templates Function templates Function templates

More information

14. Pointers, Algorithms, Iterators and Containers II

14. Pointers, Algorithms, Iterators and Containers II Recall: Pointers running over the Array Beispiel 14. Pointers, Algorithms, Iterators and Containers II Iterations with Pointers, Arrays: Indices vs. Pointers, Arrays and Functions, Pointers and const,

More information

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

Page. No. 1/15 CS201 Introduction to Programmming Solved Subjective Questions From spring 2010 Final Term Papers By vuzs Team Page. No. 1/15 CS201 Introduction to Programmming Solved Subjective Questions From spring 2010 Final Term Papers By vuzs Team Question No: 1 ( Marks: 2 ) Write a declaration statement for an array of 10

More information

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

Lists, Stacks, and Queues. (Lists, Stacks, and Queues ) Data Structures and Programming Spring / 50 Lists, Stacks, and Queues (Lists, Stacks, and Queues ) Data Structures and Programming Spring 2016 1 / 50 Abstract Data Types (ADT) Data type a set of objects + a set of operations Example: integer set

More information

SYSC 2006 C Winter 2012

SYSC 2006 C Winter 2012 SYSC 2006 C Winter 2012 Pointers and Arrays Copyright D. Bailey, Systems and Computer Engineering, Carleton University updated Sept. 21, 2011, Oct.18, 2011,Oct. 28, 2011, Feb. 25, 2011 Memory Organization

More information

15. Pointers, Algorithms, Iterators and Containers II

15. Pointers, Algorithms, Iterators and Containers II 498 Recall: Pointers running over the Array 499 Beispiel 15. Pointers, Algorithms, Iterators and Containers II int a[5] = 3, 4, 6, 1, 2; for (int p = a; p < a+5; ++p) std::cout

More information

Function Pointers. Function Pointers

Function Pointers. Function Pointers Function Pointers In this lecture What is a function pointer Defining a function pointer Using typedefs Passing a function pointer to another function Generic functions Exercises Function Pointers Function

More information

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

CSCI-1200 Data Structures Spring 2018 Lecture 7 Order Notation & Basic Recursion CSCI-1200 Data Structures Spring 2018 Lecture 7 Order Notation & Basic Recursion Review from Lectures 5 & 6 Arrays and pointers, Pointer arithmetic and dereferencing, Types of memory ( automatic, static,

More information

Structured programming

Structured programming Exercises 9 Version 1.0, 13 December, 2016 Table of Contents 1. Remainders from lectures.................................................... 1 1.1. What is a pointer?.......................................................

More information

Sorting. Weiss chapter , 8.6

Sorting. Weiss chapter , 8.6 Sorting Weiss chapter 8.1 8.3, 8.6 Sorting 5 3 9 2 8 7 3 2 1 4 1 2 2 3 3 4 5 7 8 9 Very many different sorting algorithms (bubblesort, insertion sort, selection sort, quicksort, heapsort, mergesort, shell

More information

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Lecture 4 Thomas Wies New York University Review Last week Control Structures Selection Loops Adding Invariants Outline Subprograms Calling Sequences Parameter

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 07: Linked Lists and Iterators MOUNA KACEM mouna@cs.wisc.edu Fall 2018 Linked Lists 2 Introduction Linked List Abstract Data Type General Implementation of the ListADT

More information

Introduction to C++ Systems Programming

Introduction to C++ Systems Programming Introduction to C++ Systems Programming Introduction to C++ Syntax differences between C and C++ A Simple C++ Example C++ Input/Output C++ Libraries C++ Header Files Another Simple C++ Example Inline Functions

More information

CS 2505 Computer Organization I

CS 2505 Computer Organization I Instructions: Print your name in the space provided below. This examination is closed book and closed notes, aside from the permitted one-page formula sheet. No calculators or other computing devices may

More information

Prof. Sushant S Sundikar 1

Prof. Sushant S Sundikar 1 UNIT 5 The related activities of sorting, searching and merging are central to many computer applications. Sorting and merging provide us with a means of organizing information take advantage of the organization

More information

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

C++ PROGRAMMING LANGUAGE: CLASSES. CAAM 519, CHAPTER 13 C++ PROGRAMMING LANGUAGE: CLASSES. CAAM 519, CHAPTER 13 This chapter focuses on introducing the notion of classes in the C++ programming language. We describe how to create class and use an object of a

More information

Introduction to Core C++

Introduction to Core C++ Introduction to Core C++ Lecture 04: Template Functions and Template Classes Massimiliano Culpo 1 1 CINECA - SuperComputing Applications and Innovation Department 26.02.2013 M.Culpo (CINECA) Introduction

More information

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

UNIVERSITY OF WATERLOO DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING E&CE 250 ALGORITHMS AND DATA STRUCTURES UNIVERSITY OF WATERLOO DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING E&CE 250 ALGORITHMS AND DATA STRUCTURES Final Examination Instructors: RESeviora and LTahvildari 3 hrs, Apr, 200 Name: Student ID:

More information

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)

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) Final Exam Exercises Chapters 1-7 + 11 Write C++ code to: l Determine if a number is odd or even CS 2308 Fall 2016 Jill Seaman l Determine if a number/character is in a range - 1 to 10 (inclusive) - between

More information

CHAPTER 4 LINKED LISTS

CHAPTER 4 LINKED LISTS CHAPTER 4 LINKED LISTS Iris Hui-Ru Jiang Fall 2008 2 Contents Array vs. list Singly linked lists Doubly linked lists Applications Readings Chapter 4 C++ STL list iterators iterator, const_iterator reverse_iterator,

More information

Pointers as Arguments

Pointers as Arguments Introduction as Arguments How it Works called program on start of execution xw = &i xf = &d after excution xw = &i xf = &d caller program i? d? i 3 d.14159 x 3.14159 x 3.14159 R. K. Ghosh (IIT-Kanpur)

More information

Chapter 10 - Notes Applications of Arrays

Chapter 10 - Notes Applications of Arrays Chapter - Notes Applications of Arrays I. List Processing A. Definition: List - A set of values of the same data type. B. Lists and Arrays 1. A convenient way to store a list is in an array, probably a

More information

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

CSCI-1200 Data Structures Fall 2017 Lecture 7 Order Notation & Basic Recursion CSCI-1200 Data Structures Fall 2017 Lecture 7 Order Notation & Basic Recursion Announcements: Test 1 Information Test 1 will be held Monday, Sept 25th, 2017 from 6-7:50pm Students will be randomly assigned

More information

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

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Data Structures and Algorithms. Final Examination ECE 25 Data Structures and Algorithms University of Waterloo Department of Electrical and Computer Engineering ECE 25 Data Structures and Algorithms Instructor: Douglas Wilhelm Harder Time: 2.5 hours Aides:

More information

BBM 201 DATA STRUCTURES

BBM 201 DATA STRUCTURES BBM 201 DATA STRUCTURES Lecture 8: Dynamically Allocated Linked Lists 2017-2018 Fall int x; x = 8; int A[4]; An array is stored as one contiguous block of memory. How can we add a fifth element to the

More information

DATA STRUCTURES AND ALGORITHMS

DATA STRUCTURES AND ALGORITHMS LECTURE 4 Babeş - Bolyai University Computer Science and Mathematics Faculty 2017-2018 In Lecture 3... Binary Heap Iterator Binary Heap Today Binary Heap 1 Binary Heap 2 Singly Heap - Add - example Binary

More information

Dynamic Data Structures

Dynamic Data Structures Dynamic Data Structures We have seen that the STL containers vector, deque, list, set and map can grow and shrink dynamically. We now examine how some of these containers can be implemented in C++. To

More information

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

6. Pointers, Structs, and Arrays. March 14 & 15, 2011 March 14 & 15, 2011 Einführung in die Programmierung Introduction to C/C++, Tobias Weinzierl page 1 of 47 Outline Recapitulation Pointers Dynamic Memory Allocation Structs Arrays Bubble Sort Strings Einführung

More information

Tokens, Expressions and Control Structures

Tokens, Expressions and Control Structures 3 Tokens, Expressions and Control Structures Tokens Keywords Identifiers Data types User-defined types Derived types Symbolic constants Declaration of variables Initialization Reference variables Type

More information

1 Lexical Considerations

1 Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler

More information