2011년 8월 10일 수요일

Algorithm Analysis :: Big O - notation

*O(n) means to the UPPER BOUND


O(1)     : 자료의 양에 관계없이 일정한 시간이 걸리는 작업
O(lg n)  : 자료 집합을 반으로 나누고 그 반을 다시 반으로 나누는 과정을 반복하는 작업
O(n)     : 자료 집합을 순회하는 작업
O(n*lg n): 자료 집합을 반복해서 둘로 나누고 나뉘어진 반을 순회하는 작업
O(n^2)   : 한 집합의 각 자료에 대해 같은 크기의 다른 집합을 순회하는 작업
O(2^n)   : 집합의 모든 부분집합을 생성하는 작업
O(n!)    : 집합의 모든 순열을 생성하는 작업

Call Stack (maybe...?)

            [Activation Record of Function Foo]


+---------------------------------------------------------+
|                    Input Parameters                     | <= CCS
+---------------------------------------------------------+
|                      Return Value                       |
+---------------------------------------------------------+
|                     Local Variables                     |
+---------------------------------------------------------+
|    EBP (Base Pointer of Previous Activation Record)     |
|  Return Address (Next Command of Current Function Call) |
|                           ...                           |
+---------------------------------------------------------+
| Output Parameters (Input Parameter of Next Call Stack)  | <= NCS


                            ...


* Input Parameters: 현재 콜스택에 실제 복사된 파라미터
* Return Value: 함수 리턴시 리턴된 값의 저장 공간
* Local Variables: 현재 함수의 지역변수
* EBP Register: 이전 콜스택 시작주소의 저장 공간
* Return Address: 현재 함수 호출 후 다음 수행될 명령어 위치의 저장 공간
* Output Parameter: 다음 함수 호출 시 Input Parameters가 됨


*CCS: Current Call Stack
*NCS: Next Call Stack

2011년 8월 9일 화요일

Using Pointer in C

Execution Environment :: VS2010


// #1 type conflict :: warning, runtime error
char *sptr = "abc", *tptr;
*tptr = sptr;
printf("%s\n", tptr);

// #2 type matched :: no error
char *sptr = "abc", *tptr;
tptr = sptr;
printf("%s\n", tptr);

// #3 not-allocated memory space :: runtime error
char *sptr = "abc", *tptr;
*tptr = *sptr;
printf("%s\n", tptr);

// #4 constant integer allocation in integer pointer :: runtime error
int *iptr = (int *)10;
*iptr = 11;
printf("%d\n", *iptr);

// #5 type conflict :: warning, runtime error
int *iptr = 10;
*iptr = 11;
printf("%d\n", *iptr);

// #6 soon fixed :: no error
int *iptr = (int *)10;
iptr = NULL;