0% found this document useful (0 votes)
10 views12 pages

Boolean Laws and Java Methods Explained

Uploaded by

csegunjan03
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views12 pages

Boolean Laws and Java Methods Explained

Uploaded by

csegunjan03
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

✅ 1. What are Boolean Laws?

Answer:
Boolean laws are algebraic rules used in digital logic to simplify Boolean expressions.
Important laws include:

 Commutative: A + B = B + A, AB = BA
 Associative: (A + B) + C = A + (B + C)
 Distributive: A(B + C) = AB + AC
 Identity: A + 0 = A, A·1 = A
 Null: A + 1 = 1, A·0 = 0
 Idempotent: A + A = A
 Complement: A + A' = 1, A·A' = 0
 De Morgan's: (A+B)' = A'B', (AB)' = A'+B'

✅ 2. What are the types of methods in Java?


Answer:
Types of methods include:

 Static Methods – called without an object


 Instance Methods – need an object
 Constructors – special methods to initialize objects
 Accessor (Getter) – returns value
 Mutator (Setter) – modifies value
 Methods with parameters / without parameters

✅ 3. How do we implement polymorphism?


Answer:
Polymorphism means same function name, different behaviour.

Two types:

(1) Compile-time polymorphism (Method Overloading)

Same method name, different parameters.

(2) Runtime polymorphism (Method Overriding)


Same method name/parameters but implemented differently in subclass.

✅ 4. What are actual and formal


parameters?
Answer:

 Actual parameters: Values passed by the caller.


Example: sum(5, 10);
 Formal parameters: Variables in the function definition that receive the values.
Example: void sum(int a, int b) → a and b are formal parameters.

✅ 5. What is the difference between call by


value and call by reference?
Answer:

 Call by value: A copy of the value is passed; original does not change.
 Call by reference: Address/reference is passed; changes affect original data.
 In Java, primitives use call by value; objects behave like call by reference.

✅ 6. What are redundant groups in a K-


Map?
Answer:
Redundant groups are extra groups that do not affect the simplified expression because those
minterms are already covered by other essential groups.
They are removed to keep the expression minimal.

✅ 7. What are minterms and maxterms?


Answer:

 Minterm: A product term containing all variables (in SOP form) and is true for
exactly one input combination.
 Maxterm: A sum term containing all variables (in POS form) and is false for exactly
one input combination.

✅ 8. Why do we write 00, 01, 11, 10 in a K-


Map instead of 00, 01, 10, 11?
Answer:
Because K-Maps use Gray Code, where only one bit changes at a time:

00 → 01 → 11 → 10
This allows adjacency between cells and helps in grouping and simplification.

✅ 9. What is StringTokenizer?
Answer:
StringTokenizer is a class used to break a string into tokens (words).
Default delimiter is space.

Example:

StringTokenizer st = new StringTokenizer("Hello World");

✅ 10. What are the types of inheritance?


Answer:

1. Single inheritance
2. Multilevel inheritance
3. Hierarchical inheritance
4. Multiple inheritance (not supported by classes, only by interfaces)

✅ 11. How do we implement inheritance in


Java?
Answer:
Using the extends keyword.
Example:

class A {}
class B extends A {}

✅ 12. What are getter and setter methods?


Answer:

 Getter: Method that returns the value of a private variable.


 Setter: Method that modifies the private variable.
Used for encapsulation.

✅ 13. What is a balanced Binary Search


Tree?
Answer:
A BST where height difference between left and right subtree is at most 1.
It ensures operations like search, insert, delete work in O(log n) time.

Examples: AVL tree, Red-Black tree.

✅ 14. What are common terminologies used


in BST?
Answer:

 Root – topmost node


 Leaf – node with no children
 Parent – node above
 Child – node below
 Subtree – tree under a node
 Height – longest path to leaf
 Depth – distance from root
 Successor – next higher value
 Predecessor – next lower value
 Internal Node – node with children
✅ 15. What is time complexity?
Answer:
Time complexity measures the total time taken by an algorithm as a function of input size n,
usually represented using Big-O notation.

✅ 16. What are the types of time


complexity?
Answer:

 O(1) – Constant
 O(log n) – Logarithmic
 O(n) – Linear
 O(n log n) – Linearithmic
 O(n²) – Quadratic
 O(2ⁿ) – Exponential
 O(n!) – Factorial

✅ 17. Where are different time complexities


used?
Answer:

Time Complexity Example


O(1) Accessing element in array
O(log n) Binary search
O(n) Linear search, traversals
O(n log n) Merge sort, quicksort (average)
O(n²) Bubble sort, insertion sort
O(2ⁿ) Recursive subset generation
O(n!) Travelling salesman brute force
import [Link].*;

class cir

int n, num, c = 0;

boolean flag = true;


static boolean isPrime(int x)

int f = 0;

for(int i = 1; i <= x; i++)

if(x % i == 0)

f++;

return (f == 2);

public void checkCircularPrime()

Scanner ob = new Scanner([Link]);

[Link]("enter a number");

n = [Link]();

num = n;

while(n != 0)

c++;

n = n / 10;

for(int i = 1; i <= c; i++)

int d = num % 10;

num = num / 10;

num = (d * (int)[Link](10, c - 1) + num);


if(!isPrime(num))

flag = false;

break;

if(flag)

[Link]("Circular prime number");

else

[Link]("Not a Circular prime number");

public static void main(String args[])

cir obj = new cir(); // object created

[Link](); // calling the method

import [Link].*;

