달력

1

« 2025/1 »

  • 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

'분류 전체보기'에 해당되는 글 168

  1. 2015.12.10 Binary Tree
  2. 2015.12.10 Spanning Tree
  3. 2015.12.10 Tree
  4. 2015.12.09 Isomorphic Graphs / Homeomorphic graphs/ Planar graph
  5. 2015.12.09 A shortest-path algoritnm
  6. 2015.12.09 Euler cycle & Hamiltonian cycle
  7. 2015.12.09 Graph
  8. 2015.11.24 함수 포인터
  9. 2015.10.24 [visual studio 2013] scanf_s에서 s없애기와 freopen
  10. 2015.10.23 void*
2015. 12. 10. 02:37

Binary Tree 전자공학이론/이산수학2015. 12. 10. 02:37

Binary Tree

A binary tree is a rooted tree where each vertex has zero, one or two children.

Isomorphic binary trees

Let T1 be a binary tree with root r1 and let T2 be a binary tree with root r2. 

The binary trees T1 and T2 are isomorphic if there is one-to-one, onto function f from the vertex set of T1 to the vertex set of T2 satistying the following:

(a) T1 and T2 are isomorphic as rooted trees through an isomorphism f.

(b) v is a left (right) child of w in T1 if and only if f(v) is a left (right) child of f(w) in T2.

Terminal vertices and Height

If a binary tree of height h has t terminal vertices, then

t<=2^h

Full binary tree

A full binary tree is a binary tree in which each vertex has two or no children.

If T is a full binary tree with i internal vertices, then T has i+1 terminal vertices and 2i+1 total vertices.





Binary Search Tree

A binary search tree is a binary tree T in which data are associated with the vertices. for each vertex v in T, each data item in the left subtree of v is less than the data item in v, and each data item in the right subtree of v is greater than the data item in v.




Decision Tree

Decision Tree is a rooted tree If we begin at the root, answer each question, and follow the appropriate edge, so that we eventually arrive at a  deciding terminal vertex

Theorem

when a problem has t number of all possible result , if the decision tree has n possible answering number per one vertex and h height, then   

t<=n^h








'전자공학이론 > 이산수학' 카테고리의 다른 글

Spanning Tree  (0) 2015.12.10
Tree  (0) 2015.12.10
Isomorphic Graphs / Homeomorphic graphs/ Planar graph  (0) 2015.12.09
A shortest-path algoritnm  (0) 2015.12.09
Euler cycle & Hamiltonian cycle  (0) 2015.12.09
:
Posted by youjin.A
2015. 12. 10. 01:32

Spanning Tree 전자공학이론/이산수학2015. 12. 10. 01:32

Spanning Tree

A tree T is a spannig tree of a graph G if T is a subgraph of G that contains all of the vertices of G.


method to find a spanning tree

Breadth-First search is a method to process all the vertices on a given level before moving to the next-higher level.

Depth-First search is a method to proceeds to successive levels in a tree at the earliest possible opportunity.

Breadth-First search       Depth-First search

      


Minimal spanning tree

Let G be a weighted graph. A minimal spanning tree of G is a spanning tree of G with minimum weight.


Algorithm to find a minimal spanning tree

Prim's Algorithm begins with a single vertex. Then at each iteration, it adds to the current tree a minimum-weight edge that does not complete a cycle.

Kruskal's algorithm find the edge in the graph with smallest weight that does not complete a cycle.

Prim's Algorithm

Kruskal's algorithm







'전자공학이론 > 이산수학' 카테고리의 다른 글

Binary Tree  (0) 2015.12.10
Tree  (0) 2015.12.10
Isomorphic Graphs / Homeomorphic graphs/ Planar graph  (0) 2015.12.09
A shortest-path algoritnm  (0) 2015.12.09
Euler cycle & Hamiltonian cycle  (0) 2015.12.09
:
Posted by youjin.A
2015. 12. 10. 01:21

Tree 전자공학이론/이산수학2015. 12. 10. 01:21

Tree

A (free) tree T is a simple graph such that for every pair of vertices v and w there is a unique path from v to w.

A rooted tree is a tree where one of its vertices is designated the root.


Isomorphic rooted trees

Let T1 be a rooted tree with root r1 and let T2 be a rooted tree with root r2. 

The rooted trees T1 and T2 are isomorphic if there is a one-to-one, onto function f from the vertex set of T1 to the vertex set of T2 satisfying the following:

(a) (vi, vj) ∈ T1 if and only if (f(vi), f(vj)) ∈ T2.

(b) f(r1) = r2.


Level & height

The level of a vertex v is the length of the simple path from the root to v.

The height of a rooted tree is the maximum level number of its vertices.


Terminology

Let T be a tree with root v0. Suppose that x, y and z are vertices in T and that (v0, v1, ..., vn) is a simple path in T, then

(a) the parent of v(n) is v(n-1).

(c) a child of v(n-1) is vn.

(b) ancestors of v(n) are v0, ..., v(n-1).

(d) descendants of v(n-2) are v(n-1), vn.

(e) x and y are siblings if x and y are children of z.

(f) a terminal vertex (or a leaf) is a vertex that has no children.

(g) an internal (or branch) vertex is a vertex that has at least one child. 

(h) a subtree T' of a tree T is a graph where

V(T') = { v0 and the descendants of v0 }

E(T') = { e | e is an edge on a simple path from v0 to some vertex in V(T') }


Theorem

Let T be a graph with n vertices. The following are equivalent.

(a) T is a tree.

(b) T is connected and acyclic.

(c) T is connected and has n-1 edges. //vertex들을 연결할 수 있는 최소한의 구조

(d) T is acyclic and has n-1 edges.











'전자공학이론 > 이산수학' 카테고리의 다른 글

Binary Tree  (0) 2015.12.10
Spanning Tree  (0) 2015.12.10
Isomorphic Graphs / Homeomorphic graphs/ Planar graph  (0) 2015.12.09
A shortest-path algoritnm  (0) 2015.12.09
Euler cycle & Hamiltonian cycle  (0) 2015.12.09
:
Posted by youjin.A

Isomorphic Graphs

Graphs G1 and G2 are isomorphic if there is a one-to-one, onto function f from the vertices of G1 to vertices of G2 and a one-to-one, onto function g from the edges of G1 to the edges of G2, so that e=(v,w) in G1 if and only if g(e)=(f(v), f(w)) in G2.

Theorem

Graphs G1 and G2 are isomorphic if and only if for some ordering of their vertices, their adjacency matrices are equal.




Homeomorphic graphs

Graphs G1 and G2 are homeomorphic if G1 and G2 can be reduced to isomorphic graphs by performing a sequence of series reductions




Planar graph

A graph is planar if it can be drawn in the plane without its edges crossing,

Theorem 1

if G is a connected planar graph, then v-e+f=2 and 2e>=sf.

v=number of vertices

e=number of edges

f=number of faces, including the exterior face

s=minimum number of edges for making a face

Theorem 2

G is a planar graph if and only if G does not contain a subgraph homeomorphic to either K5 or K3,3.

following graph is not planar:








'전자공학이론 > 이산수학' 카테고리의 다른 글

Spanning Tree  (0) 2015.12.10
Tree  (0) 2015.12.10
A shortest-path algoritnm  (0) 2015.12.09
Euler cycle & Hamiltonian cycle  (0) 2015.12.09
Graph  (0) 2015.12.09
:
Posted by youjin.A
2015. 12. 9. 20:58

A shortest-path algoritnm 전자공학이론/이산수학2015. 12. 9. 20:58

Dijkstra's Algorithm

Input:    A connected, weighted graph in which all weights are positive;

vertices a and z

Output:    L(z), the length of a shortest path from a to z

1
2
3
4
5
6
7
8
9
10
11
12
13
dijkstra(w, a, z, L){
    L(a) = 0
    for all vertices x≠a
        L(x) = ∞
    T = set of all vertices
 
    while(z∈T){
        choose v∈T with minimum L(v)
        T = T-{v}
        for each x∈T adjacent to v
            L(x) = min{L(x), L(v) + w(v, x)}
    }
}
cs

2~5행:     vertex a의 길이를 0으로 설정하고 a를 제외한 나머지 vertex의 L은 ∞로 설정한다. T는 그래프              의 모든 vertex의 집합이다.

8~11행:     T안에있는 vertex 중에서 L이 최소인 vertex v를 선택하고 그 v를 집합 T에서 삭제한다. T에                 포함되어 있는 것중 v와 연결되어 있는 vertex에 대하여, L를 업데이트한다. 이것은 z가 T에                 포함되지 않을 때가지 반복한다.

 ***최소 path 찾기*** vertex에 label을 붙일 때, 최소 길이 뿐만아니라 이어지는 바로 전 vertex의 이름을 같이 적으면 두 vertex 사이의 최소 path를 찾을 수 있다.






'전자공학이론 > 이산수학' 카테고리의 다른 글

Tree  (0) 2015.12.10
Isomorphic Graphs / Homeomorphic graphs/ Planar graph  (0) 2015.12.09
Euler cycle & Hamiltonian cycle  (0) 2015.12.09
Graph  (0) 2015.12.09
6. Proofs  (0) 2015.10.17
:
Posted by youjin.A

Euler cycle

An Euler cycle in a graph G is a cycle that passes through every edge of G only once.

Theorems

A graph G has an Euler cycle if and only if G is a connected graph and every vertex has even degree.




Hamiltonian cycle 

Hamiltonian cycle in a graph G is a cycle that visit every vertex of G only once by a simple cycle.

n-Cube

The n-cube, denoted I^n (n>=1), has 2^n vertices labeled 0, 1, 2, ..., 2^(n-1) , and edges connecting two vertices if the binary representation of their labels differ in exactly one bit.

n-Cube can be made from (n-1)-Cube by the following rules:

1) Let H1 and H2 be two (n-1)-Cubes whose vertices are labeled in binary 0, ..., 2^(n-1)-1.

2) Place an edge between each pair of vertices, one from H1 and one from H2, provided that the vertices have identical labels.

3) Change the label L on each vertex in H1 to 0L and change the label L on each vertex in H2 to 1L.

Gray code and Hamiltonian cycle 

 The n-Cube has a Hamiltonian cycle(n>=2).

Let Gn a n-bit Gray code, then that is a Hamiltonian cycle in n-Cube.

Gn is made from G(n-1) by the following rules:

(a) Let G^R(n-1) denote the sequence G(n-1) written in reverse.

(b) Let G'(n-1) denote the sequence obtained by prefixing each member of G(n-1) with 0.

(c) Let G''(n-1) denote the sequence obtained by prefixing each member of G^R(n-1) with 1.

(d) Let Gn be the sequence consisting of G'(n-1) followed G^n(n-1).










'전자공학이론 > 이산수학' 카테고리의 다른 글

Isomorphic Graphs / Homeomorphic graphs/ Planar graph  (0) 2015.12.09
A shortest-path algoritnm  (0) 2015.12.09
Graph  (0) 2015.12.09
6. Proofs  (0) 2015.10.17
5. Proposition  (0) 2015.10.17
:
Posted by youjin.A
2015. 12. 9. 10:36

Graph 전자공학이론/이산수학2015. 12. 9. 10:36

Graph

A graph(or undirected graph) G consists of a set V of vertices(or nodes) and a set E of edges(or arcs) such that each edge e∈E is associated with an unordered pair of vertices.

G = (V , E)


A simple graph is a graph without loops or parallel edges.


Subgraph

Let G = (V, E) be a graph, we call (V', E') a subgraph of G if

(a) V'⊆V

(b) E'⊆E such that for every edge e'∈E', if e' is incident on v' and w', then v',w'∈V'.




Degree

The degree of a vertex v, denoted by δ(v), is the number of edges incident on v.

Theorems

if G is a graph with n vertices and m edges, then

sum(δ(vi))[i=1~n] = 2m


Path

A path from vo to vn of length n is an alternation sequence of n+1 vertices and n edges beginning with vertex vo and ending with vertex vn,

(vo, e1, v1, e2, v2, ..., vn-1, en, vn),

in which edge ei is incident on vertices vi-1 and vi for i = 1, ..., n


A simple path from v to w is a path from v to w with no repeated vertices.

Theorems

A graph has a path with no repeated edges from v to w(v≠w) containing all the edges and all vertices if and only if it is connected and v and w are the only vertices having odd degrees.


Cycle

A cycle(or circuit) is a path of nonzero length from v to v with no repeated edges.


A simple cycle is a cycle from v to v in which, except for the beginning and ending vertices that are both equal to v, there are no repeated vertices.

Theorems

If a graph G contains a cycle from v to v, G contains a simple cycle from v to v




connected

The connected graph is the graph in which for any vertices v and w in G, there is a path from v to w.


Complete 

The complete graph on n vertices, denoted Kn, is the simple graph with n vertices in which there is an edge between every pair of distinct vertices.


Bipartite

The bipartite graph is the graph whose vertex set V is partitioned into sets V1 and V2 such that V1V2 = Φ, V1V2 = V, and each edge in E is incident on one vertex in V1 and one vertex in V2.


The complete bipartite graph on m and n vertices, denoted Km,n, is the simple graph whose vertex set is partitioned into sets V1 with m vertices and V2 with n vertices, and the edge set consists of all edges of the form (v1, v2) with v1∈V1, and v2∈V2. 








'전자공학이론 > 이산수학' 카테고리의 다른 글

A shortest-path algoritnm  (0) 2015.12.09
Euler cycle & Hamiltonian cycle  (0) 2015.12.09
6. Proofs  (0) 2015.10.17
5. Proposition  (0) 2015.10.17
4. function  (0) 2015.10.17
:
Posted by youjin.A
2015. 11. 24. 20:29

함수 포인터 프로그래밍/C언어2015. 11. 24. 20:29

-함수 포인터(function pointer)

함수의 메모리 주소를 가지는 포인터 변수


-함수 포인터의 선언

만약 함수 포인터 이름에다가 소괄호를 붙이지 않고 다음과 같이 선언하면 무엇을 의미할까?

int*    pFunc(int, int)

위 문장은 반환형이 int형 포인터인 함수를 선언한 것이다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <stdio.h>
 
int add(int x, int y)
{
    return x + y;
}
 
