Set Operations in Relational Algebra: Union (∪), Intersection (∩), Difference (-) Notes in Hindi & English : सेट ऑपरेशन्स: यूनियन (∪), इंटरसेक्शन (∩) और सेट डिफरेंस (-) और 20 महत्वपूर्ण MCQ प्रश्न (Rajasthan IT Exam)

Post a Comment

PGDCA, BCA, B-Tech, MCA, M-Tech, B.Sc computer science राजस्थान सूचना सहायक व कंप्यूटर शिक्षक विशेष नोट्स: इस अध्याय में हम Set Operations in Relational Algebra: Union (∪), Intersection (∩), Difference (-) (सेट ऑपरेशन्स: यूनियन (∪), इंटरसेक्शन (∩) और सेट डिफरेंस (-)) की संपूर्ण थ्योरी, मुख्य तकनीकी बिंदु, तुलनात्मक तालिका और विगत परीक्षाओं के पैटर्न पर आधारित 20 अति-महत्वपूर्ण बहुविकल्पीय प्रश्न (MCQs) विस्तृत हिंदी व अंग्रेजी व्याख्या सहित पढ़ेंगे।

Overview: Relational Algebra Set Operations—Union (∪), Intersection (∩), and Set Difference (-)—combine tuples across two relations only when both tables satisfy Union Compatibility (equal degree and compatible column domains).

अध्याय सार: रिलेशनल अलजेब्रा के सेट ऑपरेशन्स—Union (∪), Intersection (∩) और Set Difference (-)—दो टेबल्स की पंक्तियों को मिलाने या घटाने का कार्य करते हैं, जिसके लिए दोनों का Union Compatible होना अनिवार्य है।

Set Operations in Relational Algebra: Union (∪), Intersection (∩), Difference (-): Detailed Notes & Architecture (सेट ऑपरेशन्स: यूनियन (∪), इंटरसेक्शन (∩) और सेट डिफरेंस (-))

1. Union Compatibility (Type Compatibility) Precondition (यूनियन कम्पैटिबिलिटी (Union Compatibility) नियम)

[EN] Binary set operators R ∪ S, R ∩ S, and R - S CANNOT run on arbitrary tables. Both relations R and S MUST be Union Compatible, meaning: (1) both have the exact same arity/degree (equal number of columns n), and (2) for every column position i from 1 to n, domain(R_i) matches or is compatible with domain(S_i). By convention, output columns inherit attribute names from the left relation R.

[HI] दो टेबल्स R और S पर ∪, ∩ या - तभी चल सकता है जब वे Union Compatible हों: (1) दोनों में कॉलम्स की संख्या (Degree) बिल्कुल बराबर हो, और (2) क्रमानुसार प्रत्येक कॉलम का डेटा टाइप (Domain) समान हो। आउटपुट के कॉलम नाम पहली टेबल R से आते हैं।

2. Union (∪) vs Intersection (∩) (यूनियन (∪) और इंटरसेक्शन (∩))

[EN] R ∪ S produces a relation containing all tuples present in R, in S, or in both, automatically removing duplicates (equivalent to SQL UNION, NOT UNION ALL). R ∩ S returns only tuples present in BOTH R and S simultaneously. Notice ∩ is actually a derived operator since R ∩ S = R - (R - S).

[HI] R ∪ S दोनों टेबल्स की सभी पंक्तियाँ देता है और डुप्लीकेट हटाता है (SQL UNION के समान)। R ∩ S केवल वे पंक्तियाँ देता है जो दोनों टेबल्स में साझा (Common) हों; इसे मूलभूत सेट डिफरेंस से R - (R - S) द्वारा भी बनाया जा सकता है।

3. Set Difference (-) & Non-Commutativity (सेट डिफरेंस (-) और क्रम का महत्व)

