UNIT 5: INTELLIGENT SYSTEMS & PROGRAMMING FOR E-COMMERCE & GOVERNANCE
A. ARTIFICIAL INTELLIGENCE FOUNDATIONS
1. Problem Solving & Search Strategies
Uninformed Search Algorithms
-
Breadth-First Search (BFS)
-
Explores all neighbors at current depth before moving deeper.
-
Uses a queue (FIFO).
-
Complete (finds solution if exists) and optimal for uniform cost.
-
Time Complexity: $$\displaystyle O(b^d) $$, Space Complexity: $$\displaystyle O(b^d) $$ (where $b$ = branching factor, $d$ = depth).
-
-
Depth-First Search (DFS)
-
Explores as far as possible along a branch before backtracking.
-
Uses a stack (LIFO), can be implemented recursively.
-
Not complete (may get stuck in infinite loops), not optimal.
-
Time Complexity: $$\displaystyle O(b^m) $$, Space Complexity: $O(bm)$ (where $m$ = maximum depth).
-
[!TIP] Exam Focus: BFS is memory-intensive; DFS is time-intensive. BFS guarantees shortest path in unweighted graphs.
Comparative Analysis: DFS vs BFS
| Feature | BFS | DFS |
|---|---|---|
| Data Structure | Queue | Stack (Recursion) |
| Completeness | Yes (if finite branching) | No (infinite paths) |
| Optimality | Yes (unit cost) | No |
| Space Complexity | $$\displaystyle O(b^d) $$ | $O(bm)$ |
| Time Complexity | $$\displaystyle O(b^d) $$ | $$\displaystyle O(b^m) $$ |
| Use Case | Shortest path, Web crawling | Maze solving, Topological sort |
Informed Search (Heuristic Search)
-
A Algorithm*
-
Evaluates nodes by $$\displaystyle f(n) = g(n) + h(n) $$.
-
$g(n)$: actual cost from start to node $n$.
-
$h(n)$: heuristic estimated cost from $n$ to goal.
-
-
Admissible heuristic: $h(n)$ never overestimates true cost ($$\displaystyle h(n) \leq h^*(n) $$).
-
Optimal: If $h(n)$ is admissible and consistent (monotonic), A* finds optimal path.
-
Example: 8-Puzzle with:
-
Misplaced Tiles: $h(n)$ = number of tiles not in goal position.
-
Manhattan Distance: $h(n)$ = sum of distances of each tile from its goal position (horizontal + vertical).
-
-
Local Search Algorithms
-
Hill Climbing
-
Greedy algorithm; moves to neighbor with best heuristic value.
-
Types:
-
Steepest-Ascent: Evaluate all neighbors, move to best.
-
First-Choice: Move to first better neighbor.
-
Stochastic: Randomly select neighbor, move if better.
-
-
Problems:
-
Local Maxima: Peak higher than neighbors but not global.
-
Plateaus: Flat area where all neighbors have same value.
-
Ridges: Sequence of local maxima.
-
-
[!TIP] Exam Tip: Hill climbing is incomplete; often used for optimization problems like circuit design.
-
Game Theory & Adversarial Search
-
Min-Max Algorithm
-
Used in two-player, zero-sum games (e.g., Tic-Tac-Toe, Chess).
-
Max player aims to maximize score; Min player minimizes it.
-
Explores game tree; assumes both players play optimally.
-
Value of a node: $$\displaystyle \text{MinMax}(node) = \begin{cases} \text{Utility}(node) & \text{if terminal} \\ \max_{child} \text{MinMax}(child) & \text{if Max's turn} \\ \min_{child} \text{MinMax}(child) & \text{if Min's turn} \end{cases} $$
-
-
Alpha-Beta Pruning
-
Optimizes Min-Max by pruning branches that cannot affect final decision.
-
Alpha ($\alpha$): Best (highest) value found so far for Max.
-
Beta ($\beta$): Best (lowest) value found so far for Min.
-
Prune when $\alpha \geq \beta$.
-
2. Knowledge Representation (KR)
Properties of a Good KR Scheme
-
Representational Adequacy: Express all required knowledge.
-
Inferential Adequacy: Derive new knowledge efficiently.
-
Inferential Efficiency: Guide inference process.
-
Acquisitional Efficiency: Easy to acquire new knowledge.
-
Clarity & Understandability.
KR Techniques
-
Predicate Logic (First-Order Logic)
-
Syntax: Predicates, variables, constants, quantifiers, connectives.
-
Quantifiers:
-
Universal ($\forall$): "For all"
-
Existential ($\exists$): "There exists"
-
-
Translation Examples:
-
"Everybody loves Ram": $\forall x \; \text{Loves}(x, \text{Ram})$
-
"Everybody loves somebody": $\forall x \; \exists y \; \text{Loves}(x, y)$
-
"There is somebody whom everybody loves": $\exists y \; \forall x \; \text{Loves}(x, y)$
-
"There is somebody who Ram doesn't love": $\exists x \; \neg \text{Loves}(\text{Ram}, x)$
-
"There is somebody whom no one loves": $\exists x \; \forall y \; \neg \text{Loves}(y, x)$
-
-
-
Production Rules
-
Structure:
IF <condition> THEN <action>. -
Characteristics:
-
Modularity: Rules are independent.
-
Simplicity: Easy to understand.
-
Knowledge-Intensive: Encodes expert knowledge.
-
Used in expert systems (e.g., MYCIN).
-
-
-
Semantic Networks
-
Graph-based: Nodes = objects/concepts, Edges = relationships.
-
Represents facts:
(Dog)-[is a]->(Animal). -
Supports inheritance and reasoning via path traversal.
-
-
Frames & Scripts
-
Frames: Structured objects with slots (attributes) and default values.
-
Scripts: Frames for stereotypical events (e.g., "restaurant script").
-
Fuzzy Logic & Sets
-
Fuzzy Set: Defined by membership function $$\displaystyle \mu_A(x) \in [0,1] $$.
-
Operations (for sets A, B):
-
Union: $$\displaystyle \mu_{A \cup B}(x) = \max(\mu_A(x), \mu_B(x)) $$
-
Intersection: $$\displaystyle \mu_{A \cap B}(x) = \min(\mu_A(x), \mu_B(x)) $$
-
Complement: $$\displaystyle \mu_{\neg A}(x) = 1 - \mu_A(x) $$
-
Difference: $$\displaystyle A - B = A \cap \neg B $$, so $$\displaystyle \mu_{A-B}(x) = \min(\mu_A(x), 1-\mu_B(x)) $$
-
[!TIP] Exam Focus: Fuzzy operations are element-wise. Given $$\displaystyle A = 1/x_1 + 0.3/x_2 + 0.5/x_3 + 0.2/x_4 $$, $$\displaystyle B = 0.5/x_1 + 0.4/x_2 + 0.1/x_3 + 1/x_4 $$:
- Union: $$\displaystyle A \cup B = 1/x_1 + 0.4/x_2 + 0.5/x_3 + 1/x_4 $$
- Intersection: $$\displaystyle A \cap B = 0.5/x_1 + 0.3/x_2 + 0.1/x_3 + 0.2/x_4 $$
- Difference: $$\displaystyle A - B = 0.5/x_1 + 0.3/x_2 + 0.4/x_3 + 0.2/x_4 $$
- Complement A: $$\displaystyle \neg A = 0/x_1 + 0.7/x_2 + 0.5/x_3 + 0.8/x_4 $$
3. Reasoning & Inference Mechanisms
Reasoning Types
-
Forward Reasoning (Data-Driven)
-
Starts with known facts, applies rules to derive new facts.
-
Example: Medical diagnosis: Symptoms → Rules → Disease.
-
Use: Monitoring, Control systems.
-
-
Backward Reasoning (Goal-Driven)
-
Starts with goal/hypothesis, works backward to find supporting facts.
-
Example: Prove "X has disease" → find symptoms supporting it.
-
Use: Expert systems, Problem-solving.
-
-
Comparison:
| Aspect | Forward Reasoning | Backward Reasoning | |-----------------|-------------------------|-------------------------| | Control | Data-driven | Goal-driven | | Efficiency | May generate irrelevant facts | More focused | | Use Case | Real-time systems | Diagnostic systems |
Logical Inference
-
Resolution Technique
-
Rule of inference for Propositional Logic.
-
Converts statements to Clause Form (disjunction of literals).
-
Resolves two clauses containing complementary literals.
-
Principle: If $(A \lor x)$ and $(B \lor \neg x)$, then resolve to $(A \lor B)$.
-
Used in automated theorem proving (e.g., Prolog).
-
Reasoning Paradigms
-
Monotonic Reasoning: Adding knowledge never retracts conclusions. Classical logic.
-
Non-Monotonic Reasoning: New evidence can invalidate previous conclusions. Used in default reasoning, diagnosis (e.g., "Birds fly" unless "Penguin").
4. Application Areas & Case Studies
Expert Systems
-
Components:
-
Knowledge Base: Facts & rules (production rules).
-
Inference Engine: Applies rules (forward/backward chaining).
-
User Interface: Interaction with user.
-
Explanation Facility: Explains reasoning.
-
Knowledge Acquisition Tool: For adding rules.
-
-
Development Process: Identify problem → Acquire knowledge → Design KB → Implement & Test → Maintain.
-
Applications in E-Governance: Tax assessment, permit approval, fraud detection.
Bayes' Theorem
-
Statement: $$\displaystyle P(A|B) = \frac{P(B|A) \cdot P(A)}{P(B)} $$
-
$P(A|B)$: Posterior probability of A given B.
-
$P(A)$: Prior probability.
-
-
Application: Probabilistic reasoning in uncertain environments (e.g., spam filtering, medical diagnosis).
Natural Language Understanding (NLU)
-
Components:
-
Syntax: Grammatical structure (parsing).
-
Semantics: Meaning of words/sentences.
-
Pragmatics: Contextual meaning, speaker intent.
-
-
Process: Tokenization → Parsing → Semantic analysis → Pragmatic interpretation.
B. JAVA PROGRAMMING FOR E-COMMERCE APPLICATIONS
1. Core Java & OOP
Java Fundamentals (OOP Features)
-
Encapsulation: Bundling data + methods; use
privatevariables + getters/setters. -
Inheritance:
extendskeyword; single inheritance for classes. -
Polymorphism: Method overriding (runtime), overloading (compile-time).
-
Abstraction:
abstractclasses/interfaces; hide implementation. -
static: Class-level (method/variable); belongs to class, not object. -
final: Constant (variable), non-overridable (method), non-inheritable (class).
Classes, Objects & Constructors
-
Constructor: Special method same name as class, no return type.
-
Types:
-
Default: No args, provided by JVM if none defined.
-
Parameterized: Takes arguments.
-
Copy Constructor: Takes object of same class (Java doesn't have built-in; implement manually).
-
-
-
Example: Area of Circle using Constructor
class Circle {
double radius;
Circle(double r) { radius = r; }
double area() { return Math.PI * radius * radius; }
}
Inheritance & Polymorphism
-
Method Overloading: Same method name, different parameters (compile-time).
-
Method Overriding: Same signature in subclass (runtime).
-
Dynamic Method Dispatch: Superclass reference calls subclass method at runtime.
| Feature | Overloading | Overriding |
|---|---|---|
| Parameters | Must differ | Must match |
| Return Type | Can differ | Must match (or covariant) |
| Access Modifier | Can change | Cannot reduce visibility |
| Static Methods | Can overload | Cannot override (static binding) |
| Private Methods | Can overload | Not inherited, so not overriding |
Abstract Classes & Interfaces
-
Abstract Class: Can have abstract (no body) and concrete methods; single inheritance.
-
Interface: All methods
public abstractby default (Java 8+ allowsdefault/staticmethods); multiple inheritance. -
Use Interface for defining contracts; abstract class for shared code.
2. Exception Handling & I/O Operations
Exception Handling
-
Keywords:
-
try: Block where exception may occur. -
catch: Handles exception. -
throw: Throws exception explicitly. -
throws: Declares exception in method signature. -
finally: Always executes (cleanup).
-
-
Assertions:
assert condition;orassert condition : message;; enable with-eaflag.
Java I/O Streams
-
Byte Streams (
InputStream,OutputStream): For binary data (images, files). -
Character Streams (
Reader,Writer): For text data (Unicode). -
File Copy using Character Streams:
try (FileReader fr = new FileReader("input.txt");
FileWriter fw = new FileWriter("output.txt")) {
int c;
while ((c = fr.read()) != -1) fw.write(c);
}
3. Multithreading & Synchronization
Thread Fundamentals
-
Creation:
-
Extend
Threadclass, overriderun(). -
Implement
Runnableinterface, pass toThreadconstructor (preferred).
-
-
Lifecycle: New → Runnable → Running → Blocked/Waiting → Terminated.
Thread Coordination
-
Inter-Thread Communication:
wait(),notify(),notifyAll()must be called inside synchronized block. -
Example:
synchronized(obj) {
while(condition) obj.wait();
// work
obj.notify();
}
- Synchronization:
synchronizedkeyword on method/block ensures only one thread accesses resource.
Practical Multithreading
- Program: Three threads with different intervals
class MyThread extends Thread {
String msg; int interval;
MyThread(String m, int i) { msg=m; interval=i; }
public void run() {
while(true) {
System.out.println(msg);
try { Thread.sleep(interval*1000); }
catch(InterruptedException e) {}
}
}
}
// In main: new MyThread("Hello!",1).start(); etc.
4. GUI Programming (AWT & Swing)
Event-Driven Programming
-
Event Source: Component generating event (e.g.,
JButton). -
Event Listener: Interface (e.g.,
ActionListener) with methodactionPerformed(ActionEvent e). -
Implementation:
button.addActionListener(this);
Swing Program: Sum of Two Numbers
import javax.swing.*;
import java.awt.event.*;
public class SumGUI extends JFrame implements ActionListener {
JTextField t1, t2, res;
JButton b;
SumGUI() {
t1=new JTextField(10); t2=new JTextField(10); res=new JTextField(10);
b=new JButton("Sum"); b.addActionListener(this);
add(t1); add(t2); add(b); add(res);
setLayout(new java.awt.FlowLayout());
setSize(300,200); setVisible(true);
}
public void actionPerformed(ActionEvent e) {
int a=Integer.parseInt(t1.getText());
int b=Integer.parseInt(t2.getText());
res.setText(String.valueOf(a+b));
}
public static void main(String[] args) { new SumGUI(); }
}
5. Applets & Java Beans
Applets
-
Life Cycle:
-
init(): First call; initialize. -
start(): Afterinit(), each time applet becomes visible. -
stop(): When applet is not visible. -
destroy(): Final cleanup; before garbage collection.
-
Java Beans
-
Introspection: Analyzing bean properties/methods at runtime.
-
BeanInfo Interface: Provides explicit bean information (property descriptors, event sets).
-
Properties: Access via getter/setter (
getX(),setX()). -
Events: Follows delegation model (source → listener).
6. Database Connectivity & Networking
JDBC (Java Database Connectivity)
Basic Steps:
-
Load Driver:
Class.forName("com.mysql.jdbc.Driver"); -
Establish Connection:
Connection con = DriverManager.getConnection(url, user, pass); -
Create Statement:
Statement stmt = con.createStatement(); -
Execute Query:
ResultSet rs = stmt.executeQuery("SELECT * FROM table"); -
Process ResultSet:
while(rs.next()) { ... } -
Close Resources:
rs.close(); stmt.close(); con.close();
- JDBC-ODBC Bridge: Type 1 driver; uses ODBC driver to connect to DB (deprecated in Java 8+).
Client-Server Communication (Socket Programming)
- Server:
ServerSocket ss = new ServerSocket(1234);
Socket s = ss.accept();
BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
PrintWriter out = new PrintWriter(s.getOutputStream(), true);
// Read/Write
- Client:
Socket s = new Socket("localhost", 1234);
BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
PrintWriter out = new PrintWriter(s.getOutputStream(), true);
7. Advanced Java Features & JNDI
Garbage Collection
-
Mechanism: JVM automatically reclaims memory from unreachable objects.
-
System.gc(): Suggests GC; not guaranteed. -
Finalization:
protected void finalize()called before object is garbage collected (rarely used; unpredictable).
JNDI (Java Naming and Directory Interface)
-
Purpose: Access naming/directory services (LDAP, DNS).
-
Key Methods:
-
Context.bind(String name, Object obj): Bind object to name. -
Context.rebind(String name, Object obj): Replace binding. -
Context.createSubcontext(String name): Create subcontext. -
DirContext.getAttributes(String name): Retrieve attributes. -
DirContext.modifyAttributes(String name, int op, Attributes attrs): Modify attributes.
-
8. Packages & Access Control
Package Creation & Usage
-
Create:
package com.mypackage;(first statement in file). -
Directory structure:
com/mypackage/ClassName.java. -
Import:
import com.mypackage.*;or specific class.
Access Protection Levels
| Modifier | Class | Package | Subclass (same pkg) | Subclass (diff pkg) | World |
|---|---|---|---|---|---|
public |
✅ | ✅ | ✅ | ✅ | ✅ |
protected |
✅ | ✅ | ✅ | ✅ | ❌ |
| default | ✅ | ✅ | ✅ | ❌ | ❌ |
private |
✅ | ❌ | ❌ | ❌ | ❌ |
C. INTEGRATED APPLICATIONS FOR E-COMMERCE & GOVERNANCE
1. Intelligent Agent Design
-
Example: Water Jug Problem (4-gallon & 3-gallon) using Production Rules.
-
State: $(x,y)$ where $x$=water in 4-gal, $y$=water in 3-gal.
-
Rules:
-
Fill 4-gal: $$\displaystyle (x,y) \rightarrow (4,y) $$ if $$\displaystyle x<4 $$.
-
Fill 3-gal: $$\displaystyle (x,y) \rightarrow (x,3) $$ if $$\displaystyle y<3 $$.
-
Empty 4-gal: $$\displaystyle (x,y) \rightarrow (0,y) $$ if $$\displaystyle x>0 $$.
-
Empty 3-gal: $$\displaystyle (x,y) \rightarrow (x,0) $$ if $$\displaystyle y>0 $$.
-
Pour 4→3: $$\displaystyle (x,y) \rightarrow (\max(0,x-(3-y)), \min(3,x+y)) $$ if $$\displaystyle x>0, y<3 $$.
-
Pour 3→4: $$\displaystyle (x,y) \rightarrow (\min(4,x+y), \max(0,y-(4-x))) $$ if $$\displaystyle y>0, x<4 $$.
-
-
Goal: $(2, *)$.
-
Solution: $$\displaystyle (0,0) \xrightarrow{\text{Fill4}} (4,0) \xrightarrow{\text{Pour4→3}} (1,3) \xrightarrow{\text{Empty3}} (1,0) \xrightarrow{\text{Pour4→3}} (0,1) \xrightarrow{\text{Fill4}} (4,1) \xrightarrow{\text{Pour4→3}} (2,3) $$.
-
2. Knowledge-Based Systems Development
-
Java Implementation: Use
Map<String, List<String>>for rules (IF-THEN). -
Inference Engine: Forward chaining loop: match facts with rule conditions, fire rule, assert new facts.
3. Heuristic Search Implementation
-
A in Java for Logistics*:
-
Represent graph as adjacency list.
-
Nodeclass withg,h,f = g+h, parent. -
Use
PriorityQueue<Node>ordered byf. -
Reconstruct path from goal node via parent pointers.
-
4. Multithreaded E-Commerce Servers
-
Design:
ServerSocketaccepts connections; each connection handled by newThread(or thread pool). -
Example:
ExecutorService pool = Executors.newFixedThreadPool(10);to limit threads. -
Synchronization: Shared resources (e.g., inventory) accessed via
synchronizedblocks orReentrantLock.
END OF UNIT 5 NOTES
Aligned with RGPV past papers (AI Nov 2022, Java Dec 2024, Java Nov 2022).