int main(void)
{
    int sum;
    int(*pFunc)(intint= NULL;
 
    pFunc = add;
    sum = pFunc(1662);
    //sum = (*pFunc)(16, 62);
    //sum = add(16, 62);
    //sum = (*add)(16, 62);
 
    printf("16 + 62 = %d\n", sum);
 
    return 0;
}
cs




-함수 포인터 자료형

함수 포인터를 선언할 때 특정 반환값과 인자를 가지는 함수 포인터를 반복적으로 만들기 귀찮기 때문에, 이것을 자료형으로 아예 만들 수 있다.


-함수 포인터 자료형의 선언

typedef void (*funcName_1)(int);

typedef void funcName_2(int);


둘 다 함수 포인터의 자료형이지만 둘의 차이가 있다.

만약 void temp(int)의 주소값을 전달 받는 다면 

funcName_1 fc = temp

는 옳은 문장이지만 funcName_2 fc = temp는 컴파일 에러가 난다. 이를 해결하기 위해서는 

funcName_2 * fc = temp;

와 같이 사용해야 한다. 다만 매개변수로 함수의 주소값을 전달 받는 경우에는 *의 생략이 가능하다.

 


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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <stdio.h>
#include <stdlib.h>
 
typedef    int    BTData;
 
typedef    struct _bTreeNode
{
    BTData data;
    struct _bTreeNode* left;
    struct _bTreeNode* right;
}BTreeNode;
 
 
BTreeNode* MakeBTreeNode(void)
{
    BTreeNode* nd = (BTreeNode*)malloc(sizeof(BTreeNode));
    nd->left = NULL;
    nd->right = NULL;
    return nd;
}
 
BTData GetData(BTreeNode* bt)
{
    return bt->data;
}
 
void SetData(BTreeNode* bt, BTData data)
{
    bt->data = data;
}
 
BTreeNode* GetLeftSubTree(BTreeNode* bt)
{
    return bt->left;
}
 
BTreeNode* GetRightSubTree(BTreeNode* bt)
{
    return bt->right;
}
 
void MakeLeftSubTree(BTreeNode* main, BTreeNode* sub)
{
    if (main->left != NULL)
        free(main->left);
 
    main->left = sub;
}
 
void MakeRightSubTree(BTreeNode* main, BTreeNode* sub)
{
    if (main->right != NULL)
        free(main->right);
 
    main->right = sub;
}
 
typedef void VisitFuncPtr(BTData data);
 
 
void PreorderTraverse(BTreeNode* bt, VisitFuncPtr action)
{
    if (bt == NULL)
        return;
 
    action(bt->data);
    PreorderTraverse(bt->left, action);
    PreorderTraverse(bt->right, action);
}
 
void ShowIntData(int data)
{
    printf("%d ", data);
}
 
int main(void)
{
    BTreeNode* bt1 = MakeBTreeNode();
    BTreeNode* bt2 = MakeBTreeNode();
    BTreeNode* bt3 = MakeBTreeNode();
    BTreeNode* bt4 = MakeBTreeNode();
 
 
    SetData(bt1, 1);
    SetData(bt2, 2);
    SetData(bt3, 3);
    SetData(bt4, 4);
 
 
    MakeLeftSubTree(bt1, bt2);
    MakeRightSubTree(bt1, bt3);
    MakeLeftSubTree(bt2, bt4);
 
 
 
    printf("Preorder Traverse: \n");
    PreorderTraverse(bt1, ShowIntData);
    printf("\n");
 
    return 0;
}
 
cs



:
Posted by youjin.A

scanf_s에서 s없애기

프로그램 맨 위에 

#pragma warning(disable:4996)

를 붙여주면 visual studio 2013에서 scanf_s나 freopen_s 처럼 _s 를 붙여줘야하는 것을 피할 수 있다. 


freopen

freopen은 프로그래밍 문제 풀때 입력을 자동으로 받아주는 함수이다.

프로그램의 프로젝트안에 text파일을 넣어주고 함수를 쓰면 text파일 안에있는 값을 자동으로 받아서 키보드로 입력한것처럼 동작하게 한다.

text파일이 다음과 같이 저장해놓고 프로그램에서 freopen을 쓴다.

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
#include <stdio.h>
#pragma warning(disable:4996)
 
 
int main(void)
{
    int d[20];
 
    if (freopen("sample_input.txt""r", stdin) == NULL)
        fprintf(stderr, "error redirecting stdin\n");
 
    for (int i = 0; i < 20; i++){
    
        scanf("%d"&d[i]);
        
    }
 
    for (int i = 0; i < 20; i++){
 
        printf("%d ", d[i]);
    }
 
    printf("\n");
 
    return 0;
}
cs

 

'프로그래밍 > C언어' 카테고리의 다른 글

sizeof  (0) 2016.05.22
함수 포인터  (0) 2015.11.24
Visual Studio 설치시 설정 및 Hello world!  (0) 2015.09.11
구조체 포인터의 선언과 접근( -> )  (0) 2015.09.07
구조체 선언에 typedef 사용하기  (0) 2015.09.07
:
Posted by youjin.A
2015. 10. 23. 07:37

void* 프로그래밍/자료구조설계2015. 10. 23. 07:37

void*

void포인터는 어떤 타입의 포인터든 다 받을 수 있는 포인터이다.

받는 것은 어떤 포인트형이든 다 받을 수 있다.

그런데 그 포인터에 접근할 때는 해당 포인트의 자료형에 맞에 접근해야 한다.

한마디로, 주소값이 void*에 들어갈때는 자유로우나 나올때는 알맞게 접근해야한다.

다음 예제를 보면 알기쉽다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <stdio.h>
 
int main(){
    void* ptr;
 
    int i = 7;
    float f = 23.5;
 
    ptr = &i;
    printf("%d\n"*((int*)ptr));
 
    ptr = &f;
    printf("%f\n"*((float*)ptr));
 
    return 0;
}
 
cs

10줄과 13줄에 포인터가 int*와 float*f 로 형변환 시켜서 포인터에 접근한 것을 확인할 수 있다.

형변환 해주지 않으면 에러가 나서 컴파일이 안된다. 



'프로그래밍 > 자료구조설계' 카테고리의 다른 글

인터넷 check sum 함수의 구현  (0) 2016.02.08
다운  (0) 2016.02.07
열거형 enum  (1) 2015.10.23
윈도우에서 리눅스처럼 컴파일하기  (1) 2015.09.19
:
Posted by youjin.A