Happy Birthday Tony Palindromes.

Slides:



Advertisements
Similar presentations
Functional Programming Lecture 10 - type checking.
Advertisements

Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin Introduction to the Design & Analysis of Algorithms, 2 nd ed., Ch. 1 Chapter 2.
Dynamic Programming Nithya Tarek. Dynamic Programming Dynamic programming solves problems by combining the solutions to sub problems. Paradigms: Divide.
Space-for-Time Tradeoffs
Lecture 8: Dynamic Programming Shang-Hua Teng. Longest Common Subsequence Biologists need to measure how similar strands of DNA are to determine how closely.
Overview What is Dynamic Programming? A Sequence of 4 Steps
Algorithms Dynamic programming Longest Common Subsequence.
Data Structures: A Pseudocode Approach with C 1 Chapter 5 Contd... Objectives Explain the design, use, and operation of a linear list Implement a linear.
296.3: Algorithms in the Real World
Boyer Moore Algorithm String Matching Problem Algorithm 3 cases Searching Timing.
 Basically, a sequence of characters  Character? › Like… a letter › Or a number › Or even blank space.
1 CSCI-2400 Models of Computation. 2 Computation CPU memory.
Sequence Alignment Variations Computing alignments using only O(m) space rather than O(mn) space. Computing alignments with bounded difference Exclusion.
1 Efficient String Matching : An Aid to Bibliographic Search Alfred V. Aho and Margaret J. Corasick Bell Laboratories.
This material in not in your text (except as exercises) Sequence Comparisons –Problems in molecular biology involve finding the minimum number of edit.
Design and Analysis of Algorithms - Chapter 31 Brute Force A straightforward approach usually based on problem statement and definitions Examples: 1. Computing.
Aho-Corasick String Matching An Efficient String Matching.
Complexity (Running Time)
Elementary Data Types Scalar Data Types Numerical Data Types Other
1 Lab Session-III CSIT-120 Spring 2001 Revising Previous session Data input and output While loop Exercise Limits and Bounds GOTO SLIDE 13 Lab session.
Lecture 7 Topics Dynamic Programming
Longest Palindromic Substring Yang Liu. Problem Given a string S Find the longest palindromic substring in S. Example: S=“abcbcbb”. The longest palindromic.
CS1020E Sitin 1 Discussion -- Counting Palindromes.
One Dimensional Arrays (Part2) Sorting Algorithms Searching Algorithms Character Strings The string Class. 1.
favourite things family hobby (like doing....)...
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Chapter 13 - Recursion.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Chapter 8 More on Strings and Special Methods 1.
Lecture 23: Finite State Machines with no Outputs Acceptors & Recognizers.
Houyang 3/25/13. USACO March Contest Congrats to Johnny Ho for scoring over 900 points in the Gold Division o 7th place in US Kudos to Jonathan Uesato.
Boyer Moore Algorithm Idan Szpektor. Boyer and Moore.
Happy Birthday Julia Courier New. USACO December Contest - Congratulations to Jon+Julia+Andy for promoting to gold And Johnny - 2th place in gold among.
Public void main What do you call something that’s not static?
6/4/ ITCS 6114 Dynamic programming Longest Common Subsequence.
Strings and Pattern Matching Algorithms Pattern P[0..m-1] Text T[0..n-1] Brute Force Pattern Matching Algorithm BruteForceMatch(T,P): Input: Strings T.
Problem Analysis September 18, 2015 CSE 232, Shane Carr.
Introduction to Bioinformatics Algorithms DNA Mapping and Brute Force Algorithms.
C# C1 CSC 298 Elements of C# code (part 1). C# C2 Style for identifiers  Identifier: class, method, property (defined shortly) or variable names  class,
Review 1 Arrays & Strings Array Array Elements Accessing array elements Declaring an array Initializing an array Two-dimensional Array Array of Structure.
12/15/2015Engineering Problem Solving with C++, Second Edition, J. Ingber 1 Engineering Problem Solving with C++, Etter Chapter 6 One-Dimensional Arrays.
I want to thank you for being a part of my life...
CSC 270 – Survey of Programming Languages
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Python – May 12 Recap lab Chapter 2 –operators –Strings –Lists –Control structures.
Computer Science Background for Biologists CSC 487/687 Computing for Bioinformatics Fall 2005.
1 UNIT-I BRUTE FORCE ANALYSIS AND DESIGN OF ALGORITHMS CHAPTER 3:
Searching Topics Sequential Search Binary Search.
Lecture 5 Computer programming -1-. Input \ Output statement 1- Input (cin) : Use to input data from keyboard. Example : cin >> age; 2- Output (cout):
CSC 213 Lecture 19: Dynamic Programming and LCS. Subsequences (§ ) A subsequence of a string x 0 x 1 x 2 …x n-1 is a string of the form x i 1 x.
ICS220 – Data Structures and Algorithms Analysis Lecture 14 Dr. Ken Cosh.
Gator Engineering Google Code Jam 2015 Copyright © 2008 W. W. Norton & Company. All rights reserved. 1.
1 Chapter 2 Algorithm Analysis Reading: Chapter 2.
Celebrate ( 庆祝 ) the birthday have birthday cake.
Dr Nazir A. Zafar Advanced Algorithms Analysis and Design Advanced Algorithms Analysis and Design By Dr. Nazir Ahmad Zafar.
CS 461 – Oct. 26 TM practice Arithmetic on a TM TM variants (handout)
Chapter 2: Introduction to C++
Containers and Lists CIS 40 – Introduction to Programming in Python
String Processing.
Chapter 8 Dynamic Programming.
First discussion section agenda
CIS16 Application Development and Programming using Visual Basic.net
Dynamic Programming Dr. Yingwu Zhu Chapter 15.
Suffix trees.
CSE 311: Foundations of Computing
Longest Common Subsequence
Lecture 8. Paradigm #6 Dynamic Programming
Dynamic Programming II DP over Intervals
String Processing.
Longest common subsequence (LCS)
Lecture 5 Dynamic Programming
Python Strings.
Presentation transcript:

Happy Birthday Tony Palindromes

Brute force Can search all possible pairs (i, j): 1<=i <= j <=n and check if the substring is a palindrome. Runs in O(n^3) time. Can use this to find all possible palindromes, number of palindromes, longest palindrome, etc.

Dynamic Programming Store bool isPal [1...n][1...n]; isPal[i][i] is always true. isPal[i][i+1] is true iff str[i] == str[i+1] In general, isPal[i][j] is true if isPal[i+1][j-1] is true and str[i]==str[j] O(n^2) time and O(n^2) memory Uses an unnecessary amount of memory Can find longest palindrome, count palindromes, etc., and can determine if a substring is a palindrome in O(1) time, but no real reason to use it

Searching From Center For each possible center (there are 2n-1 of them because the center doesn't have to be a letter), search until the two sides don't match. Runs in O(n^2) time: O(n) per center. Finds maximal palindrome from every center. Can this to find number of palindromes or longest palindrome, and can determine if a substring is a palindrome in O(1) time.

Manacher's algorithm An advanced linear time (O(n)) algorithm to find maximal palindrome at every center. Usually you insert a dummy character between each letter, so that each letter is now a valid center (remember there are 2n-1 centers). Takes advantage of symmetry. Usually you won't need it.

Illustration

Potw Tony is making a round birthday cake to celebrate his birthday. Tony has arranged N letters around the perimeter of his cake. He wishes to give a slice of cake (1 to N consecutive letters) to someone special, so he wants it to be as large as possible. Since Tony likes palindromes, he wants the letters on the slice to form a palindrome. What's the largest slice Tony can cut?

Potw Input format: Line 1: a string of N letters Output format: Line 1: L, the length of the longest palindrome Sample input: abaacaba Sample output: (abaaba is the palindrome) 6 Constraints: 1<=N<=100: 10 points 1<=N<=1000: 20 points