[EN] R - S returns all tuples belonging to R that do NOT exist in S (mapping to SQL EXCEPT / Oracle MINUS). Unlike ∪ and ∩ (which are both commutative and associative: R ∪ S = S ∪ R), Set Difference is NOT commutative and NOT associative: R - S != S - R!

[HI] R - S केवल R की वे पंक्तियाँ लौटाता है जो S में मौजूद नहीं हैं (SQL में EXCEPT या Oracle में MINUS)। ध्यान रखें: ∪ व ∩ क्रमविनिमेय हैं पर R - S ≠ S - R होता है!

4. Cardinality Bounds & SQL Mapping (कार्डिनैलिटी सीमाएं व SQL समतुल्य)

[EN] If |R| = m and |S| = n: |R ∪ S| lies between max(m,n) and m + n; |R ∩ S| lies between 0 and min(m,n); |R - S| lies between max(0, m - n) and m. In SQL, UNION removes duplicates while UNION ALL keeps duplicates without sorting overhead.

[HI] यदि R में m और S में n पंक्तियाँ हैं: यूनियन में max(m,n) से m+n, इंटरसेक्शन में 0 से min(m,n), तथा R - S में अधिकतम m पंक्तियाँ आ सकती हैं।

Syntax, Formula & Technical Example (Set Operations in Relational Algebra: Union (∪), Intersection (∩), Difference (-))

-- Relational Algebra:
π_Email(Student) ∪ π_Email(Alumni)   -- Union (deduplicated)
π_Email(Student) ∩ π_Email(Alumni)   -- Both Student & Alumni
π_Email(Student) - π_Email(Alumni)   -- Current students not yet Alumni

-- SQL Equivalent:
SELECT Email FROM Student EXCEPT SELECT Email FROM Alumni;

Set Operations in Relational Algebra: Union (∪), Intersection (∩), Difference (-) Quick Reference & Comparison Table

Set OperatorMeaning & SQL EquivalentAlgebraic Properties
Union (R ∪ S)Rows in R or S (SQL UNION)Fundamental, Commutative, Associative
Intersection (R ∩ S)Rows in BOTH R and S (SQL INTERSECT)Derived via R-(R-S), Commutative, Associative
Difference (R - S)Rows in R but NOT S (SQL EXCEPT/MINUS)Fundamental, NOT Commutative (R-S != S-R)
Union CompatibilitySame Degree AND matching column domainsMandatory prerequisite for ∪, ∩, -

Set Operations in Relational Algebra: Union (∪), Intersection (∩), Difference (-) Top 20 Bilingual MCQs with Answers

Q1. What two conditions define 'Union Compatibility' between relations R and S?

(दो रिलेशन्स R और S के 'Union Compatible' होने की कौन सी दो अनिवार्य शर्तें हैं?)

(A) Same number of rows AND same primary keys

(B) Identical table names AND foreign keys

(C) Equal degree only, regardless of column data types

(D) Equal degree (same number of columns) AND matching domain/data type for each positional column pair

Correct Answer: (D)

[EN] Set operators require identical arity (degree) and compatible column domains from left to right.

[HI] दोनों टेबल्स में कॉलम्स की संख्या (Degree) बराबर हो और हर संगत कॉलम का डोमेन/डेटा प्रकार मेल खाना चाहिए।

Q2. Which Relational Algebra set operator is NOT commutative?

(निम्नलिखित में से कौन सा सेट ऑपरेटर क्रमविनिमेय (Commutative) नहीं है?)

(A) Union (R ∪ S)

(B) Set Difference (R - S ≠ S - R)

(C) Natural Join (R ⨝ S)

(D) Intersection (R ∩ S)

Correct Answer: (B)

[EN] R - S keeps tuples unique to R while S - R keeps tuples unique to S, so order strictly changes results.

[HI] R ∪ S और R ∩ S में क्रम बदलने से फर्क नहीं पड़ता, लेकिन R - S और S - R बिल्कुल अलग परिणाम देते हैं।

