CSCI 2670 Introduction to Theory of Computing November 10, 2005.

Slides:



Advertisements
Similar presentations
Introduction to Computer Science Theory
Advertisements

Lecture 24 MAS 714 Hartmut Klauck
Analysis of Algorithms CS Data Structures Section 2.6.
Analysis of Algorithms
Discrete Structures CISC 2315
Lecture: Algorithmic complexity
CSE 373: Data Structures and Algorithms Lecture 5: Math Review/Asymptotic Analysis III 1.
HST 952 Computing for Biomedical Scientists Lecture 10.
CS50 SECTION: WEEK 3 Kenny Yu. Announcements  Watch Problem Set 3’s walkthrough online if you are having trouble.  Problem Set 1’s feedback have been.
Reference: Tremblay and Cheston: Section 5.1 T IMING A NALYSIS.
Measuring Time Complexity Sipser 7.1 (pages )
CS 206 Introduction to Computer Science II 09 / 10 / 2008 Instructor: Michael Eckmann.
© 2006 Pearson Addison-Wesley. All rights reserved6-1 More on Recursion.
Data Structures Review Session 1
Complexity (Running Time)
 Last lesson  Arrays for implementing collection classes  Performance analysis (review)  Today  Performance analysis  Logarithm.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
Data Structure Algorithm Analysis TA: Abbas Sarraf
CS 310 – Fall 2006 Pacific University CS310 Complexity Section 7.1 November 27, 2006.
1 Section 2.3 Complexity of Algorithms. 2 Computational Complexity Measure of algorithm efficiency in terms of: –Time: how long it takes computer to solve.
Chapter 1 Introduction Definition of Algorithm An algorithm is a finite sequence of precise instructions for performing a computation or for solving.
February 17, 2015Applied Discrete Mathematics Week 3: Algorithms 1 Double Summations Table 2 in 4 th Edition: Section th Edition: Section th.
COMP s1 Computing 2 Complexity
Asymptotic Notations Iterative Algorithms and their analysis
1 Complexity Lecture Ref. Handout p
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
Algorithm Analysis & Complexity We saw that a linear search used n comparisons in the worst case (for an array of size n) and binary search had logn comparisons.
Lecture 2 Computational Complexity
CS 3343: Analysis of Algorithms
CSCI 2670 Introduction to Theory of Computing November 4, 2004.
Analysis of Algorithms
© 2011 Pearson Addison-Wesley. All rights reserved 10 A-1 Chapter 10 Algorithm Efficiency and Sorting.
Searching. RHS – SOC 2 Searching A magic trick: –Let a person secretly choose a random number between 1 and 1000 –Announce that you can guess the number.
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 19: Searching and Sorting.
Analysis of Algorithms These slides are a modified version of the slides used by Prof. Eltabakh in his offering of CS2223 in D term 2013.
Analysis of Algorithms CSCI Previous Evaluations of Programs Correctness – does the algorithm do what it is supposed to do? Generality – does it.
CSCI 2670 Introduction to Theory of Computing November 23, 2004.
CSCI 2670 Introduction to Theory of Computing November 29, 2005.
CSCI 2670 Introduction to Theory of Computing December 1, 2004.
Algorithm Analysis (Algorithm Complexity). Correctness is Not Enough It isn’t sufficient that our algorithms perform the required tasks. We want them.
Chapter 10 Algorithm Analysis.  Introduction  Generalizing Running Time  Doing a Timing Analysis  Big-Oh Notation  Analyzing Some Simple Programs.
Algorithm Analysis CS 400/600 – Data Structures. Algorithm Analysis2 Abstract Data Types Abstract Data Type (ADT): a definition for a data type solely.
Computer Science and Software Engineering University of Wisconsin - Platteville 8. Comparison of Algorithms Yan Shi CS/SE 2630 Lecture Notes Part of this.
Chapter 18: Searching and Sorting Algorithms. Objectives In this chapter, you will: Learn the various search algorithms Implement sequential and binary.
Measuring complexity Section 7.1 Giorgi Japaridze Theory of Computability.
Chapter 5 Algorithms (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
3.3 Complexity of Algorithms
CMSC 341 Asymptotic Analysis. 2 Complexity How many resources will it take to solve a problem of a given size? –time –space Expressed as a function of.
1 Asymptotic Notations Iterative Algorithms and their analysis Asymptotic Notations –Big O,  Notations Review of Discrete Math –Summations –Logarithms.
1 Algorithms  Algorithms are simply a list of steps required to solve some particular problem  They are designed as abstractions of processes carried.
Binary Search Trees (BST)
CSCI 2670 Introduction to Theory of Computing November 17, 2005.
CSE 326: Data Structures Asymptotic Analysis Hannah Tang and Brian Tjaden Summer Quarter 2002.
Searching Topics Sequential Search Binary Search.
CISC220 Spring 2010 James Atlas Lecture 07: Big O Notation.
A Introduction to Computing II Lecture 5: Complexity of Algorithms Fall Session 2000.
Computability Sort homework. Formal definitions of time complexity. Big 0. Homework: Exercises. Searching. Shuffling.
BITS Pilani Pilani Campus Data Structure and Algorithms Design Dr. Maheswari Karthikeyan Lecture1.
1 Algorithms Searching and Sorting Algorithm Efficiency.
CSE 3358 NOTE SET 2 Data Structures and Algorithms 1.
Theory of Computational Complexity TA : Junichi Teruyama Iwama lab. D3
CSCI 2670 Introduction to Theory of Computing November 15, 2005.
Sorting With Priority Queue In-place Extra O(N) space
CSCI 2670 Introduction to Theory of Computing
Analysis of Algorithms
Time complexity Here we will consider elements of computational complexity theory – an investigation of the time (or other resources) required for solving.
CSCI 2670 Introduction to Theory of Computing
CSCI 2670 Introduction to Theory of Computing
CSCI 2670 Introduction to Theory of Computing
Algorithm Analysis How can we demonstrate that one algorithm is superior to another without being misled by any of the following problems: Special cases.
Presentation transcript:

CSCI 2670 Introduction to Theory of Computing November 10, 2005

Agenda Today –Continue Section 7.1 Next week –Finish Section 7.1 –Do Section 7.2

November 10, 2005 Announcement Quiz next Tuesday (11/15) –Big-O and small-o notation –Identify Bit-O and small-o relationships –Importance of proper encoding (today’s material) This is simplified material from Section 6.4

November 10, 2005

Small-o vs. big-O Small-o is strictly less than Big-O is less than or equal to For any function f, is f(n) = o(f(n))? –No … never! For any function f, is f(n) = O(f(n))? –Yes … always!

November 10, 2005 Some identities n i = o(n k ) for every i < k log n = o(n) log log n = o(log n)

November 10, 2005 Analyzing algorithms We examine an algorithm to determine how long it will take to halt on an input of length n –The amount of time to complete is called the algorithm’s complexity class Definition: Let t:N → N be a function. The time complexity class, TIME(t(n)), is TIME(t(n))={L|L is a language decided by a O(t(n))-time Turing machine}

November 10, 2005 Example Last class, we saw that insertion sort takes 1.5 n n - 6 time –This is actually corrected in yesterday’s slides Insertion sort is in the time complexity class O(n 2 ) Insertion sort is also in the time complexity class O(n k ) for any k > 2

November 10, 2005 Importance of model The complexity of our algorithms is a function of the length of the input This length may vary depending on assumptions about our data & other model assumptions

November 10, 2005 Another example Finding minimum element in a set Amount of time depends on the structure of the input If set is a sorted array? –O(1) If set is an unsorted array? –O(n) If set is a balanced sorted tree?

November 10, 2005 Sorted tree

November 10, 2005 Sorted tree examined Finding minimum involves selecting left child until you reach a leaf –Number of steps = depth of tree Since the tree is balanced, the depth of the tree is O(log n) What if the tree was not balanced?

November 10, 2005 Size of input: Important consideration The running time is measured in terms of the size of the input –If we increase the input size can that make the problem seem more efficient –E.g., if we represent integers in unary instead of binary We consider only reasonable encodings –The space used to encode the integer value v must be O(log v)

November 10, 2005 Unary vs. binary encoding In unary encoding, the value 5 is encoded –Length of encoding of value v is v In binary encoding, the value 5 is encoded 101 –Length of encoding of value v is  log 2 v  +1

November 10, 2005 Why does encoding matter? Assume an algorithm takes as its input an integer of value v What is the time complexity of an algorithm if it takes integer input with value v and executes for v steps? –Recall time complexity is a function of the length of the input If encoding is in unary, the complexity is O(n) If encoding is binary, the complexity is O(2 n )

November 10, 2005 Example An important problem in cryptography is prime factorization –Most encryptions rely on the fact that prime factorization takes a long time (exponential in the length of the input) Clearly, we can find the prime factorization of v by checking whether each integer smaller than v divides it

November 10, 2005 Prime factorization PRIME_FACTOR(v) w = v factors =  %factors (a multiset) will contain prime factors for i = 2 to v do while i divides w w = w / i factors = factors U {i} enddo if w = 1 break next Worst case execution time is v (occurs when v is prime)

November 10, 2005 Complexity of prime factorization The algorithm has complexity O(v) –v is the value of the input A trickster could claim they have a linear algorithm simply by changing the encoding of the input –If the input is unary, then the factorization is linear in the length of the input But this is cheating! Enforcing reasonable encodings keeps this trick from occurring