write a function: def firstEven (self, d) that returns the index of the first element of...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
write a function: def firstEven (self, d) that returns the index of the first element of the linked list that is even. If there are no even elements in the list, the function should return -1. For example, if 1s is the list [4,5,6,7,8] then ls.firstEven() should return 0. Write a function: def decide (self, f) that takes as input a function f that returns booleans. Your function should return a pair (1sT, 1sF) of two new linked lists, where 1sT contains all the elements of the linked list (i.e. of self) for which f returns True when applied on them, and 1sF contains all remaining elements. The order of the elements in the two lists should be the same as in self. The list self should remain unchanged. For example, if isOdd is the function that returns True when applied to odd numbers, and False otherwise, and 1s is the list [4,5,2,5,4,7,6,7,8] then ls.decide (isOdd) should return the pair of linked lists ([5,5,7,7], [4,2,4,6,8]). For full marks, your solution should run in time linear in the length of the linked list. Ac Gc write a function: def firstEven (self, d) that returns the index of the first element of the linked list that is even. If there are no even elements in the list, the function should return -1. For example, if 1s is the list [4,5,6,7,8] then ls.firstEven() should return 0. Write a function: def decide (self, f) that takes as input a function f that returns booleans. Your function should return a pair (1sT, 1sF) of two new linked lists, where 1sT contains all the elements of the linked list (i.e. of self) for which f returns True when applied on them, and 1sF contains all remaining elements. The order of the elements in the two lists should be the same as in self. The list self should remain unchanged. For example, if isOdd is the function that returns True when applied to odd numbers, and False otherwise, and 1s is the list [4,5,2,5,4,7,6,7,8] then ls.decide (isOdd) should return the pair of linked lists ([5,5,7,7], [4,2,4,6,8]). For full marks, your solution should run in time linear in the length of the linked list. Ac Gc
Expert Answer:
Answer rating: 100% (QA)
To solve the problem in the image we can use the following Python functions Python def firstEvenself d Returns the index of the first even element in ... View the full answer
Related Book For
Introduction to Algorithms
ISBN: 978-0262033848
3rd edition
Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest
Posted Date:
Students also viewed these programming questions
-
Tom the tech used to love building computers and game boxes in his parent's garage. Now that he has a job in tech, his boss tells him which projects to work on and enforces company rules that Tom...
-
This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of an array of objects as a class data...
-
Which statement is correct? O GAAP specifies that property and equipment assets be classified by function between the following headings: Manufacturing, Marketing, Transportation. GAAP allows...
-
Discuss why the length of an OH bond obtained from X-ray diffraction experiments averages 85 pm whereas that obtained in neutron diffraction experiments averages 96 pm. Would you expect to see...
-
In a new high-efficiency furnace, natural gas, assumed to be 90% methane and 10% ethane (by volume) and 110% theoretical air each enter at 25C, 100 kPa, and the products (assumed to be 100%...
-
Identify weather the following series converge or diverge? Inn n 7n+3 n = 1
-
Under what circumstances should a healthcare professional self-insure?
-
Consider a distillation column for separating ethanol from water at 1 atm. The following specifications are set: Feed: 10 mol% ethanol (bubble-point liquid) Bottoms: 1 mol% ethanol Distillate: 80...
-
A firm's most recent dividend on common stock was $5.00, and the expected growth rate is 8.00%. If you require a rate of return of 15.00%, what is the highest price you should be willing to pay for...
-
The Bulgarian lev is currently pegged to the euro. Using ISLM diagrams for Home (Bulgarian lev) and Foreign (Eurozone), illustrate how each of the following scenarios affects the Bulgarian lev....
-
Harry just bought a new Jeep Cherokee four-wheel drive for his lumber business. The price of the vehicle was $35,000 of which he made a $5,000 down payment and took out an amortized loan for the...
-
Explain what information you would want in order to interpret some financial ratios you had calculated.
-
State two tactics that should be used by a productive focus group moderator.
-
What are the two ways you can format a research objective? Give an example of each.
-
How might different settings for a focus group affect the overall quality of the research?
-
Explain what a riskless hedge is and how the riskless hedge concept is used in the Black-Scholes OPM.
-
R is inversely proportional to the square of T. When R = 4, T = 8. Find the value of R when T = 11.
-
Calculate Total Contribution Margin for the same items. Total Revenue Total Variable Costs Total Contribution Margin $50.00 a. $116.00 $329.70 b. $275.00 $14,796.00 $7,440.00 c. $40,931.25 d....
-
List all subgroups of 9 and of * 13 .
-
Suppose that we are given a function f . n n and an initial value x 0 n . Define x i = f (x i - 1 ) for i = 1, 2, .... Let t and u > 0 be the smallest values such that x t + i = x t + u + i for...
-
Show that if A is a nonsingular, symmetric, n n matrix, then A 1 is symmetric. Show that if B is an arbitrary m n matrix, then the m m matrix given by the product BAB T is symmetric.
-
Apple stock is selling for \($120\) per share. Call options with a \($117\) exercise price are priced at \($12.\) What is the intrinsic value of the option, and what is the time value?
-
Refer to Problem 14.9. What would the loss of the seller of the put option be if, at expiration, XLB is trading at \($20?\) What would the profit of the seller be if, at expiration, XLB is trading at...
-
Ibrahim bought 200 shares of a stock trading in the Abu Dhabi Securities Exchange at AED 12 (United Arab Emirates dirham) per share. Over time, the price of the stock increased to AED 18 per share....
Study smarter with the SolutionInn App