Lab manual generator
One aim goes in. Theory, algorithm, code, output and a submission-ready PDF come out — numbered, sectioned, and branded with your institution.
Free to start · No card · 20+ languages
Drafting
practical_preview.pdf
To construct a binary search tree from a set of integer keysand print them in ascending order using in-order traversal.
A binary search tree is a rooted tree in which every node'sleft subtree holds smaller keys and its right subtree larger.The invariant holds at every node, so an in-order walk sorts.
class Node: def __init__(self, key): self.key = key self.left = self.right = Nonedef insert(root, key): if root is None: return Node(key) return root
To prepare a raw sales dataset for analysis and calculatemonthly revenue totals with percentage growth between periods.
Data cleaning removes missing or inconsistent observations beforeaggregation. Grouped summaries reveal patterns across time, whilepercentage change makes growth comparable between adjacent periods.
import pandas as pddata = pd.read_csv("sales.csv")data = data.dropna()monthly = data.groupby("month")revenue = monthly["revenue"].sum()growth = revenue.pct_change()print(growth)
To summarize packet-source frequency from a network captureand flag hosts that exceed a defined traffic threshold.
Traffic analysis groups packets into measurable communicationpatterns. Unusually frequent sources can indicate scanning, denialof service attempts, or a misconfigured application on the network.
from collections import Counterdef flag_sources(packets): sources = Counter( packet["src"] for packet in packets) return [source for source, hits in sources.items() if hits > 100]print(flag_sources(packets))
To train a supervised classification model on labelled dataand measure its predictive accuracy on an unseen test split.
A decision tree learns a hierarchy of feature-based rules fromlabelled examples. Evaluation on held-out data estimates whetherthose rules generalize beyond the observations used for training.
from sklearn.tree import DecisionTreeClassifiermodel = DecisionTreeClassifier( max_depth=4)model.fit(x_train, y_train)predictions = model.predict(x_test)score = model.score(x_test, y_test)print(f"Accuracy: {score:.2%}")
To accept operands and an operator from the user, validate eachchoice, and display the calculated result in a repeatable menu.
Interactive programs separate input, validation and calculation soinvalid values can be handled without terminating the application.A menu loop lets the user perform several operations in one session.
Scanner in = new Scanner(System.in);boolean running = true;while (running) { System.out.print("Choose +, -, *, / or q: "); String choice = in.next(); if (choice.equals("q")) break; System.out.println(calculate(choice, in));
To improve image contrast by redistributing grayscale intensityvalues and compare the original and enhanced histograms.
Histogram equalization maps pixel intensities through the cumulativedistribution function. The transformed values use more of the availablerange, which can reveal detail in low-contrast regions of an image.
import cv2import matplotlib.pyplot as pltimage = cv2.imread("sample.png", 0)enhanced = cv2.equalizeHist(image)plt.subplot(1, 2, 1)plt.imshow(image, cmap="gray")plt.imshow(enhanced, cmap="gray")