代写FIT2004 Algorithms and data structures Past Exam 2帮做R程序

Past Exam 2

Faculty of Information Technology

FIT2004

Algorithms and data structures

Analysis of Algorithms: Correctness and Complexity

Question 1

For constants b and c, consider the recurrence relation given by:

T(n) = b, if n=1

T(n) = 2 * T(n/2) + c * n * log n , if n>1

Which of the following statements is true?

Select one:

a. T(n) = Θ(n * log n * log n)

b. T(n) = Θ(n 2 * log n * log n)

c. T(n) = Θ(n * log n)

d. T(n) = Θ(n 2 )

e. T(n) = Θ(n 2 * log n)

Question 2

The pseudocode below finds the maximum degree of a graphG = (V,E).

function max_degree(G = (V,E)):

degrees[1..n] = 0

for each vertex u in V:

for each edge (u,v):

degrees[u] += 1

return max(degrees)

Assuming an adjacency list representation, what is the worst-case time complexity, total space complexity, and auxiliary space complexity of this pseudocode in terms of V and E ? Justify your solution.

Question 3

Consider the following algorithm, which returns the sum of the numbers with a factor m in the list L with n items.

def myfunc(L[1...n], m):

x = 0

loop i from 1 to n:

# loop invariant here

if L[i] % m == 0:

x = x + L[i]

return x

What is an useful loop invariant for this algorithm?

Select one:

a. x is the sum of all numbers in list L[1...i] % m

b. x is the sum of all numbers in list L[1...i-1] % m

c. x is the sum of all numbers with factor m in list L[1...i-1]

d. x is the sum of all numbers with factor m in list L[1...n]

e. x is the sum of all numbers in list L[1...n] % m

f. x is the sum of all numbers with factor m in list L[1...i]

Question 4

Justify that the loop invariant you have chosen is true each time the loop runs and when it terminates.

Question 5

Recall that the Radix Sort algorithm covered in lectures works as follows, for sorting an array of integers:

Sort the array one digit at a time, from least significant (rightmost) digit to most significant (leftmost) digit.

For each digit, sort using the stable version of counting sort.

The integers in the array do not have to be represented in base-10. Is it a good idea to increase the base representation to be as high as possible? Why, or why not? Explain your reasoning.

Graphs

Question 6

For each of the following operations, determine itsworst-case big-Θ complexity.

In this question,

The graph G is a directed weighted graph.

V refers to the number of vertices in the graph.

E refers to the number of edges in the graph.

N(A) refers to the number of neighbors of vertex A.

Assume that in the adjacency list representation, the interior list is unsorted.

Time complexity to determine if vertex B is adjacent to vertex A in an adjacency matrix representation.

• V • N(A) • log E • 1 • log V • V^2 • E

Time complexity to obtain all incoming edges for vertex A in an adjacency list representation.

• V • N(A) • log E • 1 • log V • V^2 • E

Time complexity to determine if vertex B is adjacent to vertex A in an adjacency list representation.

• V • N(A) • log E • 1 • log V • V^2 • E

Time complexity to obtain all outgoing edges for vertex A in an adjacency list representation.

• V • N(A) • log E • 1 • log V • V^2 • E

Information

Consider the weighted undirected graph below and answer the following questions.

Question 7

Perform. a breadth-first search on the graph given above, starting from A.

Whenever you have a choice between 2 vertices, break ties in ascending alphabetical order.

1st visited vertex             • A • G • C • E • D • H • F • B

2nd visited vertex            • A • G • C • E • D • H • F • B

3rd visited vertex             • A • G • C • E • D • H • F • B

4th visited vertex             • A • G • C • E • D • H • F • B

5th visited vertex             • A • G • C • E • D • H • F • B

6th visited vertex             • A • G • C • E • D • H • F • B

7th visited vertex             • A • G • C • E • D • H • F • B

8th visited vertex             • A • G • C • E • D • H • F • B

Question 8

Which of the following is true?

Select one or more:

a. Prim's minimum spanning tree algorithm will produce a maximum spanning tree if a max-heap is used instead of a min-heap.

b. Negating the weight of edges in a graph before running the Kruskal's minimum spanning tree algorithm will indicate the edges for a maximum spanning tree.

c. The parent-array in the union-find (with union-by-size) data structure used in the Kruskal's minimum spanning tree algorithm do indicate the edges of the minimum spanning tree.

d. Prim's algorithm for the minimum spanning tree is a greedy algorithm that will not work if the graph have a negative edge.

Question 9

The following pseudocode is for the generic Depth First Search algorithm covered in lectures.

function TRAVERSE(G=(V,E))

visited[1..n] = false

for each vertex u = 1 to n do

if not visited[u] then

DFS(u)

function DFS(u)

visited[u] = true

for each vertex v adjacent to u do

if not visited[v] then

DFS(v)

How would you modify this algorithm to perform. atopological sort of the vertices in a directed acyclic graph? Explain clearly which lines you would add/remove/modify, and what the purpose of each change would be.

Question 10

Consider the following version of the Bellman-Ford algorithm

and the following directed graph

Let S be the source node for the execution of the Bellman-Ford algorithm. If the edges are relaxed in the following order (C, D), (B, C), (A, B), (S, D), (S, B), (S, A), what is the value of dist[A]+dist[B]+dist[C]+dist[D] after the second iteration of the outer loop is finished? Just type the numerical answer.

Question 11

Consider the Floyd-Warshall algorithm


and the following directed graph

After the second iteration of the outer loop of the algorithm is finished, what is the value of dist[4][3]+dist[5][4]+dist[5][6]? Just type the numerical answer.

Information

Consider the flow network below and answer the following questions.

Question 12

What is the maximum possible flow for the given flow network above?

Just type in the numerical answer.

Question 13

A cut partitions the vertices into 2 disjoint setsS and T where

S contains all the vertices on the source side of the cut.

T contains all the vertices on the sink side of the cut.

Consider the minimum cut of the above flow network.

Select the vertices which are inS from the list of vertices below

Select one or more:

t

d

b

s

a

c

Question 14

Consider the following two problems of circulation with demands, in which the demands are indicated in each vertex, and the capacity in each edge.

Problem 1:

Problem 2:

Which of the problems have feasible solutions?

Select one:

a. Only Problem 1 has a feasible solution.

b. Both Problem 1 and Problem 2 have feasible solutions.

c. Only Problem 2 has a feasible solution.

d. Neither Problem 1 nor Problem 2 has a feasible solution.

Data Structures

Question 15

Consider the following AVL tree below:

You perform. the following operation in order:

Delete 90.

Insert 12.

Select the resulting AVL tree after performing the operations above.

Select one:

a.

b.

c.

d.

e.

Question 16

Consider a hash table implemented with separate chaining for collision resolution.

For a hashtable withN items, which of the following data structures would cause the worst case time complexity of an insert operation to be Θ(log N) if the data structure is used to keep the separate chains?

Select one or more:

a. Binary search tree

b. Sorted linked list

c. Sorted array

d. AVL Tree

Question 17

Assume that we are constructing the suffix array for a string S using the prefix doubling approach.

We have already sorted the suffixes for string S according to their first 2 characters; with the corresponding rank array shown below:

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

Rank  11        10        2          7          2          7          2           9         5           6         1

We are now sorting on the first 4 characters, comparing the suffixes on their first 4 characters in O(1).

Which of the following statements are true?

Select one or more:

a. Suffixes with ID4 and ID6 will have a different rank after sorting the first 4 characters where suffix ID6 would have a smaller rank than suffix ID4.

b. Suffixes with ID5 and ID7 still have the same rank after sorting the first 4 characters.

c. Suffixes with ID4 and ID6 will have a different rank after sorting the first 4 characters where suffix ID4 would have a smaller rank than suffix ID6.

d. Suffixes with ID3 and ID5 still have the same rank after sorting the first 4 characters.

Applications

Question 18

You are selecting a team of superheroes to save the world. Unfortunately, you can only bring a fixed amount of them through the portal.

You are given an unsorted list ofN superheroes where each item is in a tuple of (name, power level).

You would want to send:

The 1st team: the top-10% best superheroes by power-level from that list.

