Semester 4 Labs | BTech CSE Practical Guide
Semester 4 - Page 6: Labs. 25 numbered practical topics, worked examples, answered viva questions, record/test templates, diagrams and one complete route-reconstruction program. General common-core practice guide, not an official experiment list or assessment format. Follow your assigned tools,department format and instructor safety rules.
Topic map
- Experiment contract and evidence
- Reproducible setup and privacy
- Java objects and library state
- Java exception and boundary tests
- Collections, equality and files
- Algorithm test graphs and representation
- BFS for fewest edges
- Dijkstra for minimum nonnegative cost
- Sort,search and complexity evidence
- Greedy versus DP experiment
- DP states and reconstruction
- DFA transition table
- DFA simulation and oracle comparison
- NFA and regular-expression comparison
- Stack and grammar exercise
- PHP CLI validation exercise
- PHP escaping and security separation
- PDO persistence and duplicate constraints
- HTTP/session/CSRF integration plan
- Combinational logic truth-table lab
- K-map and equivalent expression test
- Two-bit counter simulation
- Hardware timing and safe observations
- Integrated project boundaries
- Submission and viva readiness
1. Experiment contract and evidence
Write aim,inputs,outputs,assumptions,versions and success criteria before the exercise. Expected and observed results are different records; never invent measurements or screenshots.
Answer: Yes, if it is reported honestly with the failure analysis and the required format is followed.
Aim + contract -> prediction + procedure -> actual evidence -> comparison + limitation
2. Reproducible setup and privacy
Keep source,run commands,software versions and synthetic input together. Never include passwords,session IDs or private student records in public examples or repositories.
Answer: It does not reproduce code,input,environment or the route to the result.
3. Java objects and library state
Model one physical book copy with a distinct inventory ID, and keep checkout/return rules in methods. Identity and availability are not inferred from a title string.
Answer: It keeps invalid transitions from being scattered across caller code.
4. Java exception and boundary tests
Test successful issue,duplicate issue,unknown ID and return-before-issue. Explain the error contract and leave state unchanged when an operation fails.
Answer: Expected invalid-input exceptions can be part of the contract; unexpected failures need separate investigation.
5. Collections, equality and files
Choose collection keys deliberately,define equality/hash consistently and close resources. Immutable inventory IDs are safer keys than mutable titles. File exercises need controlled paths and cleanup.
Answer: Changing equality/hash fields can move its logical bucket while stored placement remains unchanged.
6. Algorithm test graphs and representation
State directedness,weights,vertex labels and unreachable policy. Adjacency lists support efficient traversal; a disconnected vertex must remain visible in the input.
Answer: It tests unreachable output and prevents assuming every vertex has a path.
7. BFS for fewest edges
BFS uses a FIFO queue and marks vertices on discovery. On unweighted graphs it finds minimum edge counts; it does not minimize arbitrary weighted cost.
Answer: It can be queued repeatedly by different predecessors, increasing work and complicating parent tracking.
8. Dijkstra for minimum nonnegative cost
Dijkstra needs nonnegative weights and minimum-distance extraction. Track predecessors for a route and skip stale queue entries in lazy-heap implementations.
Answer: No. Shortest paths minimize source-to-vertex distances; an MST minimizes total connecting edge weight.
Shortest route with predecessor reconstruction
from heapq import heappush, heappop
from math import inf
def route(graph, source, target):
if source not in graph or target not in graph:
raise ValueError("unknown endpoint")
if any(v not in graph or type(w) is not int or w < 0
for edges in graph.values() for v, w in edges):
raise ValueError("nonnegative integer edges required")
distance, parent = dict.fromkeys(graph, inf), {}
distance[source] = 0
heap = [(0, source)]
while heap:
d, u = heappop(heap)
if d != distance[u]:
continue
for v, w in graph[u]:
if d + w < distance[v]:
distance[v] = d + w
parent[v] = u
heappush(heap, (d + w, v))
if distance[target] == inf:
return None
path = [target]
while path[-1] != source:
path.append(parent[path[-1]])
return distance[target], path[::-1]
graph = {"H": [("A", 2), ("B", 5)], "A": [("B", 1), ("L", 7)],
"B": [("L", 2)], "L": [], "X": []}
print(route(graph, "H", "L"))
print(route(graph, "H", "X"))
print(route(graph, "H", "H"))
try:
route({"H": [("L", -1)], "L": []}, "H", "L")
except ValueError:
print("negative edge rejected")
Checked output:
(5, ['H', 'A', 'B', 'L']) None (0, ['H']) negative edge rejected
9. Sort,search and complexity evidence
Separate algorithm complexity from benchmark observations. Test empty,duplicate,sorted and reversed input. Binary search assumes sorted random-access data; include preparation cost.
Answer: No. Inputs,machine effects and constants can dominate a small benchmark.
10. Greedy versus DP experiment
Compare a greedy candidate with a brute-force oracle on small inputs before trusting it. A passing experiment is not a proof; write the exchange proof or recurrence.
Answer: Fractional items can be split; whole-item choices cannot.
11. DP states and reconstruction
Define each state precisely and fill dependencies in a valid order. A value-only table does not necessarily store the choices needed to reconstruct the solution.
Answer: It prevents using one0/1 item repeatedly in the same iteration.
12. DFA transition table
Submit alphabet,states,start,final set and every transition. Trace the whole input before accepting; a valid prefix is not the final decision.
Answer: Only the suffix information needed to decide whether the final string ends in AB.
Input BAB q0 --B--> q0 --A--> qA --B--> qAB Accept: final state qAB
13. DFA simulation and oracle comparison
Implement the theoretical transition table faithfully and compare bounded inputs with an independent language predicate. Reject symbols outside the alphabet deliberately.
Answer: No. The state invariant supplies the proof; tests find implementation errors.
14. NFA and regular-expression comparison
An NFA tracks possible states; acceptance needs one successful complete branch. Theoretical regex and NFA can describe the same regular language, but programming regex extensions may differ.
Answer: No. Acceptance is existential over complete runs.
15. Stack and grammar exercise
Use a stack to recognize a^n b^n with all a symbols before b symbols. Compare with the grammar S->aSb or epsilon, and explain push/pop invariants.
Answer: Equal totals alone would incorrectly accept interleaved strings such as abab.
16. PHP CLI validation exercise
Validate scalar shape,format and bounds before conversion. A lab form can send arrays where strings are expected, so server-side checks must reject them.
Answer: No. It tests the chosen validation function,not headers,session cookies or web deployment.
17. PHP escaping and security separation
Escape display text for HTML context,bind SQL values separately and authorize identities independently. CSRF adds another check for browser state changes.
Answer: Each prevents a different kind of mistake; no single sanitizer supplies them all.
18. PDO persistence and duplicate constraints
For a database exercise,declare schema,driver,connection policy and uniqueness rules. Capacity check and insert need a transaction with a concurrency strategy.
Answer: No. Database work is an extension requiring its own driver and integration tests.
19. HTTP/session/CSRF integration plan
A real form test checks authentication,permission,token,validation,transaction and response. Use synthetic accounts and do not publish live credentials or session identifiers.
Answer: No. It reduces refresh repeats; a database rule still enforces uniqueness.
20. Combinational logic truth-table lab
Derive every output row,then simulate the Boolean circuit. A full-adder has eight input rows and must satisfy A+B+Cin=Sum+2Carry.
Answer: No. Its mismatch cases01 and10 are essential.
21. K-map and equivalent expression test
Lay out Gray-code rows/columns and verify the simplified function exhaustively. Include don't-cares only under a valid input assumption.
Answer: No. Adjacent cells differ in exactly one variable under the Gray-code layout.
22. Two-bit counter simulation
Compute next state from the old state,then update both flip-flops together. Reset is a defined operation; document whether it is synchronous or asynchronous.
Answer: D1 would use a new rather than current Q0,changing the intended state machine.
Old state -> next-state logic -> D inputs
clock edge
-> new state23. Hardware timing and safe observations
An ideal simulation does not establish setup/hold,pin compatibility or metastability behavior. Verify exact part datasheets and lab safety rules; power off before rewiring.
Answer: No. The physical part number and package determine the datasheet.
24. Integrated project boundaries
A campus-event demo can combine PHP registration,Java domain modeling,route algorithms and a logic-counter exercise without pretending they are one deployed secure system..
Answer: It prevents classroom assumptions from being mistaken for production guarantees.
25. Submission and viva readiness
Submit readable source,diagrams,test matrix,versions,run steps,actual results and limitations in the required department format. Be ready to explain one failed test and its fix.
Answer: The invariant or rule,an edge case and the reason the method satisfies its contract.
Practical test matrix
| Exercise | Success | Boundary / failure |
|---|---|---|
| Java book checkout | Available known copy issued | Duplicate,unknown ID,invalid return |
| BFS / Dijkstra | Correct route and objective | Isolated,tie,negative edge rejection |
| DFA / NFA | Whole input ends in required suffix | Empty,wrong suffix,invalid symbol |
| PHP validation | Allowed scalar ID and email | Missing,array input,bad format |
| Database extension | Unique committed registration | Duplicate,last-seat race,rollback |
| Counter | Four-state cycle and alarm11 | Reset,timing,invalid wiring conditions |
Lab record template
| Field | What to record |
|---|---|
| Aim / contract | Question,inputs,outputs,assumptions |
| Environment | Version,driver/device,run command |
| Method | Algorithm,circuit,procedure |
| Expected | Calculated result before execution |
| Actual | Observed result and raw evidence |
| Tests | Successful,boundary and failure cases |
| Conclusion | Agreement,limitations,next test |
Linked practicals and references
The subject guides provide complete examples with their own run instructions. Java Lab File programs use Main.java; Java theory demos use Demo.java. Run one whole block at a time. Check your assigned version. New HTTP,database or hardware exercises need independent tests.
Comments
Post a Comment