Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Do in PYTHON Language this Question Instructions: All programs are to be written in Python. Functions must be documented with proper comments stating the purpose

image text in transcribed

image text in transcribed

image text in transcribed

Do in PYTHON Language this Question

Instructions: All programs are to be written in Python. Functions must be documented with proper comments stating the purpose of the function the types and meanings of the input arguments any conditions on the input arguments (input specifications) the type and meaning of the return values conditions on the outputs (output specifications) Within the program you MUST document the following: Representation invariant that your function maintains stated (at least infor- mally) as a comment, and a check that this is maintained. For example, if the input arguments are assumed to contain no duplicates, there should be no duplicates in the output. Loop invariant for each loop, even if informally stated, which give the intuition about why the program is correct. Highlight (via a comment) a decreasing measure in each while loop which guarantees termination of the loop. Time complexity of the function, with at least an informal justification. Representative test data on which you have run the function. Use appropriate notation in your arguments/explanations. You will get 0 for not writing appropriate explanations. You will be asked to explain these during the demo. Next assume that the elements are drawn from a totally ordered set, e.g. integers or strings. Assume we represent sets as ordered lists of elements, according to the total order on elements of that type. Implement the following functions to give more efficient implementation (which can still be in the worst case be as inefficient). 1. A function emptyset(), which returns the representation of an empty set. 2. A boolean function isEmpty(S), returning True if S is empty and False otherwise. 3. A function member(S, e) where s is a set of elements of some type T which represented as a list and e is an element of that type. If e is a member of S, member should return True and otherwise should return False. 4. A function singleton(x), which returns the representation of a singleton set consisting of only the element x. 5. A function isSubset(P,Q), which given representations of two sets (of the same type) P and Q, returns True if P is a subset of Q and False otherwise. 6. A function setEqual(P,Q), which given representations of two sets of the same type) P and Q, returns True if P and Q have the same elements, and False otherwise. 7. A function union(P,Q), where P, Q are (representations of) two sets (of same type T), which returns the representation of the set PU Q. 8. A function intersection(P, Q) where P, Q are (representations of) two sets (of same type T), which returns the representation of the set PnQ. 9. A function cartesian(P,Q), where P, Q are (representations of) two sets (not necessarily of same type), which returns the representation of the set PxQ. 10. A function power(P), where P is (the representation of) some set, which returns the representation of the set of all subsets of P. Check that the Cartesian product and power set operations satisfy the represen- tational invariant ( i.e., check whether the Cartesian product of two sets can be represented as an ordered list over AX B, and indicate what the ordering relation is. Similarly for the power set of a given set. Again, all the expected documentation should be given

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Visual Basic 4 Ole Database And Controls Superbible

Authors: Michael Hatmaker, C. Woody Butler, Ibrahim Malluf, Bill Potter

1st Edition

1571690077, 978-1571690074

More Books

Students also viewed these Databases questions