id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

jebbert@volusia.k12.fl.us > t050115nodeCount
prev  |  next  |  chance

Write a method that returns the total number of nodes, including the root node, in a "web structure". A web structure is created by starting at a root node, then branching out into 'splitsPerNode' multiple first-layer nodes. For each of those first-layer nodes you then branch out into 'splitsPerNode' second-layer nodes. Your method returns the total number of nodes in the structure where 'splitsPerNode' is how many branches there are from each node at each layer and 'layers' is the total number of layers. If layers=0 the structure only has the root node and you should return 1. Please look at the test data for examples. Also, please ask your teacher to diagram a few examples on the board for clarity.


t050115nodeCount(5, 2) → 31
t050115nodeCount(2, 10) → 2047
t050115nodeCount(7000, 0) → 1

...Save, Compile, Run (ctrl-enter)

public int t050115nodeCount(int splitsPerNode, int layers) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 280

Copyright Nick Parlante 2017 - privacy