1.
세 개의 노드를 가진 무방향 완전 그래프의 신장 트리(spanning tree)는 최대 몇 가지인가?
- ①1
- ②2
- ③3
- ④4
정답 보기
정답 ③ · 해설 보기
시행 2022-10-15 · 책형 나 · 25문항 · 출처: 인사혁신처 공개 기출(공공데이터포털, 이용허락 제한 없음)
정답 ③ · 해설 보기

정답 ③ · 해설 보기
알고리즘 | 수행시간 복잡도 |
A | O() |
B | O() |
C | O() |
D | O() |
정답 ① · 해설 보기
ㄱ. 공백 이진 트리의 높이를 0으로 본다면, 높이가 5인 이진 트리의 최대 노드 수는 15이다.ㄴ. 9개의 노드를 가지고 있는 이진 트리는 8개의 간선을 가진다.ㄷ. 루트 노드의 인덱스를 1로 하는 1차원 배열로 완전 이진 트리를 표현할 때, 인덱스 13인 노드의 부모 노드는 인덱스가 7이다.ㄹ. 7개 노드로 구성할 수 있는 이진 트리의 최대 높이와 최소 높이의 차는 4이다.
정답 ③ · 해설 보기
push(3) → push(7) → pop() → push(5) → push(8) → peek() → push(10) → pop()




정답 ② · 해설 보기

정답 ① · 해설 보기
6, 7, 8, 2, 1, 5, 4
정답 ③ · 해설 보기
#include <stdio.h>
#include <malloc.h>
typedef struct Node {
struct Node *a;
int b;
} Node;
int listSum(Node *p) {
int sum = 0;
Node *s = p;
do {
sum += (가) ;
p = (나) ;
} while ( (다) );
return sum;
}
int main() {
int MAX = 5;
int i, s;
Node *p[MAX];
for( i = 0; i < MAX; i++) {
p[i] = (Node*)malloc(sizeof(Node));
p[i]->b = i+1;
}
for( i = 0; i < MAX-1; i++)
p[i]->a = p[i+1];
p[MAX-1]->a = p[0];
s = listSum(p[0]);
printf("Sum = %d", s);
}정답 ④ · 해설 보기
라인 번호 | C 코드 |
1
2
3
4
5
6
7
8
9
10
11 | #include <stdio.h>
int main() {
int array[] = {0,1,2};
int *p = array+2;
printf("%d\n", *(p-1));
printf("%d\n", *p-1);
printf("%d\n", *(p--));
printf("%d\n", *p);
} |
정답 ③ · 해설 보기
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 (다) ;
}
}정답 ② · 해설 보기
정답 ④ · 해설 보기
#include <stdio.h>
char stack[100];
int top = -1;
void push(char ch) {stack[++top] = ch;}
char pop() {return stack[top--];}
int isEmpty() {return top == -1;}
int isPalindrome(char *str) {
int i;
for ( i = 0; str[i]; i++ )
(가) ;
for ( i = 0; !isEmpty(); i++ )
if ( (나) )
return 0;
return 1;
}
int main() {
char input[100];
scanf("%s", input);
printf("%s",
isPalindrome(input) ? "True" : "False");
}정답 ② · 해설 보기
int search(int key, int a[], int n) {
int mid;
int left = 0;
int right = n-1;
while ((가)) {
mid = (right + left) / 2;
if (key == a[mid]) return mid;
if ((나)) right = mid - 1;
else left = mid + 1;
}
return -1;
}정답 ③ · 해설 보기
int fibonacci(int n){
int x = 0, y = 1, z = 0;
if (n < 2) return n;
while ((가)) {
(나) ;
x = y;
y = z;
}
return z;
}정답 ① · 해설 보기
○ A = 높이가 5인 완전 이진 트리가 가질 수 있는 최소 노드 수○ B = 높이가 6인 포화 이진 트리의 노드 수○ C = 높이가 7인 완전 이진 트리가 가질 수 있는 최대 노드 수
정답 ② · 해설 보기

정답 ④ · 해설 보기
정답 ① · 해설 보기

class Node:
def __init__(self, data, next):
self.data = data
self.next = next
class CircularLinkedList:
def __init__(self):
self.last = None
def insert(self, data):
n = Node(data, None)
if self.last is None:
n.next = n
self.last = n
else:
(가)
(나)
(다)
myCLL = CircularLinkedList()
myCLL.insert(1)
myCLL.insert(2)
myCLL.insert(3)A. n.next = self.lastB. n.next = self.last.nextC. self.last = nD. self.last.next = n
정답 ④ · 해설 보기
struct stack {
int data;
struct stack* link;
};
struct stack* top = NULL;
int pop(){
struct stack* temp = top;
int item;
if (!temp){
printf("Stack is empty.\n");
exit(1);
}
item = temp->data;
(가) ;
free(temp);
(나) ;
}정답 ③ · 해설 보기
○ 해시 함수: h(x) = x mod 13○ 충돌 해결책: 선형 조사법(linear probing)○ 해시 테이블의 크기: 13개 버킷(0부터 12까지 인덱스를 가짐)○ 해시 테이블 버킷당 슬롯 수: 1개
정답 ① · 해설 보기
struct node {
int data;
struct node *link;
} *head;
void reverseList() {
struct node *prevNode, *curNode;
prevNode = head;
curNode = head;
head = NULL;
while ( (가) ) {
curNode = curNode->link;
prevNode->link = head;
(나) ;
(다) ;
}
}정답 ② · 해설 보기

정답 ② · 해설 보기
#include <stdio.h>
void sort(int arr[], int n) {
int count = 1;
int i, j, k, h, val;
for (h = n/2; h > 0; h /= 2) {
for (i = 0; i < h; i++) {
for (j = i+h; j < n; j += h) {
val = arr[j];
k = j;
while (k > h-1 && arr[k-h] > val) {
arr[k] = arr[k-h];
k -= h;
}
arr[k] = val;
if (count == 5)
for (int t = 0; t < 6; t++)
printf("%d ", arr[t]);
count++;
}
}
}
}
int main() {
int a[6] = {5, 9, 2, 3, 6, 7};
sort(a, 6);
}정답 ② · 해설 보기
15, 8, 10, 18, 22, 13, 26, 7
정답 ② · 해설 보기
정답 ① · 해설 보기