Channi Studies

[ADT] Set - 1 본문

Data Science/Data Structure & Algorithm

[ADT] Set - 1

Chan Lee 2025. 5. 15. 03:56

SET ADT

A set is a collection of distinct elements.

A set add operation adds an element to the set, provided an equal element doesn't already exist in the set. (No duplicates)

Ex. The set with 3, 7, and 9 is equivalent to the set with integers 9, 3, and 7. 

만약 Python의 Set에 대해서 알고 계시다면, 그것과 동일하다고 생각할 수 있겠습니다. 

 


Element Keys and Removal

Set elements may be primitive data values, such as numbers or strings, or objects with numerous data members. 

When storing objects, set implementations commonly distinguish elements based on element's key value. A primitive data value that serves as a unique identifier for the element. 

(Ex. 대학교의 학생 정보를 Set 자료형을 통해서 다루고 있다면, 중복된 값을 가질 수 없는 Student ID 번호를 key value로 사용합니다) 

 

Sets are commonly implemented to use keys for all element types. When storing objects, the set retrieves an object's key via an external function or predetermined knowledge of which object property is the key value. When storing primitive data values, each primitive data value's key is itself. 

Given a key, a set remove operation removes the element with the specific key from the set. 

 


Searching and Subsets

Given a key, a set search opeartion returns the set element with the specified key, or null if no such element exists. The search operation can be used to implement a subset test.

A set X is a subset of Y only if every element of X is also an element of Y.