public class PangramCheck {

public static void main(String[] args) {

Scanner sc = new Scanner([Link]);

[Link]("Enter a sentence (ending with ., ?, or !):");

String sentence = [Link]();


// Valid termination check

char last = [Link]([Link]() - 1);

if (last != '.' && last != '?' && last != '!') {

[Link]("Invalid sentence termination!");

return;

// Convert to lower case for checking

String s = [Link]();

boolean[] present = new boolean[26];

// Mark which letters appear

for (int i = 0; i < [Link](); i++) {

char ch = [Link](i);

if (ch >= 'a' && ch <= 'z') {

present[ch - 'a'] = true;

// Find missing letters

ArrayList<Character> missing = new ArrayList<>();

for (int i = 0; i < 26; i++) {

if (!present[i]) {

[Link]((char) (i + 'a'));

}
// Output decision

if ([Link]() == 0) {

[Link]("PANGRAM");

else if ([Link]() == 1) {

[Link]("PANGRAMMATIC LIPOGRAM");

[Link]("Missing letter: " + [Link](0));

else {

[Link]("NEITHER");

[Link]("Missing letters: ");

for (char c : missing) {

[Link](c + " ");

import [Link];

public class Equilibrium {

public static void main(String[] args) {

Scanner sc = new Scanner([Link]);

[Link]("Enter L (3 to 50): ");

if (![Link]()) {

[Link]("Error: L must be a number between 3 and


50.");
return;

int L = [Link]();

if (L < 3 || L > 50) {

[Link]("Error: L must be between 3 and 50.");

return;

int[] A = new int[L];

[Link]("Enter " + L + " numbers:");

for (int i = 0; i < L; i++) {

if (![Link]()) {

[Link]("Error: All inputs must be numbers.");

return;

A[i] = [Link]();

[Link]("Array: ");

for (int x : A)

[Link](x + " ");

[Link]();

long total = 0;

for (int x : A) total += x;

long left = 0;

boolean found = false;

[Link]("Equilibrium indices: ");


for (int i = 0; i < L; i++) {

long right = total - left - A[i];

if (left == right) {

[Link](i + " ");

found = true;

left += A[i];

if (!found) [Link]("No equilibrium indices found.");

else [Link]();

[Link]();

Common questions

Powered by AI

The time complexity class O(n log n) is encountered in efficient sorting algorithms like merge sort and average-case quicksort, where n represents the number of elements to sort and log n arises from the nature of divide-and-conquer approaches. O(n^2) complexity is typical in simpler sorting algorithms like bubble sort and insertion sort, whose nested loops make them less efficient for larger inputs. The implications of higher time complexity include increased processing time and reduced feasibility for large datasets, notably in real-time applications where performance is critical .

Only specific sentence termination characters like '.', '?', and '!' are considered valid in the Pangram checking example to ensure a proper sentence structure and maintain the focus on content over syntax errors. This restriction enables the algorithm to function predictably without false negatives due to improper sentence endings. It affects the logic by setting a clear boundary for acceptable input, allowing character analysis for pangram detection to proceed uninterrupted .

Redundant groups in a Karnaugh Map do not affect the final simplified Boolean expression because the minterms they cover are already addressed by other essential groups. Their presence can lead to more complex expressions, so they are removed to maintain the expression in its simplest form, optimizing logic circuit designs .

Java uses call by value for primitives because it passes a copy of the variable's value to the method, ensuring the original value remains unchanged outside the method scope. For objects, Java doesn't pass the actual object but a reference to it (a copy of the reference value). Thus, while the reference itself is passed by value, the object it points to can be modified, which reflects changes outside the method, making it behave similarly to call by reference in effect .

Polymorphism in Java is implemented in two ways: compile-time polymorphism and runtime polymorphism. Compile-time polymorphism is achieved through method overloading, where multiple methods have the same name but different parameter lists. Runtime polymorphism is implemented through method overriding, where a subclass provides a specific implementation of a method that is already defined in its superclass. This allows for dynamic method dispatch, where the method execution is determined at runtime .

An equilibrium index in an array is a position where the sum of elements before it equals the sum of elements after it. To determine the equilibrium index efficiently, the total sum of the array is computed first. Then, iteratively traverse the array, maintaining a running sum of the left side. At each index, compute the right side by subtracting the left sum and the element itself from the total. If left and right sums are equal, the index is an equilibrium index. This method efficiently identifies this index without recalculating sums from scratch, optimizing the process .

Maintaining balance in a Binary Search Tree is crucial to ensure operations such as search, insert, and delete are performed in logarithmic time O(log n). This ensures efficiency regardless of the sequence of operations. The two primary types of balanced Binary Search Trees are AVL trees and Red-Black trees, both of which guarantee that the height difference between left and right subtrees is kept minimal .

Static methods in Java are significant because they can be called without creating an instance of the class, which means they belong to the class itself rather than any object instance. This contrasts with instance methods, which require creating an instance of the class to be called, and they operate on the data of the instance .

Different types of inheritance are used in Java to achieve code reuse and establish hierarchical relationships between classes. Single inheritance is used when a class inherits from one superclass, while multilevel and hierarchical inheritance involve multi-tiered levels. Multiple inheritance is not supported by classes due to the complexity and ambiguity in method resolution that arise; however, it is supported by interfaces, allowing a class to implement multiple interfaces and thereby achieve multiple inheritance without those issues .

Gray Code is used in K-Maps to ensure that adjacent cells differ by only one bit change, which simplifies the process of grouping and identifying essential groups in K-Maps for minimization of Boolean expressions .

You might also like