My programmer exam notes - the second day Posted on www.oldchild.net (old urchin station)

xiaoxiao2021-03-06  47

The next day: 9/18/2003

I have been a week, and I have compiled some programs in front of the first week: the chain, long integer, the three-dollar table transposition, and some simple functions. In fact, some algorithms think it is very simple, but written still Need to be patient and c-based, if you think that each algorithm is very understanding, try the test. Maybe there will be some new discovery and experience.

Stack and queue

Knowledge points:

List of l Stack: Operation Linear Table

l Features: Back first out

L stack storage structure: order, link

/ PUSH (S, D)

The basic operation of the L stack:

/ POP (s)

Stack definition:

Struct {

DataType Data [MAX_NUM];

Int top;

}

l Queue definition

Features: advanced first

/ Into the queue in_queue (q, x)

l Queue operation:

/ Exported Del_Queue (Q)

l Queue storage structure:

Chain queue:

Typedef struct node {

DataType Data;

Struct Node * Next;

} Node;

Typedef struct {

Node * Front;

Node * REAR;

} Queue;

Sequence queue:

Struct {

DataType Data [MAX_NUM];

Int Front, REAR;

}

problem:

Queue ó Linear Table

False overflow <= loop queue

The queue is full, the queue is the same <= Wasting a storage space

Recursion

Definition: The solution of the problem is N is the solution to the small scale problem. The solution is solved by a small scale problem.

Include two steps:

1) Trouble 6! => 5! => 4! => 3! => 2! => 1! => 0!

2) Regression 720 <= 120 <= 24 <= 6 <= 2 <= 1 <= 0

Retrieving Work Stack Removes the mechanism of recursive.

two. About algorithms:

1) Order, the outlet under the chain structure, into the stack

2) Cycling, queue from the queue, out of the queue.

3) The queue of the chain queue is out of the queue.

4) Expression calculation: suffix expression 35 6/4368 / * -

Pixel expression (3 5) / 6-4 * (3 6/8)

Because the infix is ​​more difficult to handle, the prefix is ​​generally defixed into a suffix.

Operation: When you touch the operand, do not operate, touch the operator, and operate the first two operands.

Fox => suffix

5) Maze problems

6) Recursive algorithm of linear linked list A linked list = a node a linked list

INT fuction (node ​​* p) {

IF (p == null) Return 0;

Else Return (Function (p-> next));

}

Tree with binary tree

I. Knowledge points:

1. The definition of the tree: DATA_STRUCT (D, R);

Among them: There is a root in D, remove D and exertion, can be divided into M part.

D1, D2, D3, D4, D5 ... DM

R1, R2, R3, R4, R5 ... RM

The subtree ri forms a tree.

1) Recursive definition height

2) Number of nodes = 1 o --0

O O O-1

2. Binary definition: O O O O - 2

Number of nodes> = 0 The height of this tree is 2.3. Terminology: left and right children, duplex, sub-tree, degree, high degree of concepts.

4. Nature of the binary tree

l Hierarchical two binary tree I layer nodes 2 ^ i

l The height of the binary bouting point 2 ^ (h 1) -1

L h (point) = e (edge) 1

L number is the full binary tree height of | _LOG2N_ |

l Complete binary knot number: From top to bottom, from left to right.

I Node Die: | _i / 2_ | | _i-1 / 2_ | 1

Left child of i Node: 2i 2i 1 2 3

I Node's right child: 2i 1 2i 2 4 5 6 7

(Root) 1 is the starting point 0

Storage structure of the binary tree:

1) Extension into a fully binary tree, stored in one-dimensional array.

A

B C

D e f

G H i

0 (array subscript)

1

2

3

4

5

6

Seduce

8

9

10

11

12

A

B

C

Di

E

Fly

G

Hide

I

2) Double pro

0 (subscript)

1

2

3

4

5

6

Seduce

8

A (element)

B

C

Di

E

Fly

G

Hide

I

-1 (Double Friends)

0

0

1

2

2

3

3

4

3) Double pro children say

0 (subscript)

1

2

3

4

5

...

A (element)

B

C

Di

E

Fly

...

-1 (Double Friends)

0

0

1

2

...

1 (left son)

3

4

...

2 (right)

-1

5

...

structure:

Typedef struct {

DataType Data;

Int Parent;

Int lchild;

Int rchild;

} Node;

Node trees [n]; // generate n-nodes of trees

4) Two-forked list

5) Three-forked list

6) Hufman tree

5. Traverse of the binary tree

First

The root stack traverses (left subtree) root (right child), and handles the left subtree with the same method.

Reintegration

First, the order has been found in the order: look for the root in the order, and the left and right subtals are determined in the order.

Hierarchical traversal (queue implementation)

6. Cabbage binary tree (threaded tree)

The second tree tree of the secondary linear cable: the result of directly obtaining the sequence traverses using the empty pointer.

Means (Methods): The left pointer is empty, and the forward, the right pointer is empty, pointing to success.

Node structure:

LTAG

LCH

Data

RCH

RTAG

LTAG = 0, LCH points to the left child, LTAG = 1, pointing forward

RTAG = 0, RCH pointing to the right; RTAG = 1, pointing to the subsequent node

Sub-sequence traversal: 1) find the leftmost node (which is empty)

2) When the node of RTAG = 1, the RCH of this node points to the successor

3) When RTAG = 0, the subsequent element is the leftmost left in the right man tree.

N nodes of two trees have empty pointer n 1

转载请注明原文地址:https://www.9cbs.com/read-56572.html

New Post(0)