Q3. How can Set Intersection (R ∩ S) be expressed purely using Set Difference (-)?

(सेट इंटरसेक्शन (R ∩ S) को केवल सेट डिफरेंस (-) के प्रयोग से कैसे लिखा जा सकता है?)

(A) (R - S) ∪ (S - R)

(B) R - (R - S)

(C) S - (R ∪ S)

(D) (R - S) - R

Correct Answer: (B)

[EN] Removing items present only in R (R - S) from full R leaves precisely elements in both R and S.

[HI] R में से उन तत्वों को घटा दें जो S में नहीं हैं (R - S), तो केवल दोनों में साझा तत्व (R ∩ S) बचते हैं।

Q4. In SQL, what is the exact difference between UNION and UNION ALL?

(SQL में UNION और UNION ALL के बीच क्या सटीक अंतर है?)

(A) UNION ALL sorts results automatically

(B) UNION ALL fails if columns match

(C) UNION keeps duplicates while UNION ALL removes them

(D) UNION eliminates duplicate rows like relational ∪; UNION ALL keeps all duplicates and runs faster

Correct Answer: (D)

[EN] Because UNION must deduplicate via sort/hash, UNION ALL performs faster when duplicates are acceptable or known absent.

[HI] UNION डुप्लीकेट हटाता है (अतः धीमा है), जबकि UNION ALL बिना जांच किए सभी पंक्तियाँ (डुप्लीकेट सहित) जोड़ देता है।

Q5. If relation R has 40 distinct tuples and S has 25 distinct tuples (both union compatible), what is the MAXIMUM cardinality of R ∩ S?

(यदि R में 40 और S में 25 पंक्तियाँ हैं, तो R ∩ S में अधिकतम कितनी पंक्तियाँ हो सकती हैं?)

(A) 1000

(B) 40

(C) 65

(D) 25 (min(|R|, |S|))

Correct Answer: (D)

[EN] Intersection holds rows appearing in both sets, so it can never exceed the smaller relation's size (25).

[HI] इंटरसेक्शन दोनों में कॉमन पंक्तियाँ लेता है, अतः वह छोटे सेट (25) से अधिक नहीं हो सकता।

Q6. If |R| = 40 and |S| = 25 (with R, S disjoint or overlapping), what is the MINIMUM cardinality of R ∪ S?

(यदि |R| = 40 और |S| = 25 हो, तो R ∪ S में न्यूनतम कितनी पंक्तियाँ होंगी?)

(A) 40 (max(|R|, |S|), when S is a subset of R)

(B) 0

(C) 15

(D) 25

Correct Answer: (A)

[EN] When all 25 tuples of S already exist inside R, R ∪ S equals R with 40 tuples.

[HI] जब S की सभी 25 पंक्तियाँ पहले से ही R में मौजूद हों, तब यूनियन में न्यूनतम 40 पंक्तियाँ होंगी।

Q7. Which SQL keyword equals Relational Algebra Set Difference (R - S) in PostgreSQL/SQL Server vs Oracle?

(SQL में R - S (सेट डिफरेंस) के लिए मानक कीवर्ड और Oracle का कीवर्ड क्रमशः क्या है?)

(A) DIFF and SUBTRACT

(B) DIFFERENCE and EXCLUDE

(C) NOT IN and REMOVE

(D) EXCEPT (Standard SQL/Postgres) and MINUS (Oracle)

Correct Answer: (D)

[EN] ANSI SQL defines EXCEPT (supported in PostgreSQL, SQLite, SQL Server, MySQL 8.0.31+), while Oracle historically calls it MINUS.

[HI] मानक SQL में EXCEPT और Oracle डेटाबेस में MINUS कीवर्ड सेट डिफरेंस (R - S) का काम करता है।

Q8. In R ∪ S, where do the column names of the resulting relation come from by relational algebra convention?

(R ∪ S करने पर आउटपुट टेबल के कॉलम्स के नाम कहाँ से लिए जाते हैं?)

