이 페이지는 Recursive subdivision의 동작을 간단한 binary image를 대상으로 보여준다.
사용한 image는 The Secret Life of Programs 의 5장에 나오는 Figure 5-3: A crude simley face를 사용하면서 단지 좌표를 일반적인 image에서 사용하는대로 top-left pixel을 0,0으로 처리했다.
최종으로 나오는 Tree의 leaf node의 갯수는 40개로 원래의 64개보다 줄어들며, 일종의 압축된 representation을 형성한다.
Pseudo code 및 동작
이 Recursive subdivision 예제의 Pseudo code (Recursive Functon이 사용됨)는 다음과 같다.
function subdivide(x, y, size)
{
IF size != 1 AND "the pixels in the square are not all the same color" {
half = size / 2
subdivide(x, y, half) # upper left quadrant
subdivide(x, y + half, half) # lower left quadrant
subdivide(x + half, y + half, half) # lower right quadrant
subdivide(x + half, y, half) # upper right quadrant
}
ELSE {
save the information about the square
}
}
동작은 다음과 같음.
위의 image subdivision은 Depth-First-Search로 동작하며, stack과 recursive call을 통해 쉽게 구현할 수 있음.
Stack
Stack과 stack frame은 다음과 같음.
- recursive call이 발생할 때마다, 귀환할 주소와 해당 call의 parameter에 할당된 argument를 stack에 집어넣음.
Stack Frame
: stack에 저장된 데이터들의 모음 을 Stack Frame
이라고 부르고 다음으로 구성됨.
- function(=subroutine)으로 전달하는 parameters (이들의 값은 호출 시 사용된 argument임)
- local variables (C언어)
- 복귀 주소
다음 url들을 같이 보면 도움이 됨.
2023.05.23 - [Computer/CE] - [CE] Stack
[CE] Stack
Stack은 자료구조의 하나로서 FILO (First-In-Last-Out, LIFO 와 같은 의미.)로 동작함. 많은 경우 접시 쌓기를 예로 사용하여 First-In-Last-Out (FILO), Last-In-First-Out (LIFO)를 설명한다. Stack에 저장되는 데이터 단
dsaint31.tistory.com
2023.05.24 - [Programming] - [Python] recursive call : Fibonacci Sequence
[Python] recursive call : Fibonacci Sequence
Recursive call의 경우, 특정 함수가 내부에서 자기자신을 다시 호출하는 것을 가르킴. 다음과 같은 재귀적인 수식을 있는 그대로 작성하게 해준다는 장점은 있지만, 속도의 측면에서는 그리 환영받
dsaint31.tistory.com
2023.02.20 - [Computer/CE] - [CE] Tree vs. Graph
[CE] Tree vs. Graph
Graph node와 node를 연결하는 edge로 구성된 자료구조. object들의 network를 모델링하는데 주로 사용됨. Tree Directed Acyclic Graph 에서, graph 내의 모든 node와 path가 존재하는 root node라는 것이 1개 있는 자료
dsaint31.tistory.com
https://nostarch.com/foundationsofcomp
The Secret Life of Programs
The Secret Life of Programs is a primer on the underlying technologies that allow computer programs to work.
nostarch.com
'Computer > CE' 카테고리의 다른 글
[CE] Round-off Error 예제 (1) | 2024.02.17 |
---|---|
[CE] Classless Inter-Domain Routing 표기법: IP Address (0) | 2024.02.07 |
[CE] Stack (0) | 2023.05.23 |
[Linux] Signal : SIGINT (0) | 2023.04.09 |
[CE] URL, URI and UNC (0) | 2023.04.09 |