Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i send you all information now. please as soon as possible Mon Feb 8 2:00 AM Bookmarks People Tab Window Help C5310 hws X New

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
i send you all information now. please as soon as possible
Mon Feb 8 2:00 AM Bookmarks People Tab Window Help C5310 hws X New Tab X Algorithm, Fourth Edition 9 -ofes/Varios-2/Algorithms%204%20Edition.pdf My Print Center Learning Manage Chapter 2 basic Welcome to Acad. Other Bookmar Estate Student AL 232 / 969 100% + H cong We wone me comprar com the number of components. Thus, we articulate the following APE public class UF UF(int NO initial site with internames ON-1) void union(int p. into) action panda int find(int p) com entifier for po to N-1) boolean connected(int inta) Peturn true andare in the same component int count() umber of components Union find API The union operation merges two components if the two sites are in different com ponents, the find) operation returns an integer component identifier for a given site. the connected operation determine whether two sites are in the same component, and the count method returns the number of components. We start with compo ments, and each union) that merges two different components decrements the num- ber of components by As we shall soon see, the development of an algorithmic solution for dynamic con nectivity thus reduces to the task of developing an implementation of this API. Every implementation has to Define a data structure to represent the known connections Develop efficient union().find(connected, and count implementa tions that are based on that data structure As usual, the nature of the data structure has a direct impact on the efficiency of the algorithms, sodata structure and algorithm design go hand in hand. The APt already specifies the convention that both sites and components will be identified by int val. ues between 0 and N-1, so it makes sense to use a site-indexed array id) as our basic sy COS BDO ** > HE 10 911 $ % 5 & 7 I Il + 6 8 9 0 P 80 Mon Feb 8 2:00 AM Tab Window Help + X Fourth Edition C$310 w New Tebe * D : rithms 204th 20 dition par Other Bookmarks Learning Manage Chapter 2 Estale Student Welcome to Acid 100% 231 / 969 + whether or not any given two sites in such a network are connected The first task that we face in developing an algorithm is to specify the problem in a precise manner. The more we require of an algorithm, the more time and space we may expect it to need to finish the job. It is impowible to quantify this relationship a priori and we often modify a problem specification on finding that it is difficult or expensive to solve or, in happy circumstances, on finding that an algorithm can provide informa to more useful than what was called for in the original specification For example, out 219 15 Sty Union connectivity problem specification requires only that our program be able to determine whether or not any given pair is connected, and not that it be able to demonstrate a set of connections that connect that pair Such a requirement makes the problem more difficult and leads us to a different family of algorithms, which we consider in STION To specify the problem, we develop an API that encapsulates the basic operations that we need initiale, add a connection between two sites, identify the component containing a site determine whether two sites are in the same component, and count the number of components. Thus, we articulate the following APE: 4.1 oly G 912 Il 10 4 FB * delete % 5 & 7 8 9 0 6 Mon Feb 8 2:01 AM People Tab Window Help the Fourth Edition 05110 New Tab Algorithms 620420Edition pat enter Learning Manage Chapter 2 basic { SA Welcome to Act Other took mara 1 234 / 969 1001 10 + O public class private int : Watchment de site private int count: public UFC No [Introdurray count id - nent: tiyor.txt for (int 1-0 N ) d) - 1 36 public int count 21 { return count) 50 72 public hoolean connected in pinta) EL { return find() - find(a): 3 gonents public int findint p) public void union(int p. inta) 1/ See page 222 Cucina). 24 couldkondage 228 ( white) public static void main(String args) Solve dynamic connectivity role on stil int stdin.readino: 1/ sabar of sites UF uf new UFONO Italize components while (Stdte. IsEmpty) Ent Stdin.readinti inte - Stdin.readint / Head to connect if (uf.connected()) continue / Toner connected ut.union. ) 1 Combine como Stout.println(""): w Andorint connection Stdout.printlncuf.count().components"): RA 2 FH G 12 Chart stal Student Welcome to Acad Other Bookmarks 241 / 969 100% + 1 public class Weighted uchun font rivate) 1 rent in Currenkel) private into 11 of content for roots attended) DEIVATE Wat moet public weight count dwin for Cint- ON) - 52 new int[ for (int - 0; + N) - 11 1 Dublic int count() retum count: boolean connected fren))) private int find(int p) Lollow link to find out while (1) - 1 return i } public void union(int . inta) intindo Int J - Find (1) return Wie aller root point to larger 17 (201) [- 520 - 20:) else [id) - 2011: count tv SAN 390 DO 2 FA PII $ G A % 5 & 7 6 1 0 8 9 delete T Y U I O P Bookmarks People T25 Window Helo Mon Feb 201 AM + Art Fittin C1310 -ot.es/Varios Algorithms 204120itionat Chapter . Welcome Acet Other Roomas 241 / 960 100N + COUNT int foncint - 01-N- int: for Cint- ONL) - 11 public int count) return count te boolean connected into returned in private int find(int p) { // Follow is to root while clip) - ) retum : public void union(int n, inte) intfind(); int - Findo) if 3) return keer root point to larger one 17 (2) CS350 w rios-2/Algorithms 420420Edition.pdf Print Center Learning Manage Chapter 2 Rb 9 (Esta: Student Welcome to Acad. Other Bookmarks 113 / 969 100% public class Date implements Datable trolentation code ( before) so that the Java compiler will check that it matches the interface. Adding the code implements Datable to any class that implements month day, and year pro vides a quarantee to any client that an object of that dass can invoke those methods This arrangement is known as interface inheritance-an implementing class inherit the interface. Interface inheritance allows us to write client programs that can manipulate objects of any type that implements the interface (even a type to be creat Java.lang.Comparable compare to ed in the future), by invoking meth ods in the interface. We might have Java.util.conpurator compare used interface inheritance in place of 1.5 our more informal APIs, but chose not to do so to avoid dependence on java.lang. Iterable terator 1.3 specific high-level language mecha nisms that are not critical to the sext understanding of algorithms and java.util. Iterator next 13 to avoid the extra baggage of inter- renove face files. But there are a few situa Java interfacet used in this tions where lava conventions make S RA PII o 17 TO FE F1 22 A % 5 & 7 I 0 Il + 6 8 8 9 b. Show quals in use by writing one if (..) that checks whether s Strings is equal to a string , character by character. Explain what this comparison is doing ifs="be" and t c. Find the hashCode and toString Values for Strings. Also for the Integer of value 8 9. Interfaces a. What is a Java interface? Soe S&W page 100 for an example. Note that an interface can have constants as well as methods, so the statement there that an "interface is nothing more b. Write a Juva interface source file UniFindjevato (as far as posible) express the API on page 219, the union-lind API. Also rewrite just the first line of UF java to assert that can UF implements this interface e. What methods.comstruction of Uge 221 in the interface? d. Does Weighteduickpage 22 quality for implementing the interface! Explain why or why not G ER 3 a 6 8 7 8 E R T Y U o S F F G . J L C V B N M ommand command option Mon Feb 8 2:00 AM Bookmarks People Tab Window Help C5310 hws X New Tab X Algorithm, Fourth Edition 9 -ofes/Varios-2/Algorithms%204%20Edition.pdf My Print Center Learning Manage Chapter 2 basic Welcome to Acad. Other Bookmar Estate Student AL 232 / 969 100% + H cong We wone me comprar com the number of components. Thus, we articulate the following APE public class UF UF(int NO initial site with internames ON-1) void union(int p. into) action panda int find(int p) com entifier for po to N-1) boolean connected(int inta) Peturn true andare in the same component int count() umber of components Union find API The union operation merges two components if the two sites are in different com ponents, the find) operation returns an integer component identifier for a given site. the connected operation determine whether two sites are in the same component, and the count method returns the number of components. We start with compo ments, and each union) that merges two different components decrements the num- ber of components by As we shall soon see, the development of an algorithmic solution for dynamic con nectivity thus reduces to the task of developing an implementation of this API. Every implementation has to Define a data structure to represent the known connections Develop efficient union().find(connected, and count implementa tions that are based on that data structure As usual, the nature of the data structure has a direct impact on the efficiency of the algorithms, sodata structure and algorithm design go hand in hand. The APt already specifies the convention that both sites and components will be identified by int val. ues between 0 and N-1, so it makes sense to use a site-indexed array id) as our basic sy COS BDO ** > HE 10 911 $ % 5 & 7 I Il + 6 8 9 0 P 80 Mon Feb 8 2:00 AM Tab Window Help + X Fourth Edition C$310 w New Tebe * D : rithms 204th 20 dition par Other Bookmarks Learning Manage Chapter 2 Estale Student Welcome to Acid 100% 231 / 969 + whether or not any given two sites in such a network are connected The first task that we face in developing an algorithm is to specify the problem in a precise manner. The more we require of an algorithm, the more time and space we may expect it to need to finish the job. It is impowible to quantify this relationship a priori and we often modify a problem specification on finding that it is difficult or expensive to solve or, in happy circumstances, on finding that an algorithm can provide informa to more useful than what was called for in the original specification For example, out 219 15 Sty Union connectivity problem specification requires only that our program be able to determine whether or not any given pair is connected, and not that it be able to demonstrate a set of connections that connect that pair Such a requirement makes the problem more difficult and leads us to a different family of algorithms, which we consider in STION To specify the problem, we develop an API that encapsulates the basic operations that we need initiale, add a connection between two sites, identify the component containing a site determine whether two sites are in the same component, and count the number of components. Thus, we articulate the following APE: 4.1 oly G 912 Il 10 4 FB * delete % 5 & 7 8 9 0 6 Mon Feb 8 2:01 AM People Tab Window Help the Fourth Edition 05110 New Tab Algorithms 620420Edition pat enter Learning Manage Chapter 2 basic { SA Welcome to Act Other took mara 1 234 / 969 1001 10 + O public class private int : Watchment de site private int count: public UFC No [Introdurray count id - nent: tiyor.txt for (int 1-0 N ) d) - 1 36 public int count 21 { return count) 50 72 public hoolean connected in pinta) EL { return find() - find(a): 3 gonents public int findint p) public void union(int p. inta) 1/ See page 222 Cucina). 24 couldkondage 228 ( white) public static void main(String args) Solve dynamic connectivity role on stil int stdin.readino: 1/ sabar of sites UF uf new UFONO Italize components while (Stdte. IsEmpty) Ent Stdin.readinti inte - Stdin.readint / Head to connect if (uf.connected()) continue / Toner connected ut.union. ) 1 Combine como Stout.println(""): w Andorint connection Stdout.printlncuf.count().components"): RA 2 FH G 12 Chart stal Student Welcome to Acad Other Bookmarks 241 / 969 100% + 1 public class Weighted uchun font rivate) 1 rent in Currenkel) private into 11 of content for roots attended) DEIVATE Wat moet public weight count dwin for Cint- ON) - 52 new int[ for (int - 0; + N) - 11 1 Dublic int count() retum count: boolean connected fren))) private int find(int p) Lollow link to find out while (1) - 1 return i } public void union(int . inta) intindo Int J - Find (1) return Wie aller root point to larger 17 (201) [- 520 - 20:) else [id) - 2011: count tv SAN 390 DO 2 FA PII $ G A % 5 & 7 6 1 0 8 9 delete T Y U I O P Bookmarks People T25 Window Helo Mon Feb 201 AM + Art Fittin C1310 -ot.es/Varios Algorithms 204120itionat Chapter . Welcome Acet Other Roomas 241 / 960 100N + COUNT int foncint - 01-N- int: for Cint- ONL) - 11 public int count) return count te boolean connected into returned in private int find(int p) { // Follow is to root while clip) - ) retum : public void union(int n, inte) intfind(); int - Findo) if 3) return keer root point to larger one 17 (2) CS350 w rios-2/Algorithms 420420Edition.pdf Print Center Learning Manage Chapter 2 Rb 9 (Esta: Student Welcome to Acad. Other Bookmarks 113 / 969 100% public class Date implements Datable trolentation code ( before) so that the Java compiler will check that it matches the interface. Adding the code implements Datable to any class that implements month day, and year pro vides a quarantee to any client that an object of that dass can invoke those methods This arrangement is known as interface inheritance-an implementing class inherit the interface. Interface inheritance allows us to write client programs that can manipulate objects of any type that implements the interface (even a type to be creat Java.lang.Comparable compare to ed in the future), by invoking meth ods in the interface. We might have Java.util.conpurator compare used interface inheritance in place of 1.5 our more informal APIs, but chose not to do so to avoid dependence on java.lang. Iterable terator 1.3 specific high-level language mecha nisms that are not critical to the sext understanding of algorithms and java.util. Iterator next 13 to avoid the extra baggage of inter- renove face files. But there are a few situa Java interfacet used in this tions where lava conventions make S RA PII o 17 TO FE F1 22 A % 5 & 7 I 0 Il + 6 8 8 9 b. Show quals in use by writing one if (..) that checks whether s Strings is equal to a string , character by character. Explain what this comparison is doing ifs="be" and t c. Find the hashCode and toString Values for Strings. Also for the Integer of value 8 9. Interfaces a. What is a Java interface? Soe S&W page 100 for an example. Note that an interface can have constants as well as methods, so the statement there that an "interface is nothing more b. Write a Juva interface source file UniFindjevato (as far as posible) express the API on page 219, the union-lind API. Also rewrite just the first line of UF java to assert that can UF implements this interface e. What methods.comstruction of Uge 221 in the interface? d. Does Weighteduickpage 22 quality for implementing the interface! Explain why or why not G ER 3 a 6 8 7 8 E R T Y U o S F F G . J L C V B N M ommand command option

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Logic In Databases International Workshop Lid 96 San Miniato Italy July 1 2 1996 Proceedings Lncs 1154

Authors: Dino Pedreschi ,Carlo Zaniolo

1st Edition

3540618147, 978-3540618140

More Books

Students also viewed these Databases questions

Question

Factors Affecting Conflict

Answered: 1 week ago

Question

Describe the factors that lead to productive conflict

Answered: 1 week ago

Question

Understanding Conflict Conflict Triggers

Answered: 1 week ago