(A) From the right operand relation S

(B) From the first (left) operand relation R

(C) Renamed to Col1, Col2

(D) Automatically merged as R_S

Correct Answer: (B)

[EN] Attribute names of set operation outputs default to the left-hand relation R unless renamed via ρ.

[HI] सेट ऑपरेशन्स में आउटपुट टेबल के कॉलम नाम हमेशा बायीं ओर की पहली टेबल R से आते हैं।

Q9. Is Cartesian Product (R × S) subject to the Union Compatibility requirement?

(क्या Cartesian Product (R × S) के लिए भी दोनों टेबल्स का Union Compatible होना ज़रूरी है?)

(A) Yes, otherwise degree becomes 0

(B) Only if |R| == |S|

(C) No — R × S can multiply relations of completely different degrees and column domains

(D) Yes, R and S must have identical columns

Correct Answer: (C)

[EN] Set operators ∪, ∩, - combine rows vertically so schemas must match; × and ⋈ combine columns horizontally.

[HI] ∪, ∩, - के लिए स्कीमा समान होना जरूरी है, पर × (Cartesian Product) किसी भी अलग डिग्री की टेबल्स पर चल जाता है।

Q10. What does (R - S) ∪ (S - R) compute?

(व्यंजक (R - S) ∪ (S - R) क्या परिणाम देता है?)

(A) Full Cartesian Product

(B) Intersection R ∩ S

(C) Empty relation always

(D) Symmetric Difference: rows appearing in either R or S, but NOT in both

Correct Answer: (D)

[EN] It matches XOR logic—keeping exclusive elements from both tables while excluding shared ones.

[HI] यह सममित अंतर (Symmetric Difference) देता है—केवल R या केवल S की पंक्तियाँ, दोनों में साझा नहीं।

Q11. If R(A,B) has degree 2 and S(X,Y,Z) has degree 3, what happens when computing R ∪ S?

(यदि R(A,B) की डिग्री 2 और S(X,Y,Z) की डिग्री 3 हो, तो R ∪ S करने पर क्या होगा?)

(A) Pads R with NULL as 3rd column

(B) Invalid operation — Union Compatibility is violated due to unequal degrees

(C) Outputs degree 5

(D) Outputs degree 2 ignoring Z

Correct Answer: (B)

[EN] Unequal column counts strictly forbid ∪, ∩, and - unless projected to matching arity first.

[HI] कॉलम संख्या अलग होने से Union Compatibility टूटती है और ∪ संभव नहीं होता।

Q12. What is the cardinality range of R - S when |R| = 50 and |S| = 30?

(यदि |R| = 50 और |S| = 30 हो, तो R - S में पंक्तियों की संख्या किस सीमा में रहेगी?)

(A) Always exactly 20

(B) Between 0 and 30

(C) Between 20 and 50

(D) Between 30 and 50

Correct Answer: (C)

[EN] If all 30 tuples of S exist inside R, 50 - 30 = 20 remain; if R and S share zero tuples, all 50 remain.

[HI] यदि S के सभी 30 तत्व R में हों तो न्यूनतम 20 बचेंगे; कोई साझा न हो तो सभी 50 बचेंगे।

Q13. What happens in SQL if you run SELECT Id FROM A UNION SELECT Name FROM B where Id is INT and Name is VARCHAR?

(यदि SQL में INT कॉलम और VARCHAR कॉलम पर UNION चलाया जाए तो क्या होगा?)

(A) Error due to incompatible data types in matching column position

(B) Succeeds automatically in strict mode

(C) Converts Name to integer 0

(D) Merges into 2 separate columns

Correct Answer: (A)

[EN] Both relational algebra and SQL require compatible data types across aligned columns.

[HI] दोनों संगत कॉलम्स के डेटा टाइप मेल न खाने पर टाइप असंगतता (incompatible types) एरर आती है।

