0% found this document useful (0 votes)
117 views

Computer Science and Discrete Mathematics

a) 104578690 mod 101 = 90 b) 432222187 mod 101 = 86 c) 372201919 mod 101 = 18 d) 501338753 mod 101 = 52 Therefore, the memory locations assigned are: a) 90 b) 86 c) 18 d) 52

Uploaded by

Nikhil Kanoji
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
117 views

Computer Science and Discrete Mathematics

a) 104578690 mod 101 = 90 b) 432222187 mod 101 = 86 c) 372201919 mod 101 = 18 d) 501338753 mod 101 = 52 Therefore, the memory locations assigned are: a) 90 b) 86 c) 18 d) 52

Uploaded by

Nikhil Kanoji
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Computer Science and

Discrete Mathematics
Computer representation
of relations and digraphs
WE KNOW THIS ALREADY
Data can be stored in a list
known as an array. The
locations of an array are
consecutively numbered in a
computer memory.
Example:
 Array by the name of A with 5 data items:
Index
Location
A [1] D1 Data 1

A [2] D2
Data 2

A [3] D3 Data 3

A [4] D4
Data 4

A [5] Data 5
D5

With this method, it would be difficult to add an item


between D2 and D4..
 A linked list includes a pointer
Data Pointer Index
Array Array Location
A D4 4 [1]

D1 3 [2]

D2 5 [3]

D5 0 [4]

D3 1
[5]
The pointer tells us what location to go to next. Start at
D1 location at A [2]. P[2] points to location [3]. D2 is in
location A [3].
 Location P[3] points to location A[5]. D3 is in location A [5].
 Location P[5] points to location A[1]. D4 is in location A [1].
 Location P[1] points to location A[4]. D5 is in location A [4].
 When you get to A[4], P[4] contents is 0 which means you
are done.

We can put the data in any order.


We have to go through the links to access
the data we want.
 If we have the following digraph:

2 2 1 8
7 5
1 4 3 3
5
10 6
9 6 4

 We see that we have 10 edges. We can conclude


that we have 10 pairs.

 R = {(1,2),(1,6),(1,3),(2,1),(2,3),(3,5),(3,4),(3,6),(5,4),(6,
1)}
 An array called VERT for Vertex contains a pointer for
every vertex in the digraph. The digraph has 6
vertices, so the VERT array will have 6 locations.

 The ordered pairs of the digraph will be called TAIL


to represent the beginning vertex.

 The HEAD array will represent the ending vertex.

 The NEXT array will be a pointer array to get all of the


pairs for a given vertex.
TAIL HEAD NEXT
[1]
[2]
[3]
[4]
VERT [5]
[1] 9 [6]
[2] [7]
3
[3] 6
[8]
[4] 0
[9]
[5] 5
[10]
[6] 8
TAIL HEAD NEXT
1 2 0 [1]
2 3 0 [2]
2 1 2 [3]
VERT 3 5 7 [4]
[1] 9 5 4 0 [5]
[2] 3 3 4 4 [6]
[3] 6 3 6 0 [7]
[4] 0 6 1 0 [8]
[5] 5 1 6 [9]
10
[6] 8 1 3 1 [10]
VERT tells us which location to point to for our
pairs.
First we go to TAIL location [9]. TAIL [9] = 1
and HEAD [9] = 6.
In our NEXT location [9] we point to another
relation for vertex 1. We are directed to
TAIL[10] where we see the TAIL, HEAD pair of
1,3We are then pointed to NEXT [10] to
location [1] where we find TAIL,HEAD pair(1,2).
We are done with vertex 1 so, in the NEXT [1]
we have a 0 which indicates that we need to
go to the next VERT entry, which happens to
be 3. So we go to location [3] of TAIL and we
1 look at vertex position [1]
st

edge (1,6)
(1,3)
(1,2)
0 done with edges leaving vertex 1
Next look at vertex position [2]
edge (2,1)
(2,3)
0 done with edges leaving vertex 2
Next look at vertex position [3]
edge (3,4)
(3,5)
(3,6)
0 done with edges leaving vertex 3
Next, look at vertex position [4]
It is 0 so done with edges leaving vertex 4.
Next look at vertex position [5]
edge (5,4)
0 done with edges leaving vertex 5
Last look at vertex 6
edge (6,1)
0 done with edges leaving vertex 6
FUNCTIONS FOR COMPUTER
SCIENCE
1. Characteristic Function
2. Factorial Function
3. Factorial Function
4. Floor and Ceiling Function
5. Polynomial Function
6. Base 2 Exponential Function
7. Logarithmic Function
8. Boolean Function
9. Hashing Function
 Which memory locations are assigned by the hashing
function h(k) = k mod 101 to the records of insurance
company customers with these Social Security
numbers?
 a) 104578690
 b) 432222187
 c) 372201919
 d) 501338753

You might also like