Minecraft wiki entry for Pumpkin_and_melon_farming, associated text: Thus, hydrated farmland adjacent increases growth rates of stems and production rate of fruit, having the same stem type adjacent to the stem (unless in rows) reduces growth rates and fruit production, light level 9 in the block above the stem is required for any growth, etc.
The maximum probability of fruit production from a single stem would, therefore, require a stem in hydrated farmland with hydrated farmland on all eight sides, with four of those farmland blocks remaining unplanted (the corners may be planted with some other crop). Practical farms often accept reduced per-plant production rates (⅔, ⅓, or even ⅙ of the maximum) for greater space efficiency and ease of harvest.