Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
11th Edition
ISBN: 9780134671710
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 21.2, Problem 21.2.6CP
Suppose set1 is a set that contains the strings red, yellow, and green and that set2 is another set that contains the strings red, yellow, and blue. Answer the following questions:
- What are in set1 and set2 after executing set1.addA11(set2)?
- What are in set1 and set2 after executing set1.add(set2)?
- What are in set1 and set2 after executing set1.removeA11(set2)?
- What are in set1 and set2 after executing set1.remove(set2)?
- What are in set1 and set2 after executing set1.retainAll(set2)?
- What is in set1 after executing set1.clear()?
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
24. Suppose that set1 (Set) is a set that contains the strings "red", "yellow", "green", and that
set2 (Set) is another collection that contains the strings "red", "yellow", "blue". Answer the
following questions: (All the questions are independent)
a. What is set1 after executing set1.addAll(set2)?
b. What is set1 after executing set1.add(set2)?
What is set1 after executing set1.removeAll(set2)?
d. What is set1 after executing set1.clear()?
C.
Q1. Given the following set: pets = {"cat", "dog", "horse"}, replace the word "dog"
with "cow". You cannot assume that you know the index of "dog" - you must
find it using code.
1. h is a homomorphism from the alphabet {a,b,c} to {0,1}. If h(a) = 01, h(b) = 0,
and h(c) = 10, which of the following strings is in h¨¹ (010010)?
a) baab
b) baba
c) bcab
d) cbbc
2. Find, in the list below, a regular expression whose language is the reversal of
the language of this regular expression: 10(2+3). Recall that the reversal of a
language is formed by reversing all its strings, and the reversal of a string
a₁a2...an is an...a2a₁.
a) 01(2+3)
b) (2+3)10
c) 0(2+3)1
d) (2+3)01
3. If h is the homomorphism defined by h(a) = 0 and h(b) = ε, which of the
following strings is in h¹ (000)?
a) abbba
b) abbbabaab
c) baabbbabb
d) babab
4. The operation Perm(w), applied to a string w, is all strings that can be
constructed by permuting the symbols of w in any order. For example, if w =
101, then Perm(w) is all strings with two 1's and one 0, i.e., Perm(w) = {101,
110,011}. If L is a regular language, then Perm(L) is the union of Perm(w)
taken over all w in L. For example, if L is the…
Chapter 21 Solutions
Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
Ch. 21.2 - Prob. 21.2.1CPCh. 21.2 - Prob. 21.2.2CPCh. 21.2 - Prob. 21.2.3CPCh. 21.2 - Prob. 21.2.4CPCh. 21.2 - Prob. 21.2.5CPCh. 21.2 - Suppose set1 is a set that contains the strings...Ch. 21.2 - Prob. 21.2.7CPCh. 21.2 - Prob. 21.2.8CPCh. 21.2 - What will the output be if lines 67 in Listing...Ch. 21.2 - Prob. 21.2.10CP
Ch. 21.3 - Prob. 21.3.1CPCh. 21.3 - Suppose you need to write a program that stores...Ch. 21.3 - Suppose you need to write a program that stores...Ch. 21.3 - Suppose you need to write a program that stores a...Ch. 21.3 - Prob. 21.3.5CPCh. 21.3 - Prob. 21.3.6CPCh. 21.4 - Prob. 21.4.1CPCh. 21.4 - Prob. 21.4.2CPCh. 21.5 - Prob. 21.5.1CPCh. 21.5 - Prob. 21.5.2CPCh. 21.5 - Prob. 21.5.3CPCh. 21.6 - Prob. 21.6.1CPCh. 21.6 - Prob. 21.6.2CPCh. 21.6 - Prob. 21.6.3CPCh. 21.6 - Prob. 21.6.4CPCh. 21.7 - Prob. 21.7.1CPCh. 21.7 - Prob. 21.7.2CPCh. 21 - Prob. 21.1PECh. 21 - (Display nonduplicate words in ascending order)...Ch. 21 - Prob. 21.3PECh. 21 - (Count consonants and vowels) Write a program that...Ch. 21 - Prob. 21.6PECh. 21 - (Revise Listing 21.9, CountOccurrenceOfWords.java)...Ch. 21 - Prob. 21.8PECh. 21 - Prob. 21.9PE
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Big data Big data describes datasets with huge volumes that are beyond the ability of typical database manageme...
Management Information Systems: Managing The Digital Firm (16th Edition)
What is the disadvantage of having too many features in a language?
Concepts Of Programming Languages
You can use the for loop to iterate over the individual characters in a string.
Starting Out with Python (4th Edition)
2-1 List the five types of measurements that form the
basis of traditional ptane surveying-
Elementary Surveying: An Introduction To Geomatics (15th Edition)
What is the call stack? What is a stack trace?
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
List the functions of a database application.
Database Concepts (8th Edition)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Write a section of code that creates the pairings for two sets of numbers a = {0 – 5} and b = {9 - 15}. Each number must be paired with all numbers from the other set. This is a cross product, denoted as a x b. That is, for every number in a, it should be listed with every number in b, such as (0, 9), … (0, 15), and so on. Make sure there are no spaces between numbers and the (, ), or comma.arrow_forward1- Let A = [2: 0.5: 4],and B=B(2:4). What are the value of a ,and B?arrow_forward1. The operation Perm(w), applied to a string w, is all strings that can be constructed by permuting the symbols of w in any order. For example, if w = 101, then Perm(w) is all strings with two 1's and one 0, i.e., Perm(w) = {101, 110,011}. If L is a regular language, then Perm(L) is the union of Perm(w) taken over all w in L. For example, if L is the language L(0*1*), then Perm(L) is all strings of 0's and 1's, i.e., L((0+1)*). If L is regular, Perm(L) is sometimes regular, sometimes context-free but not regular, and sometimes not even context-free. Consider each of the following regular expressions R below, and decide whether Perm(L(R)) is regular, context-free, or neither: 1. (01)* 2.0*+1* 3. (012)* 4. (01+2)* a) Perm(L((01+2)*)) is context-free but not regular. b) Perm(L(0*+1*)) is not context-free. c) Perm(L((012)*)) is context-free but not regular. d) Perm(L(0*+1*)) is context-free but not regular. 2. The language of regular expression (0+10)* is the set of all strings of O's and…arrow_forward
- Determine whether the string 010101 is in each of these sets. 1.1. {0,1}* 1.2. {01,10}*{0, 1}{1} 1.3. {0,1}*{01,11}{1} 1.4. {010,011}{0, 1}*{00,01}arrow_forwardIn java write code that will take in input from a user containing two sets. Then you will complete all 6 set operations on those sets. Your user input/output should look similar to the assignment Set Operations Assignment (which is attatched) The universal set is all integers from 1 to 100. Ideally your code would be able to accept all types of input but for practice we are going to stick to integers. You should test your code with more than the following inputs but I will be grading you based on if your code is able to accept the following as user input (one set/pair at a time) and give the correct output for the given set (do not hard code it for the all sets at once, the output should be determined by the code based on the input, meaning I could put any two set integers as input and it should work): S = {1, 2, 3, 4} T = {3, 4, 5, 6} S = {1, 3, 5} T = {3, 4, 5, 6} S = {10, 13, 22, 41} T = {40, 60, 80} S = {3, 10} T = {1, 2, 3} S = {10} T = {3}arrow_forwardImplement the Plates class buildMap function so that it populates the HashMap with the state abbreviations as keys and the counts of how many each appear in the file as values. Sometimes, the parking attendant will add special notation to help her remember something about a specific entry. There are just non alphabetic characters that she adds to the state - your program should ignore these characters so that an entry like NY* still counts toward the NY plate count. She is also very inconsistent with how she enters the plates. Sometimes she uses upper case, sometimes lowercase, and sometimes she even uses a mix. Be sure to account for this in your program. Only add information for plates in New England (Maine, New Hampshire, Vermont, Massachusetts, Rhode Island, and Connecticut). Plates.java import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; public class Plates { private Map<String, Integer> plateMap;…arrow_forward
- my_fruit1 = input()my_fruit2 = input()my_fruit3 = input() your_fruit1 = input()your_fruit2 = input() their_fruit = input() # 1. TODO: Define a set, fruits, containing my_fruit1, my_fruit2, and my_fruit3 print(sorted(fruits)) # 2. TODO: Add your_fruit1 and your_fruit2 to fruits print(sorted(fruits)) # 3. TODO: Add their_fruit to fruits print(sorted(fruits)) # 4. TODO: Add your_fruit1 to fruits print(sorted(fruits)) # 5. TODO: Remove my_fruit1 from fruits print(sorted(fruits))arrow_forwarda multiset is a collection of objects, just like a set, but can contain an object more than once ( the order of the elements still doesn't matter). for example, {1,1,2,5,5,7} is a multistset of size 6. a. how many sets of size 5 can be made using the 10 numeric digits 0 through 9? b. how many multisets of size 5 can be made using he 10 numeric digits 0 through 9?arrow_forwardIn this lab, you will create a backend class called SortableSet. A set, in computer science, is an unordered collection of unique objects. In our SortableSet, all of the objects in the set will also be immutable at the set level. This means that even if the data class used to create objects is not immutable, once they are in the set they are. We do this by making a deep copy of any objects being added to the set or returned from the set. The objects stored in the SortableSet must implement an interface called Sortable that provides a numeric sorting key and a deep copy method. SortableSet also takes advantage of two custom exception classes: DuplicateException and InvalidKeyException. Finally, the "sortable" part of SortableSet is implemented by a getSortedList method that makes a deep copy of every object in the set, saves them to an array, and then sorts them based on each object's sorting key. The sort algorithm used is a recursive radix sort modified to work with objects.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Definition of Array; Author: Neso Academy;https://www.youtube.com/watch?v=55l-aZ7_F24;License: Standard Youtube License