Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
4th Edition
ISBN: 9780134787961
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 18.3, Problem 18.24CP
Program Plan Intro
“HashSet” class:
- The “HashSet” class implements the “Set” interface.
- It uses hash codes to store the elements in a way that makes searching faster.
- The “HashSet” class gives constant time performance for the basic operations like add, delete, and size assuming the hash function separates the elements properly among the buckets.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Question1- Add to the Test class a method called
isSubSet(LinearProbingHashTable h1, LinearProbingHashTable h2)
that is receives 2 hash tables h1 and h2, and returns true if h1 is sub set of h2,
otherwise the method returns false.
Don't forget to test the method in the main of Test class
HashSet Iterator Example : How To Iterate Through
A HashSet/Set
Write a method void removeShortStrings(HashSet<String> set). The method should remove from the set any string that is shorter than 100.
Chapter 18 Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Ch. 18.1 - Prob. 18.1CPCh. 18.1 - What are the three general types of collections?Ch. 18.1 - Prob. 18.3CPCh. 18.1 - Prob. 18.4CPCh. 18.1 - Prob. 18.5CPCh. 18.1 - Prob. 18.6CPCh. 18.1 - Prob. 18.7CPCh. 18.2 - Prob. 18.8CPCh. 18.2 - Prob. 18.9CPCh. 18.2 - Prob. 18.10CP
Ch. 18.2 - Prob. 18.11CPCh. 18.2 - Prob. 18.12CPCh. 18.2 - Prob. 18.13CPCh. 18.2 - Prob. 18.14CPCh. 18.2 - Prob. 18.16CPCh. 18.2 - Prob. 18.17CPCh. 18.2 - Prob. 18.18CPCh. 18.2 - Prob. 18.20CPCh. 18.3 - Prob. 18.21CPCh. 18.3 - Prob. 18.22CPCh. 18.3 - Prob. 18.23CPCh. 18.3 - Prob. 18.24CPCh. 18.3 - Any time you override the Object classs equals...Ch. 18.3 - Prob. 18.26CPCh. 18.3 - Prob. 18.27CPCh. 18.3 - Prob. 18.28CPCh. 18.4 - Prob. 18.29CPCh. 18.4 - Prob. 18.31CPCh. 18.4 - Prob. 18.32CPCh. 18.6 - How do you define a stream of elements?Ch. 18.6 - How does a stream intermediate operation differ...Ch. 18.6 - Prob. 18.35CPCh. 18.6 - Prob. 18.36CPCh. 18.6 - Prob. 18.37CPCh. 18.6 - Prob. 18.38CPCh. 18.6 - Prob. 18.39CPCh. 18 - Prob. 1MCCh. 18 - Prob. 2MCCh. 18 - This type of collection is optimized for...Ch. 18 - Prob. 4MCCh. 18 - A terminal operation in a stream pipeline is also...Ch. 18 - Prob. 6MCCh. 18 - Prob. 7MCCh. 18 - This List Iterator method replaces an existing...Ch. 18 - Prob. 9MCCh. 18 - Prob. 10MCCh. 18 - This is an object that can compare two other...Ch. 18 - This class provides numerous static methods that...Ch. 18 - Prob. 13MCCh. 18 - Prob. 14MCCh. 18 - Prob. 15TFCh. 18 - Prob. 16TFCh. 18 - Prob. 17TFCh. 18 - Prob. 18TFCh. 18 - Prob. 19TFCh. 18 - Prob. 20TFCh. 18 - Prob. 21TFCh. 18 - Prob. 22TFCh. 18 - Prob. 1FTECh. 18 - Prob. 2FTECh. 18 - Prob. 3FTECh. 18 - Prob. 4FTECh. 18 - Write a statement that declares a List reference...Ch. 18 - Prob. 2AWCh. 18 - Assume that it references a newly created iterator...Ch. 18 - Prob. 4AWCh. 18 - Prob. 2SACh. 18 - Prob. 4SACh. 18 - Prob. 5SACh. 18 - Prob. 6SACh. 18 - How does the Java compiler process an enhanced for...Ch. 18 - Prob. 8SACh. 18 - Prob. 9SACh. 18 - Prob. 10SACh. 18 - Prob. 11SACh. 18 - Prob. 12SACh. 18 - Prob. 13SACh. 18 - Prob. 14SACh. 18 - Word Set Write an application that reads a line of...Ch. 18 - Prob. 3PCCh. 18 - Prob. 5PCCh. 18 - Prob. 8PC
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
- Which of the following statements are true about a HashSet ? Select all that apply. Hint: you should be able to answer this question based only on the material presented in class. If E inherits Object.hashCode(), then there will be no collisions. A HashSet iterator should iterate through the Hashset elements in the order in which they were added to the Hashset. Two HashSets are equal (according to the equals() method) if they have the same size and their elements can be paired such that the pairs are equal according to the E.equals() method. OA HashSet could be implemented using a HashMap namely the key is the same as the value.arrow_forwardOur hash map data is saved as a LinkedList due to improper map building. This makes hash maps less helpful.arrow_forwardIt is python language Write the code that creates a new Node class. It will store data and next attributes. You only need to create the __init__ method. data and next variables will have default values, both set to None. Assume you are using the Node class from the previous connection to create a LinkedList. You have the code below, create a method that removes the first node from the LinkedList. class LinkedList: def __init__(self): self.head = None Based on the code from the last two questions, create a new LinkedList. Add 2 values to the LinkedList (there is an add method that accepts data as an argument, called add). Then call the removeFront method created in the previous question. Based on the previous questions, create a Queue class that uses the LinkedList for its data storage. Create the __init__, isEmpty, insert, remove, and size methods. Assume that LinkedList class has the add, removeFront and size methods defined. Based on the LinkedList code already…arrow_forward
- ' make a hashmap ' import hashlib import sys def insert (hashmap, key, value): ' insert a key value pair into the hashmap ' hashmap[key] = value def remove (hashmap, key): ' remove a key value pair from the hashmap ' del hashmap[key] def search (hashmap, key): ' search for a key in the hashmap ' if key in hashmap: return hashmap[key] else: return None def print (hashmap): ' print the hashmap ' for key in hashmap: print (key, ":", hashmap[key]) 'end of print' def main (): 'make a menu that lets the user call the functions' hashmap = {} while True: print (""" Menu: 1. Insert 2. Remove 3. Search 4. Print 5. Quit """) choice = input ("Enter your choice: ") if choice == "1": key = input ("Enter the key: ") value = input ("Enter the value: ") insert (hashmap, key, value) elif choice == "2":…arrow_forwardgetListRowIndices Method public static java.util.ArrayList<java.lang.Integer> getListRowIndices(int[][] array, int rowLength) This method returns an ArrayList with the indices of rows of the two-dimensional having a length that corresponds to rowLength. You may only use one auxiliary method. The method should create an ArrayList that is passed to the auxiliary in order to place the indices (if any). If no indices are found, an empty (size of 0) ArrayList will be returned. You can assume the array parameter will not be null and every row of the two-dimensional array has an array with a size of at least 0. Your implementation must be recursive and you may not use any loop construct. Do not use ++ or -- in any recursive call argument. It may lead to an infinite recursion. For example, use index + 1, instead of index++. Parameters: array - rowLength - Returns: ArrayList<Integer>arrow_forward@return index of the point that is closest to the origin, which is (0, 0) * In case of a tie, return the lowest index */ public int closestToOriginIndex() { return 0; }arrow_forward
- code: public class PasswordGeneratorAndStorage {/*** Adds an application to the applications ArrayList. If index is -1, add application* to the end of applications. Else is index is within the size of applications, add* application at that index in applications. Otherwise, return. However, if applications * or application is null, return.* * @param applications* @param application* @param index*/public static void addApplication(ArrayList<String> applications, String application, int index) {// TODO: FILL IN BODY}/*** Generates a random password of length passwordLength and adds it to the end of* passwords if index is -1, or adds it to the index of passwords if index is within the* size of passwords (similar to how the addApplication adds an application). To generate* the random password, use rand to generate a random int within the size of characters. You* can then use this int to grab the char at that index in characters and concatenate that* to your String password variable.…arrow_forwardJavaarrow_forward7- question What keys and values are contained in the following map after execution of the following piece of code? Map map = new HashMap (); map.put (8, "Eight"); map.put (41, "Forty-one"); map.put (8, "Ocho"); map.put (18, "Eighteen"); map.put (50, "Fifty"); map.put (132, "OneThreeTwo"); map.put (28, "Twenty-eight"); map.put (79, "Seventy-nine"); map.remove ( 41); map.remove (28); map.put (28, "18"); map.remove (18); a. {8=Eight, 41=Forty-one, 8=0cho, 18=Eighteen, 50=Fifty, 132=OneThreeTwo, 28=Twenty-eight, 79=Seventy-nine, 28=18} b. {8=Eight, 8=Ocho, 50=Fifty, 132=OneThreeTwo, 79=Seventy-nine, 28=18} c. {50=Fifty, 132=DOneThreeTwo, 8=Ocho, 28=18, 79=Seventy-nine} d. {8=Eight, 50=Fifty, 132=OneThreeTwo, 79=Seventy-nine, 28=18}arrow_forward
- True or true: False or true: Map-reduce is just applications.arrow_forwardclass DoublyLinkedList: def __init__(self): self.head = None def is_empty(self): if self.head == None: return True else: return False def enqueue_front(self, data): new_node = Node(data) new_node.next = self.head if self.head is not None: self.head.prev = new_node self.head = new_node def enqueue_rear(self, data): new_node = Node(data) new_node.next = None if self.head is None: new_node.prev = None self.head = new_node return last = self.head while(last.next is not None): last = last.next last.next = new_node new_node.prev = last return def peek(self): return self.head.data def dequeue_front(self): if self.head is None: return temp = self.head self.head = self.head.next self.head.prev = None return temp.data…arrow_forwardUsing Java programming language create a linked list named Cars with four elements: "SUV cars", "Pickup cars", "Sport cars", and "Sedan cars". Apply the following activities on the code you’ve created and provide screen shot of each result: Add a new element “Classic car” at the beginning of the linked list using iterator. Add a new element “Economic cars" after the element "Sedan Cars" using iterator. Print the LinkedList backward from the last element to the first element using hasPrevious()arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT