Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Course Review FINAL.

Slides:



Advertisements
Similar presentations
1111 Abstract Data Types Cpt S 223. School of EECS, WSU.
Advertisements

Chapter 3 – Lists A list is just what the name implies, a finite, ordered sequence of items. Order indicates each item has a position. A list of size 0.
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.
CS Data Structures II Review COSC 2006 April 14, 2017
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Exception Handling: A Deeper.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Data Structures.
Chapter 12 C Data Structures Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 – Data Structures Outline 12.1Introduction.
Data Abstraction and Object- Oriented Programming CS351 – Programming Paradigms.
Data Structures Using C++ 2E Chapter 11 Binary Trees and B-Trees.
 2006 Pearson Education, Inc. All rights reserved Data Structures.
Review of C++ Programming Part II Sheng-Fang Huang.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Data Structures Trees.
 2006 Pearson Education, Inc. All rights reserved Classes: A Deeper Look.
Review for Midterm Chapter 1-9 CSc 212 Data Structures.
Pointer Data Type and Pointer Variables
Data Structures Using C++ 2E Chapter 3 Pointers and Array-Based Lists.
BASE CLASSES AND INHERITANCE CHAPTER 4. Engineer Class.
Chapter 12 Data Structure Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
Data Structures Outline Introduction Self-Referential Classes Dynamic Memory Allocation Linked Lists Stacks Queues Trees.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Custom Templatized Data Structures.
C++ How to Program, 7/e © by Pearson Education, Inc. All Rights Reserved.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Templatized Tree.
 2007 Pearson Education, Inc. All rights reserved C Data Structures.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Course Review Midterm.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Classes: A Deeper Look Part.
More C++ Classes Systems Programming. C++ Classes  Preprocessor Wrapper  Time Class Case Study –Two versions (old and new)  Class Scope and Assessing.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Course Review Midterm.
CS212: Object Oriented Analysis and Design Lecture 6: Friends, Constructor and destructors.
 2006 Pearson Education, Inc. All rights reserved Classes: A Deeper Look, Part 2.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Standard Template Library (STL)
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Course Review Midterm Exam #
Review for Final Andy Wang Data Structures, Algorithms, and Generic Programming.
1 Chapter 17 Object-Oriented Data Structures. 2 Objectives F To describe what a data structure is (§17.1). F To explain the limitations of arrays (§17.1).
Final Exam Review CS Total Points – 60 Points Writing Programs – 50 Points Tracing Algorithms, determining results, and drawing pictures – 50.
Slide 1 Linked Data Structures. Slide 2 Learning Objectives  Nodes and Linked Lists  Creating, searching  Linked List Applications  Stacks, queues.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
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.
Lists Chapter 8. 2 Linked Lists As an ADT, a list is –finite sequence (possibly empty) of elements Operations commonly include: ConstructionAllocate &
Programming Practice 3 - Dynamic Data Structure
Copyright © 2002 Pearson Education, Inc. Slide 1.
OOP using C Abstract data types How to accomplish the task??? Requirements Details Input, output, process Specify each task in terms of input.
 200 Total Points ◦ 75 Points Writing Programs ◦ 60 Points Tracing Algorithms and determining results ◦ 35 Points Short Answer ◦ 30 Points Multiple Choice.
Java How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
Chapter 6 Lists Plus. What is a Class Template? A class template allows the compiler to generate multiple versions of a class type by using type parameters.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Templatized Stack.
1 Classes II Chapter 7 2 Introduction Continued study of –classes –data abstraction Prepare for operator overloading in next chapter Work with strings.
STL CSSE 250 Susan Reeder. What is the STL? Standard Template Library Standard C++ Library is an extensible framework which contains components for Language.
April 27, 2017 COSC Data Structures I Review & Final Exam
 Saturday, April 20, 8:30-11:00am in B9201  Similar in style to written midterm exam  May include (a little) coding on paper  About 1.5 times as long.
Final Exam Review CS Total Points – 20 Points Writing Programs – 65 Points Tracing Algorithms, determining results, and drawing pictures – 50.
Copyright © 2012 Pearson Education, Inc. Chapter 10 Advanced Topics.
Chapter 10 Trees © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
Chapter 12: Pointers, Classes, Virtual Functions, Abstract Classes, and Lists.
CSCE , SPRING 2016 INSTRUCTOR: DR. NANCY M. AMATO 1.
DATA STRUCURES II CSC QUIZ 1. What is Data Structure ? 2. Mention the classifications of data structure giving example of each. 3. Briefly explain.
Chapter 20 Custom Templatized Data Structures
Cpt S 122 – Data Structures Abstract Data Types
Data Structure By Amee Trivedi.
Chapter 12 – Data Structures
Introduction to Computers Computer Generations
12 C Data Structures.
Midterm Review.
CE 221 Data Structures and Algorithms
Chapter 22 Custom Generic Data Structures
CS 2308 Final Exam Review.
Chapter 19 – Data Structures
Final Exam Review COP4530.
Today’s Objectives 10-Jul-2006 Announcements Quiz #3
Presentation transcript:

Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Course Review FINAL

Final When: Wednesday (12/12) 1:00 pm -3:00 pm Where: In Class Closed book, Closed notes Comprehensive Material for preparation:  Lecture Slides  Quizzes, Labs and Programming assignments  Deitel & Deitel book (Read and re-read Chapter 15 to 22 and Chapter 24 and the last 5 weeks lecture notes from course webpage)

Course Overview (First 5 weeks) Functions (Chapter 5)  Function Call Stack and Stack Frames  Pass-by-value and Pass-by-reference Pointers (Chapter 7)  Pointer Operators  Passing Arguments to Functions by Reference  const qualifiers with Pointers Characters and Strings (Chapter 8)  Fundamentals of Strings and Characters

Course Overview Data Structures (Chapter 12)  Self Referential Structures  Dynamic Memory Allocation  Linked Lists, Stacks and Queues  insert, delete, isEmpty, print  Binary Trees, Binary Search Trees  Tree Traversals  preOrder, inOrder, postOrder

Course Overview (Second 5 weeks) C++ as a better C; Introducing Object Technology (Chapter 15)  Inline Function  Function Overloading and Function Templates  Pass-by-value and Pass-by-reference Introduction to Classes, Objects & Strings (Chapter 16)  Data members, Members functions, set and get functions  Constructors Classes: A Deeper Look, Part I (Chapter 17)  Separating interface from implementation  Destructors

Course Overview Classes: A Deeper Look, Part 2 (Chapter 18)  const Objects and const Member functions  Composition: Objects as members of class  friend function and friend class  this pointer Operator Overloading; Class String (Chapter 19)  Implementation of operator overloading  Dynamic memory management using new operator  Explicit constructor

Course Overview Object Oriented Programming: Inheritance (Chapter 20)  Base Classes & Derived Classes  public, protected, and private Inheritance Object Oriented Programming: Polymorphism (Chap. 21)  Abstract Classes & pure virtual Functions  virtual Functions & Dynamic Binding  Polymorphism & RunTime Type Information (RTTI) downcasting, dynamic_cast  virtual Destructors

Course Overview Templates (Chapter 22)  Function Template  Class Templates  STL Containers: example of container class template such as stack Exception Handling (Chapter 24)  Use of try, catch and throw to detect, handle and indicate exceptions, respectively.  Exception handling with constructors & destructors  Processing new failures

Course Overview (Last 5 weeks) Templatized Linked List  insert, delete, isEmpty, printList Templatized Stack  push, pop, top, isStackEmpty, printStack Templatized Queue  enqueue, dequeue, isQueueEmpty, printQueue Templatized Tree  insertNode, preOrder, inOrder, postOrder

Course Overview (Last 5 weeks) Sorting algorithms and Runtime analysis  Bubble sort, Selection sort, Insertion sort, Shell sort, Merge sort, Quick sort  Enumeration of sorting algorithms in practice Standard Template Library  Containers, Iterators, Algorithms Abstract Data Types  vector, list, stack, queue  Runtime complexity

C++ enables several functions of the same name to be defined, as long as they have different signatures.  This is called function overloading. The C++ compiler selects the proper function to call  examining the number, types and order of the arguments in the call. Overloaded functions are distinguished by their signatures.  A signature is a combination of a function’s name and its parameter types (in order). Function overloading is used to create several functions of the same name  perform similar tasks, but on different data types. Function Overloading

Overloaded functions normally perform similar or identical operations on different types of data. If the operations are identical for each type, they can be expressed more compactly and conveniently using function templates. Function Templates

With object-oriented programming, we focus on the commonalities among objects in the system rather than on the special cases. We distinguish between the is-a relationship and the has-a relationship. The is-a relationship represents inheritance.  In an is-a relationship, an object of a derived class can be treated as an object of its base class. By contrast, the has-a relationship represents composition. Inheritance

Dynamic Memory Management Use the new operator to dynamically allocate (i.e., reserve) the exact amount of memory required to hold an object or array at execution time. Once memory is allocated in the free store, you can access it via the pointer that operator new returns. To destroy a dynamically allocated object, use the delete operator as follows: delete ptr; To deallocate a dynamically allocated array, use the statement delete [] ptr;

Polymorphism Compile time Polymorphism Runtime Polymorphism Function Overloading Operator Overloading Operator Overloading Virtual Functions Virtual Functions early binding, or static binding, or static linking late binding, or dynamic binding, virtual function

A class is made abstract by declaring one or more of its virtual functions to be “pure.”  A pure virtual function is specified by placing “ = 0 ” in its declaration, as in virtual void draw() const = 0; Abstract classes are classes from which you never intend to instantiate any objects. Classes that can be used to instantiate objects are called concrete classes. Abstract Classes and pure virtual Functions

Exception Handling What is exception handling?  Example: Handling an attempt to divide by zero  Use try, catch and throw to detect, handle and indicate exceptions, respectively.  Rethrowing an exception Exception Specifications  Processing unexpected and uncaught exceptions Processing new failures  Dynamic memory allocation  Use unique_ptr to prevent memory leak

try blocks enable exception handling.  The try block encloses statements that might cause exceptions and statements that should be skipped if an exception occurs. Exceptions are processed by catch handlers (also called exception handlers), which catch and handle exceptions.  At least one catch handler must immediately follow each try block. Exception Handling (cont.)

Last 5 Weeks Templated Classes Sorting and Algorithm Analysis Standard Template Library (STL) Abstract Data Type Runtime Complexity

ListNode Template Class

List Class Template

List Class Constructor

List Class Destructor

insertAtFront() & Runtime

insertAtBack() & Runtime

removeFromFront() & Runtime

removeFromBack() & Runtime

isEmpty() & Runtime

Templated Linked List Problem Please write a insertNode() method for the class List. This method should insert data in the list in order.  First create a new node with the provided value.  Make sure to check if the list is empty and if so set the pointers appropriately to insert the new node into the empty list.  Otherwise traverse the list by advancing a current pointer, compare the new Node’s value with the existing ListNode’s data to find the correct position and then set the pointers appropriately to insert the new node considering the following 3 cases insertAtFront insertInBetween insertAtBack

Option 1: Implement a stack class primarily by reusing a list class.  private inheritance of the list class. Option 2: Implement an identically performing stack class through composition  a list object as a private member of a stack class. Templated Stack

List Class is Given

Templated Stack derived from class List runtime of push, pop, isStackEmpty, printStack??

Templated Stack (cont.)

Queue Class Template runtime of enqueue, dequeue, isQueueEmpty, printQueue??

Queue Class Template

Linked lists, stacks and queues are linear data structures. A tree is a nonlinear, two-dimensional data structure.  arrays arrange data linearly, binary trees can be envisioned as storing data in two dimensions Tree nodes contain two or more links.  trees whose nodes all contain two links (none, one or both of which may be null). Trees

