Index: src/wp-includes/class-wp-walker.php
===================================================================
--- src/wp-includes/class-wp-walker.php	(revision 39474)
+++ src/wp-includes/class-wp-walker.php	(working copy)
@@ -214,8 +214,20 @@
 		 */
 		$top_level_elements = array();
 		$children_elements  = array();
+		
+		/*
+		 * Default $root to the first element
+		 * Used in the case that there are no top level elements
+		 */
+		$first = array_slice( $elements, 0, 1 );			
+		$root = $first[0];
+		$element_ids = array_map(function($element){ return $element->ID; }, $elements);
+		
 		foreach ( $elements as $e) {
-			if ( empty( $e->$parent_field ) )
+			// If the parent_field is not blank OR in the list of elements update to be the root element
+			if ( !empty( $e->parent_field) && !in_array($e->parent_field, $element_ids))
+				$root = $e;
+			elseif ( empty( $e->$parent_field ) )
 				$top_level_elements[] = $e;
 			else
 				$children_elements[ $e->$parent_field ][] = $e;
@@ -223,13 +235,9 @@
 
 		/*
 		 * When none of the elements is top level.
-		 * Assume the first one must be root of the sub elements.
+		 * Set the element buckets based on the root defined above
 		 */
 		if ( empty($top_level_elements) ) {
-
-			$first = array_slice( $elements, 0, 1 );
-			$root = $first[0];
-
 			$top_level_elements = array();
 			$children_elements  = array();
 			foreach ( $elements as $e) {