Q14. Which set operation is fundamental (cannot be expressed using the remaining basic operators σ, π, ×)?

(निम्नलिखित में से कौन सा सेट ऑपरेटर मूलभूत (Fundamental) है और बाकी ऑपरेटर्स से नहीं बन सकता?)

(A) Only Symmetric Difference

(B) Only Intersection (∩)

(C) Both Union (∪) and Set Difference (-) are fundamental; Intersection (∩) is derived

(D) Only Natural Join

Correct Answer: (C)

[EN] Codd's 5 minimal operators require both ∪ and - explicitly, whereas ∩ derives as R - (R - S).

[HI] ∪ और - दोनों मूलभूत ऑपरेटर्स हैं जबकि ∩ को इनसे व्युत्पन्न किया जाता है।

Q15. Does SQL allow ORDER BY inside the first query of SELECT ... UNION SELECT ...?

(SQL में (SELECT A FROM T1) UNION (SELECT A FROM T2) लिखते समय ORDER BY कहाँ लगाया जाता है?)

(A) Not allowed with UNION at all

(B) Inside the first SELECT only

(C) At the very end after the final SELECT query to sort the combined result

(D) Before the UNION keyword without parentheses

Correct Answer: (C)

[EN] SQL applies a single ORDER BY clause after the final query block across the unified output columns.

[HI] पूरे संयोजित परिणाम को क्रमबद्ध करने के लिए ORDER BY हमेशा सबसे अंतिम SELECT के बाद अंत में लगता है।

Q16. Which set equality always simplifies (R ∪ R) and (R ∩ R) and (R - R)?

(समान टेबल पर (R ∪ R), (R ∩ R) और (R - R) के क्रमशः क्या परिणाम आते हैं?)

(A) R, R, and ∅ (Empty Relation)

(B) 2R, R, and R

(C) ∅, R, and ∅

(D) R, ∅, and R

Correct Answer: (A)

[EN] By idempotent set laws: R ∪ R = R, R ∩ R = R, and subtracting R from itself leaves the empty set ∅.

[HI] सेट नियमों से R ∪ R = R, R ∩ R = R, और R - R = ∅ (खाली सेट) प्राप्त होता है।

Q17. Within Set Operations in Relational Algebra: Union (∪), Intersection (∩), Difference (-), which set operator directly maps to: "Rows in R or S (SQL UNION)"?

(Set Operations in Relational Algebra: Union (∪), Intersection (∩), Difference (-) में कौन सा Set Operator सीधे "Rows in R or S (SQL UNION)" से संबंधित है?)

(A) Intersection (R ∩ S)

(B) Difference (R - S)

(C) Union Compatibility

(D) Union (R ∪ S)

Correct Answer: (D)

[EN] In Set Operations in Relational Algebra: Union (∪), Intersection (∩), Difference (-), 'Union (R ∪ S)' handles 'Rows in R or S (SQL UNION)' (Fundamental, Commutative, Associative).

[HI] Set Operations in Relational Algebra: Union (∪), Intersection (∩), Difference (-) में 'Union (R ∪ S)' का कार्य/विवरण 'Rows in R or S (SQL UNION)' (Fundamental, Commutative, Associative) है।

Q18. Which option accurately describes 'Intersection (R ∩ S)' in Set Operations in Relational Algebra: Union (∪), Intersection (∩), Difference (-)?

(Set Operations in Relational Algebra: Union (∪), Intersection (∩), Difference (-) के संदर्भ में 'Intersection (R ∩ S)' की सही विशेषता कौन सी है?)

(A) Rows in R or S (SQL UNION)

(B) Same Degree AND matching column domains

(C) Rows in BOTH R and S (SQL INTERSECT)

(D) Rows in R but NOT S (SQL EXCEPT/MINUS)

Correct Answer: (C)

[EN] 'Intersection (R ∩ S)' provides 'Rows in BOTH R and S (SQL INTERSECT)' — key point: Derived via R-(R-S), Commutative, Associative.

[HI] 'Intersection (R ∩ S)' का मुख्य विवरण 'Rows in BOTH R and S (SQL INTERSECT)' है (Derived via R-(R-S), Commutative, Associative)।

Q19. In Set Operations in Relational Algebra: Union (∪), Intersection (∩), Difference (-), identify the correct parameter for the specification: "Rows in R but NOT S (SQL EXCEPT/MINUS)".

(Set Operations in Relational Algebra: Union (∪), Intersection (∩), Difference (-) में "Rows in R but NOT S (SQL EXCEPT/MINUS)" विवरण किस विकल्प के लिए सही है?)

(A) Union Compatibility

(B) Union (R ∪ S)

(C) Intersection (R ∩ S)

(D) Difference (R - S)

Correct Answer: (D)

[EN] 'Difference (R - S)' corresponds to 'Rows in R but NOT S (SQL EXCEPT/MINUS)' (Fundamental, NOT Commutative (R-S != S-R)).

[HI] 'Difference (R - S)' का संबंध 'Rows in R but NOT S (SQL EXCEPT/MINUS)' (Fundamental, NOT Commutative (R-S != S-R)) से है।

Q20. Considering Set Operations in Relational Algebra: Union (∪), Intersection (∩), Difference (-), what key behavior defines 'Union Compatibility'?

(Set Operations in Relational Algebra: Union (∪), Intersection (∩), Difference (-) में 'Union Compatibility' की मुख्य भूमिका या मान क्या है?)

(A) Same Degree AND matching column domains

(B) Rows in BOTH R and S (SQL INTERSECT)

(C) Rows in R or S (SQL UNION)

(D) Rows in R but NOT S (SQL EXCEPT/MINUS)

Correct Answer: (A)

[EN] 'Union Compatibility' represents 'Same Degree AND matching column domains' (Mandatory prerequisite for ∪, ∩, -).

[HI] 'Union Compatibility' का अर्थ/मान 'Same Degree AND matching column domains' है (Mandatory prerequisite for ∪, ∩, -)।

Set Operations in Relational Algebra: Union (∪), Intersection (∩), Difference (-) — Exam FAQs

Q1: Why isn't Intersection (∩) counted among the 5 fundamental relational algebra operators?

Intersection (∩) को 5 मूलभूत रिलेशनल अलजेब्रा ऑपरेटर्स में क्यों नहीं गिना जाता?

[EN] Because it is redundant mathematically: R ∩ S can always be written purely using Set Difference as R - (R - S).

[HI] क्योंकि R ∩ S को पहले से मौजूद मूलभूत ऑपरेटर '-' से R - (R - S) के रूप में प्राप्त किया जा सकता है।

Q2: Does Union Compatibility require both tables to have identical column names?

क्या Union Compatibility के लिए दोनों टेबल्स में कॉलम्स के नाम भी बिल्कुल एक जैसे होने ज़रूरी हैं?

[EN] No! Only the number of columns (degree) and their data types/domains must match; column names don't have to match and are taken from the left table.

[HI] नहीं! केवल कॉलम्स की संख्या और उनके डेटा टाइप समान होना जरूरी है; नाम अलग हो सकते हैं (आउटपुट में बाईं टेबल के नाम आते हैं)।

Q3: Which is faster in SQL when tables have no duplicates: UNION or UNION ALL?

यदि दोनों टेबल्स में डुप्लीकेट डेटा न हो, तो SQL में UNION और UNION ALL में कौन तेज है?

[EN] UNION ALL, because it appends results immediately without spending CPU/RAM sorting or hashing rows to check duplicates.

[HI] UNION ALL ज्यादा तेज है क्योंकि वह डुप्लीकेट जांचने के लिए सॉर्टिंग/हैशिंग नहीं करता।

Related Posts

  • Loading related posts...

Post a Comment

Search Topic Notes & 20 MCQs (Hindi / English)