How to resolve the algorithm Set step by step in the PowerShell programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Set step by step in the PowerShell programming language

Table of Contents

Problem Statement

A   set  is a collection of elements, without duplicates and without order.

Show each of these set operations:

As an option, show some other set operations. (If A ⊆ B, but A ≠ B, then A is called a true or proper subset of B, written A ⊂ B or A ⊊ B.) As another option, show how to modify a mutable set.

One might implement a set using an associative array (with set elements as array keys and some dummy value as the values). One might also implement a set with a binary search tree, or with a hash table, or with an ordered array of binary bits (operated on with bit-wise binary operators). The basic test, m ∈ S, is O(n) with a sequential list of elements, O(log n) with a balanced binary search tree, or (O(1) average-case, O(n) worst case) with a hash table.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Set step by step in the PowerShell programming language

Source code in the powershell programming language

[System.Collections.Generic.HashSet[object]]$set1 = 1..4
[System.Collections.Generic.HashSet[object]]$set2 = 3..6

#            Operation           +     Definition      +          Result
#--------------------------------+---------------------+-------------------------
$set1.UnionWith($set2)           # Union                 $set1 = 1, 2, 3, 4, 5, 6
$set1.IntersectWith($set2)       # Intersection          $set1 = 3, 4
$set1.ExceptWith($set2)          # Difference            $set1 = 1, 2
$set1.SymmetricExceptWith($set2) # Symmetric difference  $set1 = 1, 2, 6, 5
$set1.IsSupersetOf($set2)        # Test superset         False
$set1.IsSubsetOf($set2)          # Test subset           False
$set1.Equals($set2)              # Test equality         False
$set1.IsProperSupersetOf($set2)  # Test proper superset  False
$set1.IsProperSubsetOf($set2)    # Test proper subset    False

5 -in $set1                      # Test membership       False
7 -notin $set1                   # Test non-membership   True


  

You may also check:How to resolve the algorithm Vector products step by step in the XPL0 programming language
You may also check:How to resolve the algorithm Unix/ls step by step in the Haskell programming language
You may also check:How to resolve the algorithm Rep-string step by step in the Icon and Unicon programming language
You may also check:How to resolve the algorithm JortSort step by step in the Wren programming language
You may also check:How to resolve the algorithm Hello world/Newbie step by step in the Common Lisp programming language