
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Python
Using recursion only
No loops, no list method
Using such type()function, len()function, indexing, slicing
The function must return a set with all items in the sets, if no, return empty set
def getAllSetElem(lst):
![>>> s = getAllSetElem([])
set()
s = getAllSetElem(['five', [[[(1,2, 3), {'Amber', 'Erin'}]]], {'Annika', 'Andre'}, 'Python', 3.1])
>>> S
{'Amber', 'Annika', 'Erin', 'Andre'}
>>> type(s)](https://content.bartleby.com/qna-images/question/67061b77-5467-4182-94fd-55ec16076bb1/02eee1cf-7e42-4367-abb2-d0799ade8345/1qiwf1k_thumbnail.png)
Transcribed Image Text:>>> s = getAllSetElem([])
set()
s = getAllSetElem(['five', [[[(1,2, 3), {'Amber', 'Erin'}]]], {'Annika', 'Andre'}, 'Python', 3.1])
>>> S
{'Amber', 'Annika', 'Erin', 'Andre'}
>>> type(s)
![<class 'set'>
>>> s = getAllSetElem([1.5, [[[{1,2,3}, {'Amber', 'Erin'}]]], {'Annika', 'Andre'}, 'Python', {1,2,3}])
>>> S
{1,2,3, 'Erin', 'Amber', 'Andre', 'Annika'}
>>> S =
getAllSetElem([{1.1, 2.2}, [[[{1, 2, 3}, {'Amber', 'Erin'}]]], {'Annika', 'Andre'}, 'Python', {1,
2, 3}])
>>> S
{1.1,2.2, 1, 2, 3, 'Erin', 'Amber', 'Andre', 'Annika'}
>> s = getAllSetElem([[[[{1.1,2.2}]]], [[[{1,2, 3}, {'Amber', 'Erin'}]]], {'Annika', 'Andre'}, 'Python',
{1,2,3}])
>>> S
{1.1,2.2, 1, 2, 3, 'Erin', 'Amber', 'Andre', 'Annika'}
>>> s = getAllSetElem(['five', [[[(1,2, 3), 'Amber', 'Erin']]], 'Annika', 'Andre', 'Python'])
>>> S
set()
>>>](https://content.bartleby.com/qna-images/question/67061b77-5467-4182-94fd-55ec16076bb1/02eee1cf-7e42-4367-abb2-d0799ade8345/yd3otmk_thumbnail.png)
Transcribed Image Text:<class 'set'>
>>> s = getAllSetElem([1.5, [[[{1,2,3}, {'Amber', 'Erin'}]]], {'Annika', 'Andre'}, 'Python', {1,2,3}])
>>> S
{1,2,3, 'Erin', 'Amber', 'Andre', 'Annika'}
>>> S =
getAllSetElem([{1.1, 2.2}, [[[{1, 2, 3}, {'Amber', 'Erin'}]]], {'Annika', 'Andre'}, 'Python', {1,
2, 3}])
>>> S
{1.1,2.2, 1, 2, 3, 'Erin', 'Amber', 'Andre', 'Annika'}
>> s = getAllSetElem([[[[{1.1,2.2}]]], [[[{1,2, 3}, {'Amber', 'Erin'}]]], {'Annika', 'Andre'}, 'Python',
{1,2,3}])
>>> S
{1.1,2.2, 1, 2, 3, 'Erin', 'Amber', 'Andre', 'Annika'}
>>> s = getAllSetElem(['five', [[[(1,2, 3), 'Amber', 'Erin']]], 'Annika', 'Andre', 'Python'])
>>> S
set()
>>>
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

Knowledge Booster
Similar questions
- (a) Write a method public static void insert(int[] a, int n, int x) that inserts x in order among the first n elements of a, assuming these elements are arranged in ascending order. Do NOT use arraylists. x is the last element in a. n does not include x. (b) Using the insert method from Part (a), write a recursive implementation of Insertion Sort.arrow_forwardJava language NOTE THAT WE ARE USING **LINKED LISTS** SEE PICTURES FOR ALL INFORMATION Solve method public boolean inSort(double elt) { //code goes here } please and thank you!!!!arrow_forwardmust foollow rules must be in pythonn return largestt integgerr fromm inputedd listttarrow_forward
- **Cenaage Python** Question: A sequential search of a sorted list can halt when the target is less than a given element in the list. Modify the program to stop when the target becomes less than the current value being compared. In a sorted list, this would indicate that the target is not in the list and searching the remaining values is unnecessary. CODE: def sequentialSearch(target, lyst): """Returns the position of the target item if found, or -1 otherwise. The lyst is assumed to be sorted in ascending order.""" position = 0 while position < len(lyst): if target == lyst[position]: return position position += 1 return -1 def main(): """Tests with three lists.""" print(sequentialSearch(3, [0, 1, 2, 3, 4])) print(sequentialSearch(3, [0, 1, 2])) # Should stop at second position. print(sequentialSearch(3, [0, 4, 5, 6])) if __name__ == "__main__": main()arrow_forwardJava - This project will allow you to compare & contrast different 4 sorting techniques, the last of which will be up to you to select. You will implement the following: Bubble Sort (pair-wise) Bubble Sort (list-wise) [This is the selection sort] Merge Sort Your choice (candidates are the heap, quick, shell, cocktail, bucket, or radix sorts) [These will require independent research) General rules: Structures can be static or dynamic You are not allowed to use built in methods that are direct or indirect requirements for this project – You cannot use ANY built in sorting functions - I/O (System.in/out *) are ok. All compare/swap/move methods must be your own. (You can use string compares) Your program will be sorting names – you need at least 100 unique names (you can use the 50 given in project #3) – read them into the program in a random fashion (i.e. not in any kind of alpha order). *The more names you have, the easier it is to see trends in speed. All sorts will be from…arrow_forwardQuick Sort We choose an element from the list, called the pivot. We'll use it to divide the list into two sub-lists. We reorder all the elements around the pivot The ones with smaller value are placed before it All the elements greater than the pivot after it. After this step, the pivot is in its final position. This is the important partition step. We apply the above steps recursively to both sub-lists on the left and right of the pivot. Quick Sort (Example) Consider the following array Arr[] = {5, 9, 4, 6, 5, 3} Let's suppose we pick 5 as the pivot for simplicity We'll first put all elements less than 5 in the first position of the array: {3, 4, 5, 6, 5, 9} We'll then repeat it for the left sub-array {3,4}, taking 3 as the pivot There are no elements less than 3 We apply quicksort on the sub-array in the right of the pivot, i.e. {4} This sub-array consists of only one sorted element We continue with the right part of the original array, {6, 5, 9} until we get the final ordered…arrow_forward
- IN JAVA Write recursive code and iterative code for binary search.arrow_forwardPython’s list method sort includes the keyword argument reverse, whose defaultvalue is False. The programmer can override this value to sort a list in descendingorder. Modify the selectionSort function so that it allowsthe programmer to supply this additional argument to redirect the sort. selectionSort function: def selectionSort(lyst, profiler):i = 0 while i < len(lyst) - 1:minIndex = ij = i + 1 while j < len(lyst):profiler.comparison() # Countif lyst[j] < lyst[minIndex]:minIndex = jj += 1 if minIndex != i:swap(lyst, minIndex, i, profiler)i += 1 def swap(lyst, i, j, profiler):"""Exchanges the elements at positions i and j."""profiler.exchange() # Counttemp = lyst[i]lyst[i] = lyst[j]lyst[j] = temp Use this template in Python to modify the function above: def selection_sort(input_list, reverse):sorted_list = []#TODO: Your work here# Return sorted_listreturn sorted_listif __name__ == "__main__":my_list = [1, 2, 3, 4, 5]print(selection_sort(my_list, True)) # Correct Output: [5,…arrow_forwardin java pls and thank you!arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY

Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON

Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education

Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY