一站式論文代寫,英国、美国、澳洲留学生Essay代寫—FreePass代写

comp2123
時間:2021-07-06

Computer Science EXAMINATION Semester 1- Main, 2021 comp2123 Data Structures and Algorithms

EXAM WRITING TIME: 2 hours READING TIME: 10 minutes

Problem 1.

       a)Suppose we have a priority queue PQ, implemented as a min-heap, containing n keys and some integer x. 1: def foo(x) 2: result ← 0 3: while PQ.min() < x 2 do 4: temp ← PQ.remove_min() 5: result ← result + temp 2 6: return result Analyze the time complexity of running foo.

        b)We are given a set of items I = { i 1 ,...,i n } and sets S 1 ,...,S m containing subsets of these items, i.e., S k ? I for all 1 ≤ k ≤ m. The sets don’t have to contain the same number of items and an item may occur in multiple sets. We need to find the smallest set T ? I of items such that we have at least one element from each set S k (1 ≤ k ≤ m).

Example:

I = { i 1 ,...,i 6 } 

S 1 = { i 1 ,i 2 ,i 6 } 

一站式論文代寫,英国、美国、澳洲留学生Essay代寫—FreePass代写S 2 = { i 2 ,i 4 ,i 5 ,i 6}

一站式論文代寫,英国、美国、澳洲留学生Essay代寫—FreePass代写In the example above, we can return T = { i 2 } as the smallest set of items such that we have at least one element from each set, since i 2 is part of all three sets S 1 , S 2 , and S 3 . The set T = { i 1 ,i 4 } also contains an element from each of the three sets, but it isn’t the smallest set with this property, as it contains two elements and { i 2 } contains only one.

一站式論文代寫,英国、美国、澳洲留学生Essay代寫—FreePass代写Construct a counterexample to show that the following algorithm doesn’t com- pute the smallest set T: Sort the items by the number of sets that contain them (for ease of writing, we use | i j | to write the number of sets that contains the item i j ) in decreasing order. For every item i j , if i j occurs in some S k and no item in T is an element of S k , we add i j to T.

一站式論文代寫,英国、美国、澳洲留学生Essay代寫—FreePass代写1: def SmallestSet(S 1 ,...,S m , I) 2: T ← [ ] 3: Sort I by the number of sets that contains each item in decreasing order and renumber such that | i 1 | ≥ | i 2 | ≥ ... ≥ | i n | 4: for j ← 1; j ≤ n; j++ do 5: if i j is part of some S k and no other item in T is part of S k then 6: T ← T ∪ i j 7: return T

Problem 2. 一站式論文代寫,英国、美国、澳洲留学生Essay代寫—FreePass代写Consider the following edge weighted undirected graph:


Your task is to:

Compute the shortest path tree T of the graph starting from A. List the edges in T. a) [3marks] Indicate the order in which the edges are added by Dijkstra’s algorithm starting from A.

 b) (You do not have to explain your answer.)

Problem 3. Recall that a forest is a graph where every connected component is a tree. We want to design a data structure for a fixed set of n vertices that allows us to add and remove edges, as well as efficiently answer the query: "Are vertex i and vertex j part of the same tree?" You can assume that we identify the vertices by their number and that each vertex has a unique number in the range 0 to n ? 1 (or 1 to n if that’s easier for you).

一站式論文代寫,英国、美国、澳洲留学生Essay代寫—FreePass代写Your data structure should support the following operations:

一站式論文代寫,英国、美国、澳洲留学生Essay代寫—FreePass代写? initialize ( n ) : construct the data structure for the n vertices without any edges. This method is called exactly once and only as the first operation in any execu- tion.

一站式論文代寫,英国、美国、澳洲留学生Essay代寫—FreePass代写 ? insert-edge ( i, j ) : insert an undirected edge between vertex i and vertex j, if adding this edge doesn’t create cycles (otherwise, don’t add the edge) 

? remove-edge ( i, j ) : remove the edge between vertex i and vertex j, if it exists

一站式論文代寫,英国、美国、澳洲留学生Essay代寫—FreePass代写 ? in-same-tree ( i, j ) : return True if vertex i and vertex j are part of the same tree, and False otherwise (do not modify the data structure)

一站式論文代寫,英国、美国、澳洲留学生Essay代寫—FreePass代写Example: 

一站式論文代寫,英国、美国、澳洲留学生Essay代寫—FreePass代写initialize(10) - creates the data structure for 10 vertices

 in-same-tree(9,2) - returns False 

insert-edge(2,6) - adds the edge between vertex 2 and vertex 6

一站式論文代寫,英国、美国、澳洲留学生Essay代寫—FreePass代写 insert-edge(9,6) - adds the edge between vertex 9 and vertex 6 

insert-edge(9,2) - doesn’t do anything as this would create a cycle

 in-same-tree(9,2) - returns True remove-edge(6,2) - removes the edge between vertex 6 and vertex 2

 in-same-tree(9,2) - returns False

        Your task is to come up with a data structure that uses O ( n 2 ) space. The ini- tialize, insert-edge, and remove-edge operations should run in O ( n 2 ) time. The in-same-tree operation should run in O ( 1 ) time. Remember to:

一站式論文代寫,英国、美国、澳洲留学生Essay代寫—FreePass代写a) Describe your data structure implementation in plain English. 

一站式論文代寫,英国、美国、澳洲留学生Essay代寫—FreePass代写b) Prove the correctness of your data structure.

 c)Analyze the time and space complexity of your data structure.

Problem 4. Silbo Gomero is a whistling language used in the border region of France and Spain by shepherds to communicate with each other. We want to determine the number of pairs of shepherds that can communicate using this language. More specifically, we are given the locations of the shepherds in an array A, where every location is represented by a distinct positive integer. For simplicity you can assume that every shepherd whistles equally loudly and thus can cover the same distance d. Shepherds i and j can communicate with each other if | A [ i ] ? A [ j ]| ≤ d, i.e., if the absolute difference between their locations is at most the distance they can cover by whistling. Recall that | x | equals x when x ≥ 0 and | x | equals ? x if x < 0. You need to determine how many pairs of shepherds can communicate with each other.

Example: When A = [ 4,2,12,7 ] and d = 3, you should return 2, since | 4 ? 2 | = 2 ≤ d and | 4 ? 7 | = 3 ≤ d and no other pair is at distance at most d from each other.

一站式論文代寫,英国、美国、澳洲留学生Essay代寫—FreePass代写 Your task is to give a divide and conquer algorithm for this problem that runs in O ( nlogn ) time. Remember to: 

a)  Describe your algorithm in plain English. 

b) Prove the correctness of your algorithm. 

一站式論文代寫,英国、美国、澳洲留学生Essay代寫—FreePass代写c) Analyze the time complexity of your algorithm. 

 (Disclaimer: Silbo Gomero is an actual language and the background information given in the question is mostly accurate.)


學霸聯盟


在線客服

售前咨詢
售后咨詢
微信號
Essay_Cheery
微信
专业essay代写|留学生论文,作业,网课,考试|代做功課服務-PROESSAY HKG 专业留学Essay|Assignment代写|毕业论文代写-rushmyessay,绝对靠谱负责 代写essay,代写assignment,「立减5%」网课代修-Australiaway 代写essay,代写assignment,代写PAPER,留学生论文代写网 毕业论文代写,代写paper,北美CS代写-编程代码,代写金融-第一代写网 作业代写:CS代写|代写论文|统计,数学,物理代写-天天论文网 提供高质量的essay代写,Paper代写,留学作业代写-天才代写 全优代写 - 北美Essay代写,Report代写,留学生论文代写作业代写 北美顶级代写|加拿大美国论文作业代写服务-最靠谱价格低-CoursePass 论文代写等留学生作业代做服务,北美网课代修领导者AssignmentBack