Question

In: Computer Science

Consider the following statement: When designing a data structure, it is important to distinguish between what...

Consider the following statement: When designing a data structure, it is important to distinguish between what the characteristics and operations of the data structure are versus how they can be implemented.

(a) Explain why defining the ADT as a Java interface and defining classes to implement the interface is consistent with the above statement.

(b) Describe how the setup in part (a) is an example of polymorphism and provide a specific example of how polymorphism can be used to make our designed data structures more useful.

(c) Provide two (2) examples of how the specifications of the Java interface can enforce rules about how a data structure behaves. Be specific and explain your answer.

(d) Provide three (3) examples of how implementation-level decisions allowed a particular implementation to improve the runtime efficiency of an operation. Be specific and explain your answer.

Solutions

Expert Solution

Ans.

a. Abstraction is a process of hiding the details from the user and providing only the functionality i.e. hiding the implementation and showing only essential functionality. Abstraction is done for security. It reduces the complexity for users. Some of the common ADT's are List ADT, stack ADT, queue ADT etc. Interface is used in JAVA to establish abstraction. Interfaces can be considered as pure ADTs because an interface can be implemented many times and user will only see the functionality and not the implementation. Multiple Inheritance can also be achieved through interfaces in JAVA as there will be no ambiguity, as function of interface can be overridden ‘n’ number of times. Thus interfaces are consistent with the statement as we can distinguish between its working and implementation and can achieve abstraction easily by using interfaces in Java.

b. Polymorphism is another pillar of OOPs concept where the same code or functionality is used again in some different form. It is used to achieve code re-usability. There are two types of polymorphisms: runtime polymorphism and compile time polymorphism. The example of runtime polymorphism is method over-riding where name of the methods and parameters are same but have different functionalities in child classes and example of compile time polymorphism is method over- loading where the name is same but parameters differ in some or the other manner. We always over-ride functions declared in interfaces in the class which implements the interfaces and by this way polymorphism is achieved as we always need to over-ride functions to implement interfaces through classes and this is the same case with other ADTs too. Thus polymorphism is achieved.

c. Collection framework is basically a framework which provides a group of objects such as lists, maps, queues, hashmaps etc. In the collection framework there are interfaces and classes. The collection framwork is a complete group of data structures and lists, queue, sets, etc. are interfaces and thus here interfaces are enforcing rules by providing methods to implement, thus deciding how data structures behave.

d. Interfaces only provide declaration, so the main part depends upon the class which is implementing the interface and over-riding its functions as it's in the hands of user to use right data structures and logic which will increase efficiency of the code. We could always have a better logic to a problem that we can use and with that we can achieve better efficiency to the code. If one's implementation is complex then there will always be chances of logic to under-perform.


Related Solutions

What considerations are important when designing an instrument to collect quantitative data? What is reliability and...
What considerations are important when designing an instrument to collect quantitative data? What is reliability and validity of instrumentation? Why is it important? In what situations would a researcher validate an instrument? with references within five years.
What considerations are important when designing an instrument to collect quantitative data? What is reliability and...
What considerations are important when designing an instrument to collect quantitative data? What is reliability and validity of instrumentation? Why is it important? In what situations would a researcher validate an instrument?
1. What does the effectiveness of a document depend on, and what are some important elements to consider when designing a document?
Topic: “Designing Print and Online Documents,”Reflect and respond (answer one or more of the following questions):1. What does the effectiveness of a document depend on, and what are some important elements to consider when designing a document?What are similarities between designing a print document and online document?What images and visuals are you including on your site and how do they aid in connecting to your audience and furthering your purpose?Word count: 400 words
What advantages and disadvantages would be important to consider when choosing between each of the following...
What advantages and disadvantages would be important to consider when choosing between each of the following types of model organisms for researching a given scientific question: prokaryote (like E. coli), unicellular eukaryote (like yeast), invertebrate (like C. elegansand D. melanogaster), mammalian (like a mouse) and tissue culture?
1. When would it be important to distinguish between the incidence of a specific disease or...
1. When would it be important to distinguish between the incidence of a specific disease or condition in your patient population (any patient population) and the prevalence of the disease/condition. 2. What is the sensitivity and specificity of a diagnostic test used to make diagnoses for your patient population (used in #1) ? Discuss the implications of the values you present.
Why is it important to consider the entire size range of particulate matter emissions when designing...
Why is it important to consider the entire size range of particulate matter emissions when designing control strategies?
When computing a t-test, it is important to distinguish between directional and nondirectional hypotheses as the...
When computing a t-test, it is important to distinguish between directional and nondirectional hypotheses as the direction will determine the rejection regions. Describe how the rejection regions would differ according to the type of hypothesis you would use. An insurance company asks you to determine whether older drivers are safer than younger ones. Provide a directional hypothesis related to this study. Then, explain how you would need to change the hypothesis so that it would be nondirectional. What happens to...
Distinguish between the structure of a prokaryotic cell and that of a eukaryotic cell.
Distinguish between the structure of a prokaryotic cell and that of a eukaryotic cell.
Name two reasons it is important to distinguish between needs and demands for services. What are...
Name two reasons it is important to distinguish between needs and demands for services. What are the differences among causal, intervention, and impact theories?
During a Structure and Solubility experiment how do you distinguish between the following: a.) butane and...
During a Structure and Solubility experiment how do you distinguish between the following: a.) butane and 2-chlorobutane b.)butane and 1-butanol c.)1-butanol and 2-butanol d.)1-butanol and butanoic acid
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT