For the tree in Figure 4.70: a. Which node is the root? b. Which nodes are leaves?
Read moreTextbook Solutions for Data Structures and Algorithm Analysis in Java
Question
Generate an index for a book. The input file consists of a set of index entries. Eachline consists of the string IX:, followed by an index entry name enclosed in braces,followed by a page number that is enclosed in braces. Each ! in an index entryname represents a sub-level. A (|represents the start of a range, and a |) representsthe end of the range. Occasionally, this range will be the same page. In that case,output only a single page number. Otherwise, do not collapse or expand ranges onyour own. As an example, Figure 4.75 shows sample input, and Figure 4.76 showsthe corresponding output.
Solution
The first step in solving 4 problem number 53 trying to solve the problem we have to refer to the textbook question: Generate an index for a book. The input file consists of a set of index entries. Eachline consists of the string IX:, followed by an index entry name enclosed in braces,followed by a page number that is enclosed in braces. Each ! in an index entryname represents a sub-level. A (|represents the start of a range, and a |) representsthe end of the range. Occasionally, this range will be the same page. In that case,output only a single page number. Otherwise, do not collapse or expand ranges onyour own. As an example, Figure 4.75 shows sample input, and Figure 4.76 showsthe corresponding output.
From the textbook chapter Trees you will find a few key concepts needed to solve this.
Visible to paid subscribers only
Step 3 of 7)Visible to paid subscribers only
full solution