CISC220 Fall 2009 James Atlas Dec 07: Final Exam Review.

Slides:



Advertisements
Similar presentations
Exam Review 3 Chapters 10 – 13, 15 CSC212 Section FG CS Dept, CCNY.
Advertisements

©Brooks/Cole, 2003 Chapter 12 Abstract Data Type.
Advanced Data Structures
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
Binary Trees, Binary Search Trees COMP171 Fall 2006.
Data Structures: Trees i206 Fall 2010 John Chuang Some slides adapted from Marti Hearst, Brian Hayes, or Glenn Brookshear.
1 Assignment 2: (Due at 10:30 a.m on Friday of Week 10) Question 1 (Given in Tutorial 5) Question 2 (Given in Tutorial 7) If you do Question 1 only, you.
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
CISC220 Fall 2009 James Atlas Nov 13: Heap Implementations, Graphs.
CISC220 Spring 2010 James Atlas Lecture 06: Linked Lists (2), Big O Notation.
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (4) Data Structures 11/18/2008 Yang Song.
BST Data Structure A BST node contains: A BST contains
Review for Test 2 i206 Fall 2010 John Chuang. 2 Topics  Operating System and Memory Hierarchy  Algorithm analysis and Big-O Notation  Data structures.
Data Structures Data Structures Topic #8. Today’s Agenda Continue Discussing Table Abstractions But, this time, let’s talk about them in terms of new.
Course Review COMP171 Spring Hashing / Slide 2 Elementary Data Structures * Linked lists n Types: singular, doubly, circular n Operations: insert,
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.
1 abstract containers hierarchical (1 to many) graph (many to many) first ith last sequence/linear (1 to 1) set.
Important Problem Types and Fundamental Data Structures
1 MT258 Computer Programming and Problem Solving Unit 9.
Comp 249 Programming Methodology Chapter 15 Linked Data Structure - Part B Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia.
Chapter 12 Data Structure Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
CS 3610 Midterm Review.
Final Review Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2010.
Information and Computer Sciences University of Hawaii, Manoa
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Course Review Midterm.
Chapter 19 Implementing Trees and Priority Queues Fundamentals of Java.
CISC220 Fall 2009 James Atlas Lecture 13: Trees. Skip Lists.
1 Trees A tree is a data structure used to represent different kinds of data and help solve a number of algorithmic problems Game trees (i.e., chess ),
Chapter 19 Implementing Trees and Priority Queues Fundamentals of Java.
Final Review Dr. Yingwu Zhu. Goals Use appropriate data structures to solve real- world problems –E.g., use stack to implement non-recursive BST traversal,
1 Binary Trees Informal defn: each node has 0, 1, or 2 children Informal defn: each node has 0, 1, or 2 children Formal defn: a binary tree is a structure.
Review for Final Andy Wang Data Structures, Algorithms, and Generic Programming.
INTRODUCTION TO DATA STRUCTURES. INTRODUCTION A data structure is nothing but an arrangement of data either in computer's memory or on the disk storage.
Starting at Binary Trees
Data Structure Introduction.
Final Exam Review CS Total Points – 60 Points Writing Programs – 50 Points Tracing Algorithms, determining results, and drawing pictures – 50.
Java Methods Big-O Analysis of Algorithms Object-Oriented Programming
+ David Kauchak cs312 Review. + Midterm Will be posted online this afternoon You will have 2 hours to take it watch your time! if you get stuck on a problem,
Review for Final Exam – cs411/511 Definitions (5 questions, 2 points each) Algorithm Analysis (3 questions, 3 points each) General Questions (3 questions,
Chapter 12 Abstract Data Type. Understand the concept of an abstract data type (ADT). Understand the concept of a linear list as well as its operations.
Week 10 - Friday.  What did we talk about last time?  Graph representations  Adjacency matrix  Adjacency lists  Depth first search.
CISC220 Fall 2009 James Atlas Dec 04: Hashing and Maps K+W Chapter 9.
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
CISC220 Spring 2010 James Atlas Lecture 07: Big O Notation.
Week 13 - Wednesday.  What did we talk about last time?  NP-completeness.
 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.
BITS Pilani Pilani Campus Data Structure and Algorithms Design Dr. Maheswari Karthikeyan Lecture1.
Final Exam Review COP4530.
Final Exam Review CS 3358.
Chapter 12 – Data Structures
Lecture 06: Linked Lists (2), Big O Notation
DATA STRUCTURES AND OBJECT ORIENTED PROGRAMMING IN C++
Hashing Exercises.
Cse 373 April 26th – Exam Review.
November 1st – Exam Review
Binary Trees, Binary Search Trees
Chapter 22 : Binary Trees, AVL Trees, and Priority Queues
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.
CSE 326: Data Structures: Midterm Review
Final Exam Review COP4530.
ITEC 2620M Introduction to Data Structures
Binary Trees, Binary Search Trees
Final Review Dr. Yingwu Zhu.
DATA STRUCTURE.
EE 312 Final Exam Review.
Binary Trees, Binary Search Trees
Presentation transcript:

CISC220 Fall 2009 James Atlas Dec 07: Final Exam Review

Announcements Final Exam (comprehensive) Friday Dec 11 7:00PM-9:00PM WHL007 Course Evaluations

Topics Pointers/Memory Management Arrays Linked Lists Analysis/ Big O notation Stacks Queues Trees Sorting Heaps Graphs Hashing NP-completeness

NP-Completeness A class of problems having two properties: Any given solution to the problem can be verified quickly (in polynomial time) – the set of problems with this property is called NP (nondeterministic polynomial time). If the problem can be solved quickly (in polynomial time), then so can every problem in NP.

Pointers An address refers to a particular memory location. In other words, it points to a memory location. Pointer: A variable that contains the address of a variable. z x y Location (address) name 104

Pointers How to initialize a pointer: – can initialize to NULL (i.e. not currently pointing to anything) – & operator: get address of a variable int *x; x?y? int y = 3; x?y3 x = &y; xy3

Pointers How to get the value that is pointed to? – * “ dereference operator”: get value pointed to * x returns 3 How to change the variable pointed to? – Use dereference * operator to left of = xy5 *x = 5 ; xy3

Memory Allocation Two ways: –On the stack –On the heap

Memory Allocation (Stack) int main(void) { int x(5); if (x > 3) { int y(6); cout << (x + y) << endl; }

Memory Allocation (Heap) int main(void) { int *x = new int(5); if (*x > 3) { int *y = new int(6); cout << (*x + *y) << endl; }

Memory De-allocation (Heap) int main(void) { int *x = new int(5); if (*x > 3) { int *y = new int(6); cout << (*x + *y) << endl; delete y; } delete x; }

Array Allocation (Heap) int main(void) { int *x = new int[5]; *x = 5; if (*x > 3) { int *y = new int(6); cout << (*x + *y) << endl; delete y; } delete [] x; }

Arrays void ArrayTest() { int scores[100]; // operate on the elements of the // scores array... scores[0] = 1; scores[1] = 2; scores[2] = 3; }

Abstract Data Types (ADTs) Combination of data and operations Encapsulates implementation details Provides an interface for usage

Collection add(x) remove(index) member(x) size() first()

Single Linked List

Creating a Link

Efficiency of Algorithms An operation for an Absract Data Type can be thought of as a “problem” An algorithm solves the “problem” –A series of steps –Each step has a cost Time Space –Efficiency is a measurement of this cost

Example 2.14/2.16

Big-O notation Describes the relationship between input size and execution time If we double the number of inputs, n, and the execution time is approximately doubled –Linear growth rate –Growth rate has an order of n –O(n)

Let’s count individual instructions for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { Simple Statement } for (int k = 0; k < n; k++) { Simple Statement 1 Simple Statement 2 Simple Statement 3 Simple Statement 4 Simple Statement 5 } Simple Statement 1 Simple Statement 2... Simple Statement 25

Let’s count individual instructions for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { Simple Statement } n 2 executions

Let’s count individual instructions for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { Simple Statement } for (int k = 0; k < n; k++) { Simple Statement 1 Simple Statement 2 Simple Statement 3 Simple Statement 4 Simple Statement 5 } n executions, 5 statements per = 5n

Let’s count individual instructions for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { Simple Statement } for (int k = 0; k < n; k++) { Simple Statement 1 Simple Statement 2 Simple Statement 3 Simple Statement 4 Simple Statement 5 } Simple Statement 1 Simple Statement 2... Simple Statement 25 1 execution, 25 statements = 25

Let’s count individual instructions for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { Simple Statement } for (int k = 0; k < n; k++) { Simple Statement 1 Simple Statement 2 Simple Statement 3 Simple Statement 4 Simple Statement 5 } Simple Statement 1 Simple Statement 2... Simple Statement 25 T(n) = total execution time as a function of n T(n) = n 2 + 5n + 25

Formal Big-O Definition T(n) = n 2 + 5n + 25 T(n) = O(f(n)) means that there exists a function, f(n), that for sufficiently large n and some constant c: cf(n)  T(n)

n n + 25 vs. 3n 2

Common Big-O Runtimes Constant -- O(1) Logarithmic -- O(log n) Fractional -- O(sqrt n) Linear -- O(n) Log-Linear-- O(n log n) Quadratic -- O(n 2 ) Cubic -- O(n 3 ) Exponential -- O(2 n ) Factorial -- O(n!)

Various Runtimes

Calculating Big-O 1.T(n) = 6n 4 − 2n T(n) = 9 log n + 5 (log n) 3 + 3n 2 + 2n 3 3.T(n) = 3n 2 + O(log n) + O(n) + O(n log n)

Calculating Big-O 4.Binary Search on an array: T(n) = T(n/2) + O(1) 5.T(1) = 2 T(n) = 2T(n - 1) + O(1) for n>1 6.T(1) = 1 T(n) = 2T(n/2) + O(1) for n>1

Stacks

Stack ADT peek() - returns the top element of the stack without removing it pop() - removes (and returns) the top element of the stack push(x) - pushes x onto the top of the stack LIFO structure - last in, first out

Queue

Queue ADT front() - returns the front element of the queue without removing it dequeue() - removes (and returns) the front element of the queue queue(x) - queues x at the end of the queue FIFO structure - first in, first out

Priority Queue ADT front() - returns the highest priority element of the queue without removing it dequeue() - removes (and returns) the highest priority element of the queue queue(x, int) - queues x at the given priority in the queue FIFO structure??

Trees Nonlinear data structure

Tree Terminology root, leaf parent, child, sibling subtree external, internal node ancestor, descendant depth, height

Binary Trees Each node has 0, 1, or 2 children

Traversal Exercise Find the: preorder inorder postorder level-order

Ordered Binary Tree (Example)

Inserting to an Ordered Binary Tree

Removing from an Ordered Binary Tree

Worst Case Scenario?

AVL Balanced Tree (automatic)

Balancing a Binary Tree

Sorting Bubble Sort: K+W Selection Sort: K+W Insertion Sort: K+W (Self-Balancing) Binary Tree Sort: tree sort Quick Sort: K+W Merge Sort: K+W MSD Radix Sort: sort

Sorting Analysis NameWorst CaseNotes Bubble SortO(n 2 ) Selection SortO(n 2 ) Insertion SortO(n 2 ) Quick SortO(n 2 )O(n log n) average Binary Tree SortO(n log n) Merge SortO(n log n) Radix SortO(n k) k is number of bits required to represent data Counting SortO(n + r) r is the range of possible data values. Used in radix sort.

Binary Max Heap

Heap Insert (example) 2 1 3

Heap Delete (example) 12

Binary Heap Operation Running Times OperationBinary findMaxO(1) deleteMaxO(log n) insertO(log n) decreaseKeyO(log n) mergeO(n)

Binary Heap Implementations Array

Graph Representations How do we represent a graph? A B E D C

List Structures V = {A, B, C, D, E} E = {{A, B}, {A, D}, {C, E}, {D, E}} Incidence List –E = {{A, B}, {A, D}, {C, E}, {D, E}} Adjacency List –L = [A={B, D}, B={A}, C={E}, D={A, E}, E={C, D}] A B E D C

Matrix Structures V = {A, B, C, D, E} E = {{A, B}, {A, D}, {C, E}, {D, E}} Adjacency Matrix A B E D C ABCDE A11010 B11000 C00101 D10011 E00111

Minimum Spanning Tree Example

Hash Tables Goal: access item given its key (not its position) –we wish to avoid much searching Hash tables provide this capability –Constant time in the average case!O(1) –Linear time in the worst caseO(n) Searching an array: O(n) Searching BST: O(log n)

How could we resolve collisions? Goal is to still be able to insert, delete, and search based on key Smith Hall Newark, DE n-1 Array table Hash function mod(10000) ?

Performance of Hash Tables (2)

Performance of Hash Tables (3) Hash table: –Insert: average O(1) –Search: average O(1) Sorted array: –Insert: average O(n) –Search: average O(log n) Binary Search Tree: –Insert: average O(log n) –Search: average O(log n) But balanced trees can guarantee worst case O(log n)