0% found this document useful (0 votes)
76 views23 pages

Final A20 English Version

This document provides instructions and questions for an exam on data structures. It begins by explaining how to generate a character string from the student's first and last names to be used for the exam questions. It then provides three sections on priority queues, maps, and hash tables, with multiple choice and short answer questions asking students to analyze data structures, provide complexity analyses, and describe operations. The exam is designed to test understanding of core data structures concepts.

Uploaded by

karmoussa2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views23 pages

Final A20 English Version

This document provides instructions and questions for an exam on data structures. It begins by explaining how to generate a character string from the student's first and last names to be used for the exam questions. It then provides three sections on priority queues, maps, and hash tables, with multiple choice and short answer questions asking students to analyze data structures, provide complexity analyses, and describe operations. The exam is designed to test understanding of core data structures concepts.

Uploaded by

karmoussa2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

IFT2015 - Structures de données A20

Guidelines:

- The number of points for each question indicates its


relative difficulty (calculate approximately 1 point
per minute).

- This exam contains 23 pages and 169 points.

- During the exam, no questions relating to this


questionnaire will be accepted.

- Write legibly!

- You have 48 hours to submit your answers.

Submit your answers to StudiUM:

- no later than Wednesday December 16, 12:30 p.m.


- in a single file in PDF format whose name
consists of your last and given names:

<lastname>_<givenname>.pdf

🎄 GOOD WORK AND HAPPY HOLIDAYS! 🎄


1
IFT2015 - Structures de données A20

For all of the exam questions you will use a string that contains the letters of your
first and last name. To obtain this character string, merge the letters of your last
name and your first name by converting them to lowercase characters, without
repeating the same letter 2 times and up to a maximum of 20 characters. If the
result is shorter than 20 characters, complete with the unused letters of the alphabet
in alphabetical order (from 'a' to 'z') and so that there is not twice the same
character.
Enter the resulting character string with your last and first names in the table
below. This character string will be referred to by the name variable in the exam
questions. Also note the index of the last letter of the characters of your last and
first names. This index will be referred by the last variable in the exam
questions.
example) first name : “Francois”, last name : “Major”
name = ‘majorfncisbdeghklpqt’

m a j o r f n c i s b d e g h k l p q t
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

last = 9

name =

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

last =

2
IFT2015 - Structures de données A20

PRIORITY QUEUES (48 points)


For questions 1 to 3, consider the lexicographic order to determine the priority of
the characters (‘a’ has the highest priority and ‘z’ has the lowest priority). For your
complexity expressions, consider a queue of n items.

1. (16) After the following initialization:


M = UnsortedDoublyLinkedPositionalListPriorityQueue()

a. (6) Complete the table indicating the returned value and the status of the
queue after each operation:

Operation Returned value Priority Queue

len( Q )

Q.add( nom[0], None )

Q.add( nom[1], None )

Q.add( nom[2], None )

Q.removeMin()

Q.min()

Q.removeMin()

Q.isEmpty()

Q.add( nom[3], None )

Q.add( nom[4], None )

len( Q )

Q.removeMin()

3
IFT2015 - Structures de données A20

b. (2) What is the complexity of the add operation:

c. (2) What is the complexity of the len operation:

d. (2) What is the complexity of the removeMin operation:

4
IFT2015 - Structures de données A20

e. (4) Explain how, or implement a method (Python code or pseudo-code), to


access the item with the lowest priority and give its complexity.

5
IFT2015 - Structures de données A20

2. (16) After the following initialization:


Q = SortedDoublyLinkedPositionalListPriorityQueue()

a. (6) Complete the table indicating the returned value and the status of the
queue after each operation:

Operation Returned value Priority Queue

len( Q )

Q.add( nom[0], None )

Q.add( nom[1], None )

Q.add( nom[2], None )

Q.removeMin()

Q.min()

Q.removeMin()

Q.isEmpty()

Q.add( nom[3], None )

Q.add( nom[4], None )

len( Q )

Q.removeMin()

6
IFT2015 - Structures de données A20

b. (2) What is the complexity of the add operation:

c. (2) What is the complexity of the len operation:

d. (2) What is the complexity of the removeMin operation:

7
IFT2015 - Structures de données A20

e. (4) Explain how, or implement a method (Python code or pseudo-code), to


access the item with the lowest priority and give its complexity.

