Data Structures and Algorithm Analysis

Size: px
Start display at page:

Download "Data Structures and Algorithm Analysis"

Transcription

1 Data Structures and Algorithm Analysis Dr. Malek Mouhoub Department of Computer Science University of Regina Winter 2005 Malek Mouhoub, CS340 Winter

2 1. Introduction 1. Introduction 1.1 Solving problems and algorithm analysis. 1.2 Features of C ADTs and Linear Structures. Malek Mouhoub, CS340 Winter

3 1.1 Solving problems and algorithm analysis 1.1 Solving problems and algorithm analysis Boss gives the following problem to Mr Dupont, a fresh hired BSc in computer science (to test him... or may be just for fun) : T (1) = 3 T (2) = 10 T (n) = 2T (n 1) T (n 2) What is T (100)? Malek Mouhoub, CS340 Winter

4 1.1 Solving problems and algorithm analysis Mr Dupont decides to directly code a recursive function tfn, in Java, to solve the problem : if (n==1) { return 3; } else if (n==2) {return 10;} else { return 2 tfn(n-1) - tfn(n-2); } 1. First mistake : no analysis of the problem risk to be fired! 2. Second mistake : bad choice of the programming language increasing the risk to be fired! Malek Mouhoub, CS340 Winter

5 1.1 Solving problems and algorithm analysis n = 1 3 n = 2 10 n = 3 17 n = 35 it takes 4.19 seconds n = 100 waits... and then kills the program! Mr Dupont decides then to use C : if (n==1) return 3; if (n==2) return 10; return 2 tfn(n-1) - tfn(n-2); n = 35 it takes only 1.25 seconds n = 50 waits and then kills the program! Malek Mouhoub, CS340 Winter

6 1.1 Solving problems and algorithm analysis Finally, Mr Dupont decides to (experimentally) analyze the problem : he times both programs and plots the results. 100 seconds 10 Java C N It seems that each time n increases by 1 the time increases by At n = 40 the C program took seconds, so for n = 100 he estimates : , 627, 995 years!!! Malek Mouhoub, CS340 Winter

7 1.1 Solving problems and algorithm analysis Mr Dupont remembers he has seen this kind of problem in one of the courses he has taken (data structures course). After consulting his course notes, Mr Dupont decides to use Dynamic Programming : int t[n+1]; t[1]=3; t[2]=10; for(i=3;i =n;i++) t[i] = 2 t[i-1] - t[i-2]; return t[n]; Malek Mouhoub, CS340 Winter

8 1.1 Solving problems and algorithm analysis This solution provides a much better complexity in time but despite of the space complexity : n = 100 takes only a fraction of a second, but for n = 10, 000, 000 (a test that may make the boss happy... if it succeeds) a segmentation fault occurs. Too much memory required. Malek Mouhoub, CS340 Winter

9 1.1 Solving problems and algorithm analysis Mr Dupont analyses the problem again : there is no reason to keep all the values, only the last 2 : if (n==1) return 3; last = 3; current = 10; for (i=3;i<=n;i++) { temp = current; current = 2 current - last; last = temp; } return current; At n = 100,000,000 it takes 3.00 seconds At n = 200,000,000 it takes 5,99 seconds at n = 300,000,000 it takes 8.99 seconds Malek Mouhoub, CS340 Winter

10 1.1 Solving problems and algorithm analysis How to solve such problems? 1. Analyze the problem on paper in order to find an efficient algorithm in terms of time and memory space complexity. (a) First look at the problem : T (1) = 3 T (2) = 10 T (3) = 17 T (4) = 24 T (5) = 31 Each step increases the result by 7. (b) Guess : T (n) = 7n 4 (c) Proof by induction 2. Code : return 7 n-4 Malek Mouhoub, CS340 Winter

11 1.1 Solving problems and algorithm analysis An algorithm analyst might ask : 1. What makes the first program so slow? 2. How fast are the 3 programs asymptotically? 3. Is the last version really the ultimate solution? Malek Mouhoub, CS340 Winter

12 1.1 Solving problems and algorithm analysis Let us look at the recursion tree for the first program at n= Here each circle represents one call to the routine tfn. So, for n=4 there are 5 such calls. In general, a call to tfn(n) requires a recursive call to tfn(n-1)(represented by the shaded region on the left) and a call to tfn(n-2)(shaded region on the right). Malek Mouhoub, CS340 Winter

13 1.1 Solving problems and algorithm analysis If we let f(n) represent the number of calls to compute T (n), then : f(n) = f(n 1) + f(n 2) + 1 f(1) = f(2) = 1 This is a version of the famous Fibonacci recurrence. It is known that f(n) n. This agrees very well with the times we presented earlier where each increase of n by 1 increases the time by a factor of a little under We say such growth is exponential with asymptotic growth rate O(1.618 n ). This answers question (1). Malek Mouhoub, CS340 Winter

14 1.1 Solving problems and algorithm analysis In the second and third program there was a loop for (i=3;i<=n;i++) This loop contained two or three assignments, a multiplication and a subtraction. We say such a loop takes O(n) time. This means that running time is proportional to n. Recall that increasing n from 100 million to 300 million increased the time from approximately 3 to approximately 9 seconds. The last program has one multiplication and one subtraction and takes O(1) or constant time. This answers question (2). Malek Mouhoub, CS340 Winter

15 1.1 Solving problems and algorithm analysis The answer to the last question is also NO. If the boss asked for T ( ) we would get integer overflow on most computers. Switching to a floating point representation would be of no value since we need to maintain all the significant digits in our results. The only alternative is to use a method to represent and manipulate large integers. Malek Mouhoub, CS340 Winter

16 1.1 Solving problems and algorithm analysis A straightforward way to represent a large integer is to use an array of integers, where each array slot stores one digit. The addition and subtraction require a linear-time algorithm. A simple algorithm for multiplication requires a quadratic-time cost. Malek Mouhoub, CS340 Winter

17 1.1 Solving problems and algorithm analysis The third question, is the last program the ultimate solution, begins to cross the line from algorithm analysis to computing science. A Computer Scientist might ask : 1. How do you justify counting function calls in the first case, counting array assignments in the second case, counting variable assignments in the third, and counting arithmetic operations in the last? 2. Is it really true that you can multiply two arbitrary large numbers together in constant time? 3. Is the last program really the ultimate one? Malek Mouhoub, CS340 Winter

