You are on page 1of 8

Instruktioner inför digital hemtentamen/ examination

Jag vill undvika fusk – hur gör jag? / All form av fusk anmäls

Du ska följa instruktionerna för uppgiften. Om du är osäker, fråga ansvarig lärare om
något i instruktionerna är oklart.

Du får inte samarbeta. Det här är en individuell examinationsuppgift. Du ska inte prata
med någon, ställa frågor till eller ta hjälp av andra studenter eller kurskamrater. Att hjälpa
andra under en individuell examination är också fusk.

Lägg undan mobilen. Stäng av sociala medier.

Du får inte använda hjälpmedel. Det vill säga att du får inte använda dig av något annat
än det som står angivet i instruktionerna.

Du får inte använda andra formuleringar än dina egna. Dina svar ska vara självständigt
formulerade och redovisa dina kunskaper. Det betyder att inga citat eller referat ska förekomma
i dina svar om det inte står i instruktionerna att du får använda citat eller referat.

Dina svar kontrolleras via Urkund.

All misstanke om fusk anmäls till universitetets rektor och kan leda till en prövning i uni-
versitets disciplinnämnd.

Konsekvenser av fusk

Om du fuskar kan detta leda till en avstängning som kan få följder både för dina studier och
privat:
ˆ Uteblivet studiemedel som t.ex. som kan påverka din möjlighet att behålla din bostad.
ˆ Ingen åtkomst till digitala plattformar.
ˆ Du kan behöva meddela dina kursare om att du är fälld för fusk, om du t.ex. ingår i ett
grupparbete på en pågående kurs men blir avstängd.
ˆ Tillfällen för examination går förlorade vilket kan innebära att du inte kommer vidare i
dina studier nästa läsperiod/termin och din studiegång blir därmed påverkad.
ˆ Beslutet är en offentlig handling som begärs regelbundet ut av en nyhetsbyrå. Och kan
även begäras ut av framtida arbetsgivare eller andra.
ˆ Om du fuskar dig igenom din utbildning har du inte den kunskap som arbetsmarknaden
förväntar av dig.
OBS: Tänk efter en gång till innan du påbörjar och genomför din tentamen!

1
Data Structures and Algorithms
(DT133G)

Third Examination VT2021 (Exam #7)

Teacher: Marjan Alirezaie (ext. 3785)


Published: 2021-08-24 at 08:15
No. exercises: 6
Total points: 70 (42 required to pass)
No. pages containing questions: 6

ˆ This is a personalized exam


ˆ Compile your answers into a single Word or PDF file named
7 submission.pdf
ˆ You may include images (e.g., snapshots of drawings) in your single answer file
ˆ Submit your answer file (7 submission.pdf) via Wiseflow
ˆ Submissions are due at 12:15 today (unless you are given another deadline
by Funka)
ˆ The teacher is available from 10:00 to 11:00 to answer questions at:
– Zoom (browser): https://oru-se.zoom.us/j/3021813077
– Tel.: +4619303785 (meeting ID: 302 181 3077)
– If you are put on hold, please wait, as this means there is a queue
ˆ If further doubts arise, make reasonable assumptions and write them down
Exercise 1 (10 points)
Given the array A = h10, 16, 4, 9, 8, 14, 5, 13, 7, 6i, show how the Quicksort and Insertion
sort algorithms work. Step through each algorithm, illustrating how it modifies the input
array A. State the worst- and best-case computational complexity of the two algorithms
in terms of the size |A| of the input array, and explain why.

1
Exercise 2 (12 points)
Construct a Binary Search Tree (BST) from the array of integers A in the previous
exercise. Do this by inserting each integer into the tree, one by one, starting from the left
(element ‘10’). Draw the resulting tree and state its height. Is the tree balanced?
Remove the third element of A (element ‘4’) from the BST, explaining the operations
that this procedure performs. Now, insert the element you removed back into the BST,
and draw the resulting tree. Is the resulting BST different from the BST before the
element was removed? If so, will this be the case for any element that is removed and
then re-inserted?
Illustrate the algorithm for finding the predecessor of an element in a BST. Show how this
works, step by step, for the fourth element of A (element ‘9’). In general, how many key
comparisons are performed by the algorithm for finding the predecessor of an element in
a BST? What is the computational complexity of the algorithm?
Construct a new BST using the sorted array you obtained in Exercise 1, again by inserting
the elements of the array into the tree one by one. What is the height of this BST, and
is it balanced?

2
Exercise 3 (12 points)
Given the same array A as in the first exercise, design a recursive algorithm that returns
the smallest element in A. Hints:

ˆ The smallest element in the array is either the first element in the array or the
smallest of the rest of the array.

ˆ If the array only has 1 element, then of course this is its smallest element;

ˆ The algorithm takes two arguments, the array A and an index i;

ˆ The first call to the algorithm is getMinimum(A, 1).

State the worst- and best-case computational complexity of the algorithm in terms of the
size |A| of the input array, and explain why.

3
Exercise 4 (12 points)
Given a directed, unweighted graph G = (V, E), describe an algorithm to solve each of
the following problems:

ˆ Return whether the graph is connected.

ˆ Return whether the graph is a tree.

ˆ Find all the strongly connected components of the graph.

ˆ Find the shortest path from node x1 to every other node.

Show all the steps performed by each algorithm, using as input the graph G given below.
Also, state and explain the computational complexity required to solve each problem in
terms of the number of nodes |V | and number of edges |E| of the input graph.

x5

x4

x6

x7 x1

x2

x3

4
Exercise 5 (12 points)
Given the following directed graph G = (V, E) with weight funtion w : E 7→ Z \ {0} as
specified on the edges of the graph, illustrate an algorithm for finding a shortest path
from vertex x1 to every other vertex in the graph. Show how, at each step, the algorithm
updates the distance estimate d[xi ] of every vertex xi ∈ V . State the computational
complexity of the algorithm in terms of the number of nodes |V | and number of edges |E|
of the input graph.

x1

x2 −6 −3

−10 10 10 −13

3 −12 −2 x4 x6

3 11 −2 −2

x3 x7 9

x5

5
Exercise 6 (12 points)
State whether each of the following 6 statements on the asymptotic behavior of the func-
tion f is true or false.

1. f (n) = 4 log(n), g(n) = 9n , f (n) ∈ O(g(n))


2. f (n) = 3n, g(n) = 9 log(n), f (n) ∈ Θ(g(n))
3. f (n) = 3n , g(n) = 7n log(n), f (n) ∈ Ω(g(n))
4. f (n) = 2 log(n), g(n) = 8n , f (n) ∈ Θ(g(n))
5. f (n) = 8 log(n), g(n) = 3n log(n), f (n) ∈ O(g(n))
6. f (n) = 7n , g(n) = 6n , f (n) ∈ o(g(n))

You might also like