Chapter 8 Recursive Thinking - PowerPoint PPT Presentation

1 / 3
About This Presentation
Title:

Chapter 8 Recursive Thinking

Description:

is the concept of a method calling itself. is often an alternative to ... Recursive algorithms ... Recursion example. Add up all the integers in a linked list ... – PowerPoint PPT presentation

Number of Views:19
Avg rating:3.0/5.0
Slides: 4
Provided by: markt2
Category:

less

Transcript and Presenter's Notes

Title: Chapter 8 Recursive Thinking


1
Chapter 8Recursive Thinking
  • CS 260 Data Structures
  • Indiana University Purdue University Fort Wayne

2
Recursive thinking
  • We will just briefly review the concept of
    recursion
  • Recursion . . .
  • is the concept of a method calling itself
  • is often an alternative to iteration
  • sometimes provides a simpler solution
  • Recursive algorithms
  • A recursive algorithm must have at least one
    stopping case with a non-recursive solution
  • Other cases must be replaced by reduced cases
    closer to a stopping case

3
Recursion example
  • Add up all the integers in a linked list
  • Note that the reduced case it closer to the
    stopping case because the length of the linked
    list pointed to by head.link is closer to zero

public static int addUp( IntNode head )
if ( head null ) return 0

// stopping case else
return head.data Node.addUp( head.link )
// reduced case
33
11
19
92
56
head
Write a Comment
User Comments (0)
About PowerShow.com