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)
Step 1 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 re... 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
-
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...
-
Suppose a firm pays total dividends of $750,000 out of net income of $5 million. What would the firm's payout ratio be?
-
American Express has established something it calls Open Forum to allow entrepreneurs and small business owners to communicate with one another and share ideas. Visit the Open Forum Web site and...
-
Discuss the themes, theory, and/or phenomenon that would be anticipated to emerge as a result of the examination. Develop a hypothetical research scenario that would necessitate the use of the Action...
-
At the beginning of 2016, the Redd Company had the following balances in its accounts: Cash ........ $ 6,900 Inventory ....... 15,000 Land ......... 7,000 Common stock .... 15,000 Retained earnings...
-
What are some practical advantages to using a star schema data model over a relational model in healthcare?
-
Jeremiah Restoration Company completed the following selected transactions during January: Jan. 3. Store supplies, $470. 7. Express charges on merchandise sold, $s5 (Delivery Expense). 9. Office...
-
Determine the temperatures at the nine nodes. All nodes are evenly spaced. Generate the finite-difference equations at each node. Use Eqn. 4.29. 50C T T 300C 100C T; 3 T 9 200C
-
YostCom, Inc. just paid a dividend yesterday of $2.10 on its common stock, which has a beta of 1.4, with 8 million shares outstanding. Common dividends are expected to grow at a relatively constant 5...
-
Diane wants to receive annuity payments of $2500 at the beginning of each quarter for eight years. The annuity term is to start four years from now and interest is 6% compounded quarterly. a) How...
-
Which of the five primary components of national security is MOST focused on protecting the financial markets, such as banking and trading? economic security political security military security ...
-
The Northern Command oversees which aspect of National Security? defending the continental United States and coordinating with Canada and Mexico defending US interests in Europe, especially in...
-
Xiofang has just been appointed as a diplomat to Poland for the United States. Xiofang's duties as a diplomat include relocating to Poland to more easily meet with other diplomats and Polish...
-
1..math function is same to math operations * Yes No 2..in order to transpose matrix A we write A^-1 * False true 3..clear command :clear variable and functions * true False
-
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...
-
A 17 g audio compact disk has a diameter of 12 cm. The disk spins under a laser that reads encoded data. The first track to be read is 2.3 cm from the axis; as the disk plays, the laser scans tracks...
-
A spin bike is an indoor bike that is designed to duplicate the feeling of regular road cycling. A typical spin bike has a very heavy flywheel. A friction pad or other brake provides damping that...
-
A trap-jaw ant has mandibles that can snap shut with some force, as you might expect from its name. The formidable snap is good for more than capturing prey. When an ant snaps its jaws against the...
Study smarter with the SolutionInn App