•Download as PPTX, PDF•

6 likes•8,668 views

The document discusses recursion and provides examples of recursion including nested recursion. It explains recursion using functions like the Ackermann function and Fibonacci numbers. It discusses excessive recursion and how it can lead to many repeated computations. The document also covers backtracking as a method for systematically trying sequences of decisions to find a solution. It provides the example of solving the eight queens problem using backtracking and recursion.

Report

Share

Report

Share

Queue- 8 Queen

This document discusses data structures and algorithms related to queues. It defines queues as first-in first-out (FIFO) linear lists and describes common queue operations like offer(), poll(), peek(), and isEmpty(). Implementations of queues using linked lists and circular arrays are presented. Applications of queues include accessing shared resources and serving as components of other data structures. The document concludes by explaining the eight queens puzzle and presenting an algorithm to solve it using backtracking.

backtracking algorithms of ada

The document describes the backtracking method for solving problems that require finding optimal solutions. Backtracking involves building a solution one component at a time and using bounding functions to prune partial solutions that cannot lead to an optimal solution. It then provides examples of applying backtracking to solve the 8 queens problem by placing queens on a chessboard with no attacks. The general backtracking method and a recursive backtracking algorithm are also outlined.

BackTracking Algorithm: Technique and Examples

This slides gives a strong overview of backtracking algorithm. How it came and general approaches of the techniques. Also some well-known problem and solution of backtracking algorithm.

5.5 back tracking

The document discusses backtracking algorithms. It begins by defining backtracking as a methodical way to try different sequences of decisions to solve a problem until a solution is found. It then provides examples of backtracking for finding a maze path and coloring a map. The key aspects of a backtracking algorithm are that it uses depth-first search to recursively explore choices, pruning paths that do not lead to solutions.

Back tracking and branch and bound class 20

Backtracking and branch and bound are algorithms used to solve problems with large search spaces. Backtracking uses depth-first search and prunes subtrees that don't lead to viable solutions. Branch and bound uses breadth-first search and pruning, maintaining partial solutions in a priority queue. Both techniques systematically eliminate possibilities to find optimal solutions faster than exhaustive search. Examples where they can be applied include maze pathfinding, the eight queens problem, sudoku, and the traveling salesman problem.

Backtracking

The document discusses the problem solving technique of backtracking. It begins by explaining backtracking as systematically trying and eliminating possibilities, using a maze as an example. It then provides the example of solving the eight queens problem using backtracking by placing queens on the board one at a time and backtracking when a placement leads to a conflict. Finally, it notes that other problems like Sudoku puzzles and mazes can also be solved using backtracking.

Algorithm chapter 11

The document discusses two principal approaches to solving intractable problems: exact algorithms that guarantee an optimal solution but may not run in polynomial time, and approximation algorithms that can find a suboptimal solution in polynomial time. It focuses on exact algorithms like exhaustive search, backtracking, and branch-and-bound. Backtracking constructs a state space tree and prunes non-promising nodes to reduce search space. Branch-and-bound uses bounding functions to determine if nodes are promising or not, pruning those that are not. The traveling salesman problem is used as an example to illustrate branch-and-bound, discussing different bounding functions that can be used.

Backtracking

This slides explain the basic concepts of Backtracking.Also explain the 8 queen problem,sum of subsets,Hamiltonian cycle and Graph coloring problem.

Queue- 8 Queen

This document discusses data structures and algorithms related to queues. It defines queues as first-in first-out (FIFO) linear lists and describes common queue operations like offer(), poll(), peek(), and isEmpty(). Implementations of queues using linked lists and circular arrays are presented. Applications of queues include accessing shared resources and serving as components of other data structures. The document concludes by explaining the eight queens puzzle and presenting an algorithm to solve it using backtracking.

backtracking algorithms of ada

The document describes the backtracking method for solving problems that require finding optimal solutions. Backtracking involves building a solution one component at a time and using bounding functions to prune partial solutions that cannot lead to an optimal solution. It then provides examples of applying backtracking to solve the 8 queens problem by placing queens on a chessboard with no attacks. The general backtracking method and a recursive backtracking algorithm are also outlined.

BackTracking Algorithm: Technique and Examples

This slides gives a strong overview of backtracking algorithm. How it came and general approaches of the techniques. Also some well-known problem and solution of backtracking algorithm.

5.5 back tracking

The document discusses backtracking algorithms. It begins by defining backtracking as a methodical way to try different sequences of decisions to solve a problem until a solution is found. It then provides examples of backtracking for finding a maze path and coloring a map. The key aspects of a backtracking algorithm are that it uses depth-first search to recursively explore choices, pruning paths that do not lead to solutions.

Back tracking and branch and bound class 20

Backtracking and branch and bound are algorithms used to solve problems with large search spaces. Backtracking uses depth-first search and prunes subtrees that don't lead to viable solutions. Branch and bound uses breadth-first search and pruning, maintaining partial solutions in a priority queue. Both techniques systematically eliminate possibilities to find optimal solutions faster than exhaustive search. Examples where they can be applied include maze pathfinding, the eight queens problem, sudoku, and the traveling salesman problem.

Backtracking

The document discusses the problem solving technique of backtracking. It begins by explaining backtracking as systematically trying and eliminating possibilities, using a maze as an example. It then provides the example of solving the eight queens problem using backtracking by placing queens on the board one at a time and backtracking when a placement leads to a conflict. Finally, it notes that other problems like Sudoku puzzles and mazes can also be solved using backtracking.

Algorithm chapter 11

The document discusses two principal approaches to solving intractable problems: exact algorithms that guarantee an optimal solution but may not run in polynomial time, and approximation algorithms that can find a suboptimal solution in polynomial time. It focuses on exact algorithms like exhaustive search, backtracking, and branch-and-bound. Backtracking constructs a state space tree and prunes non-promising nodes to reduce search space. Branch-and-bound uses bounding functions to determine if nodes are promising or not, pruning those that are not. The traveling salesman problem is used as an example to illustrate branch-and-bound, discussing different bounding functions that can be used.

Backtracking

This slides explain the basic concepts of Backtracking.Also explain the 8 queen problem,sum of subsets,Hamiltonian cycle and Graph coloring problem.

The n Queen Problem

This document summarizes the n-queen problem, which involves placing N queens on an N x N chessboard so that no queen can attack any other. It describes the problem's inputs and tasks, provides examples of solutions for different board sizes, and outlines the backtracking algorithm commonly used to solve this problem. The backtracking approach guarantees a solution but can be slow, with complexity rising exponentially with problem size. It is a good benchmark for testing parallel computing systems due to its iterative nature.

Branch and bound

Backtracking and branch and bound are algorithms for solving problems systematically by trying options in an orderly manner. Backtracking uses depth-first search and prunes subtrees that don't lead to solutions. Branch and bound uses breadth-first search and pruning, maintaining upper and lower bounds to eliminate options. Both aim to avoid exhaustive search by eliminating non-promising options early. Examples that can use these techniques include maze navigation, the eight queens problem, and Sudoku puzzles.

algorithm Unit 4

The document discusses various algorithms that can be solved using backtracking. It begins by defining backtracking as a general algorithm design technique for problems that involve searching for solutions satisfying constraints. It then provides examples of problems that can be solved using backtracking, including the 8 queens problem, sum of subsets, graph coloring, and finding Hamiltonian cycles in a graph. For each problem, it outlines the key steps and provides pseudocode for the backtracking algorithm.

Backtracking

Backtracking is a general algorithm for finding all (or some) solutions to some computational problems, notably constraint satisfaction problems, that incrementally builds candidates to the solutions, and abandons each partial candidate c ("backtracks") as soon as it determines that c cannot possibly be completed to a valid solution.

Backtracking

Backtracking is used to systematically search for solutions to problems by trying possibilities and abandoning ("backtracking") partial candidate solutions that fail to satisfy constraints. Examples discussed include the rat in a maze problem, the traveling salesperson problem, container loading, finding the maximum clique in a graph, and board permutation problems. Backtracking algorithms traverse the search space depth-first and use pruning techniques like discarding partial solutions that cannot lead to better complete solutions than those already found.

N Queens problem

This document describes a project on solving the 8 queens problem using object-oriented programming in C++. It includes an introduction to the 8 queens puzzle, a methodology section on the backtracking algorithm used, pseudocode for the algorithm, analysis of the time complexity, a flowchart, results and discussion of the 12 fundamental solutions, and the source code. It was completed by 5 students under the guidance of a professor to fulfill the requirements for a bachelor's degree in computer science and engineering.

Backtracking

Backtracking is a general algorithm for finding all (or some) solutions to some computational problems, notably constraint satisfaction problems, that incrementally builds candidates to the solutions, and abandons each partial candidate c ("backtracks") as soon as it determines that c cannot possibly be completed to a valid solution.

algorithm unit 1

The document discusses algorithm analysis and design. It begins with an introduction to analyzing algorithms including average case analysis and solving recurrences. It then provides definitions of algorithms both informal and formal. Key aspects of algorithm study and specification methods like pseudocode are outlined. Selection sort and tower of Hanoi problems are presented as examples and analyzed for time and space complexity. Average case analysis is discussed assuming all inputs are equally likely.

algorithm Unit 5

The branch and bound method searches a tree model of the solution space for discrete optimization problems. It uses bounding functions to prune subtrees that cannot contain optimal solutions, avoiding evaluating all possible solutions. The method generates the tree in a depth-first manner, and selects the next node to expand (the E-node) based on cost estimates. Common strategies are FIFO, LIFO, and least cost search. The traveling salesman problem can be solved using branch and bound by formulating the solution space as a tree and applying row and column reduction techniques to the cost matrix at each node to identify prunable branches.

Knapsack problem using fixed tuple

This document discusses the 0/1 knapsack problem and how it can be solved using backtracking. It begins with an introduction to backtracking and the difference between backtracking and branch and bound. It then discusses the knapsack problem, giving the definitions of the profit vector, weight vector, and knapsack capacity. It explains how the problem is to find the combination of items that achieves the maximum total value without exceeding the knapsack capacity. The document constructs state space trees to demonstrate solving the knapsack problem using backtracking and fixed tuples. It concludes with examples problems and references.

Randomized algorithms ver 1.0

This document discusses randomized algorithms. It begins by listing different categories of algorithms, including randomized algorithms. Randomized algorithms introduce randomness into the algorithm to avoid worst-case behavior and find efficient approximate solutions. Quicksort is presented as an example randomized algorithm, where randomness improves its average runtime from quadratic to linear. The document also discusses the randomized closest pair algorithm and a randomized algorithm for primality testing. Both introduce randomness to improve efficiency compared to deterministic algorithms for the same problems.

algorithm Unit 2

1) The document describes the divide-and-conquer algorithm design paradigm. It splits problems into smaller subproblems, solves the subproblems recursively, and then combines the solutions to solve the original problem.
2) Binary search is provided as an example algorithm that uses divide-and-conquer. It divides the search space in half at each step to quickly determine if an element is present.
3) Finding the maximum and minimum elements in an array is another problem solved using divide-and-conquer. It recursively finds the max and min of halves of the array and combines the results.

44 randomized-algorithms

This document discusses randomized algorithms and how they use random numbers to help solve problems. It covers topics like pseudorandom number generation, shuffling arrays randomly, and using randomization to approximate optimal strategies for problems like the 0-1 knapsack problem that are difficult to solve deterministically. Randomized algorithms are presented as a useful technique for simulation, finding good solutions when perfect solutions are intractable, or as an alternative approach when no other algorithms are known.

algorithm Unit 3

This document discusses dynamic programming and algorithms for solving all-pair shortest path problems. It begins by defining dynamic programming as avoiding recalculating solutions by storing results in a table. It then describes Floyd's algorithm for finding shortest paths between all pairs of nodes in a graph. The algorithm iterates through nodes, calculating shortest paths that pass through each intermediate node. It takes O(n3) time for a graph with n nodes. Finally, it discusses the multistage graph problem and provides forward and backward algorithms to find the minimum cost path from source to destination in a multistage graph in O(V+E) time, where V and E are the numbers of vertices and edges.

Algorithm chapter 1

This document provides an overview of the CS303 Computer Algorithms course taught by Dr. Yanxia Jia. It discusses the importance of algorithms, provides examples of classic algorithm problems like sorting and searching, and summarizes common algorithm design techniques and data structures used, including arrays, linked lists, stacks, queues, heaps, graphs and trees.

Recursion

1. The document discusses recursion and provides examples of recursively defined problems and their solutions, including factorials, powers, greatest common divisor, Fibonacci series, Towers of Hanoi, and counting cells in a blob.
2. Recursion involves breaking a problem into smaller subproblems of the same type until reaching a base case that can be solved directly. The solutions to subproblems are then combined to solve the original problem.
3. Examples of recursively defined problems include mathematical formulas, searching and sorting algorithms like binary search, and problems like Towers of Hanoi that are naturally broken down recursively.

Signal Processing Assignment Help

I am Charles G. I am a Signal Processing Assignment Expert at matlabassignmentexperts.com. I hold a Ph.D. in Matlab, The Pennsylvania State University. I have been helping students with their homework for the past 6 years. I solve assignments related to Signal Processing.
Visit matlabassignmentexperts.com or email info@matlabassignmentexperts.com.
You can also call on +1 678 648 4277 for any assistance with Signal Processing Assignments.

Algorithm Homework Help

I am Elijah L. I am an Algorithm Assignment Expert at programminghomeworkhelp.com. I hold a Bachelor’s Degree in Programming, Leeds University, UK. I have been helping students with their homework for the past 6 years. I solve assignments related to Algorithms.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com.You can also call on +1 678 648 4277 for any assistance with Algorithm assignments.

3 recursion

The document discusses recursion, including recursive definitions, recursive programs/algorithms, and applications of recursion. It covers key concepts such as the anatomy of a recursive call, classifying recursions by the number of recursive calls, tail recursion, and avoiding excessive recursion. Examples of recursively defined sequences, functions, and algorithms are provided to illustrate recursive concepts.

Skyline queries

The document discusses skyline queries and algorithms for computing skylines. It begins by defining skylines and providing examples. It then discusses two main options for implementing skyline queries: extending SQL with a skyline operator, or building skylines on top of relational databases using nested SQL queries. The document focuses on algorithms for computing skylines, including the block-nested loops algorithm, divide and conquer algorithm, and algorithms using B-trees and R-trees. It also discusses combining skyline queries with joins and top-N queries. Experimental results show divide and conquer performs best for multidimensional skylines while block-nested loops is better for small skylines.

4. Recursion - Data Structures using C++ by Varsha Patil

The document discusses recursion in computer programming. It defines recursion as a function that calls itself or is called by another function. It categorizes different types of recursion such as direct, indirect, linear, tree, and tail recursion. It explains how recursive functions work by using a stack to store information from each function call. Examples of recursively-defined problems like factorials and Fibonacci numbers are provided. Guidelines for writing recursive functions and solving problems recursively are also outlined.

Introduction to Recursion (Python)

A presentation about the ideas of recursion and recursive functions.
This is my lecture presentation during A. Paruj Ratanaworabhan’s basic preparatory programming course for freshmen: Introduction to Programming: A Tutorial for New Comers Using Python

The n Queen Problem

This document summarizes the n-queen problem, which involves placing N queens on an N x N chessboard so that no queen can attack any other. It describes the problem's inputs and tasks, provides examples of solutions for different board sizes, and outlines the backtracking algorithm commonly used to solve this problem. The backtracking approach guarantees a solution but can be slow, with complexity rising exponentially with problem size. It is a good benchmark for testing parallel computing systems due to its iterative nature.

Branch and bound

Backtracking and branch and bound are algorithms for solving problems systematically by trying options in an orderly manner. Backtracking uses depth-first search and prunes subtrees that don't lead to solutions. Branch and bound uses breadth-first search and pruning, maintaining upper and lower bounds to eliminate options. Both aim to avoid exhaustive search by eliminating non-promising options early. Examples that can use these techniques include maze navigation, the eight queens problem, and Sudoku puzzles.

algorithm Unit 4

The document discusses various algorithms that can be solved using backtracking. It begins by defining backtracking as a general algorithm design technique for problems that involve searching for solutions satisfying constraints. It then provides examples of problems that can be solved using backtracking, including the 8 queens problem, sum of subsets, graph coloring, and finding Hamiltonian cycles in a graph. For each problem, it outlines the key steps and provides pseudocode for the backtracking algorithm.

Backtracking

Backtracking is a general algorithm for finding all (or some) solutions to some computational problems, notably constraint satisfaction problems, that incrementally builds candidates to the solutions, and abandons each partial candidate c ("backtracks") as soon as it determines that c cannot possibly be completed to a valid solution.

Backtracking

Backtracking is used to systematically search for solutions to problems by trying possibilities and abandoning ("backtracking") partial candidate solutions that fail to satisfy constraints. Examples discussed include the rat in a maze problem, the traveling salesperson problem, container loading, finding the maximum clique in a graph, and board permutation problems. Backtracking algorithms traverse the search space depth-first and use pruning techniques like discarding partial solutions that cannot lead to better complete solutions than those already found.

N Queens problem

This document describes a project on solving the 8 queens problem using object-oriented programming in C++. It includes an introduction to the 8 queens puzzle, a methodology section on the backtracking algorithm used, pseudocode for the algorithm, analysis of the time complexity, a flowchart, results and discussion of the 12 fundamental solutions, and the source code. It was completed by 5 students under the guidance of a professor to fulfill the requirements for a bachelor's degree in computer science and engineering.

algorithm unit 1

The document discusses algorithm analysis and design. It begins with an introduction to analyzing algorithms including average case analysis and solving recurrences. It then provides definitions of algorithms both informal and formal. Key aspects of algorithm study and specification methods like pseudocode are outlined. Selection sort and tower of Hanoi problems are presented as examples and analyzed for time and space complexity. Average case analysis is discussed assuming all inputs are equally likely.

algorithm Unit 5

The branch and bound method searches a tree model of the solution space for discrete optimization problems. It uses bounding functions to prune subtrees that cannot contain optimal solutions, avoiding evaluating all possible solutions. The method generates the tree in a depth-first manner, and selects the next node to expand (the E-node) based on cost estimates. Common strategies are FIFO, LIFO, and least cost search. The traveling salesman problem can be solved using branch and bound by formulating the solution space as a tree and applying row and column reduction techniques to the cost matrix at each node to identify prunable branches.

Knapsack problem using fixed tuple

This document discusses the 0/1 knapsack problem and how it can be solved using backtracking. It begins with an introduction to backtracking and the difference between backtracking and branch and bound. It then discusses the knapsack problem, giving the definitions of the profit vector, weight vector, and knapsack capacity. It explains how the problem is to find the combination of items that achieves the maximum total value without exceeding the knapsack capacity. The document constructs state space trees to demonstrate solving the knapsack problem using backtracking and fixed tuples. It concludes with examples problems and references.

Randomized algorithms ver 1.0

This document discusses randomized algorithms. It begins by listing different categories of algorithms, including randomized algorithms. Randomized algorithms introduce randomness into the algorithm to avoid worst-case behavior and find efficient approximate solutions. Quicksort is presented as an example randomized algorithm, where randomness improves its average runtime from quadratic to linear. The document also discusses the randomized closest pair algorithm and a randomized algorithm for primality testing. Both introduce randomness to improve efficiency compared to deterministic algorithms for the same problems.

algorithm Unit 2

1) The document describes the divide-and-conquer algorithm design paradigm. It splits problems into smaller subproblems, solves the subproblems recursively, and then combines the solutions to solve the original problem.
2) Binary search is provided as an example algorithm that uses divide-and-conquer. It divides the search space in half at each step to quickly determine if an element is present.
3) Finding the maximum and minimum elements in an array is another problem solved using divide-and-conquer. It recursively finds the max and min of halves of the array and combines the results.

44 randomized-algorithms

This document discusses randomized algorithms and how they use random numbers to help solve problems. It covers topics like pseudorandom number generation, shuffling arrays randomly, and using randomization to approximate optimal strategies for problems like the 0-1 knapsack problem that are difficult to solve deterministically. Randomized algorithms are presented as a useful technique for simulation, finding good solutions when perfect solutions are intractable, or as an alternative approach when no other algorithms are known.

algorithm Unit 3

This document discusses dynamic programming and algorithms for solving all-pair shortest path problems. It begins by defining dynamic programming as avoiding recalculating solutions by storing results in a table. It then describes Floyd's algorithm for finding shortest paths between all pairs of nodes in a graph. The algorithm iterates through nodes, calculating shortest paths that pass through each intermediate node. It takes O(n3) time for a graph with n nodes. Finally, it discusses the multistage graph problem and provides forward and backward algorithms to find the minimum cost path from source to destination in a multistage graph in O(V+E) time, where V and E are the numbers of vertices and edges.

Algorithm chapter 1

This document provides an overview of the CS303 Computer Algorithms course taught by Dr. Yanxia Jia. It discusses the importance of algorithms, provides examples of classic algorithm problems like sorting and searching, and summarizes common algorithm design techniques and data structures used, including arrays, linked lists, stacks, queues, heaps, graphs and trees.

Recursion

1. The document discusses recursion and provides examples of recursively defined problems and their solutions, including factorials, powers, greatest common divisor, Fibonacci series, Towers of Hanoi, and counting cells in a blob.
2. Recursion involves breaking a problem into smaller subproblems of the same type until reaching a base case that can be solved directly. The solutions to subproblems are then combined to solve the original problem.
3. Examples of recursively defined problems include mathematical formulas, searching and sorting algorithms like binary search, and problems like Towers of Hanoi that are naturally broken down recursively.

Signal Processing Assignment Help

I am Charles G. I am a Signal Processing Assignment Expert at matlabassignmentexperts.com. I hold a Ph.D. in Matlab, The Pennsylvania State University. I have been helping students with their homework for the past 6 years. I solve assignments related to Signal Processing.
Visit matlabassignmentexperts.com or email info@matlabassignmentexperts.com.
You can also call on +1 678 648 4277 for any assistance with Signal Processing Assignments.

Algorithm Homework Help

I am Elijah L. I am an Algorithm Assignment Expert at programminghomeworkhelp.com. I hold a Bachelor’s Degree in Programming, Leeds University, UK. I have been helping students with their homework for the past 6 years. I solve assignments related to Algorithms.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com.You can also call on +1 678 648 4277 for any assistance with Algorithm assignments.

3 recursion

The document discusses recursion, including recursive definitions, recursive programs/algorithms, and applications of recursion. It covers key concepts such as the anatomy of a recursive call, classifying recursions by the number of recursive calls, tail recursion, and avoiding excessive recursion. Examples of recursively defined sequences, functions, and algorithms are provided to illustrate recursive concepts.

Skyline queries

The document discusses skyline queries and algorithms for computing skylines. It begins by defining skylines and providing examples. It then discusses two main options for implementing skyline queries: extending SQL with a skyline operator, or building skylines on top of relational databases using nested SQL queries. The document focuses on algorithms for computing skylines, including the block-nested loops algorithm, divide and conquer algorithm, and algorithms using B-trees and R-trees. It also discusses combining skyline queries with joins and top-N queries. Experimental results show divide and conquer performs best for multidimensional skylines while block-nested loops is better for small skylines.

The n Queen Problem

The n Queen Problem

Branch and bound

Branch and bound

algorithm Unit 4

algorithm Unit 4

Backtracking

Backtracking

Backtracking

Backtracking

N Queens problem

N Queens problem

Backtracking

Backtracking

algorithm unit 1

algorithm unit 1

algorithm Unit 5

algorithm Unit 5

Knapsack problem using fixed tuple

Knapsack problem using fixed tuple

Randomized algorithms ver 1.0

Randomized algorithms ver 1.0

algorithm Unit 2

algorithm Unit 2

44 randomized-algorithms

44 randomized-algorithms

algorithm Unit 3

algorithm Unit 3

Algorithm chapter 1

Algorithm chapter 1

Recursion

Recursion

Signal Processing Assignment Help

Signal Processing Assignment Help

Algorithm Homework Help

Algorithm Homework Help

3 recursion

3 recursion

Skyline queries

Skyline queries

4. Recursion - Data Structures using C++ by Varsha Patil

The document discusses recursion in computer programming. It defines recursion as a function that calls itself or is called by another function. It categorizes different types of recursion such as direct, indirect, linear, tree, and tail recursion. It explains how recursive functions work by using a stack to store information from each function call. Examples of recursively-defined problems like factorials and Fibonacci numbers are provided. Guidelines for writing recursive functions and solving problems recursively are also outlined.

Introduction to Recursion (Python)

A presentation about the ideas of recursion and recursive functions.
This is my lecture presentation during A. Paruj Ratanaworabhan’s basic preparatory programming course for freshmen: Introduction to Programming: A Tutorial for New Comers Using Python

Ch 7 recursion

Recursion involves a method that calls itself directly or indirectly. This can be done linearly, where a method calls itself once, or exponentially, where it calls itself multiple times. Recursive algorithms can generate complex structures from simple instructions and are often more efficient than iterative approaches, though they require additional memory. Common examples of recursion in nature and mathematics are fractals, trees, and recursive algorithms used to generate structures like the Sierpinski triangle.

Recursion

This document provides an overview of syntax and generative grammar. It defines syntax as the way words are arranged to show relationships of meaning within and between sentences. Grammar is defined as the art of writing, but is now used to study language. Generative grammar uses formal rules to generate an infinite set of grammatical sentences. It distinguishes between deep structure and surface structure. Tree diagrams are used to represent syntactic structures with symbols like S, NP, VP. Phrase structure rules, lexical rules, and movement rules are discussed. Complement phrases and recursion are also explained.

1 Recur

The document discusses recursion in Java methods. It provides examples of recursive methods to calculate factorials, Fibonacci numbers, and other functions. Recursive methods must have a base case and move toward this base case in each recursive call. Tail recursion can be optimized into a loop by the compiler, while other recursion requires transforming the method into an iterative form using loops and additional data structures.

Recursion in c++

Recursion in c++.
The document discusses recursion, which is a programming technique where a function calls itself. It provides examples of using recursion to calculate the factorial of a number and to generate the Fibonacci series. Specifically, it shows a recursive function that calls itself with decreasing arguments to repeatedly multiply numbers to calculate a factorial, and another recursive function that calls itself twice, each time with decreasing arguments, to add the previous two values in the Fibonacci series.

Tail recursion

Tail recursion is when a recursive call is the last thing executed by a function. This allows the call stack to reuse stack frames rather than building up the call stack, avoiding stack overflow issues. A tail recursive function calculates results as it goes rather than waiting to return from recursive calls. This optimization makes tail recursive functions more efficient than regular recursive functions in terms of speed and memory usage.

Recursion Pattern Analysis and Feedback

This presentation describes an approach to analysis of common recursion patterns in purely functional code. The goal is to recognize common patterns and provide the user with hints how to improve them using standard FP techniques (map, fold etc.). This presentation was given as part of the Advanced Functional Programming Seminar at Utrecht University.

9. Searching & Sorting - Data Structures using C++ by Varsha Patil

The document discusses various searching and sorting algorithms. It covers sequential search, binary search, Fibonacci search, hashed search, indexed sequential search and their time complexities. Sorting algorithms like bubble sort, insertion sort, selection sort are explained along with their analysis. Internal sorting techniques like quicksort, heapsort, radix sort and bucket sort are also mentioned. The document provides details on sorting methods, order, stability and efficiency.

Data Structures- Part5 recursion

The document discusses recursion, including:
1) Recursion involves breaking a problem down into smaller subproblems until a base case is reached, then building up the solution to the overall problem from the solutions to the subproblems.
2) A recursive function is one that calls itself, with each call typically moving closer to a base case where the problem can be solved without recursion.
3) Recursion can be linear, involving one recursive call, or binary, involving two recursive calls to solve similar subproblems.

4. Recursion - Data Structures using C++ by Varsha Patil

4. Recursion - Data Structures using C++ by Varsha Patil

Introduction to Recursion (Python)

Introduction to Recursion (Python)

Ch 7 recursion

Ch 7 recursion

Recursion

Recursion

1 Recur

1 Recur

Recursion in c++

Recursion in c++

Tail recursion

Tail recursion

Recursion Pattern Analysis and Feedback

Recursion Pattern Analysis and Feedback

9. Searching & Sorting - Data Structures using C++ by Varsha Patil

9. Searching & Sorting - Data Structures using C++ by Varsha Patil

Data Structures- Part5 recursion

Data Structures- Part5 recursion

Recursion and Sorting Algorithms

These slides are part of a full series of slides which covers almost all the basic concepts of data structures and algorithms.
Part 3

مدخل إلى تعلم الآلة

This document provides an overview of regression analysis and linear regression. It explains that regression analysis estimates relationships among variables to predict continuous outcomes. Linear regression finds the best fitting line through minimizing error. It describes modeling with multiple features, representing data in vector and matrix form, and using gradient descent optimization to learn the weights through iterative updates. The goal is to minimize a cost function measuring error between predictions and true values.

Class13_Quicksort_Algorithm.pdf

Quick Sort is a sorting algorithm that partitions an array around a pivot element, recursively sorting the subarrays. It has a best case time complexity of O(n log n) when partitions are evenly divided, and worst case of O(n^2) when partitions are highly imbalanced. While fast, it is unstable and dependent on pivot selection. It is widely used due to its efficiency, simplicity, and ability to be parallelized.

Dsoop (co 221) 1

The document discusses recursion and provides examples of recursive algorithms like factorial, Fibonacci series, and Towers of Hanoi. It explains recursion using these examples and discusses the disadvantages of recursion. It also covers divide and conquer algorithms like quicksort and binary search. Finally, it discusses backtracking and provides the example of the eight queens problem to illustrate recursive backtracking.

Functional Programming in Javascript - IL Tech Talks week

The document discusses a presentation about functional programming in JavaScript. It will cover inner functions and closures, higher order functions, and decomplecting calls patterns. It will discuss how these functional programming concepts can improve performance, provide different perspectives on objects, avoid array mistakes, and allow for recursion. The presentation will provide an overview of functional programming and JavaScript, and then do a deep dive into combining the two paradigms.

Time series representations for better data mining

The document discusses time series representations, which can be used to reduce dimensionality, remove noise, and emphasize patterns in time series data. It introduces the TSrepr R package, which implements various time series representation methods like PAA, DWT, DFT, and SAX. It allows creating representation matrices from multiple time series and provides functions for normalization, windowing, and extending the package with custom representations. Time series representations help with tasks like clustering, classification, and forecasting of time series data.

Backtracking Algorithm.pptx

Analysis and design of Algorithm
Backtracking algorithm and its comparison with Dynamic programing problems

Accelerating Key Bioinformatics Tasks 100-fold by Improving Memory Access

Presented at PEARC21.
Most experimental sciences now rely on computing, and biolog- ical sciences are no exception. As datasets get bigger, so do the computing costs, making proper optimization of the codes used by scientists increasingly important. Many of the codes developed in recent years are based on the Python-based NumPy, due to its ease of use and good performance characteristics. The composable nature of NumPy, however, does not generally play well with the multi-tier nature of modern CPUs, making any non-trivial multi- step algorithm limited by the external memory access speeds, which are hundreds of times slower than the CPU’s compute capabilities. In order to fully utilize the CPU compute capabilities, one must keep the working memory footprint small enough to fit in the CPU caches, which requires splitting the problem into smaller portions and fusing together as many steps as possible. In this paper, we present changes based on these principles to two important func- tions in the scikit-bio library, principal coordinates analysis and the Mantel test, that resulted in over 100x speed improvement in these widely used, general-purpose tools.

Chap 4 local_search

This document provides an overview of local search algorithms. It discusses how local search works by iteratively improving a single current state rather than exploring the entire state space. Key aspects covered include representing problems as states, defining neighbor states and objective functions, getting stuck in local optima, and techniques like hill climbing, gradient descent, simulated annealing, and random restarts to escape local optima. Local search is memory efficient but can find good solutions more slowly than optimal algorithms. Algorithm design considerations like state representation, neighbors, and constraints are discussed. Pseudocode outlines for basic local search, tabu search, and simulated annealing wrappers are also provided.

DeepLearningLecture.pptx

The document provides an introduction to deep learning and how to compute gradients in deep learning models. It discusses machine learning concepts like training models on data to learn patterns, supervised learning tasks like image classification, and optimization techniques like stochastic gradient descent. It then explains how to compute gradients using backpropagation in deep multi-layer neural networks, allowing models to be trained on large datasets. Key steps like the chain rule and backpropagation of errors from the final layer back through the network are outlined.

lec10svm.ppt

This document provides an overview of support vector machines and kernel methods for machine learning.
It discusses how preprocessing input data with nonlinear features can make classification problems linearly separable in high-dimensional space. However, directly using all possible features risks overfitting.
Support vector machines find a maximum-margin separating hyperplane in feature space to minimize overfitting. They use only a subset of training points, called support vectors, to define the decision boundary.
The kernel trick allows support vector machines to implicitly operate in very high-dimensional feature spaces without explicitly computing the feature vectors. All computations can be done using kernel functions that evaluate scalar products in feature space. This makes support vector machines computationally feasible even for huge feature spaces

Optimization for Neural Network Training - Veronica Vilaplana - UPC Barcelona...

Optimization for Neural Network Training - Veronica Vilaplana - UPC Barcelona...Universitat Politècnica de Catalunya

https://telecombcn-dl.github.io/2018-dlai/
Deep learning technologies are at the core of the current revolution in artificial intelligence for multimedia data analysis. The convergence of large-scale annotated datasets and affordable GPU hardware has allowed the training of neural networks for data analysis tasks which were previously addressed with hand-crafted features. Architectures such as convolutional neural networks, recurrent neural networks or Q-nets for reinforcement learning have shaped a brand new scenario in signal processing. This course will cover the basic principles of deep learning from both an algorithmic and computational perspectives.Data structure and algorithm using java

This presentation created for people who like to go back to basics of data structure and its implementation. This presentation mostly helps B.Tech , Bsc Computer science students as well as all programmer who wants to develop software in core areas.

[Paper Reading] Attention is All You Need

The document summarizes the "Attention Is All You Need" paper, which introduced the Transformer model for natural language processing. The Transformer uses attention mechanisms rather than recurrent or convolutional layers, allowing for more parallelization. It achieved state-of-the-art results in machine translation tasks using techniques like multi-head attention, positional encoding, and beam search decoding. The paper demonstrated the Transformer's ability to draw global dependencies between input and output with constant computational complexity.

Unit ii linear data structures

This document discusses different types of queues, including circular queues and priority queues. It provides examples of how circular queues resolve the memory wastage problem of linear queues by connecting the last node to the first. Priority queues are described as storing elements according to priority level, with higher priority elements processed before lower priority ones. Examples of using priority queues include theatre seating and job scheduling. The key operations and implementation using a heap data structure are also summarized.

DSJ_Unit I & II.pdf

This document outlines the syllabus for a course on data structures and algorithms using Java. It covers topics such as the role of algorithms and data structures, algorithm design techniques, types of data structures including primitive types, arrays, stacks, queues, linked lists, trees, graphs, and algorithm analysis. Specific algorithms and data structures discussed include sorting, searching, priority queues, stacks, queues, linked lists, trees, graphs, hashing, and complexity theory.

Divide and Conquer Case Study

The document discusses the divide and conquer algorithm design paradigm and provides examples of algorithms that use this approach, including binary search, matrix multiplication, and sorting algorithms like merge sort and quicksort. It explains the three main steps of divide and conquer as divide, conquer, and combine. Advantages include solving difficult problems efficiently, enabling parallelization, and optimal memory usage. Disadvantages include issues with recursion, stack size, and choosing base cases. The La Russe method for multiplication is provided as a detailed example that uses doubling and halving to multiply two numbers without the multiplication operator.

Topological Sort Algorithm.pptx

Topological sorting is a linear ordering of vertices in a directed acyclic graph (DAG). It is performed by recursively processing vertices with no incoming edges before others. The algorithm uses a stack to push vertices after processing their adjacent vertices. It has applications in project scheduling, circuit design, and detecting cyclic dependencies. The time complexity is O(V+E) where V is vertices and E is edges.

"Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)

This slide was shared on Tech in Asia Jakarta 2016 @ 17 November 2016.
Get updates about our dev events delivered straight to your inbox by signing up here: http://bit.ly/tia-dev ! Be the first to know when new information is available!

Case Study of Convolutional Neural Network

This document summarizes the evolution of convolutional neural networks (CNNs) from LeNet to ResNet. It discusses key CNN architectures like AlexNet, VGGNet, GoogLeNet, and ResNet and the techniques they introduced such as ReLU, dropout, batch normalization, and residual connections. These techniques helped reduce overfitting and allowed training of much deeper networks, leading to substantially improved accuracy on the ImageNet challenge over time, from AlexNet's top-5 error of 15.3% in 2012 to ResNet's 3.57% in 2015.

Recursion and Sorting Algorithms

Recursion and Sorting Algorithms

مدخل إلى تعلم الآلة

مدخل إلى تعلم الآلة

Class13_Quicksort_Algorithm.pdf

Class13_Quicksort_Algorithm.pdf

Dsoop (co 221) 1

Dsoop (co 221) 1

Functional Programming in Javascript - IL Tech Talks week

Functional Programming in Javascript - IL Tech Talks week

Time series representations for better data mining

Time series representations for better data mining

Backtracking Algorithm.pptx

Backtracking Algorithm.pptx

Accelerating Key Bioinformatics Tasks 100-fold by Improving Memory Access

Accelerating Key Bioinformatics Tasks 100-fold by Improving Memory Access

Chap 4 local_search

Chap 4 local_search

DeepLearningLecture.pptx

DeepLearningLecture.pptx

lec10svm.ppt

lec10svm.ppt

Optimization for Neural Network Training - Veronica Vilaplana - UPC Barcelona...

Optimization for Neural Network Training - Veronica Vilaplana - UPC Barcelona...

Data structure and algorithm using java

Data structure and algorithm using java

[Paper Reading] Attention is All You Need

[Paper Reading] Attention is All You Need

Unit ii linear data structures

Unit ii linear data structures

DSJ_Unit I & II.pdf

DSJ_Unit I & II.pdf

Divide and Conquer Case Study

Divide and Conquer Case Study

Topological Sort Algorithm.pptx

Topological Sort Algorithm.pptx

"Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)

"Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)

Case Study of Convolutional Neural Network

Case Study of Convolutional Neural Network

Information Security- Threats and Attacks presentation by DHEERAJ KATARIA

Information Security- Threats and Attacks, Types of Threats,Trespassing, Espionage, Software Attacks, Trojan Horse, Worms,Worm Propagation Model, Virus

Microprocessor Protected Mode Memory addressing By DHEERAJ KATARIA

The document discusses protected mode memory addressing in microprocessors. It describes how protected mode allows access to 4GB of memory using 32-bit offsets and segment descriptors. Segment descriptors stored in global and local descriptor tables define memory segment locations, lengths, and access rights. Operating systems like Windows use protected mode and 32-bit environments while DOS uses 16-bit. The microprocessor caches descriptor information from the tables in program-invisible registers associated with segment registers to efficiently access memory segments.

C++ functions presentation by DHEERAJ KATARIA

The document discusses C++ functions. It defines what a function is and describes the different types of C++ functions including standard and user-defined functions. It explains the structure of C++ functions including the function header, signature, and body. It provides examples of defining, declaring, implementing and calling functions. It also discusses topics like function parameters, scope of variables, inline functions, and building libraries.

E facilities of Municipal Corporation of Delhi By DHEERAJ KATARIA

This document provides an overview of the various departments, services, and information available on the Municipal Corporation of Delhi website. It lists sections for knowing the corporation, zones/wards/colonies, departments, logins, RTI acts, press/information, advertisements, awards/photos, jobs, downloads, parking management, complaints, tenders, sanitation workers, building plans, contacts, citizen services, general services, hospitals/courts/banks, GIS maps, nursing admissions, reports, attendance, help, and details about the website development and maintenance.

Matrix presentation By DHEERAJ KATARIA

