Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
The following code implements Newton's
n = 17 # we want the square root of 17 for example
g = 4 # our guess is 4 initially
error = 0.0000000001 # we want to stop when we are this close
while abs(n - (g**2)) > error:
g = g - ((g**2 - n)/(2 * g))
# g holds the square root of n at this point
Implement this algorithm in a function sqRoot(n), that returns the square root using recursion.
Assume that the function will be called with positive numbers only.
Note: Your initial guess cannot be zero!
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 2 steps with 1 images
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
- Python Algorithm Question (similar to celebrity Python problem). Having trouble implementing the algorithm. Here's the question: Let’s say you’re going to invite some people to a party. You’re considering n friends, but you knowthat they will only have a good time if each of them knows at least k others at the party. (Assume that if A knows B, then B automatically knows A.) Solve your problem by designing an algorithm for finding the largest possible subset of your friends where everyone knows at least k of the others, if such a subset exists. To help you get started I’ve made a graph of “my friends”: G={'Rachel':['Ross','Monica'], 'Ross':['Rachel','Monica'], 'Monica':['Rachel','Ross'], 'Jon Snow':['Daenerys','Sansa','Arya'], 'Daenerys':['Jon Snow','Sansa','Arya','Khal Drogo'], 'Sansa':['Jon Snow','Daenerys','Arya'], 'Arya':['Jon Snow','Daenerys','Sansa'], 'Khal Drogo':['Daenerys'], 'Cersei':['Jaime'], 'Jaime':['Cersei'], 'Bart':['Milhouse'], 'Milhouse':['Bart','Lisa'],…arrow_forwardHelp me pleasearrow_forward1. Design an algorithm to find the weighted sum of four test scores (https://en.wikipedia.org/wiki/Weight_function). Assume that the weights have been accurately calculated in advance such that their sum equals one. Your algorithm must-read in the four test scores and four corresponding weights in the following order: score1 weight1 score2 weight2 score3 weight3 score4 weight4 Write your algorithm such that it can be run with any set of data values. However, you can test your algorithm on the following sample data to verify that the result is 70: 90 0.10 80 0.20 70 0.30 60 0.40 2. Write an algorithm that prompts the user for the radius, in inches, and price of a pizza, and then reads in those values. Finally, have the algorithm compute and output the pizza’s cost per square inch. 3. Sports exercise advisor algorithm. In this algorithm you will start out with a temperature value in Celsius, so you do not need to ask the user for it. First, convert the temperature to Fahrenheit.…arrow_forward
- In python, The function decodeFromAscii takes a list L of integers in the range 32 through 126. Each item in L is an ASCII code representing a single printable character. The function accumulates the string of characters represented by the list of ASCII codes and returns that string. For example, decodeFromAscii([78, 105, 99, 101, 33]) returns "Nice!" because N is chr(78), i is chr(105), c is chr(99), etc. Note: ASCII was created in the 1960's so programmers could have a standard encoding for common keyboard characters as numbers. It was later expanded to create Unicode so that characters from languages other than English, mathematical symbols, and many other symbols could also be represented by numerical codes. For example: Test Result print(decodeFromAscii([36, 49, 44, 48, 48, 48])) $1,000 print(decodeFromAscii([115, 110, 111, 119])) snowarrow_forwardt for several problems you will modify some provided Python code to implement algorithms to solve the same instance of the knapsack problem. After implementing all of the code and solving the problem, you must provide a single table of all results similar to the following: Table 1: Example of results summary (numbers are not realistic) Algorithm Iterations Items Selected Weight Objective Local Search (Best Improvement) 3102 49 97 117 Local Search with Random Restarts (k = 100) Local Search with Random walk (p = 0.25) 9510 121 21 147 2102 87 32 184 etc. Knapsack Problem Definition Given n different items, where each item i has an assigned value (v.) and weight (w), select a combination of the items to maximize the total value without exceeding the weight limitations, W, of the knapsack. IMPORTANT!: When generating random problem instance set you must use the code provided and values: n = 150; max weight of 2500; and, use a seed value (for the random number generator) of 51132023.arrow_forwardplease help with the python problem, thank youarrow_forward
- 1. Write a recursive method expFive(n) to compute y=5^n. For instance, if n is 0, y is 1. If n is 3, then y is 125. If n is 4, then y is 625. The recursive method cannot have loops. Then write a testing program to call the recursive method. If you run your program, the results should look like this: > run RecExpTest Enter a number: 3 125 >run RecExpTest Enter a number: 3125 2. For two integers m and n, their GCD(Greatest Common Divisor) can be computed by a recursive function. Write a recursive method gcd(m,n) to find their Greatest Common Divisor. Once m is 0, the function returns n. Once n is 0, the function returns m. If neither is 0, the function can recursively calculate the Greatest Common Divisor with two smaller parameters: One is n, the second one is m mod n. Although there are other approaches to calculate Greatest Common Divisor, please follow the instructions in this question, otherwise you will not get the credit. Meaning your code needs to follow the given algorithm. Then…arrow_forward1. Both mergesort and quicksort uses divide and conquer paradigm to sort unsorted list. (a) Imagine you want to write the quicksort algorithm to sort an array into non-increasing order. Write down the partition algorithm that is used in the divide phase in the quicksort algorithm. Show that the time complexity of this algorithm is 0(n). (b) Identify the worst case situation in the naive quicksort algorithm and show that in the worst case situation its time complexity is O(n2)arrow_forwardUsing recursion, write a function sum that takes a single argument n and computes the sum of all integers between 0 and n inclusive. Do not write this function using a while or for loop. Assume n is non-negative. def sum(n): """Using recursion, computes the sum of all integers between 1 and n, inclusive. Assume n is positive. >>> sum(1) 1 >>> sum(5) # 1 + 2 + 3+ 4+ 5 15 "*** YOUR CODE HERE ***"arrow_forward
- irses/135852/quizzes/807844/take/questions/13768818 inal Exam A+ arted: Jun 17 at 10:03pm Quiz Instructions Show Instructions D 00 1 pts Question 5 Let p, q, and r be propositional variables. After simplification using equivalence laws, p^ (p v ¬¬(r⇒ q)) becomes ____ Op ^ (r+q) OP OT Op ^ q < Previous Next ▸ Il app.honorlock.com is sharing your screen. Stop sharing Hide Your Webcam JUN tv ♫ NA 30 17 F5 F6 80 F3 F4 F7 (((( DII F8 8£ Narrow_forwardGiven a positive integer 'n', find and return the minimum number of steps that 'n' has to take to get reduced to 1. You can perform any one of the following 3 steps:1.) Subtract 1 from it. (n = n - 1) ,2.) If its divisible by 2, divide by 2.( if n % 2 == 0, then n = n / 2 ) ,3.) If its divisible by 3, divide by 3. (if n % 3 == 0, then n = n / 3 ). Write brute-force recursive solution for this.Input format :The first and the only line of input contains an integer value, 'n'.Output format :Print the minimum number of steps.Constraints :1 <= n <= 200 Time Limit: 1 secSample Input 1 :4Sample Output 1 :2 Explanation of Sample Output 1 :For n = 4Step 1 : n = 4 / 2 = 2Step 2 : n = 2 / 2 = 1 Sample Input 2 :7Sample Output 2 :3Explanation of Sample Output 2 :For n = 7Step 1 : n = 7 - 1 = 6Step 2 : n = 6 / 3 = 2 Step 3 : n = 2 / 2 = 1 SolutionDp///.arrow_forwardPython please I need help with this problem from zybooksarrow_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