Introduction to Algorithms Jiafen Liu Sept. 2013.

Slides:



Advertisements
Similar presentations
Introduction to Algorithms 6.046J/18.401J
Advertisements

Introduction to Algorithms 6.046J/18.401J
Introduction to Algorithms 6.046J Lecture 1 Prof. Shafi Goldwasser Prof. Erik Demaine.
Analysis of Algorithms
Introduction to Algorithms Jiafen Liu Sept
Chapter 2. Getting Started. Outline Familiarize you with the to think about the design and analysis of algorithms Familiarize you with the framework to.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 5.
Spring 2015 Lecture 5: QuickSort & Selection
CS Section 600 CS Section 002 Dr. Angela Guercio Spring 2010.
CSC401 – Analysis of Algorithms Lecture Notes 1 Introduction
CS421 - Course Information Website Syllabus Schedule The Book:
CS3381 Des & Anal of Alg ( SemA) City Univ of HK / Dept of CS / Helena Wong 2. Analysis of Algorithms - 1 Analysis.
Algorithm Analysis CS 201 Fundamental Structures of Computer Science.
Analysis of Algorithms CS 477/677
CS Main Questions Given that the computer is the Great Symbol Manipulator, there are three main questions in the field of computer science: What kinds.
Analysis of Algorithms 7/2/2015CS202 - Fundamentals of Computer Science II1.
Algorithms. Introduction The methods of algorithm design form one of the core practical technologies of computer science. The main aim of this lecture.
Analysis of Performance
Introduction to Algorithms Jiafen Liu Sept
Efficient Algorithms Quicksort. Quicksort A common algorithm for sorting non-sorted arrays. Worst-case running time is O(n 2 ), which is actually the.
CSC 201 Analysis and Design of Algorithms Lecture 03: Introduction to a CSC 201 Analysis and Design of Algorithms Lecture 03: Introduction to a lgorithms.
Week 2 CS 361: Advanced Data Structures and Algorithms
Mon 29 Sep 2014Lecture 4 1. Running Time Performance analysis Techniques until now: Experimental Cost models counting execution of operations or lines.
1 Chapter 24 Developing Efficient Algorithms. 2 Executing Time Suppose two algorithms perform the same task such as search (linear search vs. binary search)
{ CS203 Lecture 7 John Hurley Cal State LA. 2 Execution Time Suppose two algorithms perform the same task such as search (linear search vs. binary search)
Lecture 2 Computational Complexity
Algorithm Efficiency CS 110: Data Structures and Algorithms First Semester,
1 Computer Algorithms Lecture 3 Asymptotic Notation Some of these slides are courtesy of D. Plaisted, UNC and M. Nicolescu, UNR.
CS 3343: Analysis of Algorithms
Algorithm Analysis An algorithm is a clearly specified set of simple instructions to be followed to solve a problem. Three questions for algorithm analysis.
Analysis of Algorithms
Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 1 Prof. Charles E. Leiserson.
Algorithms Lecture 1. Introduction The methods of algorithm design form one of the core practical technologies of computer science. The main aim of this.
Introduction to Algorithms Lecture 1. Introduction The methods of algorithm design form one of the core practical technologies of computer science. The.
Lecture 2 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
CS 221 Analysis of Algorithms Instructor: Don McLaughlin.
Introduction to Algorithms Jiafen Liu Sept
CMPT 438 Algorithms. Why Study Algorithms? Necessary in any computer programming problem ▫Improve algorithm efficiency: run faster, process more data,
Analysis of Algorithms CS 477/677
A Lecture /24/2015 COSC3101A: Design and Analysis of Algorithms Tianying Ji Lecture 1.
Introduction to Algorithms Jiafen Liu Sept
1Computer Sciences Department. Book: Introduction to Algorithms, by: Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest Clifford Stein Electronic:
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 Algorithms1 O-notation (upper bound) Asymptotic running times of algorithms are usually defined by functions whose domain are N={0, 1, 2, …}
Algorithm Analysis Part of slides are borrowed from UST.
1/6/20161 CS 3343: Analysis of Algorithms Lecture 2: Asymptotic Notations.
Midterm Review 1. Midterm Exam Thursday, October 15 in classroom 75 minutes Exam structure: –TRUE/FALSE questions –short questions on the topics discussed.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
Introduction to Algorithms (2 nd edition) by Cormen, Leiserson, Rivest & Stein Chapter 2: Getting Started.
E.G.M. PetrakisAlgorithm Analysis1  Algorithms that are equally correct can vary in their utilization of computational resources  time and memory  a.
Algorithms A well-defined computational procedure that takes some value as input and produces some value as output. (Also, a sequence of computational.
1 Ch. 2: Getting Started. 2 About this lecture Study a few simple algorithms for sorting – Insertion Sort – Selection Sort (Exercise) – Merge Sort Show.
Lecture 2 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
2IL50 Data Structures Spring 2016 Lecture 2: Analysis of Algorithms.
Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 1 Prof. Charles E. Leiserson.
Big O David Kauchak cs302 Spring Administrative Assignment 1: how’d it go? Assignment 2: out soon… Lab code.
BITS Pilani Pilani Campus Data Structure and Algorithms Design Dr. Maheswari Karthikeyan Lecture1.
Chapter 15 Running Time Analysis. Topics Orders of Magnitude and Big-Oh Notation Running Time Analysis of Algorithms –Counting Statements –Evaluating.
CSCI 6212 Design and Analysis of Algorithms Which algorithm is better ? Dr. Juman Byun The George Washington University Please drop this course if you.
Lecture 2 Algorithm Analysis
CMPT 438 Algorithms.
CS 3343: Analysis of Algorithms
CS 583 Fall 2006 Analysis of Algorithms
CS 3343: Analysis of Algorithms
CS 3343: Analysis of Algorithms
Foundations II: Data Structures and Algorithms
CS200: Algorithms Analysis
David Kauchak cs161 Summer 2009
Algorithms Presented By:- Mr. Anup Ashok Shinde BBA (C.A) Dept.
Presentation transcript:

Introduction to Algorithms Jiafen Liu Sept. 2013

About me Teacher : Liu Jiafen Mail: Research Interest: –Information security –Formal Method and Verification of Correctness –Data Mining and Business Intelligence –Development of soft under iOS Homepage: – 09/24/ html

Now it’s your turn Please introduce yourself –Name –Age –Graduated School –Specialty and Interest Background Investigation Have you studied data structure and other prerequisite courses of CS? Have you programmed in practice before?

About the Course Site: – go.htmlLecture –Notes can be found here. Related Resources can also be found on you can also watch lectures online No Textbook

About the Course 16 weeks (the last 2 is reserved for exam) Site: Tongbo Building 206 Time: Can we choose another proper time? –Tuesday afternoon ( 5-7 or 6-8 ) ? –Tuesday night ( ) ? –Thursday night ( ) –Or we have to split into 2 period(first 2 in classroom, and last 1 on computers)?

Grading 20%Attendance 50%Performance –1 presentation at least (10%) –assignments (30%) 30% Final paper

Course Objectives What is an algorithm? What’s the difference between algorithm and program? Why we need this course? How to evaluate a algorithm? How can we design a good algorithm? How to make an algorithm implemented?

What is an algorithm? Algorithm is a problem-solving method or process. It helps us to understand scalability. Algorithm satisfy the following properties: –Input –Output –Unambiguous –Finite –Feasible

Algorithm and Program Program is an implementation of algorithm using a programming language. Algorithm design takes the most important place in Software Engineering. Programmer VS Coder? How to become an excellent programmer?

What is important for a program? correctness functionality maintainablity robustness simplicity user- friendliness Performance scalability

Why we need performance? currencyPerformance is the currency of computing. Example: C family VS Java This course makes theoretical study of computer program performance and resource usage. –How to evaluate an algorithm? –How can we design a good algorithm? –How to make an algorithm implemented?

The problem of sorting InputInput: sequence 〈 a 1, a 2, …, a n 〉 of numbers. OutputOutput: permutation 〈 a 1 ', a 2 ', …, a n ' 〉 such that a 1 ' ≤ a 2 ' ≤…≤ a n '. Example: Input : Output: How can we do that? –Recall the process of playing cards.

Insertion sort

Insertion sort

Insertion sort

Insertion sort

Insertion sort

Insertion sort Done!

Insertion sort

Running time The running time depends on the input: an already sorted sequence is easier to sort. Since short sequences are easier to sort than long ones, we will parameterize the running time by the size of the input.

Kinds of analyses Worst-case: (usually) –T(n) =maximum time of algorithm on any input of size n. Average-case: (sometimes) –T(n) =expected time of algorithm over all inputs of size n. –Need assumption of statistical distribution of inputs. Best-case: (bogus) –Cheat with a slow algorithm that works fast on some input.

Machine-independent time Generally, we seek upper bounds on the running time, Why? –Because everybody likes a guarantee. What is insertion sort’s worst-case time? It depends on the speed of our computer: –relative speed (on the same machine) –absolute speed (on different machines)

Big Idea Asymptotic Analysis Ignore machine-dependent constants. growthLook at growth of T(n) as n→∞.

Θ-notation Math: Θ(g(n)) = { f(n) : there exist positive constants c 1, c 2, and n 0 such that 0 ≤ c 1 g(n) ≤ f (n) ≤ c 2 g(n) for all n ≥ n 0 } Engineering: Drop low-order terms; Ignore leading constants. Example: 3n n 2 –5n = Θ(n 3 )

Θ-notation Θ-notation is fabulous because it satisfies our issue of being able to compare both relative and absolute speed.

Asymptotic performance When n gets large enough, a Θ (n 2 ) algorithm always beats a Θ(n 3 ) algorithm. We shouldn’t ignore asymptotically slower algorithms, however. Real-world design situations often call for a careful balancing of engineering objectives. Asymptotic analysis is a useful tool to help to structure our thinking.

Insertion sort analysis Assume that every elemental operation is going to take some constant amount of time. Worst case : Input reverse sorted. [arithmetic series] Average case: All permutations equally likely.

About Θ-notation It is more of a descriptive notation than it is a manipulative notation. Is insertion sort a fast sorting algorithm? –Moderately so, for small n. –Not at all, for large n.

Another method : Merge sort Merging two sorted arrays Time = Θ(n) to merge a total of n elements (linear time)

Merge Sort T(n) Θ(1) 2T(n/2) Θ(n) Θ(1) : Abuse, but we can ignore it. 2T(n/2) : Should be, but it turns out not to matter asymptotically.

Cost for merge sort We shall usually omit stating the base case when T(n) = Θ(1) because it has no effect on the asymptotic solution to the recurrence. Lecture 2 will provide several ways to find a good upper bound on T(n), for example, Recursion Tree.

Recursion Tree We can write as T(n) = 2T(n/2) + cn, where c > 0 and it is constant. T(n)

Recursion Tree We can write as T(n) = 2T(n/2) + cn, where c > 0 and it is constant. cn T(n/2) T(n/2)

Recursion Tree We can write as T(n) = 2T(n/2) + cn, where c > 0 and it is constant. cn cn/2 cn/2 T(n/4) T(n/4) T(n/4) T(n/4)

Recursion Tree We can write as T(n) = 2T(n/2) + cn, where c > 0 and it is constant. cn cn/2 cn/2 T(n/4) T(n/4) T(n/4) T(n/4) …… Θ(1) Height = ? cn #(leaves) = ? n logn+1 Θ(n) Total = cn*logn+ Θ(n)Θ (n logn)

Conclusion Θ(nlgn) grows more slowly than Θ(n 2 ). Therefore, merge sort asymptotically beats insertion sort in the worst case. In practice, merge sort beats insertion sort for n > 30 or so. Go test it out for yourself!

Homework Read Chapter1 and Chapter 2. Recall another sort method “Bubble sort” and express with pseudocode, then compute its cost using Θ -notation (Hand in paper edition the next class).