Sciprog DS Lab
dev
  • Home
    • Timetable and lecture rooms
    • Lab slides
    • News
    • Office hours
    • References
      • Part A References
      • Part B References page
      • Editors
    • Exams
      • Past exams
      • Exam modalities
      • Expectations
      • Grading
      • Exams FAQ
      • Exams How To
        • How to edit and run
        • Debugging
    • Acknowledgements
  • Past Exams
    • Data science
      • Exam - Wed 08, Jun 2022
        • Download exercises and solutions
      • A. Trans-Atlantic Slave Trade
        • A1 read_trade
        • A2 Deportation
        • A3 The time to stop
        • B1.1 Theory
        • B1.2 BFS
        • B2 BinaryTree is_heap_stack
        • B3 GenericTree rightmost
      • Exam - Wed 09, Feb 2022
        • Download exercises and solutions
        • Part A - Zoom surveillance
        • Part B
        • B1 Theory
        • B2 flatv
        • B3 univalued_rec
      • Exam - Wed 12, Jan 2022
        • Download exercises and solutions
        • Part A - Prezzario
        • A1 extract_bounds
        • A2 extract_product
        • A3 plot_product
        • Part B
        • B1 Theory
        • B1.1
        • B1.2
        • B2 find_couple
        • B3 swap
      • Midterm B- Thu 16, Dec 2021
        • Download exercises and solutions
        • B1 Theory
        • B1.1 complexity
        • B1.2 postfix
        • B2 norep
        • B3 family_sum_rec
      • Exam - Fri 12, Nov 2021
        • Download exercises and solutions
        • Part A - Mexican Drug Wars
        • Attacks during elections
        • load_mexico
        • show_attacks
        • cartels
      • Midterm sim - Fri 05, Nov 2021
        • Download exercises and solutions
        • Part A - Terence Hill and Bud Spencer movies
        • The files
        • load
        • save_table
        • show_graph
      • Exam - Mon 06, Sep 2021
        • Download exercises and solutions
        • Part A - I CHING Divination
        • A1 load_db
        • A2 divine
        • A3 plot_divination
        • Part B
        • B1 Theory
        • B2 Train race
        • B3 linked algebra
      • Exam - Mon 12, Jul 2021
        • Download exercises and solutions
        • Part A - DOOM
        • A1 parse_map
        • A2 simulate
        • A3 plot_map
        • Part B
        • B1 Theory
        • B2 PyraStack
        • B3 union_rec
      • Exam - Fri 11, Jun 2021
        • Download exercises and solutions
        • Part A - Trans-Atlantic Slave Trade
        • A1 read_trade
        • A2 Deportation
        • A3 The time to stop
        • Part B
        • B1 Theory
        • B2 - is_heap_stack
        • B3 - sepel
      • Exam - Wed 10, Feb 2021
        • Download exercises and solutions
        • Part A - Wikispeedia
        • A1 filter_back
        • A2 load_db
        • A3 calc_stats
        • A4 plot_network
        • Part B
        • B1.1 Theory - Complexity
        • B1.2 Theory - BST
        • B2 Reconstruct BinaryTree
        • B3 Marvelous
      • Exam - Tue 14, Jan 2021
        • Download exercises and solutions
        • Part A - Witchcraft
        • A1 parse_bool_cols
        • A2 fix_date
        • A3 parse_db
        • A4 plot_cases
        • Part B
        • B1.1 Theory - Complexity
        • B1.2 Theory - Graph
        • B2 Bank
        • B2.1 constructor, log and pos
        • B2.2 revert
        • B2.3 max_interval
      • Midterm B - Wed 16, Dec 2020
        • Download exercises and solutions
        • Introduction
        • B1 Theory
        • B2 LinkedList pivot
        • B3 swap_stack
        • B4 family_sum_rec
      • Midterm A - Fri 06, Nov 2020
        • Download exercises and solutions
        • Music Sequencer
        • 1. parse_melody
        • 2. parse_tunes
        • 3. sequencer
        • 4. plot_tune
      • Midterm Sim - Mon 02, Nov 2020
        • Download exercises and solutions
        • Part A - Galactic Love
        • parse_stars
        • plot_stars 1
        • plot_stars 2 - new_center
        • parse_zodiac
        • plot_love
      • Exam - Mon 24, Aug 2020
        • Download exercises and solutions
        • Introduction
        • Part A - Prezzario
        • A1 extract_bounds
        • A2 extract_product
        • A3 plot_product
        • Part B
        • B1 Theory
        • B2 couple_sort
        • B3 schedule_rec
      • Exam - Fri 17, Jul 2020
        • Download exercises and solutions
        • Introduction
        • Part A - NACE codes
        • A1 Extracting codes
        • A1.1 is_nace
        • A1.2 extract_codes
        • A2 build_db
        • A3 plot
        • Part B
        • B2 - OfficeQueue
        • B2.1 - time_to_service
        • B2.2 split
      • Exam - Tue 16, Jun 2020
        • Download exercises and solutions
        • Introduction
        • Part A - Zoom surveillance
        • Part B
        • B1 Theory
        • B2 - LinkedList slice
        • B3 BinaryTree prune_rec
      • Exam - Mon 10, Feb 2020
        • Download exercises and solutions
        • Introduction
        • Part A - Wordnet
        • A1 parse_db
        • A2 to_adj
        • A.3 hist
        • Part B
        • B1 Theory
        • B2 ItalianQueue v2
        • B2.1 enqueue
        • B2.2 dequeue
      • Exam - Thu 23, Jan 2020
        • Download exercises and solution
        • Introduction
        • Part A
        • Metamath
        • A.1 Metamath db
        • A.2 Metamath proof
        • A.3 Metamath top statements
        • Part B
        • B1 Theory
        • B2 plus_one
        • B3 add_row
      • Midterm B - Fri 20, Dec 2019
        • Download exercises and solution
        • Introduction
        • Part B
        • B1 Theory
        • B2 LinkedList
        • B2.1 rotate
        • B2.2 rotaten
        • B3 Binary trees
        • B3.1 sum_leaves_rec
        • B3.2 leaves_stack
      • Midterm - Thu 07, Nov 2019
        • Download exercises and solution
        • Introduction
        • Part A - Town events
        • A.1 leap_year
        • A.2 full_date
        • A.3 partial_date
        • A.4 parse_dates_and
        • A.5 Fake news generator
      • Midterm sim - Tue 31, October 2019
        • Introduction
        • Part A - EURES Job Offers
        • MOVED TO en.softpython.org/pandas/eures-jobs-sol.html
      • Exam - Mon 26, Aug 2019
        • Download exercises and solution
        • Introduction
        • Part A - University of Trento staff
        • Part B
        • B1 Theory
        • B2 Backpack
        • B.3 Concert
      • Exam - Tue 02, July 2019
        • Download exercises and solution
        • Introduction
        • Part A
        • A1 Botteghe storiche
        • A2 dump
        • Part B
        • B1 Theory
        • B2 Linked List sorting
        • B3 Stacktris
      • Exam - Mon 10, Jun 2019
        • Download exercises and solution
        • Introduction
        • Part A
        • A1 ITEA real estate
        • A2 Air quality
        • Part B
        • B1 Theory
        • B2 WStack
        • B3 GenericTree
        • B3.1 is_triangle
        • B3.2 has_triangle
      • Exam - Wed 13, Feb 2019
        • Download exercises and solution
        • Introduction
        • Part A - Bus network visualization
        • Part B
        • B.1 Theory
        • B2 Company queues
        • B3 GenericTree
        • B3.1 fill_left
        • B3.2 follow
      • Exam - Wed 23, Jan 2019
        • Download exercises and solution
        • Part A
        • A.1 table_to_adj
        • A.2 bus stops
        • Part B
        • B.1 Theory
        • B.2 Linked List flatv
        • B.3 Generic Tree rightmost
      • Midterm - Thu 10, Jan 2019
        • Download exercises and solution
        • Introduction
        • B1 Theory
        • B2 Gaps linked list
        • B3 Tasks stack
        • B4 Exits graph
      • Midterm - Fri 16 Nov 2018
        • Download exercises and solution
        • Introduction
        • A2 surjective
      • Midterm Sim - Tue 13, Nov 2018
        • Download exercises and solution
        • Introduction
        • 1. matrices
        • 2. phones
    • 2017-18 (QCB)
    • 2016-17 (QCB)
  • Slides 2021/22
    • Part A
    • Lab A.1
      • Links
    • Lab A.2
    • Lab A.3
    • Lab A.4
      • (sets)
      • Dictionaries
      • Conditionals
      • only for the pros
    • Lab A.5
      • In class:
      • At home:
    • Lab A.6
      • In class:
      • At home:
    • Lab A.7
      • In class:
    • Lab A.8
      • In class:
      • At home:
    • Lab A.9
      • Looking at the midterm
      • In class:
      • At home:
    • Lab A.10
      • In class:
      • At home:
    • Lab A.11
      • Looking at the midterm
      • In class:
      • At home:
    • Lab B.1
    • Lab B.2
      • OOP
      • Indexing
    • Lab B.3
    • Lab B.4
    • Lab B.5
    • Lab B.6
    • Lab B.7
    • Lab B.8
    • Lab B.9
  • Commandments
    • MOVED TO https://en.softpython.org/commandments.html
  • Part A
    • Installation
      • Visual Studio Code
      • The debugger
      • VS Code - collaborative coding
      • VS Code - Sharing test runs
    • Python basics
      • MOVED TO en.softpython.org/basics/basics-sol.html
    • Strings
      • MOVED TO https://en.softpython.org/#strings
    • Lists
      • MOVED TO https://en.softpython.org/#lists
    • Tuples
      • MOVED TO https://en.softpython.org/tuples/tuples-sol.html
    • Sets
      • MOVED TO https://en.softpython.org/sets/sets1-sol.html
    • Dictionaries
      • MOVED TO https://en.softpython.org/#dictionaries
    • Control flow
      • MOVED TO https://en.softpython.org/#control-flow
    • Functions
      • Download exercises zip
      • Introduction
        • What to do
        • What is a function ?
      • Namespace and variable scope
      • Argument passing
        • Positional arguments
        • Passing arguments by keyword
        • Specifying default values
      • Simple exercises
        • sum2
        • comparep
        • comparer
        • even
        • gre
        • is_vocal
        • sphere_volume
        • ciri
        • age
      • Verify comprehension
        • gre3
        • final_price
        • arrival_time
      • Lambda functions
        • Exercises: lambdas
        • apply_borders
        • process
    • Errors and testing
      • Testing
        • Where Is Your Software?
        • even_numbers example
        • Error kinds
      • Testing with Unittest
        • Running tests
        • When tests don’t run
        • Adding tests
        • Exercise: boundary cases
        • Exercise: expecting assertions
        • Exercise: good tests
        • Running unittests in Visual Studio Code
        • TROUBLESHOOTING
      • Functional programming
    • Matrices: lists
      • Moved to https://en.softpython.org/matrices-lists/matrices-lists1-sol.html
    • Matrices: numpy
      • Moved to https://en.softpython.org/matrices-numpy/matrices-numpy-sol.html
    • Data formats
      • MOVED TO https://en.softpython.org/formats/formats-sol.html
    • Graph formats
      • Moved to https://en.softpython.org/formats/formats4-graph-sol.html
    • Visualization
      • Moved to https://en.softpython.org/visualization/visualization-sol.html
    • Pandas
      • Moved to https://en.softpython.org/pandas/pandas1-sol.html
    • Binary relations
      • MOVED TO https://en.softpython.org/binary-relations/binary-relations-sol.html
  • Part B
    • OOP
      • OOP
        • Download exercises zip
        • What to do
        • 1. Abstract Data Types (ADT) Theory
        • 2. ComplexNumber class
        • 3. MultiSet
        • 3.1 __init__ add and get
        • 3.2 removen
        • 4. Challenges
      • OOP Matrix Challenge
        • Download exercises zip
        • What to do
        • DenseMatrix
        • Constructors and printing
        • shape
        • Brackets operator
        • nonzero
        • isclose
        • Equality
        • Sum
        • Multiplication
        • SparseMatrix
        • Sparse constructors and printing
        • Sparse shape
        • Sparse Brackets operator
        • Sparse nonzero
        • Sparse isclose
        • Sparse equality
        • Sparse sum
        • Sparse multiplication
    • Indexing
      • Download exercises zip
      • 1. Exercise - chains
        • 1.1 has_duplicates
        • 1.2 chain
      • 2. Exercise - Bank
        • 2.1 bank constructor, log and pos
        • 2.2 bank revert
        • 2.3 bank max_interval
    • Recursion
      • simple functional programming
        • SimpleFP - how-to
        • SimpleFP - variable assignment
        • SimpleFP - list creation
        • SimpleFP - boxing
        • SimpleFP - concatenation
        • SimpleFP - accessing list elements
        • SimpleFP - slicing
        • SimpleFP - minimal instruction set
        • SimpleFP - functions and conditionals
        • SimpleFP - recursion
        • Simple FP - Example - scount
        • Simple FP - debugging
        • SimpleFP: a recursion scheme
        • Example - sdouble
        • Exercise - debug double
        • Exercise - sfilter_even
        • Exercise - smerry
        • Exercise - ssum
        • Exercise - smin
        • Exercise - ssearch
        • Exercise - sbin_search
        • Exercise - szip
        • Exercise - sunnest
        • Exercise - sfib
        • Exercise - sall
        • Exercise - srev
        • Exercise - spalindrome
        • Exercise - snest
        • Exercise - spalace
        • Exercise - srep
        • Exercise - ssortin
      • accumulators and indeces
        • Example - adouble
        • Exercise - debug adouble
        • Exercise - afilter_even
        • Exercise - amerry
        • Exercise - afib
        • Exercise - asearch
        • Exercise - abin_search
        • Exercise - azip
        • Exercise - aunnest
        • Exercise - arev
        • Exercise - apalindrome
        • Exercise - anest
        • Exercise - apalace
        • Exercise - arep
        • Exercise - asortin
        • Exercise - ahist
        • Exercise - agap
        • Continue
      • divide and conquer
        • Managing solutions
        • Divide and conquer - SimpleFP style
        • Divide and conquer - Accumulator style
        • More exercises
        • Continue
      • challenges
        • Challenge - Cthulhu
        • Challenge - Ghatanothoa
        • Challenge - Hastur
        • Challenge - Tsathoggua
        • Challenge - Yig
        • Challenge - Shub-Niggurath
        • Challenge - Shoggoth
        • Challenge - Azathoth
        • References
    • Algorithm analysis
      • Introduction
      • List performance
        • Fast or not?
        • Sublist iteration performance
      • Some formulas
      • Lists - exercises
        • Exercise - rollsroyce
        • Exercise - honda
        • Exercise - lamborghini
        • Exercise - maserati
        • Exercise - toyota
        • Exercise - mercedes
        • Exercise - acura
        • Exercise - alfaromeo
        • Exercise - jeep
        • Exercise - chevrolet
        • Exercise - kia
        • Exercise - aston_martin
        • Exercise - subaru
        • Exercise - dodge
        • Exercise - lotus
        • Exercise - jaguar
        • Exercise - hyundai
        • Exercise - buick
        • Exercise - saab
      • Sets performance
      • Sets - exercises
        • Exercise - land_rover
        • Exercise - volkswagen
        • Exercise - pontiac
        • Exercise - volvo
        • Exercise - chrysler
      • Dictionaries performance
      • Dictionaries - exercises
        • Exercise - tesla
        • Exercise - bmw
        • Exercise - nissan
        • Exercise - ferrari
        • Exercise - bentley
        • Exercise - mclaren
        • Exercise - fiat
        • Exercise - mustang
      • Recursion
      • Recursion - exercises
        • Exercise - yamaha
        • Exercise - cadillac
        • Exercise - ducati
      • Analysis - more exercises
    • Sorting
      • intro
        • Download exercises zip
        • Introduction
        • Exercises
        • 1 Selection Sort
        • 2 Insertion sort
        • 3 Merge sort
        • 4 quick sort
        • 5 SwapArray
        • Challenges
      • challenges
        • Download exercises zip
        • Crime parade
        • McFat’s
        • Partitocracy
    • Stacks
      • Download exercises zip
      • 0. Introduction
        • References
        • What to do
      • 1. CappedStack
        • CappedStack Examples
        • Capped Stack basic methods
        • 1.1 __init__
        • 1.2 cap
        • 1.3 size
        • 1.4 __str__
        • 1.5 is_empty
        • 1.6 push
        • 1.7 peek
        • 1.8 pop
        • 1.9 peekn
        • 1.10 popn
        • 1.11 set_cap
      • 2. SortedStack
        • 2.1 transfer
        • 2.2 merge
      • 3. WStack
        • 3.1 implement class WStack
        • 3.2 accumulate
      • 4. Backpack
        • 4.1 class
        • 4.2 remove
      • 5. Train race
      • 6. PyraStack
      • 7. Tasks
        • 7.1 do
        • 7.2 do_level
      • 8. Stacktris
        • 8.1 _shorten
        • 8.2 drop1
        • 6.3 drop2h
    • Linked lists
      • intro
        • Download exercises zip
        • 0 Introduction
        • 1 v1: a slow LinkedList
        • 2 v2 faster size
        • 3 v3 Faster append
        • 4 v4 Go bidirectional
        • 5 EqList
        • 6 Cloning
        • 7 More exercises
        • 8 Last exercises
        • Challenge
      • challenges
        • Download exercises zip
        • rshift
        • lshift
    • Queues
      • intro
        • Download exercises zip
        • Introduction
        • 1. LinkedQueue
        • 2. CircularQueue
        • 3. ItalianQueue
        • 4. Supermarket queues
        • 5. Shopping mall queues
        • 6. Company queues
        • 7. Concert
        • 8. OfficeQueue
      • circular queue
        • Download exercises zip
        • 1. Introduction
        • 2. Example
        • 3. Circular span
        • 4. Implement CircularQueue
    • Binary Trees
      • Download exercises zip
        • What to do
      • 0. Introduction
        • 0.1 References
        • 0.2 Terminology - relations
        • 0.3 Terminology - levels
        • 0.4 Terminology - shapes
        • 0.2 Code skeleton
        • 0.3 Building trees
        • 0.3.1 Pointers
        • 0.3.2 Building with insert_left
        • 0.3.3 Building with bt
      • 1. Insertions
        • 1.1 insert_left
        • 1.2 insert_right
      • 2. Recursive visit
        • 2.1 sum_rec
        • 2.2 height_rec
        • 2.3 depth_rec
        • 2.4 contains_rec
        • 2.5 join_rec
        • 2.6 fun_rec
        • 2.7 bin_search_rec
        • 2.8 univalued_rec
        • 2.9 same_rec
        • 2.10 sum_leaves_rec
        • 2.11 schedule_rec
        • 2.12 paths
        • 2.12.1 paths_slow_rec
        • 2.12.2 paths_fast_rec
      • 3. Stack visit
        • 3.1 sum_stack
        • 3.2 height_stack
        • 3.3 leaves_stack
        • 3.4 swap_stack
        • 3.5 is_heap_stack
        • 3.6 others
      • 4. Queue visit
      • 5. Modifying the tree
        • 5.1 mod_sum_rec
        • 5.2 bin_insert_rec
        • 5.2 add_row
        • 5.3 prune_rec
        • 5.3 family_sum_rec
        • 5.4 union_rec
        • 5.5 reconstruct
    • Generic Trees
      • Download exercises zip
      • 0. Introduction
        • What to do
        • 0.1 References
        • 0.2 Code skeleton
        • 0.3 Building trees
        • 0.3.1 Pointers
        • 0.3.2 Building with insert_child
        • 0.3.3 Building with gt
        • 0.4 Displaying trees side by side with str_trees
        • 0.5 Look at the tests
        • 0.6 Look at gen_tree_test.GenericTreeTest
      • 1 Implement basic methods
        • 1.1 insert_child
        • 1.2 insert_children
        • 1.3 insert_sibling
        • 1.4 insert_siblings
        • 1.5 detach_child
        • 1.6 detach_sibling
        • 1.7 detach
        • 1.8 ancestors
      • 2 Implement more complex functions
        • 2.1 grandchildren
        • 2.2 Zig Zag
        • 2.3 uncles
        • 2.4 common_ancestor
        • 2.5 mirror
        • 2.6 clone
        • 2.7 rightmost
        • 2.8 fill_left
        • 2.9 follow
        • 2.10 is_triangle
        • 2.11 has_triangle
        • 2.12 marvelous
    • Graph algorithms
      • Download exercises zip
        • What to do
      • Introduction
        • 0.1 Graph theory
        • 0.2 Directed graphs
        • 0.3 Serious graphs
        • 0.4 Code skeleton
        • 0.5 Building graphs
        • 0.5.1 Building basics
        • 0.5.2 dig()
        • 0.6 Equality
        • 0.7 Basic querying
        • 0.7.1 adj
        • 0.7.2 is_empty()
        • 0.7.3 verteces()
        • 0.8 Blow up your computer
      • 1. Implement building
        • 1.1 has_edge
        • 1.2 full_graph
        • 1.3 dag
        • 1.4 list_graph
        • 1.5 star_graph
        • 1.6 odd_line
        • 1.7 even_line
        • 1.8 quads
        • 1.9 pie
        • 1.10 Flux Capacitor
      • 2. Manipulate graphs
        • 2.1 remove_vertex
        • 2.2 transpose
        • 2.3 has_self_loops
        • 2.4 remove_self_loops
        • 2.5 undir
      • 3. Query graphs
        • 3.1 distances()
        • 3.2 equidistances()
        • 3.3 Play with dfs and bfs
        • 3.4 Exits graph
        • 3.4.1 Exits graph cp
        • 3.4.2 Exit graph exits
        • 3.5 connected components
        • 3.6 has_cycle
        • 3.7 top_sort
    • Part B References
      • LeetCode for Part B
        • LeetCode LinkedLists
        • LeetCode Queues
        • LeetCode Trees
        • LeetCode Graphs
      • Geeks for geeks
        • Geeks for geeks Queues
        • Geeks for geeks Graphs
    • Changelog
      • 1.0 September 2020
      • 0.1, September 2018
  • Index
Sciprog DS Lab

Sets solutions¶

MOVED TO https://en.softpython.org/sets/sets1-sol.html¶

Next Previous

© Copyright # 2020 - 2022, David Leoni.

Built with Sphinx using a theme provided by Read the Docs.