57
Problem Complexity Review

Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Embed Size (px)

Citation preview

Page 1: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Problem ComplexityReview

Page 2: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Problem Complexity

Page 3: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Online Survey

The Spring term course/instructor opinion survey will be available during the period Monday, April 17th through Friday, April 28th from 6am to 11:59pm each day:

http://www.coursesurvey.gatech.edu

LB

Page 4: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Final Exam Schedule

• CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M.

• Exam Scheduled for 8:00 Friday May 5, 2000• Physics L1

LB

Page 5: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Final Exam Schedule

• CS1311 Sections E/F Tuesday/Thursday 2:00 P.M.

• Exam Scheduled for 2:50 Wednesday May 3, 2000• Physics L1

LB

Page 6: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Relations between Problems, Algorithms, and Programs

Problem

Algorithm Algorithm

Program ProgramProgram Program

. . . .

. . . . . . . .

Page 7: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Cost and Complexity

• Algorithm complexity can be expressed in Order notation, e.g. “at what rate does work grow with N?”:– O(1) Constant– O(logN) Sub-linear– O(N) Linear– O(NlogN) Nearly linear– O(N2) Quadratic– O(XN) Exponential

• But, for a given problem, how do we know if a better algorithm is possible?

Page 8: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

The Problem of Sorting

For example, in discussing the problem of sorting:

• Two algorithms to solve:– Bubblesort – O(N2)– Mergesort – O(N Log N)

• Can we do better than O(N Log N)?

Page 9: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Algorithm vs. Problem Complexity

• Algorithmic complexity is defined by analysis of an algorithm

• Problem complexity is defined by– An upper bound – defined by an

algorithm– A lower bound – defined by a proof

Page 10: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

The Upper Bound

• Defined by an algorithm• Defines that we know we can do

at least this good• Perhaps we can do better• Lowered by a better algorithm

– “For problem X, the best algorithm was O(N3), but my new algorithm is O(N2).”

Page 11: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

The Lower Bound

• Defined by a proof• Defines that we know we can do no

better than this• It may be worse• Raised by a better proof

– “For problem X, the strongest proof showed that it required O(N), but my new, stronger proof shows that it requires at least O(N2).”

Page 12: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Upper and Lower Bounds

• The Upper bound is the best algorithmic solution that has been found for a problem.– “What’s the best that we know we can do?”

• The Lower bound is the best solution that is theoretically possible.– “What cost can we prove is necessary?”

Page 13: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Changing the Bounds

Upper bound Lowered by betteralgorithm

Lower bound Raised by betterproof

Page 14: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Open Problems

The upper and lower bounds differ.

Upper bound Lowered by betteralgorithm

Lower bound Raised by betterproof

Unknown

Page 15: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Closed Problems

The upper and lower bounds are identical.

Upper bound

Lower bound

Page 16: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Closed Problems

• Better algorithms are still possible

• Better algorithms will not provide an improvement detectable by “Big O”

• Better algorithms can improve the constant costs hidden in “Big O” characterizations

Page 17: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Tractable vs. Intractable

Problems are tractable if the upper and lower bounds have only polynomial factors.– O (log N)– O (N)

– O (NK) where K is a constant

Problems are intractable if the upper and lower bounds have an exponential factor.– O (N!)

– O (NN)

– O (2N)

Page 18: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Problems that “Cross the Line”

• The upper bound implies intractable • The lower bound implies a tractable• Could go either way…

Next time!!!

Page 19: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Terminology

• Polynomial algorithms are reasonable• Polynomial problems are tractable

• Exponential algorithms are unreasonable• Exponential problems are intractable

Page 20: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Terminology

Tractable

Intractable

Reasonable

Unreasonable

Problems Algorithms

Polynomial

Exponential

Page 21: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Questions?

Page 22: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Review

• The Algorithmic Model– Algorithm defined– Properties of good algorithms– How to describe algorithms– Relating problems to algorithms to programs

(hierarchy needed)

Page 23: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Review

• View of programming languages/algorithms

– Data vs. instructions

– Built-in vs. user-defined

– Complex vs. atomic

• Data

– Type vs. variable (Declaration and Initialization of variables)

– The 4 atomic built-in types (Num, Characters, Booleans, Pointers)

– The complex built in type String

Page 24: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Review

• Operations – Assignment– Arithmetic

• +, -, x, /, div, mod• Precedence rules• Using parenthesis to modify precedence

– Input and output• Print• Read

Page 25: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Review

• Conditionals– Purpose & defined– Relational operators (<, >, =, <>, >=, <=)– Boolean operators (AND, OR, NOT)– Boolean expressions (Simple & Complex)– Control flow of the if-then-else statement– Elseif as shorthand

• Writing an algorithm (how to begin)

Page 26: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Review

• Program maintenance• Software Engineering facts about program

cost• Documentation• Benefits of Constants

Page 27: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Review

• Procedural Abstraction• Why modularity (Benefits)

• Need for interface• Scope of variables• Contract (Pre, post, and purpose statements

for every module)• Information flow – in, out, in/out• Parameters intro (In, out, in/out)• Types of modules

Page 28: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Review

• Procedure• Rules when to use a procedure• Declaration• Function• Rules when to use a function• Declaration• Returning values via the “returns”

Page 29: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Review

• Module invocation

• Parameters

• Formal vs. actual

• Parameter matching

• How parameters work (In, Out, & In/out)

• Tracing

• Activation stack

• Frames

• Rules of parameter matching (In, Out, & In/out)

• Examples

