Analysis of Algorithms (complexity). Search Example: Finding a Name in a List Consider a list of N names ordered randomly. 1.How many comparisons must.

Slides:



Advertisements
Similar presentations
Zabin Visram Room CS115 CS126 Searching
Advertisements

Recursion Chapter 14. Overview Base case and general case of recursion. A recursion is a method that calls itself. That simplifies the problem. The simpler.
Types of Algorithms.
Part2 AI as Representation and Search
CSC 423 ARTIFICIAL INTELLIGENCE
Searching Kruse and Ryba Ch and 9.6. Problem: Search We are given a list of records. Each record has an associated key. Give efficient algorithm.
Searching Chapter Chapter Contents The Problem Searching an Unsorted Array Iterative Sequential Search Recursive Sequential Search Efficiency of.
The Theory of NP-Completeness
Chapter 11: Limitations of Algorithmic Power
Ch 13 – Backtracking + Branch-and-Bound
CS10 The Beauty and Joy of Computing Lecture #23 : Limits of Computing Thanks to the success of the Kinect, researchers all over the world believe.
Chapter 11 Limitations of Algorithm Power Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Searching Chapter Chapter Contents The Problem Searching an Unsorted Array Iterative Sequential Search Recursive Sequential Search Efficiency of.
Searching1 Searching The truth is out there.... searching2 Serial Search Brute force algorithm: examine each array item sequentially until either: –the.
Chapter 2 Recursion: The Mirrors. © 2005 Pearson Addison-Wesley. All rights reserved2-2 Recursive Solutions Recursion is an extremely powerful problem-
Analysis of Algorithms CPS212 Gordon College. Measuring the efficiency of algorithms There are 2 algorithms: algo1 and algo2 that produce the same results.
Algorithms. Problems, Algorithms, Programs Problem - a well defined task. –Sort a list of numbers. –Find a particular item in a list. –Find a winning.
BIT Presentation 4.  An algorithm is a method for solving a class of problems.  While computer scientists think a lot about algorithms, the term.
Data Structures and Algorithms Semester Project – Fall 2010 Faizan Kazi Comparison of Binary Search Tree and custom Hash Tree data structures.
A Level Computer Science Topic 9: Data Structures T eaching L ondon C omputing William Marsh School of Electronic Engineering and Computer Science Queen.
Chapter 11 Limitations of Algorithm Power. Lower Bounds Lower bound: an estimate on a minimum amount of work needed to solve a given problem Examples:
A. Levitin “Introduction to the Design & Analysis of Algorithms,” 3rd ed., Ch. 11 ©2012 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
Chapter 2 Recursion: The Mirrors. © 2005 Pearson Addison-Wesley. All rights reserved2-2 Recursive Solutions Recursion is an extremely powerful problem-
2.3 Functions A function is an assignment of each element of one set to a specific element of some other set. Synonymous terms: function, assignment, map.
SEARCHING UNIT II. Divide and Conquer The most well known algorithm design strategy: 1. Divide instance of problem into two or more smaller instances.
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 19: Searching and Sorting.
Searching. Linear (Sequential) Search Search an array or list by checking items one at a time. Linear search is usually very simple to implement, and.
More on Heuristics Genetic Algorithms (GA) Terminology Chromosome –candidate solution - {x 1, x 2,...., x n } Gene –variable - x j Allele –numerical.
CSE 143 Lecture 15 Binary Search; Comparable reading: 13.2; 10.2 slides created by Marty Stepp
Major objective of this course is: Design and analysis of modern algorithms Different variants Accuracy Efficiency Comparing efficiencies Motivation thinking.
1 Lower Bounds Lower bound: an estimate on a minimum amount of work needed to solve a given problem Examples: b number of comparisons needed to find the.
CSC 211 Data Structures Lecture 13
State-Space Representation General Problem Solving via simplification Read Chapter 3.
BLAST: Basic Local Alignment Search Tool Altschul et al. J. Mol Bio CS 466 Saurabh Sinha.
Hard problems in computer science Prof. Noah Snavely CS1114
Introduction to Genetic Algorithms. Genetic Algorithms We’ve covered enough material that we can write programs that use genetic algorithms! –More advanced.
Beauty and Joy of Computing Limits of Computing Ivona Bezáková CS10: UC Berkeley, April 14, 2014 (Slides inspired by Dan Garcia’s slides.)
Artificial Intelligence
Types of Algorithms. 2 Algorithm classification Algorithms that use a similar problem-solving approach can be grouped together We’ll talk about a classification.
Data Structures Using C++
LIMITATIONS OF ALGORITHM POWER
The Beauty and Joy of Computing Lecture #23 Limits of Computing Researchers at Facebook and the University of Milan found that the avg # of “friends” separating.
Computer Science Background for Biologists CSC 487/687 Computing for Bioinformatics Fall 2005.
CompSci On the Limits of Computing  Reasons for Failure 1. Runs too long o Real time requirements o Predicting yesterday's weather 2. Non-computable.
Copyright © Cengage Learning. All rights reserved. CHAPTER 11 ANALYSIS OF ALGORITHM EFFICIENCY ANALYSIS OF ALGORITHM EFFICIENCY.
Hossain Shahriar Announcement and reminder! Tentative date for final exam shown below, please choose a time slot! December 19.
Analysis of Algorithms & Recurrence Relations. Recursive Algorithms Definition –An algorithm that calls itself Components of a recursive algorithm 1.Base.
Copyright © 2014 Curt Hill Algorithm Analysis How Do We Determine the Complexity of Algorithms.
Ch03-Algorithms 1. Algorithms What is an algorithm? An algorithm is a finite set of precise instructions for performing a computation or for solving a.
Ch3 /Lecture #4 Brute Force and Exhaustive Search 1.
Building Java Programs Chapter 12: Recursive public/private pairs Chapter 13: Searching reading: 13.3.
Hard Problems Some problems are hard to solve.
SAT problem SAT – Boolean satisfiability problem
Subject Name: Design and Analysis of Algorithm Subject Code: 10CS43
Analysis of Algorithms & Orders of Growth
Searching.
Analysis of Algorithms (complexity)
Types of Algorithms.
CS 2210 Discrete Structures Algorithms and Complexity
i206: Lecture 8: Sorting and Analysis of Algorithms
Lecture 14: binary search and complexity reading:
Objective of This Course
Design and Analysis of Algorithms
Lecture 15: binary search reading:
CS 2210 Discrete Structures Algorithms and Complexity
3. Brute Force Selection sort Brute-Force string matching
3. Brute Force Selection sort Brute-Force string matching
Algorithms CSCI 235, Spring 2019 Lecture 36 P vs
3. Brute Force Selection sort Brute-Force string matching
CS 2210 Discrete Structures Algorithms and Complexity
Presentation transcript:

Analysis of Algorithms (complexity)

Search Example: Finding a Name in a List Consider a list of N names ordered randomly. 1.How many comparisons must be made in order to find if a given name is in the list? 2.What if the list is in alphabetic order? John Sarah Bob Frank Sally Anita Barbara Sam Fred Wilma Alan Harold Carol Mike Tom Beth Alan Anita Barbara Beth Bob Carol Frank Fred Harold John Mike Sally Sam Sarah Tom Wilma

Algorithm SequentialSearch (of an array) found=“not” for i = 1 to number of items in the array if array(i)= desired element found=“” i = number of items in array + 1 end if next i print “Element was ”; found; “ found” John Sarah Bob Frank Sally Anita Barbara Sam Fred Wilma Alan Harold Carol Mike Tom Beth

Algorithm binarySearch (a, first, last, desiredItem) mid = (first + last)/2 // approximate midpoint of array if (first > last) return false else if (desiredItem equals a[mid]) return true else if (desiredItem a[mid] return binarySearch (a, mid+1, last, desiredItem) Alan Anita Barbara Beth Bob Carol Frank Fred Harold John Mike Sally Sam Sarah Tom Wilma

Search Example: The Traveling Salesman Problem What is the shortest route a salesman can take to visit all of the cities in his territory and return home?

Search Example: The Traveling Salesman Problem What is the shortest route a salesman can take to visit all of the cities in his territory and return home?

The (Real) Traveling Salesman “Problem” As the number of cities increases, the time it takes to find an exact solution increases exponentially. Example: Number of cities# pathsTime to solve (on a fast PC) almost instantaneously almost instantaneously 10181,4401 second 10181,4401 second 1220 million 20 seconds 1220 million 20 seconds ……… ……… 2060,800,000,000,000,000? 2060,800,000,000,000,000? x ? x ?Intractable!

Chess

Carrano (2006), Data Structures and Abstractions with Java

How Can We put a List in Alphabetic order? John Sarah Bob Frank Sally Anita Barbara Sam Fred Wilma Alan Harold Carol Mike Tom Beth How much effort is required?

Eight Puzzle

30 shuffle moves Compare: best-first with depth factor: 26 moves to solution (7725 in CLOSED; 7498 left in OPEN) best-first without depth factor: 48 moves to solution (272 in CLOSED; 332 in OPEN)

Shown below is a screen shot of a breath-first search in process for the 15-puzzle. The optimal solution is known (by another method) to be located at depth 26. How long will it take the breadth-first algorithm to discover this?

Time t i spent at level i ≈4*t i-1 (e.g., 53278/13034=4.09, 13034/3171=4.11, 3171/782=4.05). The search needs to go = 10 levels deeper. So, it will take approximately 53278*4 9 to 53278*4 10 seconds to find the optimal solution (depending upon whether it finds it at the beginning of the search of level 26 or at the end). Taking the lower limit, we get 53278*4 9 seconds/(3600sec/hr)/(24hrs/day)/ (365days/yr) = 443 years. A similar calculation for the upper limit (or just multiply by 4) gives 1772 years. So, between 443 and 1772 years!

Complexity Comparison Carrano (2006), Data Structures and Abstractions with Java

Let f and g be functions mapping nonnegative reals into nonnegative reals. Then f is BIG OH of g, written f = O(g), if there exist positive constants x 0 and c such that for x ≥ x 0, f(x) ≤ cg(x). In this case, an algorithm's time requirement f(x) is of order at most g(x).

Consider a pattern matching algorithm whose purpose is to find all occurrences of string A in string B where A < B. What is the complexity of the task?

Identify the factors that determine the complexity…

Consider a pattern matching algorithm whose purpose is to find all occurrences of string A in string B where A < B. What is the complexity of the task? Identify the factors that determine the complexity… Length of each string Algorithm used to perform the match

Consider a pattern matching algorithm whose purpose is to find all occurrences of string A in string B where A < B. What is the complexity of the task? Identify the factors that determine the complexity… Length of each string Algorithm used to perform the match Suggest some techniques and evaluate each…

Data Structures ListsStacksQueuesTreesGraphs ABCD D C B A ABCD