18 1.1 Solving problems and algorithm analysis More CS questions that occur after thinking about the previous ones : What is computation? What is the simplest model of computation? How do various models relate - in terms of what can be computed and how efficiently? What are the theoretical limits of computation? What are the physical limits? What are the practical limits? How should we define a computational problem? Can we prove some problems are hard to compute for all possible programs? How can we classify problems as to how hard they are to compute? Malek Mouhoub, CS340 Winter

19 1.1 Solving problems and algorithm analysis CS questions with an engineering orientation : What general techniques can we use to solve computational problems? What data structures are best, and in what situations? Which models should we use to analyze algorithms in practice? When trying to improve the efficiency of a given program, which aspects should we focus on first? Malek Mouhoub, CS340 Winter

20 1.1 Solving problems and algorithm analysis Well... there is also CS and the BIG questions : Is the underlying foundation of the universe computational? Aristote, Newton, Lovelace, Einstein, Turing, Feymann Is computation sufficient to explain intelligence and consciousness? Babbage, Lovelace, Turing, Searle, Minsky, Penrose Is evolution a computational process? Holland, Kaufmann Malek Mouhoub, CS340 Winter

21 1.2 Features of C Features of C++ Default parameters Initializer list explicit constructor Constant member function Interface and Implementation Vectors, strings and pointers Function and class templates Malek Mouhoub, CS340 Winter

22 1.2 Features of C++ /* A class for simulating an integer memory cell */ class IntCell { public: /* Construct the IntCell. Initial value is 0. */ IntCell() { storedvalue = 0;} /* Construct the IntCell. Initial value is initialvalue. */ IntCell(int initialvalue) { storedvalue = initialvalue; } /* Return the stored value */ int read() { return storedvalue; } /* Change the stored value to x */ void write( int x ) { storedvalue = x; } private: int storedvalue; }; Malek Mouhoub, CS340 Winter

23 1.2 Features of C++ class IntCell { public: /*1*/ explicit IntCell( int initialvalue = 0 ) /*2*/ : storedvalue( initialvalue ) {} /*3*/ int read() const /*4*/ { return storedvalue; } /*5*/ void write( int x ) /*6*/ { storedvalue =x; } private: /*7*/ int storedvalue; }; Malek Mouhoub, CS340 Winter

24 1.2 Features of C++ File IntCell.h Separation of Interface and Implementation #ifndef _IntCell_H_ #define _IntCell_H_ class IntCell { public: explicit IntCell( int initialvalue = 0); int read() const; void write( int x ); private: int storedvalue; }; #endif Malek Mouhoub, CS340 Winter

25 1.2 Features of C++ File IntCell.cpp Separation of Interface and Implementation #include "IntCell.h" /* Construct the IntCell with initialvalue */ IntCell::IntCell( int initialvalue ) : storedvalue(initialvalue) {} /* Return the stored value */ int IntCell::read() const { return storedvalue;} /* Store x */ void IntCell::write( int x ) { storedvalue = x; } Malek Mouhoub, CS340 Winter

26 1.2 Features of C++ Separation of Interface and Implementation #include "IntCell.h" int main() { } IntCell m; //Or, IntCell m( 0 ); but not IntCell m(); m.write( 5 ); cout << "Cell contents: " << m.read() << endl; return 0; Malek Mouhoub, CS340 Winter

27 1.2 Features of C++ Separation of Interface and Implementation Preprocessor commands Scoping operator Signature must match exactly Objects are declared like primitive types IntCell obj1; // Zero parameter constructor obj2( 12 ); // One parameter constructor IntCell obj3 = 37; /* Error : Constructor is explicit */ IntCell obj4(); // Error : Function declaration Malek Mouhoub, CS340 Winter

28 1.2 Features of C++ #include <iostream.h> #include "vector.h" #include "mystring.h" Vectors and strings int main() { vector<string> v( 5 ); int itemread = 0; string x; while( cin >> x) { if( itemread == v.size()) v.resize(v.size() * 2); v[ itemread++] = x; } for (int i = itemsread - 1; i >=0; i--) cout << v[i] << endl; return 0; } Malek Mouhoub, CS340 Winter

29 1.2 Features of C++ int main() { /*1*/ IntCell *m; Pointers /*2*/ m=new IntCell( 0 ); /*3*/ m->write( 5 ); /*4*/ cout << "Cell contents:"<< m->read() << endl; /*5*/ delete m; /*6*/ return 0; } Malek Mouhoub, CS340 Winter

30 1.2 Features of C++ Function Templates template <class Comparable> const Comparable & findmax(const vector<comparable> & a) { /*1*/ int maxindex=0; /*2*/ for (int i=1;i <a.size();i++) /*3*/ if (a[maxindex] < a[i]) /*4*/ maxindex = i; /*5*/ return a[maxindex]; } Malek Mouhoub, CS340 Winter

