Data-Structures-and-Algorithms-in-Java-6th-Edition | Code extracts and notes from the book by Michael | Learning library
kandi X-RAY | Data-Structures-and-Algorithms-in-Java-6th-Edition Summary
kandi X-RAY | Data-Structures-and-Algorithms-in-Java-6th-Edition Summary
ISBN: 978-1-118-80857-3 Aug 2014 The design and analysis of efficient data structures has long been recognized as a key component of the Computer Science curriculum. Goodrich and Tomassia's approach to this classic topic is based on the object-oriented paradigm as the framework of choice for the design of data structures. For each ADT presented in the text, the authors provide an associated Java interface. Concrete data structures realizing the ADTs are provided as Java classes implementing the interfaces. The Java code implementing fundamental data structures in this book is organized in a single Java package, net.datastructures. This package forms a coherent library of data structures and algorithms in Java specifically designed for educational purposes in a way that is complimentary with the Java Collections Framework.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Demonstrates how to enter a game
- Places a mark at position i
- Entry point for testing
- Reverse an array
- Prints the command
- Transform the given string by letter
- Draw an English ruler for the given major tick length
- Draw a line
- Inserts the specified element at the specified position
- Resize internal array
- Returns a string representation of the board
- Adds a new entry to the list
- Replaces the element at the specified position
- Removes the element from the queue
- Computes the power of x
- Removes the first element from the queue
- Checks whether the given expression is properly matched
- Removes the first element and returns it
- Inserts an element at position i
- Simple test method
- Inserts a list of integers into a sorted order
- Creates a clone of this list
- Checks if the given HTML string contains a matching tag
- Removes the element at the given position
- Replaces the element at the given position
Data-Structures-and-Algorithms-in-Java-6th-Edition Key Features
Data-Structures-and-Algorithms-in-Java-6th-Edition Examples and Code Snippets
Community Discussions
Trending Discussions on Data-Structures-and-Algorithms-in-Java-6th-Edition
QUESTION
I am having a hard time understanding the process of drawing the repeated square diagram of recursion.
I have the book of data structure and algorithms which shows this code on page 210:
...ANSWER
Answered 2020-Jun-28 at 14:05The difference in numbers that you see in the recursion trace comes from n/2
in the code. It is an integer division by two. So 13/2 is 6 and 6/2 is 3 and 3/2 is 1, and finally 1/2 is 0. This is what you see when you read the diagram from top to bottom. The diagram shows these entries shifted more and more to the right to represent the depth of the recursion. The function calls itself, and then it calls itself again, ...etc. All of these calls are pending... Each time these calls pass a value for n
that is smaller (halved).
Somewhere this stops. It needs to, of course. This stops when the value of n
receives the value 0. You see this state at the bottom of the diagram. At that moment, the recursion does not go deeper and starts to unwind, and you need to read the diagram now from bottom back to the top. For n
equal to 0, the return value is 1 (return 1
).
This value is read by the function execution where n
is 1 and where the call power(2, 0)
was made and waiting for a return value. It receives 1 as result. This value is then squared (partial * partial
) which in this case still is 1. And because n
is odd (it is 1 here), there is an additional multiplication *= x
. So we actually calculate partial * partial * x
, which is 1 * 1 * 2
. You'll see this in the diagram.
And this value (2) is returned to the function execution where n
is 3 and where the call power(2, 1)
was made. It receives 2 as result. This value is then squared (partial * partial
) which in this case is 4. And because n
is odd (it is 3 here), there is an additional multiplication *= x
. So we actually calculate partial * partial * x
, which is 2 * 2 * 2
. You'll see this in the diagram.
I hope you see the pattern. The function executions that are pending for a result, all get their value back from the recursive function call they made, do some multiplication with it and return that, in turn, to their caller.
And so the recursion backtracks to the top, providing the end result to the top-level call of power(2, 13)
.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install Data-Structures-and-Algorithms-in-Java-6th-Edition
You can use Data-Structures-and-Algorithms-in-Java-6th-Edition like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the Data-Structures-and-Algorithms-in-Java-6th-Edition component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page