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:
![write a function: def firstEven (self, d) that returns the index of the first element of the linked list that](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2023/09/6513d77ff0a2a_1695799159586.jpg)
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
-
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...
-
A DI has the following balance sheet (in millions). The DIs securities portfolio includes $16 million in T-bills and $10 million in GNMA securities. The DI has a $20 million line of credit to borrow...
-
Using the video " Agile and the Seven Deadly Sins of Project Managing" answer the two questions below 1. Explain how you can estimate the most likely end date, pessimistic and optimist end date of an...
-
What are some consumer-oriented pricing tactics?
-
A heat-treated steel shaft is to be designed to support the spur gear and the overhanging worm shown in the figure. A bearing at A takes pure radial load. The bearing at B takes the worm-thrust load...
-
Airport Application Project : Spring 2020 CISP360 in c++ task is to design, develop and test and a software product for the AA Airline that runs small aircraft out of Los Angeles Airport. It is a...
-
Your client is a city with a growing urban agriculture movement. The city wants to know about the regulation of urban agriculture, particularly micro livestock ordinances. What is a 2015 journal...
-
Which of the following is not a component of return on equity (ROE)? Select one: a. Equity/sales b. Net Income/sales c. Total assets/equity d. Sales/total assets e. Net Profit Margin 26. Assume an...
-
1) Factor the following Expressions (Write your factors only, don't show your work) a) 2x - 32 = c) 3x-2x-8= b) 2x-6x-8=
-
Bloomfield Inc. manufactures widgets. A major piece of equipment used to make the widget is nearing the end of its useful life. The company is trying to decide whether they should lease new equipment...
-
1. a. What is network management? Illustrate network management functional flowchart. [2.5] b. What encoding and decoding mechanisms are used in fast Ethernet and gigabit Ethernet? What is meant by...
-
Project Data: Sam Parker owns and operates a consulting firm called Business Solutions. The business began operating in October 202X. Transactions for October and November 202X have been recorded and...
-
3. Use Hooke's law to predict which one out of each pair vibrates at a higher wavenumber. Explain your answer. (7 points) a) C-H and C-D* b) C-C and C=C where: 1 k v = 2, v=wavenumber c = velocity of...
-
compound instruments Transformational Airlines issued several convertible bonds on January 1, 2021. Each bond is convertible into a specified number of common shares. The bonds pay interest on...
-
What did Lennox gain by integrating their WMS, TMS, and labor management systems?
-
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 are the materiality constraint and the conservatism constraint? AppendixLO1
-
What are the major sections in a classified balance sheet? AppendixLO1
-
What qualitative characteristics make accounting information useful? AppendixLO1
![Mobile App Logo](https://dsd5zvtm8ll6.cloudfront.net/includes/images/mobile/finalLogo.png)
Study smarter with the SolutionInn App