Review for Midterm Chapter 1-9 CSc 212 Data Structures.

Slides:



Advertisements
Similar presentations
1 CSC211 Data Structures Lectures 4 & 5 Container Classes Instructor: Prof. Xiaoyan Li Department of Computer Science Mount Holyoke College.
Advertisements

C++ Templates. What is a template? Templates are type-generic versions of functions and/or classes Template functions and template classes can be used.
Review of Stacks and Queues Dr. Yingwu Zhu. Our Focus Only link-list based implementation of Stack class Won’t talk about different implementations of.
@ Zhigang Zhu, CSC212 Data Structure - Section RS Lectures 6/7 Pointers and Dynamic Arrays Instructor: Zhigang Zhu Department of Computer Science.
Lecture 3 Feb 4 summary of last week’s topics and review questions (handout) Today’s goals: Chapter 1 overview (sections 1.4 to 1.6) c++ classes constructors,
Reviews for Exam 1 Chapter 1-4 CSc 212 Data Structures, Sec FG CCNY, Fall 2010.
@ Zhigang Zhu, CSC212 Data Structure - Section FG Lecture 8 Dynamic Classes and the Law of the Big Three Instructor: Zhigang Zhu Department.
1 CSC212 Data Structure - Section FG Lectures 4 & 5 Container Classes Instructor: Zhigang Zhu Department of Computer Science City College of New York.
Exam Review 2 Chapter 5 – 9 CSC212 RS March 31, 2011, CS Dept, CCNY.
Reviews for Exam 1 Chapter 1-4 CS 211 Data Structures MHC, 2007.
@ Zhigang Zhu, CSC212 Data Structure - Section FG Lecture 10 The Bag and Sequence Classes with Linked Lists Instructor: Zhigang Zhu Department.
Exam Review 2 Chapter 5 – 9 CS211 November 05,2007, CS Dept, MHC.
© Copyright Eliyahu Brutman Programming Techniques Course Version 1.0.
Data Structures Using C++ 2E
Templates and the STL.
Object Oriented Data Structures
CSIS 123A Lecture 12 Templates. Introduction  C++ templates  Allow very ‘general’ definitions for functions and classes  Type names are ‘parameters’
Data Structures Using C++ 2E Chapter 7 Stacks. Data Structures Using C++ 2E2 Objectives Learn about stacks Examine various stack operations Learn how.
Data Structures Using C++ 2E
 200 Total Points ◦ 74 Points Writing Programs ◦ 60 Points Tracing Algorithms and determining results ◦ 36 Points Short Answer ◦ 30 Points Multiple Choice.
Adapted from instructor resources Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights.
COP3530 Data Structures600 Stack Stack is one the most useful ADTs. Like list, it is a collection of data items. Supports “LIFO” (Last In First Out) discipline.
Xiaoyan Li, CSC211 Data Structures Lecture 10 The Bag and Sequence Classes with Linked Lists Instructor: Prof. Xiaoyan Li Department of Computer.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Standard Template Library (STL)
Data Structures Using C++ 2E Chapter 8 Queues. Data Structures Using C++ 2E2 Objectives Learn about queues Examine various queue operations Learn how.
Edgardo Molina, CSC212 Data Structure - Section AB Lectures 6/7 Pointers and Dynamic Arrays Instructor: Edgardo Molina Department of Computer Science.
Exam 1 Review CS Total Points – 60 Points Writing Programs – 20 Points Tracing Algorithms, determining results, and drawing pictures – 40 Points.
Final Exam Review CS Total Points – 60 Points Writing Programs – 50 Points Tracing Algorithms, determining results, and drawing pictures – 50.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Stacks.
Review of Stacks and Queues Dr. Yingwu Zhu. How does a Stack Work? Last-in-First-out (LIFO) data structure Adding an item Push operation Removing an item.
Standard Template Library The Standard Template Library was recently added to standard C++. –The STL contains generic template classes. –The STL permits.
Iterator for linked-list traversal, Template & STL COMP171 Fall 2005.
CSC212 Data Structure - Section FG Lecture 11 Templates, Iterators and STL Instructor: Professor Zhigang Zhu Department of Computer Science City College.
Edgardo Molina, CSC212 Data Structure - Section AB Lecture 8 Dynamic Classes and the Law of the Big Three Instructor: Edgardo Molina Department.
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 1: Introduction Data.
 200 Total Points ◦ 75 Points Writing Programs ◦ 60 Points Tracing Algorithms and determining results ◦ 35 Points Short Answer ◦ 30 Points Multiple Choice.
1 CSC212 Data Structure Lecture 4 Container Classes Instructor: George Wolberg Department of Computer Science City College of New York.
Copyright © 2009 – Curt Hill Standard Template Library An Introduction.
Exam Review 2 Chapter 5 – 9 CSC212 FG CS Dept, CCNY.
Xiaoyan Li, CSC211 Data Structures Lecture 8 Dynamic Classes and the Law of the Big Three Instructor: Prof. Xiaoyan Li Department of Computer Science.
Final Exam Review CS Total Points – 20 Points Writing Programs – 65 Points Tracing Algorithms, determining results, and drawing pictures – 50.
Chapter 17 – Templates. Function Templates u Express general form for a function u Example: template for adding two numbers Lesson 17.1 template Type.
@ George Wolberg, CSC212 Data Structure Lecture 6 Dynamic Classes and the Law of the Big Three Instructor: George Wolberg Department of Computer.
Final Exam Review CS 3358.
Link-Based Implementations
Object-Oriented Programming (OOP) Lecture No. 41
CSCE 210 Data Structures and Algorithms
Data Structures Using C++ 2E
Copy Constructor / Destructors Stacks and Queues
CS 215 Final Review Ismail abumuhfouz Fall 2014.
Chapter 1-4 CSc 212 Data Structures, Sec AB CCNY, Spring 2012
The Bag and Sequence Classes with Linked Lists
Map interface Empty() - return true if the map is empty; else return false Size() - return the number of elements in the map Find(key) - if there is an.
Array Lists Chapter 6 Section 6.1 to 6.3
Chapter 5 – 9 CSC212 AB April 03, CS Dept, CCNY
Chapter 5 – 9 CSC212 KL Nov 8, CS Dept, CCNY
CS 2308 Final Exam Review.
Exam 1 Review CS 3358.
Introduction to Data Structures
Exam 1 Review CS 3358.
Chapter 5 – 9 CSC212 RS April 08, CS Dept, CCNY
Data Structures and Algorithms for Information Processing
CSC212 Data Structure - Section RS
EE 312 Final Exam Review.
Standard Template Library
Dynamic allocation (continued)
Standard Template Library
CS 2308 Final Exam Review.
Chapter 1-4 CSc 212 Data Structures, Sec FG CCNY, 2009
Presentation transcript:

Review for Midterm Chapter 1-9 CSc 212 Data Structures

Chapter 1 Course Objectives – WHAT (Topics – ADTs, classes) – WHY (Importance – not only for credits) – WHERE (Goals – data structure experts) – HOW (Lectures, Self-Test Exercises, Assignments, Quizzes and Exams) The Phase of Software Development – Basic design strategy four steps- S, D, I, T – Pre-conditions and post-conditions assert – Running time analysis big-O notation Self-Test Exercises: 3-6, 11-15, 17-20

Chapter 2 A Review of C++ Classes (Lecture 2) OOP, ADTs and Classes Class Definition, Implementation and Use Constructors and Value Semantics More on Classes (Lecture 3) Namespace and Documentation –three ways to use namespace; pre- /post-conditions Classes and Parameters –value, reference, const reference Operator Overloading –nonmember, member and friend function Self-Test Exercises: 1, 4,513,15,17,21,23, 25,28,31

A container class is a class that can hold a collection of items. Container classes can be implemented with a C++ class. The class is implemented with –a header file (containing documentation and the class definition) bag1.h and –an implementation file (containing the implementations of the member functions) bag1.cpp. Other details are given in Section 3.1, which you should read, especially the real bag code. Chapter 3

Time Analysis of the Bag Class count – the number of occurrence erase_one – remove one from the bag erase – remove all += - append b1+b2 - union insert – add one item size – number of items in the bag

The Invariant of a Class Two rules for our bag implementation – The number of items in the bag is stored in the member variable used ; – For an empty bag, we don’t care what is stored in any of data ; for a non-empty bag, the items are stored in data [0] through data [ used -1], and we don’t care what are stored in the rest of data. The rules that dictate how the member variables of a (bag) class are used to represent a value (such as a bag of items) are called the invariant of the class

