Recursion as a Problem-Solving Technique. What is recursion? There are two types of recursive functions: Direct and Indirect Explain… There are two basic.

Slides:



Advertisements
Similar presentations
Modeling Computation Chapter 13.
Advertisements

CSC411Artificial Intelligence 1 Chapter 3 Structures and Strategies For Space State Search Contents Graph Theory Strategies for Space State Search Using.
A question from last class: construct the predictive parsing table for this grammar: S->i E t S e S | i E t S | a E -> B.
Translator Architecture Code Generator ParserTokenizer string of characters (source code) string of tokens abstract program string of integers (object.
COMP-421 Compiler Design Presented by Dr Ioanna Dionysiou.
CMPT 225 Stacks-part2.
1 The Post Correspondence Problem continued We will prove that the MPC problem is undecidable 2. We will prove that the PC problem is undecidable.
© 2006 Pearson Addison-Wesley. All rights reserved7 B-1 Chapter 7 (continued) Stacks.
© 2006 Pearson Addison-Wesley. All rights reserved7A-1 Chapter 7 Stacks.
© 2006 Pearson Addison-Wesley. All rights reserved6-1 Chapter 6 Recursion as a Problem- Solving Technique.
1 Finite Automata. 2 Finite Automaton Input “Accept” or “Reject” String Finite Automaton Output.
Section 5.2 Defining Languages. © 2005 Pearson Addison-Wesley. All rights reserved5-2 Defining Languages A language –A set of strings of symbols –Examples:
Pushdown Automaton (PDA)
Chapter 6 Stacks. © 2005 Pearson Addison-Wesley. All rights reserved6-2 The Abstract Data Type Specifications of an abstract data type for a particular.
Chapter 5 Recursion as a Problem-Solving Technique.
1 Applications of Recursion (Walls & Mirrors - Chapter 5)
Turing Machines A more powerful computation model than a PDA ?
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 6: Stacks Data Abstraction & Problem Solving with C++
© 2006 Pearson Addison-Wesley. All rights reserved7A-1 Chapter 7 Stacks (and a bit of generics for flavor)
Chapter 2. Regular Expressions and Automata From: Chapter 2 of An Introduction to Natural Language Processing, Computational Linguistics, and Speech Recognition,
Chapter 4: Induction and Recursion
COSC2007 Data Structures II
Lexical Analysis - An Introduction. The Front End The purpose of the front end is to deal with the input language Perform a membership test: code  source.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 5: Recursion as a Problem-Solving Technique Data Abstraction.
Languages, Grammars, and Regular Expressions Chuck Cusack Based partly on Chapter 11 of “Discrete Mathematics and its Applications,” 5 th edition, by Kenneth.
CSE 311 Foundations of Computing I Lecture 17 Structural Induction: Regular Expressions, Regular Languages Autumn 2011 CSE 3111.
Recursion as a Problem- Solving Technique Chapter 5 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
The Distributive Property Chapter 1 Lesson 4. Try these problems: 1.3 * (4 * x) s * m * * (4 + x) 1.3 * (4 * x) s *
EXAMPLES OF RECURSION Towers of Hanoi Writing Linked Lists Backwards Recursive Insert 8 Queens Recognizing Simple Languages Prefix Expressions Conversion.
Department of Computer Science 1 Recursion & Backtracking 1.The game of NIM 2.Getting out of a maze 3.The 8 Queen’s Problem 4.Sudoku.
A grammar for arithmetic expressions involving the four basic operators and parenthesized expressions. Parenthesized expressions have the highest precedence.
CSE 311 Foundations of Computing I Lecture 17 Structural Induction Spring
Lecture 5 Regular Expressions CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine.
Chapter 6 B Stacks. © 2004 Pearson Addison-Wesley. All rights reserved6 B-2 Comparing Implementations All of the three implementations are ultimately.
Lexical Analysis S. M. Farhad. Input Buffering Speedup the reading the source program Look one or more characters beyond the next lexeme There are many.
Parsing — Part II (Top-down parsing, left-recursion removal) Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students.
Recursion as a Problem- Solving Technique Chapter 5 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Finite State Machines 1.Finite state machines with output 2.Finite state machines with no output 3.DFA 4.NDFA.
Algebra: a language of symbols including variables Variable: a symbol, usually a letter, used to represent a number.
© 2006 Pearson Addison-Wesley. All rights reserved 6-1 Chapter 6 Recursion as a Problem- Solving Technique.
Overview of Previous Lesson(s) Over View  A token is a pair consisting of a token name and an optional attribute value.  A pattern is a description.
1 Course Overview Why this course “formal languages and automata theory?” What do computers really do? What are the practical benefits/application of formal.
CS 461 – Oct. 28 TM applications –Recognize a language √ –Arithmetic √ –Enumerate a set –Encode a data structure or problem to solve Two kinds of TMs –Decider:
CSE 311 Foundations of Computing I Lecture 19 Recursive Definitions: Context-Free Grammars and Languages Spring
CSE 311 Foundations of Computing I Lecture 19 Recursive Definitions: Context-Free Grammars and Languages Autumn 2012 CSE
Akram Salah ISSR Basic Concepts Languages Grammar Automata (Automaton)
CSE 311 Foundations of Computing I Lecture 18 Recursive Definitions: Context-Free Grammars and Languages Autumn 2011 CSE 3111.
CSE 311 Foundations of Computing I Lecture 20 Context-Free Grammars and Languages Autumn 2012 CSE
Department of Software & Media Technology
Chapter 4: Induction and Recursion
CS Data Structures Chapter 6 Stacks Mehmet H Gunes
Stacks Chapter 6.
Chapter 5 Recursion as a Problem-Solving Technique
Programming Languages Translator
Parsing — Part II (Top-down parsing, left-recursion removal)
Natural Language Processing - Formal Language -
Induction and Recursion
CSE 311 Foundations of Computing I
LIMITS OF ALGORITHMIC COMPUTATION
Method of Language Definition
Chapter 6 Stacks.
CSE 311: Foundations of Computing
Finite Automata.
Introduction Reading: Sections 1.5 – 1.7.
B.Ramamurthy Chapter 9 CSE116A,B
Recursion as a Problem-Solving Technique
Decidability continued….
Figure 6.1 Stack of cafeteria dishes. Figure 6.1 Stack of cafeteria dishes.
Presentation transcript:

Recursion as a Problem-Solving Technique

What is recursion? There are two types of recursive functions: Direct and Indirect Explain… There are two basic parts of recursive functions. What are they? They are: Base Case/Stopping Condition Recursive Call.

Defining Languages Algebraic Expressions Backtracking

A language is A set of strings of symbols From a finite alphabet. C++Programs = {string s : s is a syntactically correct C++ program} Algebraic Expressions = {string s : s is an algebraic expression}

Special symbols x | y means x or y xy (and sometimes x y ) means x followed by y means any instance of word, where word is a symbol that must be defined elsewhere in the grammar. C++Identifiers = {string s : s is a legal C++ identifier}

Palindromes = {string s : s reads the same left to right as right to left} Grammar for the language of palindromes:

A recognition algorithm for palindromes

Consider searching for an airline route Input text files that specify all of the flight information for HPAir Company Names of cities HPAir serves Pairs of city names, each pair representing origin and destination of one of HPAir’s flights Pairs of city names, each pair representing a request to fly from some origin to some destination

Flight Graph

A recursive strategy

Possible outcomes of applying the previous strategy 1.Eventually reach destination city and can conclude that it is possible to fly from origin to destination. 2.Reach a city C from which there are no departing flights. 3.Go around in circles

Place one queen at a time.