TDDB56 DALGOPT-D TDDB57 DALG-C – Lecture 1 Jan Maluszynski - HT 20061.1 TDDB56 – DALGOPT-D Algorithms and optimization TDDB57 – DALG-C Data Structures.

Slides:



Advertisements
Similar presentations
Analysis of Algorithms
Advertisements

Analysis of Algorithms
Estimating Running Time Algorithm arrayMax executes 3n  1 primitive operations in the worst case Define a Time taken by the fastest primitive operation.
CSC401 – Analysis of Algorithms Lecture Notes 1 Introduction
© 2004 Goodrich, Tamassia 1 Lecture 01 Algorithm Analysis Topics Basic concepts Theoretical Analysis Concept of big-oh Choose lower order algorithms Relatives.
Analysis of Algorithms Algorithm Input Output. Analysis of Algorithms2 Outline and Reading Running time (§1.1) Pseudo-code (§1.1) Counting primitive operations.
TDDB56 DALGOPT-D TDDB57 DALG-C Lecture 2 Jan Maluszynski - HT TDDB56 – DALGOPT-D Algorithms and optimization TDDB57 – DALG-C Data Structures and.
DAST, Spring © L. Joskowicz 1 Data Structures – LECTURE 1 Introduction Motivation: algorithms and abstract data types Easy problems, hard problems.
Analysis of Algorithms1 CS5302 Data Structures and Algorithms Lecturer: Lusheng Wang Office: Y6416 Phone:
TDDB57 DALG-C, DALG Exam Requirements Jan Maluszynski - HT 2006DALG-C.1 TDDB57 – DALG-C Examination Requirements.
Analysis of Algorithms (Chapter 4)
Analysis of Algorithms1 Estimate the running time Estimate the memory space required. Time and space depend on the input size.
Analysis of Algorithms
Fall 2006CSC311: Data Structures1 Chapter 4 Analysis Tools Objectives –Experiment analysis of algorithms and limitations –Theoretical Analysis of algorithms.
CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Lecture 8+9 Time complexity 1 Jan Maluszynski, IDA, 2007
TTIT33 Algorithms and Optimization – Lecture 1 Jan Maluszynski - HT Analysis of Algorithms Introductory Example Principles of Analysis Big-Oh notation.
The Seven Functions. Analysis of Algorithms. Simple Justification Techniques. 2 CPSC 3200 University of Tennessee at Chattanooga – Summer Goodrich,
Analysis of Algorithms1 CS5302 Data Structures and Algorithms Lecturer: Lusheng Wang Office: Y6416 Phone:
PSU CS 311 – Algorithm Design and Analysis Dr. Mohamed Tounsi 1 CS 311 Design and Algorithms Analysis Dr. Mohamed Tounsi
DAST, Spring © L. Joskowicz 1 Data Structures – LECTURE 1 Introduction Motivation: algorithms and abstract data types Easy problems, hard problems.
Analysis of Performance
CS2210 Data Structures and Algorithms Lecture 2:
Analysis of Algorithms Algorithm Input Output © 2014 Goodrich, Tamassia, Goldwasser1Analysis of Algorithms Presentation for use with the textbook Data.
Analysis of Algorithms Lecture 2
Analysis of Algorithms
Program Performance & Asymptotic Notations CSE, POSTECH.
Analysis Tools Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University.
Analysis of Algorithms
Analysis of Algorithms1 The Goal of the Course Design “good” data structures and algorithms Data structure is a systematic way of organizing and accessing.
Mathematics Review and Asymptotic Notation
Algorithm Input Output An algorithm is a step-by-step procedure for solving a problem in a finite amount of time. Chapter 4. Algorithm Analysis (complexity)
1 Computer Algorithms Lecture 3 Asymptotic Notation Some of these slides are courtesy of D. Plaisted, UNC and M. Nicolescu, UNR.
Data Structures Lecture 8 Fang Yu Department of Management Information Systems National Chengchi University Fall 2010.
CS 3343: Analysis of Algorithms
Analysis of Algorithms Algorithm Input Output Last Update: Aug 21, 2014 EECS2011: Analysis of Algorithms1.
Analysis of Algorithms
Algorithms and their Applications CS2004 ( ) Dr Stephen Swift 4.1 Time Complexity and Asymptotic Notation.
1 Dr. J. Michael Moore Data Structures and Algorithms CSCE 221 Adapted from slides provided with the textbook, Nancy Amato, and Scott Schaefer.
Algorithm Analysis CS 400/600 – Data Structures. Algorithm Analysis2 Abstract Data Types Abstract Data Type (ADT): a definition for a data type solely.
Analysis of Algorithms Algorithm Input Output An algorithm is a step-by-step procedure for solving a problem in a finite amount of time.
Introduction to Analysis of Algorithms CS342 S2004.
Analysis of Algorithms Algorithm Input Output © 2010 Goodrich, Tamassia1Analysis of Algorithms.
Data Structures and Algorithms IT12112
Analysis of algorithms. What are we going to learn? Need to say that some algorithms are “better” than others Criteria for evaluation Structure of programs.
1/6/20161 CS 3343: Analysis of Algorithms Lecture 2: Asymptotic Notations.
TTIT33 Algorithms and Optimization – Organisation Jan Maluszynski - HT 2006O.1 TTIT33 – Tema Algorithms and Optimization Organization issues Jan Maluszynski,
DATA STRUCTURES (CS212D) Overview & Review Instructor Information 2  Instructor Information:  Dr. Radwa El Shawi  Room: 
BITS Pilani Pilani Campus Data Structure and Algorithms Design Dr. Maheswari Karthikeyan Lecture1.
Announcement We will have a 10 minutes Quiz on Feb. 4 at the end of the lecture. The quiz is about Big O notation. The weight of this quiz is 3% (please.
1 COMP9024: Data Structures and Algorithms Week Two: Analysis of Algorithms Hui Wu Session 2, 2014
Analysis of Algorithms Algorithm Input Output © 2014 Goodrich, Tamassia, Goldwasser1Analysis of Algorithms Presentation for use with the textbook Data.
Analysis of Algorithms
Analysis of Algorithms
COMP9024: Data Structures and Algorithms
COMP9024: Data Structures and Algorithms
Analysis of Algorithms
COMP9024: Data Structures and Algorithms
Analysis of Algorithms
CS 3343: Analysis of Algorithms
Analysis of Algorithms
Analysis of Algorithms
Analysis of Algorithms
Analysis of Algorithms
Analysis of Algorithms
Analysis of Algorithms
Analysis of Algorithms
Analysis of Algorithms
Analysis of Algorithms
Analysis of Algorithms
Presentation transcript:

TDDB56 DALGOPT-D TDDB57 DALG-C – Lecture 1 Jan Maluszynski - HT TDDB56 – DALGOPT-D Algorithms and optimization TDDB57 – DALG-C Data Structures and Algorithms Jan Maluszynski, IDA, ida.liu.se

TDDB56 DALGOPT-D TDDB57 DALG-C – Lecture 1 Jan Maluszynski - HT Structure: TDDB56 has two parts: DALG (data structures and algorithms) – IDA OPT (optimization) – MAI They are given in two periods : ht1/2006:11 Fö DALG, 5 Le DALG, 4 Labs DALG ht2/2006:10 Fö OPT, 10 Le OPT, 3 Labs OPT TDDB57 goes ht1/2006 and consists of : DALG-part of TDDB56 Additional classes: 2 Fö, 1 Le, 1 Lab

TDDB56 DALGOPT-D TDDB57 DALG-C – Lecture 1 Jan Maluszynski - HT Staff 2006: DALG-part: Kursledare, examinator, DALG föreläsningar: Jan Maluszynski epost: Kursassistent, lektionsgrupp, labgrupper: Magnus Wahlström epost: Assistent, lektionsgrupp, labgrupper: David Broman epost: Assistent, lektionsgrupp, labgrupper: Vladislav Jahundovicsd epost: Kurssekreterare: Madeleine Hager epost: OPT-part: Ansvarig : Kaj Holmberg epost: Kursassistent: to be announced If mailing: write TDDB56 or TDDB57 in the subject field!

TDDB56 DALGOPT-D TDDB57 DALG-C – Lecture 1 Jan Maluszynski - HT Literature: DALG TDDB56/TDDB57 (data structures and algorithms) –Michael T. Goodrich, Roberto Tamassia: Data Structures and Algorithms in Java (4th edition), Wiley 2006 –Exercises for lektionerna (.pdf respective homepages) –Labkompendium (.pdf respective homepages) notice actual references at respective homepages OPT TDDB56 (optimization) –Kaj Holmberg: Kombinatorisk optimering med linjärprogrammering (kompendium 2006), Bokakademien –Labkompendium (.pdf homepage/labs)

TDDB56 DALGOPT-D TDDB57 DALG-C – Lecture 1 Jan Maluszynski - HT Examination TDDB56 Kontrollskrivning (KS) after p1 (not obligatory) 3 usual exams covering DALG and OPT: the first exam after p2 –you may skip DALG part ; –In this case KS result will be counted as DALG part result –KS result valid only 2006/07 TDDB57 3 usual exams covering whole TDDB57 material the first exam after p1

TDDB56 DALGOPT-D TDDB57 DALG-C – Lecture 1 Jan Maluszynski - HT Planning – Lectures Period 1 (prel): 1.Organisation, Objectives, Complexity, big-Oh-notation 2. Analysis of Algorithms 3.Simple Abstract Data Types : Stack, Queue, Array List,… 4.Hashing, Skip Lists 5.Binary Search Trees 6.AVL Trees, Multi-way search Trees 7.Priority Queues, Heaps 8.Sorting I 9.Sorting II, Selection 10.Union/Find, ADT Graph 11.Graph Search, Topological sorting 12.TDDB57 Graph algorithms I 13.TDDB57 Graph algorithms II Period 2 (prel): 1. Optimering - Intro, problemformulering, grafisk lösning. 2. Linjärprogrammeringens grunder 3. …Simplexmetoden Dualitet och känslighetsanalys 5. Grafteori, billigaste-uppspännande- trädproblemet,handelsresandeproble met, kinesiska brevbärarprobemet 6. Billigaste-vägproblem, dynamisk programmering 7. Flöden i nätverk 8. Heltals problem 9. Problemkomplexitet 10. Heuristiker, approximativa algoritmer

TDDB56 DALGOPT-D TDDB57 DALG-C – Lecture 1 Jan Maluszynski - HT Planning – Lektioner Lektioner, ”räknestuga” handledd problemlösning... Period 1: TDDB56/57 5 lektioner (see homepage) TDDB57 1 lektion – graph algorithms Period 2 : TDDB56 10 lektioner OPT

TDDB56 DALGOPT-D TDDB57 DALG-C – Lecture 1 Jan Maluszynski - HT Planning – Labs Period 1: Experimental evaluation of time complexity Hashing (Java) Binary Search Trees (Java) Quicksort (Java) TDDB57 only: Priority queues and Heapsort (Ada) Please register in week 34 through IDAs webReg Period 2 (TDDB56): Simplexmetoden: Övning och implementering. Flöden i nätverk: Modellering och lösning med programpaket Netlin. Lokaliseringsproblemet: Lösning med AMPL samt heuristik.

TDDB56 DALGOPT-D TDDB57 DALG-C – Lecture 1 Jan Maluszynski - HT DALGOPT – why it is important?

TDDB56 DALGOPT-D TDDB57 DALG-C – Lecture 1 Jan Maluszynski - HT DALG – basics: Abstract data types (ADTs) machine-independent, high-level description of data and operations on them e.g.: Dictionary, Stack, Queue, PriorityQueue, Set,... Data structures: logical organization of computer memory for storing data Algorithms: high-level description of concrete operations on data structures (to be cont.) ADT implemented by suitable data structures and algorithms Program: implements algorithms and data structures in some programming language

TDDB56 DALGOPT-D TDDB57 DALG-C – Lecture 1 Jan Maluszynski - HT Algorithm Concrete but machine- and language-independent specification of all necessary steps (simple operations on data) to compute a solution (output) from a given problem instance (input) Correctness – the computed output for any given input is as stated in the problem description Algorithm analysis – time and space consumption, scalability, efficiency, worst case, best case, average case, amortized analysis Algorithmic paradigms – commonly used problem solving strategies e.g., divide&conquer, dynamic programming, greedy strategy,...

TDDB56 DALGOPT-D TDDB57 DALG-C – Lecture 1 Jan Maluszynski - HT Solving algorithmic problems An algorithmic problem: Legal input-data Example: –results of an exam –A query: student’s name Expected output in our case: yes or no What kind of data, which operations on data?  ADT reuse standard ADTs (to be discussed here) How the data is represented in the computer ?  data structure How the operations are implemented ?  algorithm(s)

TDDB56 DALGOPT-D TDDB57 DALG-C – Lecture 1 Jan Maluszynski - HT Example cont. Step 1 – choose suitable Abstract Data Type  domain and operations: we choose ADT dictionary: Domain: K : linearly ordered set of keys here: students names with alphabetic order I : information (here: ”yes” or ”no”) Dictionary D : set of elements (key,info) Operations on a dictionary: LookUp(D,key) returns info …details not visible for the user

TDDB56 DALGOPT-D TDDB57 DALG-C – Lecture 1 Jan Maluszynski - HT Example cont. Step 2: Implement ADT as a data structure  choose representation of data in the computer memory  write algorithms for the operations of the ADT Re-use standard ADT’s: Step 2 can be omitted Step 3: Use the operations of the ADT to describe the algorithm solving the problem In our example LookUp(D,key) returns info Algorithms will be described in pseudocode

TDDB56 DALGOPT-D TDDB57 DALG-C – Lecture 1 Jan Maluszynski - HT Pseudocode in course book § Control flow –if … then … [else …] –while … do … –repeat … until … –for … do … –Indentation replaces braces Method declaration Algorithm method (arg [, arg…]) Input … Output … Structured Data array/table … We take some freedom Method call var.method (arg [, arg…]) Return value return expression Expressions  Assignment (like  in Java)  Equality testing (like  in Java) n 2 Superscripts and other mathematical formatting allowed

TDDB56 DALGOPT-D TDDB57 DALG-C – Lecture 1 Jan Maluszynski - HT The Random Access Machine (RAM) Model A CPU An potentially unbounded bank of memory cells, each of which can hold an arbitrary number or character Memory cells are numbered and accessing any cell in memory takes unit time. © 2004 Goodrich, Tamassia

TDDB56 DALGOPT-D TDDB57 DALG-C – Lecture 1 Jan Maluszynski - HT Example : Implementing ADT Dictionary with data structure array/table function LookUpTable ( table T[1..n], key k ):bool for i from 1 to n do if T [i] = k then return true if T [i] > k then return false return false...”scope” indicated by indentation!

TDDB56 DALGOPT-D TDDB57 DALG-C – Lecture 1 Jan Maluszynski - HT Different implementation

TDDB56 DALGOPT-D TDDB57 DALG-C – Lecture 1 Jan Maluszynski - HT Discussion ADT tells what to do: set of operations on data. To describe how to do that, we choose a data structure (representation in memory) construct algorithms for the ADT operations The same ADT can be implemented: with different data structures with different algorithms The algorithms depend on the data structure chosen. Choose the most efficient solution. What is efficiency?

TDDB56 DALGOPT-D TDDB57 DALG-C – Lecture 1 Jan Maluszynski - HT Analysis of Algorithms... What to analyze correctness termination efficiency-- yes! Time/space efficiency [Goodrich/Tamassia 4.2] growth rate worst case, expected case, amortized analysis techniques for iterative algorithms analysis techniques for recursive algorithms Mathematical background [Goodrich/Tamassia 4.1, 4.2.3]...not in TDDB56!

TDDB56 DALGOPT-D TDDB57 DALG-C – Lecture 1 Jan Maluszynski - HT Principles of Algorithm Analysis An algorithm should work for (input) data of any size. (Example LookUpTable: input size is the size of the table.) Show the resource (time/memory) used as an increasing function of input size. Focus on the worst case performance. Ignore constant factors analysis should be machine-independent; more powerful computers introduce speed-up by constant factors. Study scalability / asymptotic behaviour for large problem sizes: ignore lower-order terms, focus on dominating terms.

TDDB56 DALGOPT-D TDDB57 DALG-C – Lecture 1 Jan Maluszynski - HT How to compare time/space efficiency? Study execution time (or memory usage) as a function of the size of input data: When are they ”equally” effective? When is one better than the other?

TDDB56 DALGOPT-D TDDB57 DALG-C – Lecture 1 Jan Maluszynski - HT …comparison with simple math function: 1.84* µ sec = 2.14 * 10 8 days = 5845 centuries nlog 2 nnn log 2 nn2n2 2n2n * * 10 19

TDDB56 DALGOPT-D TDDB57 DALG-C – Lecture 1 Jan Maluszynski - HT Big-Oh Notation (§4.2.5) Given functions f(n),g(n) f(n) is O(g(n)) if there are positive constants c and n 0 such that f(n)  cg(n) for n  n 0 Example: 4n  2 is O(n) –4n  2  cn –(c  4) n  2 –n  2  (c  4) –Pick c  5 and n 0  2 But also n is O(4n+2)

TDDB56 DALGOPT-D TDDB57 DALG-C – Lecture 1 Jan Maluszynski - HT Big-Oh Example Example: the function n 2 is not O(n) –n 2  cn –n  c –The above inequality cannot be satisfied since c must be a constant © 2004 Goodrich, Tamassia

TDDB56 DALGOPT-D TDDB57 DALG-C – Lecture 1 Jan Maluszynski - HT Big-Oh and Growth Rate “ f(n) is O(g(n)) ” means the growth rate of f(n) is no more than the growth rate of g(n) We can use the big-Oh notation to rank functions according to their growth rate f(n) is O(g(n))g(n) is O(f(n)) g(n) grows moreYesNo f(n) grows moreNoYes Same growthYes © 2004 Goodrich, Tamassia

TDDB56 DALGOPT-D TDDB57 DALG-C – Lecture 1 Jan Maluszynski - HT Types of growth comparison: f, g growing functions from natural numbers to positive real numbers f is (in) O ( g) iff there exist c > 0, n 0  1 such that f(n )  c g(n) for all n  n 0 Intuition: Apart from constant factors, f grows at most as quickly as g f is (in)  ( g ) iff there exist c > 0, n 0  1 such that f ( n)  c g(n) for all n  n 0 Intuition: Apart from constant factors, f grows at least as quickly as g  is the converse of O, i.e. f is in  (g) iff g is in O(f)  f is (in)  (g) iff f(n)  O(g(n)) and g(n)  O(f(n)) Intuition: Apart from constant factors, f grows exactly as quickly as g

TDDB56 DALGOPT-D TDDB57 DALG-C – Lecture 1 Jan Maluszynski - HT Types of growth comparison:  (g),  (g), O ( g)..??

TDDB56 DALGOPT-D TDDB57 DALG-C – Lecture 1 Jan Maluszynski - HT Big-Oh Rules If is f(n) a polynomial of degree d, then f(n) is O(n d ), i.e., 1.Drop lower-order terms 2.Drop constant factors Use the smallest possible class of functions –Say “ 2n is O(n) ” instead of “ 2n is O(n 2 ) ” Use the simplest expression of the class –Say “ 3n  5 is O(n) ” instead of “ 3n  5 is O(3n) ” © 2004 Goodrich, Tamassia

TDDB56 DALGOPT-D TDDB57 DALG-C – Lecture 1 Jan Maluszynski - HT Examples: Prove or disprove... Asuming algorithm f has an execution time behaviour T(f) as listed below, e.g., T(f) = (n+1) 2...

TDDB56 DALGOPT-D TDDB57 DALG-C – Lecture 1 Jan Maluszynski - HT To check growth rate?