TreeNode Class Template

ListNode Member Function

TreeNode Class Template (cont.)

Tree Class Template (cont.)

Tree Class Template preorder Traversal preOrder traversal is: root, left, right

Tree Class Template inOrder Traversal inOrder traversal is: left, root, right

Tree Class Template postOrder Traversal postOrder traversal is: left, right, root

Other Binary Tree Operations The level order traversal of a binary tree visits the nodes of the tree row-by-row starting at the root node level.  On each level of the tree, the nodes are visited from left to right.  The level order traversal is not a recursive algorithm. Implement the level order binary tree traversal using a common data structure we have discussed in the class.  Write the pseudo code of this algorithm.

Level Order Binary Tree Traversal Use the Queue data structure to control the output of the level order binary tree traversal. Algorithm  Insert / enqueue the root node in the queue  While there are nodes left in the queue, Get/dequeue the node in the queue Print the node’s value If the pointer to the left child of the node is not null  Insert/enqueue the left child node in the queue If the pointer to the right child of the node is not null  Insert/enqueue the right child node in the queue

Problem in Tress Given the preOrder, inOrder or postOrder traversals of a binary tree, draw the binary tree.  preOrder:  inOrder:  postOrder:

Problem in Trees Draw the a binary search tree after inserting the following sequence of values using the insertNode() method from the tree class:  50, 25, 12, 6, 13, 33, 75, 67, 68, 88

Sorting Algorithms Bubble sort Worst case Runtime O(?) Insertion sort Worst case Runtime O(?) Selection sort Worst case Runtime O(?) Shell sort Worst case Runtime O(?) Merge sort Worst case Runtime O(?) Quick sort Worst case Runtime O(?) Which one is best at least theoretically? Which one is best in practice and Why?

Comparison of Sorting Algorithms Selection Sort  (N 2 )  (N 2 )  (N 2 ) Best Case is quadratic Bubble Sort  (N 2 )  (N 2 )  (N)

Enumeration of Sorting Algorithms Try the insertion sort, selection sort, shell sort, merge sort and quick sort, algorithm on the following list of integers for example:  {7, 3, 9, 5, 4, 8, 0, 1}

Standard Template Library (STL) Containers Iterators Algorithms

Abstract Data Types (ADTs) ADT is a set of objects together with a set of operations  Abstract implementation of operations is not specified in ADT definition E.g., List  Operations on a list: Insert, delete, search, sort C++ class are perfect for ADTs Can change ADT implementation details without breaking code that uses the ADT

Lists Using STL Two popular implementation of the List ADT  The vector provides a growable array implementation of the List ADT Advantage: it is indexable in constant time Disadvantage: insertion and deletion are computationally expensive  The list provides a doubly linked list implementation of the List ADT Advantage: insertion and deletion are cheap provided that the position of the changes are known Disadvantage: list is not easily indexable Vector and list are class templates  Can be instantiated with different type of items

Lists Using STL (cont’d) vector  Array-based implementation  findKth – O(1)  insert and remove – O(N) Unless change at end of vector list  Doubly-linked list with sentinel nodes  findKth – O(N)  insert and remove – O(1) If position of change is known Both require O(N) for search

Course Evaluations Please take a few minutes to complete the online course evaluations available at Thank you for taking CptS 122.

Tentative Final Structure Part I: Conceptual Questions (45pts)  Multiple Choice, Fill-in-the-blank, and True/False  Go though the self-review exercises at the end of each chapter Part II: Programming Questions (35pts)  Write Templated C++ code for Linked List, Stack, Queue and Tree  Retake Quiz 1 to Quiz 6 Part III: Enumerative and Pseudo code Questions (20pts)  Workout all the sorting algorithm on an example input set  Remember the time complexity  Practice preOrder, inOrder, postOrder & level-order traversal algorithm

Good Luck !