1) A matrix is a rectangular array of numbers arranged in rows and columns. The dimensions of a matrix are specified by the number of rows and columns.
2) The inverse of a square matrix A exists if and only if the determinant of A is not equal to 0. The inverse of A, denoted A^-1, is the matrix that satisfies AA^-1 = A^-1A = I, where I is the identity matrix.
3) For two matrices A and B to be inverses, their product must result in the identity matrix regardless of order, i.e. AB = BA = I. This shows that one matrix undoes the effect of the other.

Heritage and tourism in india by DHEERAJ KATARIA

Explore the sites to Visit in India And also explore the vast Built Heritage of India
Built heritage of India....

Information Security- Threats and Attacks presentation by DHEERAJ KATARIA

Information Security- Threats and Attacks presentation by DHEERAJ KATARIA

Microprocessor Protected Mode Memory addressing By DHEERAJ KATARIA

Microprocessor Protected Mode Memory addressing By DHEERAJ KATARIA

C++ functions presentation by DHEERAJ KATARIA

C++ functions presentation by DHEERAJ KATARIA

E facilities of Municipal Corporation of Delhi By DHEERAJ KATARIA

E facilities of Municipal Corporation of Delhi By DHEERAJ KATARIA

Matrix presentation By DHEERAJ KATARIA

Matrix presentation By DHEERAJ KATARIA

Heritage and tourism in india by DHEERAJ KATARIA

Heritage and tourism in india by DHEERAJ KATARIA

How to Manage Reception Report in Odoo 17

A business may deal with both sales and purchases occasionally. They buy things from vendors and then sell them to their customers. Such dealings can be confusing at times. Because multiple clients may inquire about the same product at the same time, after purchasing those products, customers must be assigned to them. Odoo has a tool called Reception Report that can be used to complete this assignment. By enabling this, a reception report comes automatically after confirming a receipt, from which we can assign products to orders.

Juneteenth Freedom Day 2024 David Douglas School District

Juneteenth Freedom Day DDSD

RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students

Physical pharmaceutics notes for B.pharm students

Gender and Mental Health - Counselling and Family Therapy Applications and In...

A proprietary approach developed by bringing together the best of learning theories from Psychology, design principles from the world of visualization, and pedagogical methods from over a decade of training experience, that enables you to: Learn better, faster!

Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"

Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"National Information Standards Organization (NISO)

This presentation was provided by Racquel Jemison, Ph.D., Christina MacLaughlin, Ph.D., and Paulomi Majumder. Ph.D., all of the American Chemical Society, for the second session of NISO's 2024 Training Series "DEIA in the Scholarly Landscape." Session Two: 'Expanding Pathways to Publishing Careers,' was held June 13, 2024.How to Fix [Errno 98] address already in use

This slide will represent the cause of the error “[Errno 98] address already in use” and the troubleshooting steps to resolve this error in Odoo.

BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...

BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...Nguyen Thanh Tu Collection

https://app.box.com/s/nrwz52lilmrw6m5kqeqn83q6vbdp8yzpLevel 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt

The History of NZ 1870-1900.
Making of a Nation.
From the NZ Wars to Liberals,
Richard Seddon, George Grey,
Social Laboratory, New Zealand,
Confiscations, Kotahitanga, Kingitanga, Parliament, Suffrage, Repudiation, Economic Change, Agriculture, Gold Mining, Timber, Flax, Sheep, Dairying,

Electric Fetus - Record Store Scavenger Hunt

Electric Fetus is a record store in Minneapolis, MN

Haunted Houses by H W Longfellow for class 10

Haunted Houses by H W Longfellow for class 10 ICSE

Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...

Andreas Schleicher, Director of Education and Skills at the OECD presents at the launch of PISA 2022 Volume III - Creative Minds, Creative Schools on 18 June 2024.

spot a liar (Haiqa 146).pptx Technical writhing and presentation skills

sample presentation

Temple of Asclepius in Thrace. Excavation results

The temple and the sanctuary around were dedicated to Asklepios Zmidrenus. This name has been known since 1875 when an inscription dedicated to him was discovered in Rome. The inscription is dated in 227 AD and was left by soldiers originating from the city of Philippopolis (modern Plovdiv).

CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx

Slides from a Capitol Technology University webinar held June 20, 2024. The webinar featured Dr. Donovan Wright, presenting on the Department of Defense Digital Transformation.

How to Predict Vendor Bill Product in Odoo 17

This slide will guide us through the process of predicting vendor bill products based on previous purchases from the vendor in Odoo 17.

Benner "Expanding Pathways to Publishing Careers"

This presentation was provided by Rebecca Benner, Ph.D., of the American Society of Anesthesiologists, for the second session of NISO's 2024 Training Series "DEIA in the Scholarly Landscape." Session Two: 'Expanding Pathways to Publishing Careers,' was held June 13, 2024.

BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx

Practical manual for National Examination Council, Nigeria.
Contains guides on answering questions on the specimens provided

How to Download & Install Module From the Odoo App Store in Odoo 17

Custom modules offer the flexibility to extend Odoo's capabilities, address unique requirements, and optimize workflows to align seamlessly with your organization's processes. By leveraging custom modules, businesses can unlock greater efficiency, productivity, and innovation, empowering them to stay competitive in today's dynamic market landscape. In this tutorial, we'll guide you step by step on how to easily download and install modules from the Odoo App Store.

Educational Technology in the Health Sciences

Plenary presentation at the NTTC Inter-university Workshop, 18 June 2024, Manila Prince Hotel.

How to Manage Reception Report in Odoo 17

How to Manage Reception Report in Odoo 17

Juneteenth Freedom Day 2024 David Douglas School District

Juneteenth Freedom Day 2024 David Douglas School District

RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students

RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students

Gender and Mental Health - Counselling and Family Therapy Applications and In...

Gender and Mental Health - Counselling and Family Therapy Applications and In...

Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"

Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"

How to Fix [Errno 98] address already in use

How to Fix [Errno 98] address already in use

BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...

BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...

Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt

Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt

Electric Fetus - Record Store Scavenger Hunt

Electric Fetus - Record Store Scavenger Hunt

Haunted Houses by H W Longfellow for class 10

Haunted Houses by H W Longfellow for class 10

Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...

Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...

spot a liar (Haiqa 146).pptx Technical writhing and presentation skills

spot a liar (Haiqa 146).pptx Technical writhing and presentation skills

Temple of Asclepius in Thrace. Excavation results

Temple of Asclepius in Thrace. Excavation results

CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx

CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx

REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf

REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf

How to Predict Vendor Bill Product in Odoo 17

How to Predict Vendor Bill Product in Odoo 17

Benner "Expanding Pathways to Publishing Careers"

Benner "Expanding Pathways to Publishing Careers"

BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx

BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx

How to Download & Install Module From the Odoo App Store in Odoo 17

How to Download & Install Module From the Odoo App Store in Odoo 17

Educational Technology in the Health Sciences

Educational Technology in the Health Sciences

- 2. A more complicated case of recursion is found in definitions in which a function is not only defined in terms of itself but it is also used as one of the parameters. Example: 4if))2(2( ,4if ,0if0 )( nnhh nn n nh h(1)=h(2+h(2))=h(14)=14 h(2)=h(2+h(4))=h(12)=12 h(3)=h(2+h(6))=h(2+6)=h(8)=8 h(4)=h(2+h(8))=h(2+8)=h(10)=10 Recursion • Nested Recursion
- 3. The Ackermann function otherwise))1,(,1( ,0,0if)1,1( ,0if1 ),( mnAnA mnnA nm mnA This function is interesting because of its remarkably rapid growth. It grows so fast that it is guaranteed not to have a representation by a formula that uses arithmetical operations such as addition, multiplication, and exponentiation. Recursion • Nested Recursion
- 5. Logical simplicity and readability are used as an argument supporting the use of recursion. The price for using recursion is slowing down execution time and storing on the run-time stack more things than required in a non-recursive approach. Example: The Fibonacci numbers .2if)1()2( ,2if1 ,1if1 )( iiFiF i i iF void Fibonacci(int n) { If (n<2) return 1; else return Fibonacci(n-1)+Fibonacci(n-2); } Recursion • Excessive Recursion
- 6. Many repeated computations Recursion • Excessive Recursion
- 8. void IterativeFib(int n) { if (n < 2) return n; else { int i = 2, tmp, current = 1, last = 0; for ( ; i<=n; ++i) { tmp= current; current += last; last = tmp; } return current; } } Recursion • Excessive Recursion
- 10. We can also solve this problem by using a formula discovered by A. De Moivre. The characteristic formula is :- 5 ) 2 51 () 2 51 ( )( nn nf Can be neglected when n is large Recursion • Excessive Recursion The value of is approximately -0.618034) 2 51 (
- 11. Suppose you have to make a series of decisions, among various choices, where • You don’t have enough information to know what to choose • Each decision leads to a new set of choices • Some sequence of choices (possibly more than one) may be a solution to your problem Backtracking is a methodical way of trying out various sequences of decisions, until you find one that “works” Recursion • Backtracking
- 12. Backtracking allows us to systematically try all available avenues from a certain point after some of them lead to nowhere. Using backtracking, we can always return to a position which offers other possibilities for successfully solving the problem. Recursion • Backtracking
- 13. Recursion • Backtracking Place 8 queens on an 8 by 8 chess board so that no two of them are on the same row, column, or diagonal The Eight Queens Problem
- 14. Recursion • Backtracking The Eight Queens Problem
- 15. The Eight Queens Problem Pseudo code of the backtracking algorithm PutQueen(row) for every position col on the same row if position col is available { place the next queen in position col; if (row < 8) PutQueen(row+1); else success; remove the queen from position col; /* backtrack */ } Recursion • Backtracking
- 16. The Eight Queens Problem Natural Implementation 1 Initialization 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Q The first queen 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 1 0 1 1 1 1 1 0 1 1 0 1 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 1 0 1 1 0 1 1 1 1 1 0 1 0 1 1 1 1 1 1 0 Q The second queen 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 Q 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 1 0 0 1 1 1 0 0 1 1 0 0 1 1 0 0 1 1 1 0 0 1 0 0 1 1 1 1 0 0 Recursion • Backtracking
- 17. The Eight Queens Problem Natural Implementation Q The third queen 0 0 0 0 0 0 0 0 0 0 1 1 0 1 1 0 Q 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 Q 0 0 0 0 0 0 0 0 1 0 0 1 1 0 0 0 1 1 0 0 1 0 0 0 1 1 1 0 0 Q The fourth queen 0 0 0 0 0 0 0 0 0 0 Q 0 0 0 0 0 Q 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0 0 Q 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0 0 0 0 1 1 0 0 Q The 5th & 6th queen 0 0 0 0 0 0 0 0 0 0 Q 0 0 0 0 0 Q 0 0 0 0 0 0 0 0 0 0 Q 0 0 0 0 0 Q 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Q 0 0 Have to backtrack now!This would be queen now. Recursion • Backtracking
- 18. The Eight Queens Problem Natural Implementation The setting and resetting part would be the most time-consuming part of this implementation. However, if we focus solely on the queens, we can consider the chessboard from their perspective. For the queens, the board is not divided into squares, but into rows, columns, and diagonals. Recursion • Backtracking
- 19. The Eight Queens Problem Simplified data structure A 4 by 4 chessboard Row-column = constant for each diagonal Recursion • Backtracking
- 20. The Eight Queens Problem Recursion • Backtracking
- 21. The Eight Queens Problem Recursion • Backtracking
- 22. The Eight Queens Problem Recursion • Backtracking
- 23. Recursion • Backtracking The Eight Queens Problem
- 24. Recursion • Backtracking The Eight Queens Problem
- 25. • Usually recursive algorithms have less code, therefore algorithms can be easier to write and understand - e.g. Towers of Hanoi. However, avoid using excessively recursive algorithms even if the code is simple. • Sometimes recursion provides a much simpler solution. Obtaining the same result using iteration requires complicated coding - e.g. Quicksort, Towers of Hanoi, etc. Why Recursion?
- 26. Why Recursion? • Recursive methods provide a very natural mechanism for processing recursive data structures. A recursive data structure is a data structure that is defined recursively – e.g. Linked-list, Tree. Functional programming languages such as Clean, FP, Haskell, Miranda, and SML do not have explicit loop constructs. In these languages looping is achieved by recursion.
- 27. • Recursion is a powerful problem-solving technique that often produces very clean solutions to even the most complex problems. • Recursive solutions can be easier to understand and to describe than iterative solutions. Why Recursion?
- 28. • By using recursion, you can often write simple, short implementations of your solution. • However, just because an algorithm can be implemented in a recursive manner doesn’t mean that it should be implemented in a recursive manner. Why Recursion?
- 29. Limitations of Recursion • Recursive solutions may involve extensive overhead because they use calls. • When a call is made, it takes time to build a stackframe and push it onto the system stack. • Conversely, when a return is executed, the stackframe must be popped from the stack and the local variables reset to their previous values – this also takes time.
- 30. Limitations of Recursion • In general, recursive algorithms run slower than their iterative counterparts. • Also, every time we make a call, we must use some of the memory resources to make room for the stackframe.
- 31. Limitations of Recursion • Therefore, if the recursion is deep, say, factorial(1000), we may run out of memory. • Because of this, it is usually best to develop iterative algorithms when we are working with large numbers.
- 32. Main disadvantage of programming recursively • The main disadvantage of programming recursively is that, while it makes it easier to write simple and elegant programs, it also makes it easier to write inefficient ones. • when we use recursion to solve problems we are interested exclusively with correctness, and not at all with efficiency. Consequently, our simple, elegant recursive algorithms may be inherently inefficient.