31 1.2 Features of C++ Function Templates int main() { vector<int> v1( 37 ); vector<double> v2( 40 ); vector<string> v3( 80 ); vector<intcell> v4( 75 ); // Additional code to fill in the vectors cout << findmax( v1 ) << endl; cout << findmax( v2 ) << endl; cout << findmax( v3 ) << endl; cout << findmax( v4 ) << endl; // Error : operator < undefined return 0; } Malek Mouhoub, CS340 Winter

32 1.2 Features of C++ Class Templates // A class for simulating a memory cell. template <class Object> class MemoryCell { public: explicit MemoryCell (const Object &initialvalue=object()) : storedvalue ( initialvalue ) {} const Object & read() const { return storedvalue; } void write( const Object & x ) { storedvalue = x; } private: Object storedvalue; }; Malek Mouhoub, CS340 Winter

33 1.2 Features of C++ int main() { MemoryCell<int> m1; Class Templates MemoryCell<string> m2( hello ); m1.write( 37 ); m2.write( m2.read() + world ); cout << m1.read() << endl << m2.read() << endl; return 0; } Malek Mouhoub, CS340 Winter

34 1.3 ADTs and Linear Structures 1.3 ADTs and Linear Structures Abstract Data Types (ADTs) The List ADT The Stack ADT The Queue ADT Malek Mouhoub, CS340 Winter

35 Data Structures Data Structures A scalar item A sequential vector A linked list A n-dimentional space A hierarchical tree Malek Mouhoub, CS340 Winter

36 Data Structures The most important property to express of any entity in a system is its type. In this course we used entities that are structured objects (e.g., an object that is a collection of other objects). When determining its type, the kinds of distinguishing properties include : Ordering : are elements ordered or unordered? If ordering matters, is the order partial or total? Are elements removed FIFO (queues), LIFO (stacks), or by priority (priority queues)? Duplicates : are duplicates allowed? Boundedness : is the object bounded in size or unbounded? Can the bound change or it is fixed at creation time? Associative access : are elements retrieved by an index or key? Is the type of the index built-in (e.g. as for sequences and arrays) or user-definable (e.g. as for symbol tables and hash tables)? Shape : is the structure of the object linear, hierarchical, acyclic, n-dimensional, or arbitrarily complex (e.g. graphs, forests)? Malek Mouhoub, CS340 Winter

37 Data Structures Abstract Data Type (ADT) Set of data together with a set of operations. Definition of an ADT : [what to do?] Definition of data and the set of operations (functions). Implementation of an ADT : [how to do it?] How are the objects and operations implemented. use the C++ class. Malek Mouhoub, CS340 Winter

38 Data Structures ADT List Structure List is Data : A list of elements. Functions : for every list List, item Element List createlist() ::= return an empty list List insert(item,i,list) ::= add item at the position i and return the new list List remove(item,list) ::= remove item and return the new list Boolean isempty(list) ::= return list == empty find(item,list) ::= If item list return position of item else return ERROR findkth(i,list) ::= return the item at position i if it exists, ERROR otherwise. Malek Mouhoub, CS340 Winter

39 Data Structures Array Implementation of Lists Contiguous allocation of memory to store the elements of the list. Estimation (overestimation) of the maximum size of the list is required waste of memory space. O(N) for find, constant time for findkth But O(N) is required for insertion and deletion in the worst case. building a list by N successive inserts would require O(N 2 ) in the worst case. Malek Mouhoub, CS340 Winter

40 Data Structures List findkth(3)=52 find(52)=3 remove(34) insert(1,34) n n n n findkth=list[kth] O(C) find(x): O(n) removekth: O(n) remove(x):o(n) insert(kth,x) O(n) Figure 1: Contiguous allocation of memory to store the elements of the list Malek Mouhoub, CS340 Winter

41 Data Structures Linked Lists Non contiguous allocation of memory. O(N) for find O(N) for findkth (but better time in practice if the calls to findkth are in sorted order by the argument). Constant time for insertion and deletion. Malek Mouhoub, CS340 Winter

42 Data Structures Head Data Link \ 3 4 Head List = printlist():o(n) find(x):o(n) findkth(i):o(i) Figure 2: Non contiguous allocation of memory Malek Mouhoub, CS340 Winter

43 Data Structures A1 A2 A3 A4 A5 (a) A1 A2 A3 A4 A5 (b) Figure 3: (a) A double linked list (b) A double circular linked list Malek Mouhoub, CS340 Winter

44 Data Structures header header (a) A lilnked list remove(52) header (b) Deletion from a linked list insert(3,52) 52 (c) Insertion into a linked list A1 A2 A3 A4 A5 header (d) Linked list with a header header (e) Empty list with header Figure 4: Linked List Functions Malek Mouhoub, CS340 Winter

45 Data Structures ADT Stack Structure Stack is Data : A list of elements. Functions : for every stack Stack, item Element, capacity Natural Stack createstack(capacity) ::= return an empty stack Boolean isfull(stack) ::= return (number of items in stack == capacity) Boolean isempty(stack) ::= return (stack == createstack(capacity)) Stack push(item,stack)::= If isfull(stack) return stack else add item at the top of stack and return the new stack Stack pop(stack) ::= If isempty(stack) return stack else delete the element at the top of the stack and return the new stack Element topandpop(stack) ::= If isempty(stack) return ERROR else delete and return the element at the top of the stack Malek Mouhoub, CS340 Winter

46 Data Structures string input = "[()]" read "[" read "(" read ")" read "]" read "" Top Top [ ( [ Top [ Top push("[") push ("(") top()="(" pop() top()="[" pop() empty() correct Figure 5: Application: Balancing Symbols Malek Mouhoub, CS340 Winter

47 Data Structures intput infix = a+b*c+(d*e+f)*g read "a" read "+" read "b" read "*" read "c" output:a push ("+") + + output:ab * + push("*") * + output:abc read "+" read "(" read "d" read "*" read "e" + pop() output:abc*+ ( ( + + push ("(") output:abc*+d read "+" read "f" read ")" * ( + push("*") read "*" * ( + output:abc*+de read "g" + ( + + ( + pop() output:abc*+de*f pop() output:abc*+de* push("+") output:abc*+de*f+ pop() + * + push("*") * + output:abc*+def+g pop() output:abc*+def+g* pop() output:abc*+def+g*+ Figure 6: Application : Infix and Postfix Conversion Malek Mouhoub, CS340 Winter

48 Data Structures ADT Queue Structure Queue is Data : A list of elements. Functions : for every queue Queue, item Element, capacity Natural Queue createqueue(capacity)::= return an empty queue Boolean isfull(queue) ::= return (number of items in stack == capacity) Boolean isempty(queue) ::= return (queue == createqueue(capacity)) Queue enqueue(item,queue) ::= If isfull(queue) return queue else add item at the end of queue and return the new queue Queue dequeue(queue) ::= If isempty(queue) return queue else delete the element at the front of the queue and return the new queue Element getfront(stack) ::= If isempty(stack) return ERROR else delete and return the element at the front of queue Malek Mouhoub, CS340 Winter

49 Data Structures (1)Initial State (2)After enqueue(1) ^ front 2 4 ^ back 1 ^ back 2 4 ^ front (3)After enqueue(3) (4)After dequeue, which returns ^ back ^ front ^ back ^ front (5)After dequeue, which returns 4 (6)After dequeue, which returns ^ ^ front front ^ back back 1 3 (7)After dequeue, which return 3 and Makes the Queue Empty ^ ^ backfront 2 4 Figure 7: Array Implementation of Queues Malek Mouhoub, CS340 Winter

Purpose of Review. Review some basic C++ Familiarize us with Weiss s style Introduce specific constructs useful for implementing data structures

Purpose of Review. Review some basic C++ Familiarize us with Weiss s style Introduce specific constructs useful for implementing data structures C++ Review 1 Purpose of Review Review some basic C++ Familiarize us with Weiss s style Introduce specific constructs useful for implementing data structures 2 Class The Class defines the data structure

More information

C++ Review. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University

C++ Review. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University C++ Review CptS 223 Advanced Data Structures Larry Holder School of Electrical Engineering and Computer Science Washington State University 1 Purpose of Review Review some basic C++ Familiarize us with

More information

Stacks, Queues (cont d)

Stacks, Queues (cont d) Stacks, Queues (cont d) CSE 2011 Winter 2007 February 1, 2007 1 The Adapter Pattern Using methods of one class to implement methods of another class Example: using List to implement Stack and Queue 2 1

More information

Algorithms in Systems Engineering IE172. Midterm Review. Dr. Ted Ralphs

Algorithms in Systems Engineering IE172. Midterm Review. Dr. Ted Ralphs Algorithms in Systems Engineering IE172 Midterm Review Dr. Ted Ralphs IE172 Midterm Review 1 Textbook Sections Covered on Midterm Chapters 1-5 IE172 Review: Algorithms and Programming 2 Introduction to

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

List, Stack, and Queues

List, Stack, and Queues List, Stack, and Queues R. J. Renka Department of Computer Science & Engineering University of North Texas 02/24/2010 3.1 Abstract Data Type An Abstract Data Type (ADT) is a set of objects with a set of

More information

Module 1: Asymptotic Time Complexity and Intro to Abstract Data Types

Module 1: Asymptotic Time Complexity and Intro to Abstract Data Types Module 1: Asymptotic Time Complexity and Intro to Abstract Data Types Dr. Natarajan Meghanathan Professor of Computer Science Jackson State University Jackson, MS 39217 E-mail: natarajan.meghanathan@jsums.edu

More information

Stacks and Queues. CSE Data Structures April 12, 2002

Stacks and Queues. CSE Data Structures April 12, 2002 Stacks and Queues CSE 373 - Data Structures April 12, 2002 Readings and References Reading Section 3.3 and 3.4, Data Structures and Algorithm Analysis in C, Weiss Other References 12-Apr-02 CSE 373 - Data

More information

Algorithms and Data Structures

Algorithms and Data Structures Algorithms and Data Structures Dr. Malek Mouhoub Department of Computer Science University of Regina Fall 2002 Malek Mouhoub, CS3620 Fall 2002 1 6. Priority Queues 6. Priority Queues ffl ADT Stack : LIFO.

More information

CS 216 Exam 1 Fall SOLUTION

CS 216 Exam 1 Fall SOLUTION CS 216 Exam 1 Fall 2004 - SOLUTION Name: Lab Section: Email Address: Student ID # This exam is closed note, closed book. You will have an hour and fifty minutes total to complete the exam. You may NOT

More information

3. Priority Queues. ADT Stack : LIFO. ADT Queue : FIFO. ADT Priority Queue : pick the element with the lowest (or highest) priority.

3. Priority Queues. ADT Stack : LIFO. ADT Queue : FIFO. ADT Priority Queue : pick the element with the lowest (or highest) priority. 3. Priority Queues 3. Priority Queues ADT Stack : LIFO. ADT Queue : FIFO. ADT Priority Queue : pick the element with the lowest (or highest) priority. Malek Mouhoub, CS340 Winter 2007 1 3. Priority Queues

More information

DATA STRUCUTRES. A data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently.

DATA STRUCUTRES. A data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently. DATA STRUCUTRES A data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently. An algorithm, which is a finite sequence of instructions, each of which

More information

Abstract Data Types 1

Abstract Data Types 1 Abstract Data Types 1 Purpose Abstract Data Types (ADTs) Lists Stacks Queues 2 Abstract Data Types (ADTs) ADT is a set of objects together with a set of operations. Abstract in that implementation of operations

More information

Short Notes of CS201

Short Notes of CS201 #includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system

More information

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR STUDENT IDENTIFICATION NO MULTIMEDIA COLLEGE JALAN GURNEY KIRI 54100 KUALA LUMPUR FIFTH SEMESTER FINAL EXAMINATION, 2014/2015 SESSION PSD2023 ALGORITHM & DATA STRUCTURE DSEW-E-F-2/13 25 MAY 2015 9.00 AM

More information

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

Abstract Data Types. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University Abstract Data Types CptS 223 Advanced Data Structures Larry Holder School of Electrical Engineering and Computer Science Washington State University 1 Purpose Abstract Data Types (ADTs) Lists Stacks Queues

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

More information

Abstract Data Types 1

Abstract Data Types 1 Abstract Data Types 1 Purpose Abstract Data Types (ADTs) Lists Stacks Queues 2 Primitive vs. Abstract Data Types Primitive DT: programmer ADT: programmer Interface (API) data Implementation (methods) Data

More information

Data Structures Question Bank Multiple Choice

Data Structures Question Bank Multiple Choice Section 1. Fundamentals: Complexity, Algorthm Analysis 1. An algorithm solves A single problem or function Multiple problems or functions Has a single programming language implementation 2. A solution

More information

Arrays and Linked Lists

Arrays and Linked Lists Arrays and Linked Lists Abstract Data Types Stacks Queues Priority Queues and Deques John Edgar 2 And Stacks Reverse Polish Notation (RPN) Also known as postfix notation A mathematical notation Where every

More information

INSTITUTE OF AERONAUTICAL ENGINEERING

INSTITUTE OF AERONAUTICAL ENGINEERING INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad - 500 043 COMPUTER SCIENCE AND ENGINEERING TUTORIAL QUESTION BANK Course Name Course Code Class Branch DATA STRUCTURES ACS002 B. Tech

More information

CS6202 - PROGRAMMING & DATA STRUCTURES I Unit IV Part - A 1. Define Stack. A stack is an ordered list in which all insertions and deletions are made at one end, called the top. It is an abstract data type

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

CS301 - Data Structures Glossary By

CS301 - Data Structures Glossary By CS301 - Data Structures Glossary By Abstract Data Type : A set of data values and associated operations that are precisely specified independent of any particular implementation. Also known as ADT Algorithm

More information

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

R10 SET - 1. Code No: R II B. Tech I Semester, Supplementary Examinations, May www.jwjobs.net R10 SET - 1 II B. Tech I Semester, Supplementary Examinations, May - 2012 (Com. to CSE, IT, ECC ) Time: 3 hours Max Marks: 75 *******-****** 1. a) Which of the given options provides the

More information

4. Trees. 4.1 Preliminaries. 4.2 Binary trees. 4.3 Binary search trees. 4.4 AVL trees. 4.5 Splay trees. 4.6 B-trees. 4. Trees

4. Trees. 4.1 Preliminaries. 4.2 Binary trees. 4.3 Binary search trees. 4.4 AVL trees. 4.5 Splay trees. 4.6 B-trees. 4. Trees 4. Trees 4.1 Preliminaries 4.2 Binary trees 4.3 Binary search trees 4.4 AVL trees 4.5 Splay trees 4.6 B-trees Malek Mouhoub, CS340 Fall 2002 1 4.1 Preliminaries A Root B C D E F G Height=3 Leaves H I J

More information

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

Bachelor Level/ First Year/ Second Semester/ Science Full Marks: 60 Computer Science and Information Technology (CSc. 154) Pass Marks: 24 Prepared By ASCOL CSIT 2070 Batch Institute of Science and Technology 2065 Bachelor Level/ First Year/ Second Semester/ Science Full Marks: 60 Computer Science and Information Technology (CSc. 154) Pass

More information

Course Review. Cpt S 223 Fall 2009

Course Review. Cpt S 223 Fall 2009 Course Review Cpt S 223 Fall 2009 1 Final Exam When: Tuesday (12/15) 8-10am Where: in class Closed book, closed notes Comprehensive Material for preparation: Lecture slides & class notes Homeworks & program

More information

EC8393FUNDAMENTALS OF DATA STRUCTURES IN C Unit 3

EC8393FUNDAMENTALS OF DATA STRUCTURES IN C Unit 3 UNIT 3 LINEAR DATA STRUCTURES 1. Define Data Structures Data Structures is defined as the way of organizing all data items that consider not only the elements stored but also stores the relationship between

More information

SAURASHTRA UNIVERSITY

SAURASHTRA UNIVERSITY SAURASHTRA UNIVERSITY RAJKOT INDIA Accredited Grade A by NAAC (CGPA 3.05) CURRICULAM FOR B.Sc. (Computer Science) Bachelor of Science (Computer Science) (Semester - 1 Semester - 2) Effective From June

More information

Overloading Operators

Overloading Operators Overloading Operators and Dynamic Memory Allocation Week 5 Gaddis: 14.5 CS 5301 Fall 20 Jill Seaman 9.8 Dynamic Memory Allocation! When a function is called, memory for local variables is automatically

More information

// The next 4 functions return true on success, false on failure

// The next 4 functions return true on success, false on failure Stacks and Queues Queues and stacks are two special list types of particular importance. They can be implemented using any list implementation, but arrays are a more practical solution for these structures

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

List of Transparencies

List of Transparencies List of Transparencies Chapter 1 Primitive Java 1 A simple first program 2 The eight primitve types in Java 3 Program that illustrates operators 4 Result of logical operators 5 Examples of conditional

More information

Stacks. stacks of dishes or trays in a cafeteria. Last In First Out discipline (LIFO)

Stacks. stacks of dishes or trays in a cafeteria. Last In First Out discipline (LIFO) Outline stacks stack ADT method signatures array stack implementation linked stack implementation stack applications infix, prefix, and postfix expressions 1 Stacks stacks of dishes or trays in a cafeteria

More information

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

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Data Structures and Algorithms. Final Examination T09:00 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 18 pages Final Examination

More information

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING UNIT-1

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING UNIT-1 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING Year & Semester : I / II Section : CSE - 1 & 2 Subject Code : CS6202 Subject Name : Programming and Data Structures-I Degree & Branch : B.E C.S.E. 2 MARK

More information

CSE 143. Complexity Analysis. Program Efficiency. Constant Time Statements. Big Oh notation. Analyzing Loops. Constant Time Statements (2) CSE 143 1

CSE 143. Complexity Analysis. Program Efficiency. Constant Time Statements. Big Oh notation. Analyzing Loops. Constant Time Statements (2) CSE 143 1 CSE 1 Complexity Analysis Program Efficiency [Sections 12.1-12., 12., 12.9] Count number of instructions executed by program on inputs of a given size Express run time as a function of the input size Assume

More information

How much space does this routine use in the worst case for a given n? public static void use_space(int n) { int b; int [] A;

How much space does this routine use in the worst case for a given n? public static void use_space(int n) { int b; int [] A; How much space does this routine use in the worst case for a given n? public static void use_space(int n) { int b; int [] A; } if (n

More information

Largest Online Community of VU Students

Largest Online Community of VU Students WWW.VUPages.com http://forum.vupages.com WWW.VUTUBE.EDU.PK Largest Online Community of VU Students MIDTERM EXAMINATION SEMESTER FALL 2003 CS301-DATA STRUCTURE Total Marks:86 Duration: 60min Instructions

More information

CS 221 Review. Mason Vail

CS 221 Review. Mason Vail CS 221 Review Mason Vail Inheritance (1) Every class - except the Object class - directly inherits from one parent class. Object is the only class with no parent. If a class does not declare a parent using

More information

CS24 Week 4 Lecture 2

CS24 Week 4 Lecture 2 CS24 Week 4 Lecture 2 Kyle Dewey Overview Linked Lists Stacks Queues Linked Lists Linked Lists Idea: have each chunk (called a node) keep track of both a list element and another chunk Need to keep track

More information

Operator overloading

Operator overloading 1 Introduction 2 The copy constructor 3 Operator Overloading 4 Eg 1: Adding two vectors 5 The -> operator 6 The this pointer 7 Overloading = 8 Unary operators 9 Overloading for the matrix class 10 The

More information

PROGRAMMING IN C++ (Regulation 2008) Answer ALL questions PART A (10 2 = 20 Marks) PART B (5 16 = 80 Marks) function? (8)

PROGRAMMING IN C++ (Regulation 2008) Answer ALL questions PART A (10 2 = 20 Marks) PART B (5 16 = 80 Marks) function? (8) B.E./B.Tech. DEGREE EXAMINATION, NOVEMBER/DECEMBER 2009 EC 2202 DATA STRUCTURES AND OBJECT ORIENTED Time: Three hours PROGRAMMING IN C++ Answer ALL questions Maximum: 100 Marks 1. When do we declare a

More information

CMSC 341 Lecture 6 Templates, Stacks & Queues. Based on slides by Shawn Lupoli & Katherine Gibson at UMBC

CMSC 341 Lecture 6 Templates, Stacks & Queues. Based on slides by Shawn Lupoli & Katherine Gibson at UMBC CMSC 341 Lecture 6 Templates, Stacks & Queues Based on slides by Shawn Lupoli & Katherine Gibson at UMBC Today s Topics Data types in C++ Overloading functions Templates How to implement them Possible

More information

CS 506, Sect 002 Homework 5 Dr. David Nassimi Foundations of CS Due: Week 11, Mon. Apr. 7 Spring 2014

CS 506, Sect 002 Homework 5 Dr. David Nassimi Foundations of CS Due: Week 11, Mon. Apr. 7 Spring 2014 CS 506, Sect 002 Homework 5 Dr. David Nassimi Foundations of CS Due: Week 11, Mon. Apr. 7 Spring 2014 Study: Chapter 4 Analysis of Algorithms, Recursive Algorithms, and Recurrence Equations 1. Prove the

More information

Chapter 5. The Standard Template Library.

Chapter 5. The Standard Template Library. Object-oriented programming B, Lecture 11e. 1 Chapter 5. The Standard Template Library. 5.1. Overview of main STL components. The Standard Template Library (STL) has been developed by Alexander Stepanov,

More information

Stack ADT. ! push(x) puts the element x on top of the stack! pop removes the topmost element from the stack.

Stack ADT. ! push(x) puts the element x on top of the stack! pop removes the topmost element from the stack. STACK Stack ADT 2 A stack is an abstract data type based on the list data model All operations are performed at one end of the list called the top of the stack (TOS) LIFO (for last-in first-out) list is

More information

The Class. Classes and Objects. Example class: Time class declaration with functions defined inline. Using Time class in a driver.

The Class. Classes and Objects. Example class: Time class declaration with functions defined inline. Using Time class in a driver. Classes and Objects Week 5 Gaddis:.2-.12 14.3-14.4 CS 5301 Fall 2014 Jill Seaman The Class A class in C++ is similar to a structure. A class contains members: - variables AND - functions (often called

More information

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

MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct. MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct. In linked list the elements are necessarily to be contiguous In linked list the elements may locate at far positions

More information

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

Draw a diagram of an empty circular queue and describe it to the reader. 1020_1030_testquestions.text Wed Sep 10 10:40:46 2014 1 1983/84 COSC1020/30 Tests >>> The following was given to students. >>> Students can have a good idea of test questions by examining and trying the

More information

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

Where does the insert method place the new entry in the array? Assume array indexing starts from 0(zero). Suppose we have a circular array implementation of the queue,with ten items in the queue stored at data[2] through data[11]. The current capacity of an array is 12. Where does the insert method place the

More information

Cpt S 223 Fall Cpt S 223. School of EECS, WSU

Cpt S 223 Fall Cpt S 223. School of EECS, WSU Course Review Cpt S 223 Fall 2012 1 Final Exam When: Monday (December 10) 8 10 AM Where: in class (Sloan 150) Closed book, closed notes Comprehensive Material for preparation: Lecture slides & class notes

More information

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305 Q.1 If h is any hashing function and is used to hash n keys in to a table of size m, where n

More information

Course Review for Finals. Cpt S 223 Fall 2008

Course Review for Finals. Cpt S 223 Fall 2008 Course Review for Finals Cpt S 223 Fall 2008 1 Course Overview Introduction to advanced data structures Algorithmic asymptotic analysis Programming data structures Program design based on performance i.e.,

More information

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS Contents Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS 1.1. INTRODUCTION TO COMPUTERS... 1 1.2. HISTORY OF C & C++... 3 1.3. DESIGN, DEVELOPMENT AND EXECUTION OF A PROGRAM... 3 1.4 TESTING OF PROGRAMS...

More information

Data Structure. Recitation VII

Data Structure. Recitation VII Data Structure Recitation VII Recursion: Stack trace Queue Topic animation Trace Recursive factorial Executes factorial(4) Step 9: return 24 Step 8: return 6 factorial(4) Step 0: executes factorial(4)

More information

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

University of Waterloo Department of Electrical and Computer Engineering ECE250 Algorithms and Data Structures Fall 2014 University of Waterloo Department of Electrical and Computer Engineering ECE250 Algorithms and Data Structures Fall 2014 Midterm Examination Instructor: Ladan Tahvildari, PhD, PEng, SMIEEE Date: Tuesday,

More information

Data Structures and Algorithms

Data Structures and Algorithms Data Structures and Algorithms About the course (objectives, outline, recommended reading) Problem solving Notions of Algorithmics (growth of functions, efficiency, programming model, example analysis)

More information

Stacks and Queues. Chris Kiekintveld CS 2401 (Fall 2010) Elementary Data Structures and Algorithms

Stacks and Queues. Chris Kiekintveld CS 2401 (Fall 2010) Elementary Data Structures and Algorithms Stacks and Queues Chris Kiekintveld CS 2401 (Fall 2010) Elementary Data Structures and Algorithms Two New ADTs Define two new abstract data types Both are restricted lists Can be implemented using arrays

More information

Algorithm Design and Analysis

Algorithm Design and Analysis Algorithm Design and Analysis LECTURE 3 Data Structures Graphs Traversals Strongly connected components Sofya Raskhodnikova L3.1 Measuring Running Time Focus on scalability: parameterize the running time

More information

Data Structure (CS301)

Data Structure (CS301) WWW.VUPages.com http://forum.vupages.com WWW.VUTUBE.EDU.PK Largest Online Community of VU Students Virtual University Government of Pakistan Midterm Examination Spring 2003 Data Structure (CS301) StudentID/LoginID

More information

Programming Abstractions

Programming Abstractions Programming Abstractions C S 1 0 6 B Cynthia Lee Today s Topics ADTs Stack Example: Reverse-Polish Notation calculator Queue Example: Mouse Events Stacks New ADT: Stack stack.h template

More information

A. Year / Module Semester Subject Topic 2016 / V 2 PCD Pointers, Preprocessors, DS

A. Year / Module Semester Subject Topic 2016 / V 2 PCD Pointers, Preprocessors, DS Syllabus: Pointers and Preprocessors: Pointers and address, pointers and functions (call by reference) arguments, pointers and arrays, address arithmetic, character pointer and functions, pointers to pointer,initialization

More information

LIFO : Last In First Out

LIFO : Last In First Out Introduction Stack is an ordered list in which all insertions and deletions are made at one end, called the top. Stack is a data structure that is particularly useful in applications involving reversing.

More information

Standard ADTs. Lecture 19 CS2110 Summer 2009

Standard ADTs. Lecture 19 CS2110 Summer 2009 Standard ADTs Lecture 19 CS2110 Summer 2009 Past Java Collections Framework How to use a few interfaces and implementations of abstract data types: Collection List Set Iterator Comparable Comparator 2

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

DATA STRUCTURE UNIT I

DATA STRUCTURE UNIT I DATA STRUCTURE UNIT I 1. What is Data Structure? A data structure is a mathematical or logical way of organizing data in the memory that consider not only the items stored but also the relationship to

More information

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

1. Stack overflow & underflow 2. Implementation: partially filled array & linked list 3. Applications: reverse string, backtracking Review for Test 2 (Chapter 6-10) Chapter 6: Template functions & classes 1) What is the primary purpose of template functions? A. To allow a single function to be used with varying types of arguments B.

More information

Absolute C++ Walter Savitch

Absolute C++ Walter Savitch Absolute C++ sixth edition Walter Savitch Global edition This page intentionally left blank Absolute C++, Global Edition Cover Title Page Copyright Page Preface Acknowledgments Brief Contents Contents

More information

CS302. Today s Topics: More on constructor/destructor functions More on STL <list>

CS302. Today s Topics: More on constructor/destructor functions More on STL <list> CS302 Today s Topics: More on constructor/destructor functions More on STL Tuesday, Sept. 5, 2006 Recall: Constructor and destructor functions What are they? Remember example: Constructor function

More information

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

Cpt S 122 Data Structures. Course Review Midterm Exam # 1 Cpt S 122 Data Structures Course Review Midterm Exam # 1 Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Midterm Exam 1 When: Friday (09/28) 12:10-1pm Where:

More information

Data Structures Lecture 8

Data Structures Lecture 8 Fall 2017 Fang Yu Software Security Lab. Dept. Management Information Systems, National Chengchi University Data Structures Lecture 8 Recap What should you have learned? Basic java programming skills Object-oriented

More information

Linked List. April 2, 2007 Programming and Data Structure 1

Linked List. April 2, 2007 Programming and Data Structure 1 Linked List April 2, 2007 Programming and Data Structure 1 Introduction head A linked list is a data structure which can change during execution. Successive elements are connected by pointers. Last element

More information

12 Abstract Data Types

12 Abstract Data Types 12 Abstract Data Types 12.1 Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: Define the concept of an abstract data type (ADT). Define

More information

CS 206 Introduction to Computer Science II

CS 206 Introduction to Computer Science II CS 206 Introduction to Computer Science II 07 / 26 / 2016 Instructor: Michael Eckmann Today s Topics Comments/Questions? Stacks and Queues Applications of both Priority Queues Michael Eckmann - Skidmore

More information

CSCE 2014 Final Exam Spring Version A

CSCE 2014 Final Exam Spring Version A CSCE 2014 Final Exam Spring 2017 Version A Student Name: Student UAID: Instructions: This is a two-hour exam. Students are allowed one 8.5 by 11 page of study notes. Calculators, cell phones and computers

More information

STACKS AND QUEUES. Problem Solving with Computers-II

STACKS AND QUEUES. Problem Solving with Computers-II STACKS AND QUEUES Problem Solving with Computers-II 2 Stacks container class available in the C++ STL Container class that uses the Last In First Out (LIFO) principle Methods i. push() ii. iii. iv. pop()

More information

VALLIAMMAI ENGINEERING COLLEGE

VALLIAMMAI ENGINEERING COLLEGE VALLIAMMAI ENGINEERING COLLEGE SRM Nagar, Kattankulathur 603 203 DEPARTMENT OF INFORMATION TECHNOLOGY QUESTION BANK III SEMESTER CS8391-Data Structures Regulation 2017 Academic Year 2018 19(odd Semester)

More information

Loop Invariants. while!done do // what is true at every step // Update/iterate // maintain invariant od CPS

Loop Invariants. while!done do // what is true at every step // Update/iterate // maintain invariant od CPS Loop Invariants Want to reason about the correctness of a proposed iterative solution Loop invariants provide a means to effectively about the correctness of code while!done do // what is true at every

More information

CS302 Topic: Algorithm Analysis. Thursday, Sept. 22, 2005

CS302 Topic: Algorithm Analysis. Thursday, Sept. 22, 2005 CS302 Topic: Algorithm Analysis Thursday, Sept. 22, 2005 Announcements Lab 3 (Stock Charts with graphical objects) is due this Friday, Sept. 23!! Lab 4 now available (Stock Reports); due Friday, Oct. 7

More information

CSCI-1200 Data Structures Spring 2018 Lecture 8 Templated Classes & Vector Implementation

CSCI-1200 Data Structures Spring 2018 Lecture 8 Templated Classes & Vector Implementation CSCI-1200 Data Structures Spring 2018 Lecture 8 Templated Classes & Vector Implementation Review from Lectures 7 Algorithm Analysis, Formal Definition of Order Notation Simple recursion, Visualization

More information

CSc 328, Spring 2004 Final Examination May 12, 2004

CSc 328, Spring 2004 Final Examination May 12, 2004 Name: CSc 328, Spring 2004 Final Examination May 12, 2004 READ THIS FIRST Fill in your name above. Do not turn this page until you are told to begin. Books, and photocopies of pages from books MAY NOT

More information

Computer Science BS Degree - Data Structures (I2206) Abstract Data Types (ADT)

Computer Science BS Degree - Data Structures (I2206) Abstract Data Types (ADT) Abstract Data Types (ADT) 70 Hierarchy of types Each type is implemented in terms if the types lower in the hierarchy Level 0 Bit Byte Word Level 1 Integer Real Char Boolean Pointer Level 2 Array Record

More information

Fun facts about recursion

Fun facts about recursion Outline examples of recursion principles of recursion review: recursive linked list methods binary search more examples of recursion problem solving using recursion 1 Fun facts about recursion every loop

More information

HO #13 Fall 2015 Gary Chan. Hashing (N:12)

HO #13 Fall 2015 Gary Chan. Hashing (N:12) HO #13 Fall 2015 Gary Chan Hashing (N:12) Outline Motivation Hashing Algorithms and Improving the Hash Functions Collisions Strategies Open addressing and linear probing Separate chaining COMP2012H (Hashing)

More information

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

double d0, d1, d2, d3; double * dp = new double[4]; double da[4]; All multiple choice questions are equally weighted. You can generally assume that code shown in the questions is intended to be syntactically correct, unless something in the question or one of the answers

More information

Basic Data Structures

Basic Data Structures Basic Data Structures Some Java Preliminaries Generics (aka parametrized types) is a Java mechanism that enables the implementation of collection ADTs that can store any type of data Stack s1

More information

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

University of Illinois at Urbana-Champaign Department of Computer Science. Second Examination University of Illinois at Urbana-Champaign Department of Computer Science Second Examination CS 225 Data Structures and Software Principles Spring 2012 7p-9p, Tuesday, April 3 Name: NetID: Lab Section

More information

VALLIAMMAI ENGNIEERING COLLEGE SRM Nagar, Kattankulathur DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING QUESTION BANK

VALLIAMMAI ENGNIEERING COLLEGE SRM Nagar, Kattankulathur DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING QUESTION BANK VALLIAMMAI ENGNIEERING COLLEGE SRM Nagar, Kattankulathur 603203. DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING QUESTION BANK Degree & Branch : B.E E.C.E. Year & Semester : II / IV Section : ECE 1, 2 &

More information

CS2 Algorithms and Data Structures Note 1

CS2 Algorithms and Data Structures Note 1 CS2 Algorithms and Data Structures Note 1 Analysing Algorithms This thread of the course is concerned with the design and analysis of good algorithms and data structures. Intuitively speaking, an algorithm

More information

EEE2020 Data Structures and Algorithms Abstract Data Types: Stacks and Queues

EEE2020 Data Structures and Algorithms Abstract Data Types: Stacks and Queues EEE2020 Data Structures and Algorithms Abstract Data Types: Stacks and Queues W. Jinho Song School of Electrical & Electronic Engineering Yonsei University 1 Textbook Chapter and Objectives Textbook "Data

More information

CPSC 221: Algorithms and Data Structures Lecture #1: Stacks and Queues

CPSC 221: Algorithms and Data Structures Lecture #1: Stacks and Queues CPSC 221: Algorithms and Data Structures Lecture #1: Stacks and Queues Alan J. Hu (Slides borrowed from Steve Wolfman) Be sure to check course webpage! http://www.ugrad.cs.ubc.ca/~cs221 1 Lab 1 is available.

More information

CSC 1052 Algorithms & Data Structures II: Queues

CSC 1052 Algorithms & Data Structures II: Queues CSC 1052 Algorithms & Data Structures II: Queues Professor Henry Carter Spring 2018 Recap Recursion solves problems by solving smaller version of the same problem Three components Applicable in a range

More information

Lecture Notes. char myarray [ ] = {0, 0, 0, 0, 0 } ; The memory diagram associated with the array can be drawn like this

Lecture Notes. char myarray [ ] = {0, 0, 0, 0, 0 } ; The memory diagram associated with the array can be drawn like this Lecture Notes Array Review An array in C++ is a contiguous block of memory. Since a char is 1 byte, then an array of 5 chars is 5 bytes. For example, if you execute the following C++ code you will allocate

More information

Sequential Containers Cont'd

Sequential Containers Cont'd Cont'd Carlos Moreno cmoreno @ uwaterloo.ca EIT-4103 https://ece.uwaterloo.ca/~cmoreno/ece250 Today's class: Sequential Containers We'll complete our discussion on sequential containers We'll briefly talk

More information

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

Revision Statement while return growth rate asymptotic notation complexity Compare algorithms Linear search Binary search Preconditions: sorted, [1] Big-O Analysis AVERAGE(n) 1. sum 0 2. i 0. while i < n 4. number input_number(). sum sum + number 6. i i + 1 7. mean sum / n 8. return mean Revision Statement no. of times executed 1 1 2 1 n+1 4 n

More information

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

Discussion 2C Notes (Week 3, January 21) TA: Brian Choi Section Webpage: Discussion 2C Notes (Week 3, January 21) TA: Brian Choi (schoi@cs.ucla.edu) Section Webpage: http://www.cs.ucla.edu/~schoi/cs32 Abstraction In Homework 1, you were asked to build a class called Bag. Let

More information

CMSC Introduction to Algorithms Spring 2012 Lecture 7

CMSC Introduction to Algorithms Spring 2012 Lecture 7 CMSC 351 - Introduction to Algorithms Spring 2012 Lecture 7 Instructor: MohammadTaghi Hajiaghayi Scribe: Rajesh Chitnis 1 Introduction In this lecture we give an introduction to Data Structures like arrays,

More information

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?

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? Review for Final (Chapter 6 13, 15) 6. Template functions & classes 1) What is the primary purpose of template functions? A. To allow a single function to be used with varying types of arguments B. To

More information