Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help on these quetions I am having problems understanding these questions

ID: 3677382 • Letter: I

Question

I need help on these quetions I am having problems understanding these questions for a exam review thank you

1.A language-independent specification for a group of values and operations on those values is called a/an:

2.An implementation of an ADT with a programming language is called a/an:

3.Which of the following is not true with regard to bags?

4.You wish to keep track of the distribution of words in a document, for example, how many times the word “apple” appears. You store each word in the document in a bag. Why is a bag a potentially good solution?

5.What are the consequences of returning a reference to the bag array in the toArray method?

Explanation / Answer

1)A language-independent specification for a group of values and operations on those values is called a/an: Binding

2.An implementation of an ADT with a programming language is called a/an:Information hiding

5) toArray() method, this method acts as bridge between array-based and collection-based APIs. Further, this method allows precise control over the runtime type of the output array, and may, under certain circumstances, be used to save allocation costs.

Suppose that we define toArray as follows:

public String[] toArray()

{

return bag;

} // end toArray

This simple definition would certainly return an array of the bag's contents to a client. For example, the

statement

String[] bagArray = myBag.toArray();

provides a reference to an array of the entries in myBag . A client could use the variable bagArray to

display the contents of myBag .

The reference bagArray , however, is to the array bag itself. That is, bagArray is an alias for the

private instance variable bag within the object myBag , and therefore it gives the client direct access

to this private data. Thus, a client could change the contents of the bag without calling the class's

public methods. For instance, if myBag is the full bag pictured in Figure 2-3, the statement

bagArray[2] = null ;

would change the entry Ted to null . Although this approach might sound good to you if the intent is to remove Ted from the bag, doing so would destroy the integrity of the bag. In particular, the entries in the array bag would no longer be consecutive, and the count of the number of entries in the bag would be incorrect.

4)A bag is a collection of objects, where you can keep adding objects to the bag, but you cannot remove them once added to the bag. So with a bag data structure, you can collect all the objects, and then iterate through them

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote