Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

...

2014-2015

15/3/2015

: 08/05/2015
: 13/05/20151
: 16/05/2015
: 31/05/2015

1. ( 20)

2. ( 25)

3. ( 25)

4. ( 30)

( 100)

1
, ..
..
4 2014-2015

1. ( 20)


. n .
0 n-1.
matrixF n x n,
. , i j ,
1 matrixF[i][j] matrixF[j][i]
matrixF. , 0.
(n = 5),
:

1
0

2 3

matrixF :

0 1 2 3 4
0 0 1 1 0 0
1 1 0 1 1 1
2 1 1 0 1 0
3 0 1 1 0 0
4 0 1 0 0 0

C :
1. void loadMatrix(int **matrixF, int size)
matrixF
size . ,

matrixF.

2 12
4 2014-2015

2. int findFriends(int **matrixF, int size, int user)


matrixF, size
user
.
3. int commonFriends(int **matrixF, int size, int user1, int user2)
matrixF, size
user1 user2
.
4. void sortUsers(int **matrixF, int size, int *matrixS)
matrixF
matrixS size .
matrixS
matrixS
.

: fun(int **F, int size) fun(F[][], int size)


ypoergasia1_code_template.c code_templates
4 .

.

3 12
4 2014-2015

2. ( 25)

:
,
k.
, k- .
( ) ,

k
. , ,
. , Ann, Bob, Claudia, Dan
Ed k = 3 Ann
,
Claudia, Ann, Ed Bob Dan.


(,
, )
CListNode :

typedef struct node {


char name[10]; /* 9 \0 */
struct node *next;
} CListNode;

list_end_ptr NULL ,
.
C :
1. CListNode* insert_at_end(CListNode *end_ptr, char *a)
end_ptr
CListNode a, 10
, CListNode
a name.
.
2. CListNode* initialize_list(int n)
n ,
CListNode

4 12
4 2014-2015

.
,
insert_at_end get_name ( template).
3. CListNode* delete_next_node(CListNode *end_ptr, CListNode *p)
end_ptr
CListNode p
,
p
free ( stdlib.h). H
. ,
,
.
4. void print_list(CListNode *end_ptr)
end_ptr
CListNode
name ( ),
6
. .
5. CListNode* select(CListNode *end_ptr, int k)
end_ptr
CListNode
k
k, delete_next_node. H
,
( print_list),
, .


ypoergasia2_code_template.c code_templates
4 .

.

5 12
4 2014-2015

3. ( 25)

PRE POST,
, ,
. ,
1 n. PRE
, , . POST

. , ,
.

, PRE (preorder)

. k
k. PRE. ,
POST (postorder)
.
POST.

, n = 7, 1, 2, 3, 4, 5, 6, 7.
PRE POST ( PRE),
:

PRE POST
4 7
2 5
3 1
6

2 7

1 3 5

6 12
4 2014-2015

( PRE): 4, 2, 1, 3, 7, 5, 6

PRE: 1 ( 2 )

( POST): 1, 3, 2, 6, 5, 7, 4

POST: 2 ( 1 5 )

n = 9, :

1.

PRE POST
5 2
7 3
6 4
8 9
1
,
.

2. , : 4, 2, 1, 3, 7, 6,
5, 9, 8. PRE (
) ,
POST, :

PRE POST
7
9
3
8 5

3. PRE POST;
PRE
POST .

7 12
4 2014-2015

4. ( 30)


R0, R1, R2,
. , Ri = f(Ri-1) i 0, R-1
( ) f .
, 0 Ri m,
m f(x) 0 f(x) <
m, 0 x < m.

, , ,
. , ,
, R0, R1, , R,
, R+-1 , R+ R.

R, , R+-1. .

f(x)=(ax+c) mod m, 0 a,c,x < m m > 0. ,
a = 3, c = 4, m = 10, R-1 = 5 9, 1, 7, 5, 9, 1,
7, 5, 9, 4 ( ). ,
.


. , ,
,

.

.


(hash table). ,
(.., ,
.), ,
.
, .

8 12
4 2014-2015

.
m .
htsize, htsize < m. ,
h(x), x
, x ,
h(x)
( ). .

x
: h(x), .
() h(x) ,
. ,
h(x).

S={6,1,2,9,12,20,10,3}
5.
0. , h(x) =
(3*x+1) mod 5.
:

S ,
6. , h(x) x=6
h(6) = (3*6+1) mod 5 = 19 mod 5 = 4. , 6
4 .

4 6

9 12
4 2014-2015

1, 2 9
h(1) = 4, h(2) = 2 h(9) = 3, .

2 2

3 9

4 6 1

,
:

0 3

1 20 10

2 2 12

3 9

4 6 1

12 h(12) = 2
, . ,
7 ,
h(7) = 2. x

.

C,

. h(x) = x mod 500.

:
typedef struct node {
int value; //
int counter; //
struct node *next; //
} t_listnode;

10 12
4 2014-2015

:
typedef struct {
t_listnode *head;
t_listnode *tail;
} t_htentry;
head tail
.

, :

1. int insertElement(int x, int counter, t_htentry *ht, int size)

x ,
counter ,
ht size.
, 1, 0.

2. int searchElement(int x, t_htentry *ht, int size)

x ,
ht size.
x ,
(counter) x, 0.

3. int generate(int a, int c, int m, int x)

a, c m,
x, .
, a = 3, c = 19, m = 15001
27, .

4. int findPeriod(int a, int c, int m, int x)

a, c m,
x ( 3) generate()

insertElement(), searchElement()
. .

:
.

11 12
4 2014-2015


ypoergasia4_code_template.c code_templates
4 .
.

:
)

, . ,
(
) .

(.. ,
0, 20 .).
(.. , , .)
.
)
) C,
:
( ) .doc
Word .c (ANSI C).
.c ,
(..
, 1
Georgiou_1b.c).
C (ANSI C)
.
) (.. Word)
4 .
- ,
.
) .c .doc
http://study.eap.gr .zip,
, ..
Ioannou_82345.zip.
***********************************************************************************

12 12

You might also like