The 2nd team: the top-10% best superheroes by power-level from the remainder of the list.

You would however not send in the 2nd team until everyone in the 2nd team has a power level greater than or equivalent to the median of the power level of the 1st team. The 2nd team would need to train until they reach that power level.

Describe an efficient algorithm using Quickselectto determine the total power level needed to be gained during training before the 2nd team can be sent out. Your algorithm should run inO(N) time; and you can assume that you have access to a Quickselect algorithm which runs in O(N) time.

Question 19

You are coordinating a industry placement unit.

There are a total of 240 students that are enrolled in the unit; and there are 30 companies to choose from.

Each student is allowed to select 1 to 3 companies as their preferred placement, but they would only be placed in 1 company at the end.

Each company would be able to accept 8 students.

Students would reject any placement that is not in their preferred selection.

You realized that it is not possible for all students to be placed in their preferred company as some companies are more popular than others. You would however try to place as many students in their preferred companies as possible; any students not placed in this round would be placed in the following round.

Describe how you would model this problem as a maximum flow problem; which is then solved using the Ford-Fulkerson method.

Question 20

You find yourself curiously stranded on a grid (shown in the figure below), unsure of how you got there, or how to leave. Some of the cells of the grid are blocked and cannot be walked through. Anyway, while you’re here, you decide to solve the following problem. You are currently standing at the bottom-left corner of the grid, and are only able to move up (to the next row) and to the right (to the next column). You wonder, in how many different ways can you walk to the top-right corner of the grid while avoiding blocked cells? Just type the numerical answer.









热门主题

课程名

omp9727 ddes9903 mgt253 fc021 int2067/int5051 bsb151 babs2202 mis2002s phya21 18-213 cege0012 math39512 math38032 mech5125 mdia1002 cisc102 07 mgx3110 cs240 11175 fin3020s eco3420 ictten622 comp9727 cpt111 de114102d mgm320h5s bafi1019 efim20036 mn-3503 comp9414 math21112 fins5568 comp4337 bcpm000028 info6030 inft6800 bcpm0054 comp(2041|9044) 110.807 bma0092 cs365 math20212 ce335 math2010 ec3450 comm1170 cenv6141 ftec5580 ecmt1010 csci-ua.0480-003 econ12-200 ectb60h3f cs247—assignment ib3960 tk3163 ics3u ib3j80 comp20008 comp9334 eppd1063 acct2343 cct109 isys1055/3412 econ7230 msinm014/msing014/msing014b math2014 math350-real eec180 stat141b econ2101 fit2004 comp643 bu1002 cm2030 mn7182sr ectb60h3s ib2d30 ohss7000 fit3175 econ20120/econ30320 acct7104 compsci 369 math226 127.241 info1110 37007 math137a mgt4701 comm1180 fc300 ectb60h3 llp120 bio99 econ7030 csse2310/csse7231 comm1190 125.330 110.309 csc3100 bu1007 comp 636 qbus3600 compx222 stat437 kit317 hw1 ag942 fit3139 115.213 ipa61006 econ214 envm7512 6010acc fit4005 fins5542 slsp5360m 119729 cs148 hld-4267-r comp4002/gam cava1001 or4023 cosc2758/cosc2938 cse140 fu010055 csci410 finc3017 comp9417 fsc60504 24309 bsys702 mgec61 cive9831m pubh5010 5bus1037 info90004 p6769 bsan3209 plana4310 caes1000 econ0060 ap/adms4540 ast101h5f plan6392 625.609.81 csmai21 fnce6012 misy262 ifb106tc csci910 502it comp603/ense600 4035 csca08 8iar101 bsd131 msci242l csci 4261 elec51020 blaw1002 ec3044 acct40115 csi2108–cryptographic 158225 7014mhr econ60822 ecn302 philo225-24a acst2001 fit9132 comp1117b ad654 comp3221 st332 cs170 econ0033 engr228-digital law-10027u fit5057 ve311 sle210 n1608 msim3101 badp2003 mth002 6012acc 072243a 3809ict amath 483 ifn556 cven4051 2024 comp9024 158.739-2024 comp 3023 ecs122a com63004 bms5021 comp1028
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图