[7급 국가직 자료구조론 2022년 10번]

다음 tree_height() 함수는 이진 트리의 루트 노드를 매개변수로 받아 트리의 높이를 반환한다. (가) ~ (다)에 들어갈 내용을 바르게 연결한 것은?
typedef struct node {
   int value;
   struct node *left;
   struct node *right;
} node;

int tree_height (node *ptr) {
   int left_h, right_h;
   if (ptr == NULL) 
      return 0;
   else {
      left_h = tree_height(ptr->left);
      right_h = tree_height(ptr->right);
      if ( (가) )
         return (나) ;
      else 
         return (다) ;
   }
}
(가) (나) (다)
자료구조론
  1. ①left_h > right_h left_h right_h
  2. ②left_h > right_h left_h + 1 right_h + 1
  3. ③left_h < right_h left_h right_h
  4. ④left_h < right_h left_h + 1 right_h + 1

선지를 골라 바로 채점해 보세요.

정답 ②

출처: 인사혁신처 공개 기출(공공데이터포털, 이용허락 제한 없음)

신고가 접수됐습니다. 감사합니다.

오류 신고