8
IFT2015 - Structures de données A20

3. (16) After the following initialization:


Q = HeapPriorityQueue()

a. (14) Complete the table indicating the returned value and the status of the
queue after each operation:

Operation Returned value Priority Queue

len( Q )

Q.add( nom[0], None )

Q.add( nom[1], None )

Q.add( nom[2], None )

Q.removeMin()

Q.min()

Q.removeMin()

Q.isEmpty()

Q.add( nom[3], None )

Q.add( nom[4], None )

len( Q )

Q.removeMin()

9
IFT2015 - Structures de données A20

b. (2) What is the complexity of the add operation:

c. (2) What is the complexity of the len operation:

d. (2) What is the complexity of the removeMin operation:

10
IFT2015 - Structures de données A20

e. (4) Explain how, or implement a method (Python code or pseudo-code), to


access the item with the lowest priority and give its complexity.

11
IFT2015 - Structures de données A20

ADT Map (121 points)


For questions 4 to 6, consider the lexicographic order to determine the order of the
keys (‘a’ <‘b’ <‘c’… <‘z’). For your complexity expressions, consider a Map that
contains n elements.

For question 4, for the values of coin.flip(), consider the following


sequence:

Head Head Tail Tail Head Tail Head Tail Tail Head Head Head Tail Head Tail Head

(2)0 Considérez
1 2 trier
3 à l’aide
4 5d’une6file d’attente
7 8 avec
9 priorités.
10 11 Quels
12 énoncés
13 14 sont
15

that is Head the value (index 0) returned by the first call to flip()
Head the value (index 1) returned by the second call to flip()
Tail the value (index 2) returned by the third call to flip()
… and so on
If you need more values use this array as a circular sequence, i.e. value (index 0) of
17th call to flip() is Head, value (index 1) of 18th call to flip() is Head,
19th call Tail, and so on.
Reminder: The height of a column/tower for an insertion in a skipList
increases as coin.flip() results in Head.
For question 5, use the hash function
h(x) = ord( x ) mod (last + 9)
where
ord( ‘a’ ) = 97
ord( ‘b’ ) = 98

ord( ‘z’ ) = 122

12
IFT2015 - Structures de données A20

4. (40) Given the following initialization:


M = SkipListMap( )

a. (4) Draw the SkipList after its initialization.

13
IFT2015 - Structures de données A20

Now, consider the loop:

for key in range( 6 ):


k = (key+1)*3
M[name[k]] = name[k]

b. (18) Draw the resulting SkipList after each iteration:

14
IFT2015 - Structures de données A20

15
IFT2015 - Structures de données A20

c. (12) How many key comparisons were made at each iteration?

d. (2) What is the complexity of the operation __setitem__ ?

e. (4) Explain how, or implement a method (Python code or pseudo-code), to


access the item with the lowest key and give its complexity.

16
IFT2015 - Structures de données A20

5. (38) Given the following initialization:


M = ProbeHashMap( last + 9 )

a. (2) What is the size of your ProbeHashMap hash table after initialization?

Now, consider the loop:

for key in range( 6 ):


k = key*2
M[name[k]] = name[k]

b. (18) Using the hash function given on page 12, draw the state of your
ProbeHashMap hash table after each iteration:

17
IFT2015 - Structures de données A20

18
IFT2015 - Structures de données A20

c. (12) How many key comparisons were made at each iteration?

d. (2) What is the complexity of the operation __setitem__ ?

e. (4) Explain how, or implement a method (Python code or pseudo-code), to


access the item with the lowest key and give its complexity.

19
IFT2015 - Structures de données A20

6. (43) Given the initialization:


M = AVLTreeMap()

a. (2) Draw the status of your AVLTreeMap after initialization.

20
IFT2015 - Structures de données A20

Now, consider the loop:

for key in range( 8 ):


k = (key+2) * 2
M[name[k]] = name[k]
del M[12]

b. (27) Draw the AVL trees of your AVLTreeMap after each iteration of the
loop and after the deletion.

21
IFT2015 - Structures de données A20

22
IFT2015 - Structures de données A20

c. (8) How many key comparisons were made at each iteration?

d. (2) What is the complexity of the operation __setitem__ ?

e. (4) Explain how, or implement a method (Python code or pseudo-code), to


access the item with the lowest key and give its complexity.

23

You might also like