What’s the most important, then? Concept of Container Classes – the bag class is not particularly important Other kinds of container classes –Other types of bags using typedef – sequence – similar to a bag, both contain a bunch of items. But unlike a bag, the items in a sequence is arranged in order.(assignment 2) Self-Test Exercises: 1,3, 5,10,11,14,18-24

Chapter 4 Pointers –*(asterisk) and &(ampersand) operators Dynamic Variables and new Operator – Dynamic Arrays and Dynamic Objects – Stack (local) vs. heap (dynamic) memory Garbage Collection and delete Operator Parameters revisited –Pointers and Arrays as Parameters

Why Dynamic Classes Limitation of our bag class – bag::CAPACITY constant determines the capacity of every bag – wasteful and hard to reuse Solution: – provide control over size in running time, by – pointers and dynamic memory – => dynamic arrays –=> dynamic classes

Dynamic Classes (Ch 4.3–4) Pointers Member Variables Dynamic Memory Allocation –where and how Value Semantics (with dynamic memory) – assignment operator overloading – your own copy constructor Destructor the Law of the Big Three Self-Test Exercises:1-4, ,

Time Analysis of the Bag Class count – the number of occurrence erase_one – remove one from the bag erase – remove all += - append b1+b2 - union insert – add one item size – number of items in the bag

Chapter 5: Linked Lists Node Class (Ex 1-4, 6-9) Linked List Toolkit (Ex ) The bag Class with a Linked List (Ex 19-21, 23,24,26) The sequence class with a Linked List (Ex 27-30: please refer to assignment 4) Comparison of dynamic arrays, linked lists and doubly linked lists (Ex 31-36)

Chapter 6: Templates, Iterators and STL Template Functions and Template Classes –for code that is meant be reused in a variety of settings in a single program –Sections , Ex 1-3, 6-11 Iterators (Sec , Ex 17-28) –step through all items of a container in a standard manner Standard Template Library (Section 6.3, Ex ) –the ANSI/ISO C++ Standard provides a variety of container classes in the STL

All you need to know about Templates Template Function (Ex. 1-3) –a template prefix before the function implementation –template Function Prototype –a template prefix before the function prototypes Template Class (Ex. 6-10) –a template prefix right before the class definition Instantiation (Ex 11) –template functions/classes are instantiated when used Better Understanding of classes and functions

Iterators (Sec , Ex 17-28) We discussed how to build an iterator for the linked list so that each of the containers can build its own iterator(s) easily A node iterator is an object of the node_iterator class, and can step through the nodes of the linked list

Linked List Version the bag Template Class with an Iterator Most of the implementation of this new bag is a straightforward translation of the bag in Chapter 5 that used an ordinary linked list Two new features –Template class with a underlying type Item –iterator and const_iterator – defined from node_iterator and const_node_iterator, but use the C++ standard [...) left inclusive pattern

Standard Template Library (STL) The ANSI/ISO C++ Standard provides a variety of container classes in the STL –set, multiset, stack, queue, string, vector Featured templates and iterators For example, the multiset template class is similar to our bag template class More classes summarized in Appendix H

Chapters 7/8 Stacks and Queues Stacks and LIFO ( Read Chapter 7, esp. 7.1 and 7.3 ) –Self-Test: 1, 2, 7, 8, 9, 10, Queues and FIFO ( Read Chapter 8, esp. 8.1 and 8.3 ) –Self-Test: 1, 2, 6,10, 11,12 Priority Queues ( Read Section 8.4 ) –Self-Test: 16, 17 References Return Values ( Read Section 8.5 and p. 302 in Chapter 6 ) –Self-Test: class note of Lecture 12

Chapter 9 Recursive Thinking Recursive Functions (Section 9.1) –Recursive Calls and Stopping Cases –Activation Record and Run-Time Stack –Self-Test: Exercises 1-4 Reasoning about Recursion (Section 9.3) –Infinite Recursion and One Level Recursion –Ensure no Infinite recursion and Correctness –Ex. 9, 10 on page 448 Applications of Recursion (Optional :Section 9.2)

Midterm Two parts (100 minutes, 30 questions) –Short Answers (10), e.g. What is an automatic default constructor, and what does it do? –Multiple Choices (20), e.g. Suppose that the foo class does not have an overloaded assignment operator. What happens when an assignment a=b; is given for two foo objects? A. The automatic assignment operator is used B. The copy constructor is used C. Compiler error D. Run-time error