write a function: def firstEven (self, d) that returns the index of the first element of...
Fantastic news! We've located 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
Expert Answer:
Answer rating: 100% (QA)
To solve the problem in the image we can use the following Python functions Python def firstEven self d Returns the index of the first even element in ... View the full answer
Related Book For
Introduction to Algorithms
ISBN: 9780262033848
3rd edition
Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest
Posted Date:
Students also viewed these programming questions

This assignment reviews objectoriented 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...

If one movie ticket costs $13.50, how much will y tickets cost?

Gateway, Inc., and Dell Computer Corporation assemble computers and sell them over the telephone or the Internet. Access the website of either of these companies. Become familiar with the products of...

Go back to the numerical example with no factor substitution that leads to the production possibility frontier in Figure a. What is the range for the relative price of cloth such that the economy...

The pH of a 0.100 M acetic acid solution is 2.88. Calculate K a .

Lawrence owns a small candy store that sells one type of candy. His beginning inventory of candy was made up of 10,000 boxes costing $1.50 per box ($15,000), and he made the following purchases of...

There is great demand for the Molly Doll that sells for $100 and is made by the Cutesy Toy Company. In fact, the demand is so great that the company can sell every doll that it manufactures. There...

Effective financial statement analysis requires an understanding of a firms economic characteristics. The relations between various financial statement items provide evidence of many of these...

1. From an industrybased view, why does Microsoft feel threatened by Linux in China and globally?

In Problems 944, find each indefinite integral and check the result by differentiating. (1+ (1 + ex) dx

In Problems 5970, find each indefinite integral and check the result by differentiating. +3 2x + 3 dx

Estimate the expected return for each of the following companies: Company T U V W Current Dividends per Share $1.00 $0.50 $1.25 $0.25 Expected Growth Rate of Dividends 2% 3% 1% 2% Value of the Stock...

Solve the linear programming problems stated in Problem. Minimize and maximize P = 30x + 10y subject to 2x + 2y = 4 6x + 4y = 36 2x + y 10 x, y = 0

You are thinking of operating a summer camp for high school soccer players, and you want to use whatever documents will be helpful in dealing with liability issues. First, review the law of the state...

How many compounds among the following may 90. exhibit tautomerism? CH NO; 'N. Ph CH = CHOH Ph Ph (1) 1 (2) 2 3) 3 4) 4

Digital Fruit is financed solely by common stock and has outstanding 25 million shares with a market price of $10 a share. It now announces that it intends to issue $160 million of debt and to use...

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.

What do the collocation and finite element methods have in common, and how do they differ?

Set up the normal equations and derive expressions for b 0 and b 1 in a linear model.

How can the parameters in vector b be determined using the matrix form?
Question Categories