Page 30: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Review

• Recursion (Intro)

• Purpose – repetition

• Characteristics – calls itself, terminating condition, move closer

• 2 forms – final action or not

• Examples

• Tracing recursive modules

• Recursion (Advanced)

• Mutual recursion

• Design by Contract

Page 31: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Review

• Data Abstraction– Records

• Declaring records• Creating variables of record type• Accessing fields of a record variable (the ‘.’

operator)• Avoid anonymous types• Combining records (records inside records)

Page 32: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Review

• Static vs. dynamic memory/data

• Pointers

• Simple example of ptr toa num

• Following the pointer via the ‘^’ operator

• Dynamic data structures

• Linked Lists

• Defined/properties

• Proper Record declaration

• Accessing information in a linked list via pointers

Page 33: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Review

• Linked Lists (continued)– Adding nodes– Simple – no recursion (To front)– Insertion recursive method– To end– In middle (when sorted)– Deleting nodes

• Simple - no recursion (From front)• Deletion recursive method

Page 34: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Review

• Doubly-linked lists– Defined– Example methods (simple insertion)

• Stack– Defined/properties– Push– Pop– Tracing changes (example of algorithm using

push & pop)

Page 35: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Review

• Queue

• Defined/properties

• Enqueue

• Dequeue

• Tracing changes (example of algorithm using enqueue and dequeue)

• Trees

• Defined/properties

• Binary trees (Record declaration)

• Binary search trees

Page 36: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Review

• Trees (Continued)• Recursive insertion in BST• Deleting from BST (conceptually)

• Graphs• Defined/properties• Record definition

Page 37: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Review

• Static data structures• Arrays

• Defined• Need of constants• Accessing elements via the index• Multi-dimensional arrays (Declaring and

accessing)

Page 38: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Review

• Iteration• Defined, use for repetition• How looping works• Loop• Endloop• Exitif

• Combined types• Examples – array of lists, list of array, tree of

lists, etc.

Page 39: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Review

• Methods of Accessing Data Structures• Traversal

• Lists• Recursive on lists• Iterative on lists

• Trees• In-order• Pre-order• Post-order• Miscellaneous Traversals

• (Rt before Left)

Page 40: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Review

• Breadth-first vs. depth- first• Arrays

• Iterative on arrays• Recursive on arrays

• Search• Linear

• Recursive on lists• Traversal-search on binary tree (not BST)• Linear, iterative search on array

Page 41: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Review

• Binary, recursive search on BST• Binary, iterative search on sorted array

• Sort• Bubble sort• Merge sort

Page 42: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Review

• Conversion• Defined• Helper module advantages• List to Tree• Array to List• Tree to List

Page 43: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Review

• Optimization• Defined & example problems• Greedy algorithms• Dynamic programming

• Minimum spanning trees• Defined• Prim’s algorithm• Kruskal’s algorithm

Page 44: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Review

• Object-Oriented• Defined• Behavioral abstraction (Defined & Advantages)• Encapsulation• Abstract data types• Queue & stack examples• Need for formal programmatic construct

Page 45: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Review

• Classes• Defined• Advantages• Structure - public & protected• Role for each• Benefits• Examples• Scope of attributes in protected

Page 46: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Review

• Initialize (not built-in, but useful)• Using classes

• Declaring objects• Objects vs. classes• Accessing methods via the ‘.’ Operator

• Example Classes• Airplane example• Queue example• Pile example

Page 47: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Review• Generic classes

• Defined & benefits• Search and replace type then use a “magic”

keyword• Syntax• Defining objects in algorithm

• Use cases• Clone vs. copy• Inheritance

• Defined & benefits• Extension • Redefinition

Page 48: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Review

• Resolving method reference ambiguity• Class hierarchies• Deferred class & methods

• Polymorphism• Defined & benefits• Simple assignment example• Complex collection example

• Pure OO

Page 49: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Review

• Algorithm Cost and Complexity• Measuring performance (space & time)

• Measuring work (counting instructions)• Best, worst, average

• Measuring work growth• O() notation• Complex O() rules (drop constants, keep

dominant term, etc.)

Page 50: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Review

• Analysis– Linear vs. binary search– Traversals– Data structures

• Compare on traversals, search, & insert– Bubblesort vs. mergesort

• Exponential growth– Hanoi, Monkey tiling, wise peasant

• Reasonable vs. unreasonable• Using O() analysis in data structure design of

solution

Page 51: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Review

• Systems– Concurrency vs. sequential processing (what

we’ve done so far)• Defined & advantages• Multiprogramming• Multiprocessing• Multitasking• Distributed systems

Page 52: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Review

• Issues– Protection, mutual exclusion– Starvation, fairness– Deadlock– Time– Synchronization– Overhead costs (context switch)

Page 53: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Review

• Parallelism– Defined & advantages– Pipeline processing– Product complexity

• Dependencies• Precedence

– Dependence Graphs– Precedence Graphs

Page 54: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Review

• Problem Complexity– Defined– Problems vs. algorithms– Upper bound– Lower bound– Open vs. closed– Tractable vs. intractable

Page 55: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Review

• NP-Complete– Defined– Examples– Certificates– Oracles– Deterministic vs. nondeterministic

• Decidable vs. undecidable• Highly vs. partially

Page 56: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,

Questions?

Review slides available at

http://prism.gatech.edu/~wl48

Double U Ell

Page 57: Problem Complexity Review. Problem Complexity Online Survey The Spring term course/instructor opinion survey will be available during the period Monday,