Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
Tags
- 실버
- DP 알고리즘
- 문제 풀이
- 한반도평화와공공외교
- 연산자 문제
- N과 M
- 이항계수
- 알고리즘
- 백준
- 해설
- CSS
- 풍선터뜨리기
- 백준 1246번
- 풀이
- 0의 개수
- 가치규범의 공공외교
- Python
- 챗봇
- 주창형 공공외교
- 1
- 백준 1487번
- 해싱
- hashing
- 백준 11050번
- 백준 14501번
- 파이썬
- B-tree
- html
- BTREE
- 1141번
Archives
- Today
- Total
SunFly의 코딩 및 정보 블로그
B-tree 탐색(searching or Retrieval) 알고리즘 본문
m-원 탐색 트리와 알고리즘은 동일하다.
(이진 탐색을 사용한다.)
※ Searhing 알고리즘
- (1) Pointer curr를 Tree의 Root노드에 지정한다.
- (2) curr 노드에서 왼쪽부터 오른쪽으로 record를 스캔한다. => if curr==NULL, retrun with fail(만약 curr노드가 NULL이면 실패한다.)
- (3) i=0;
- (3-1) if (i >= fill_cnt) { curr = P[i]; goto 2; } // 더이상 비교하지 않고 마지막 포인터를 사용한다.
- (3-2)
- (Case1) rec.key < skey : i = i++; go to (3-1) //다음 record를 스캔한다.
- (Case2) rec.key == skey : return with success //탐색 성공
- (Case3) rec.key > skey : curr = P[i]; goto 2; //go down to a child
ex) key값 45를 탐색한다고 하자.
★code
// retrieval.c
#include "functions.h"
void retrieval(nodeptr curr, char CompName[])
{
nodeptr temp_ptr = NULL;
int level = 1;
int i = 0;
do {
for (i = 0; i < curr->fill_cnt; i++) {
if (strcmp(CompName, curr->rec[i].name) < 0) {
break;
} // if (CompName)
else if (strcmp(CompName, curr->rec[i].name) == 0) {
printf("\t%s 레코드는\n", CompName);
printf("\t레벨%d에 위치하며 이 노드의 %d번째 레코드에 존재합니다.\n", level, i+1);
return;
} // else if (CompName)
} // for (i)
temp_ptr = curr->ptr[i];
if (temp_ptr) { curr = temp_ptr; level++; }
} while (temp_ptr);
printf("%s 레코드가 존재하지 않습니다.\n", CompName);
}
'알고리즘' 카테고리의 다른 글
이진 탐색 트리(Binary Search Tree)란? (0) | 2021.10.11 |
---|---|
B-tree 구현 (C언어 구현) (0) | 2021.10.11 |
B-tree 삭제(Deletion) 알고리즘 (Redistribution/Merge 알고리즘) (0) | 2021.10.11 |
B-tree 삽입(insertion) 알고리즘 (0) | 2021.10.10 |
B-tree 알고리즘이란? (0) | 2021.10.10 |