Below is the IntList class we discussed in week 2. We are in the middle of...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Below is the IntList class we discussed in week 2. We are in the middle of implementing a new recursive method called contains that should return true if the list contains the given number and false if it does not. What code should replace the comment/* recursive case */ so that the contains method works correctly? public class IntList { private class IntNode { } } private IntNode first; private int data; private IntNode next; public IntList() { first = null; } public IntNode(int data, IntNode next) { this.data data; this.next next; } public void insertAtFront (int data) { first = new IntNode (data, first); 8 } /** * Determins if the list contains target. 8 @param target the number to search for @return true if the list contains tgarget and false otherwise. public boolean contains (int target) { return containsH(first, target); private boolean containsH(IntNode n, int target) { if (n == null) /* base case */ else { boolean temp containsH(n.next, target); /* recursive case */ else { boolean temp = containsH(n.next, target); /* recursive case */ return temp && (n.data == target); return temp || (n.data == target); if (temp == true) else } return (n.data == target); return false; if (temp == false) return containsH(first, target); else return true; True False Question 15 (5 points) The SequentialsearchST class allows null as a possible key. What is the order of growth of the worst case running time of the delete operation for the book's BinarySearchST with n keys, when the key being deleted is present in the symbol table? O logarithmic O constant O quadratic Olinear O(lgn) O(1) O(n) O(n) What is the order of growth of the worst case running time of the delete operation for the book's BinarySearchST with n keys, when the key being deleted is not present in the symbol table? O quadratic O logarithmic O linear O constant O(n) O(lgn) O(n) O(1) What happens when the following function is called with a valid Map object? public static void fun (Map dict) { dict.put("hello", null); } if (dict.containsKey("hello")) stdout.println("dict else stdout.println("dict does NOT contain hello"); it depends on what is already stored in dict dict does NOT contain hello is printed to the screen an exception is thrown dict contains hello is printed to the screen contains hello"); Question 18 (5 points) What is the order of growth of the worst case running time of the get operation for the book's BinarySearchST with n keys, when the key being searched for is not in the symbol table? O linear O logarithmic O quadratic constant O(n) O(lgn) O(n.) O(1) Below is the IntList class we discussed in week 2. We are in the middle of implementing a new recursive method called contains that should return true if the list contains the given number and false if it does not. What code should replace the comment/* recursive case */ so that the contains method works correctly? public class IntList { private class IntNode { } } private IntNode first; private int data; private IntNode next; public IntList() { first = null; } public IntNode(int data, IntNode next) { this.data data; this.next next; } public void insertAtFront (int data) { first = new IntNode (data, first); 8 } /** * Determins if the list contains target. 8 @param target the number to search for @return true if the list contains tgarget and false otherwise. public boolean contains (int target) { return containsH(first, target); private boolean containsH(IntNode n, int target) { if (n == null) /* base case */ else { boolean temp containsH(n.next, target); /* recursive case */ else { boolean temp = containsH(n.next, target); /* recursive case */ return temp && (n.data == target); return temp || (n.data == target); if (temp == true) else } return (n.data == target); return false; if (temp == false) return containsH(first, target); else return true; True False Question 15 (5 points) The SequentialsearchST class allows null as a possible key. What is the order of growth of the worst case running time of the delete operation for the book's BinarySearchST with n keys, when the key being deleted is present in the symbol table? O logarithmic O constant O quadratic Olinear O(lgn) O(1) O(n) O(n) What is the order of growth of the worst case running time of the delete operation for the book's BinarySearchST with n keys, when the key being deleted is not present in the symbol table? O quadratic O logarithmic O linear O constant O(n) O(lgn) O(n) O(1) What happens when the following function is called with a valid Map object? public static void fun (Map dict) { dict.put("hello", null); } if (dict.containsKey("hello")) stdout.println("dict else stdout.println("dict does NOT contain hello"); it depends on what is already stored in dict dict does NOT contain hello is printed to the screen an exception is thrown dict contains hello is printed to the screen contains hello"); Question 18 (5 points) What is the order of growth of the worst case running time of the get operation for the book's BinarySearchST with n keys, when the key being searched for is not in the symbol table? O linear O logarithmic O quadratic constant O(n) O(lgn) O(n.) O(1)
Expert Answer:
Answer rating: 100% (QA)
To implement the recursive case of the contains method we need to check if the current node contains the target or if it is in the rest of the list If the current node contains the target we return tr... View the full answer
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Posted Date:
Students also viewed these programming questions
-
You are the head of Human Resources Management in a manufacturing company. The staff fall into two broad categories. Ninety percent of the factory staff are technicians. The other 10% are...
-
see below questions and provide me adjusted coding by using my coding. I share my coding and test failure message at the end. 1. BST.java 2.BSTNode.java Binary Search Tree you will be coding the...
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
ABC Client Preliminary Analytics - PBC Trial Balance December 31, 2019 Scope: Performance Materiality $210,000 and 10% 12/31/19 Balance 12/31/18 Account Class Balance Variance * Varlance Cash...
-
What ketones would be formed from the acid-catalyzed hydration of 3-heptyne?
-
In Problems 7178, s denotes the length of the arc of a circle of radius r subtended by the central angle . Find the missing quantity. Round answers to three decimal places. r = 6 meters, s = S 8...
-
What are the advantages and disadvantages to the opt-in versus the opt-out approaches to collecting personal information from the viewpoint of the customer? From the viewpoint of the organization...
-
Simuflite, a Texas aviation training company, expected to whip the competition with FasTrak, its computer-based training (CBT) curriculum for corporate pilots. Instead, the new venture sent Simuflite...
-
Comparative balance sheets for 2024 and 2023 and a statement of income for 2024 are given below for Metagrobolize Industries. Additional information from the accounting records of Metagrobolize also...
-
Joe has $16 to spend on Twinkies and Ho-Hos. Twinkies have a price of $1 per pack, and Ho-Hos have a price of $2 per pack. Use the information in these graphs to determine the number of Twinkies and...
-
Zoom is an exceptional communication tool, but does it have limits on how many people can be on a Zoom call at one time - possibly limiting the message delivery?
-
Differentiate between the centralization accounting system and decentralization accounting system
-
The 2015 quarterly prices for The Hershey Company and Packaging Corporation of America are listed below along with any dividend paid. Hershey Packaging Corporation of America Quarter P0 P1 Dividend...
-
PerfectFit Company sells shirts for men and boys. The selling price and variable costs for men's shirts are $98.00 and $69.60 respectively. The selling price and variable costs for boys' shirts are...
-
How do you analyze the CVP and BE when a company has more than one product?
-
You have just moved into your first apartment. Opening the door you notice the studio apartment you just rented is completely empty. Other than the refrigerator, dishwasher, stove, washer and dryer...
-
Can you give at least 3-4 examples of administrators' leadership behaviors that promote the intended school culture?
-
Construct a 4 x 25 design confounded in two blocks of 16 observations each. Outline the analysis of variance for this design.
-
Assume a runner runs 14 kilometers in 45 minutes and 30 seconds. Write a program that displays the average speed in miles per hour.
-
Write a program that will count the number of characters, words, and lines in a file. Words are separated by whitespace characters. The file name should be passed as a command-line argument, as shown...
-
Revise the program in Listing 21.7. If a keyword is in a comment or in a string, don?t count it. Pass the Java file name from the command line. Assume that the Java source code is correct and line...
-
Denise Young, an accountant for Chiles Corporation, has been asked to prepare an income statement that reports contribution margin. Miss Young has asked you to prepare an analysis of three months...
-
How is a present value factor determined?
-
How are interest rates and the rate of return stated?
Study smarter with the SolutionInn App