Discrete Sets

================)==

A Discrete Set is a collection of Distinct elements, meaning that each element in the set is unique and cannot be repeated. In other words, every element in the set belongs to it exclusively.

Characteristics of discrete sets


  • Each element in the set is unique.
  • No element can be repeated within the set.
  • Elements are distinct and separate from one another.

Definition


A Discrete Set is defined as a set that satisfies the following criteria:

  • The set contains only Distinct elements (i.e., No duplicates).
  • Each element in the set has a unique identity (i.e., no two elements have the same properties or characteristics).

Examples of discrete sets


Properties of discrete sets


Operations on discrete sets


Use cases for discrete sets


  • Data analysis: Discrete sets can be used to represent categorical data, such as Colors, shapes, or temperatures.
  • Computer science: Discrete sets are used in algorithms and data structures, such as binary trees, graphs, and hash tables.
  • Mathematics: Discrete sets play a crucial role in number theory, set theory, and mathematical logic.

Comparison with continuous sets


  • Key differences:
    • Equality: In continuous sets, elements can be equal (e.g., 3.14 = 3.14159).
    • Order: In discrete sets, the Order of elements matters (e.g., {1, 2} ≠ {2, 1}).
  • Example:

Real-world examples


Code Implementation

# [Discrete Set](/Discrete_Set) Example: Fractions
from fractions import Fraction

def get_fractions():
    # Create a [Discrete Set](/Discrete_Set) of fractions
    fractions = {Fraction(1, 2), Fraction(3, 4)}
    
    # Iterate over the elements in the set and print them
    for fraction in fractions:
        print(fraction)

get_fractions()

Code Implementation (Graph Theory)

# [Discrete Set](/Discrete_Set) Example: Graphs ( Adjacency Matrix )
from itertools import combinations

def get_adjacency_matrix(graph):
    # Create a [Discrete Set](/Discrete_Set) of nodes and edges
    nodes = list(graph.keys())
    edges = [(node, neighbor) for node, neighbors in graph.items() for neighbor in neighbors]
    
    # Convert the edges to an adjacency matrix
    adjacency_matrix = []
    for i, (node1, node2) in enumerate(edges):
        row = [0] * len(nodes)
        row[node1] = 1
        row[node2] = 1
        adjacency_matrix.append(row)
    
    return adjacency_matrix

# Example graph: Adjacency Matrix of a graph with nodes A and B
graph = {
    'A': ['B'],
    'B': ['C', 'D']
}

adjacency_matrix = get_adjacency_matrix(graph)

for row in adjacency_matrix:
    print(row)

Code Implementation (Set Theory)

# [Discrete Set](/Discrete_Set) Example: Union of Two Sets
from operator import add

def union_of_sets(set1, set2):
    # Perform element-wise addition and return the result as a new set
    result = set()
    for elem in set1:
        result.add(elem)
        result.add(elem)
    
    return result

# Example sets: Set1 = {1, 2} and Set2 = {3, 4}
set1 = {1, 2}
set2 = {3, 4}

result_set = union_of_sets(set1, set2)

print(result_set)  # Output: {1, 2, 3, 4}