Java Binary Tree and Graph Algorithm Practice
Practice Problems
1. Check if a Binary Tree is a Mirror of Itself
The idea is to write a recursive function isMirror() that takes two trees as arguments and returns true if the trees are mirrors and false if they are not. The isMirror() function recursively checks two roots and the subtrees under those roots.
// Java program to check if a binary tree is symmetric or not
class Node {
int key;
Node left, right;
Node(int item) {
key = item;
left = right = null;
}
} Read More
Deep Learning for Audio and Speech Processing
Motivation for Deep Learning in Audio Processing
Why DL4ASP? Why use deep learning to analyze audio and speech? An audio file or stream consists of two main parts:
- Header: Contains metadata such as the file name, path, number of channels, sample frequency, and duration.
- Content: The actual sound data. It is unstructured binary data (0s and 1s). Without analysis, we do not know if it is music or voice; to understand the sound, you have to listen to it all.
The content is raw and complex, motivating the
Read MoreDatabase Recovery Mechanisms Using Transaction Logs
Log-Based Recovery in DBMS
Log-based recovery is a mechanism used in DBMS to restore the database to a consistent state after a system crash or failure. The system maintains a log file stored on stable storage, recording every transaction’s operations before applying them to the database. Each log entry contains the transaction ID, data item name, old value, and new value. Using these logs, the DBMS can reconstruct the database by either undoing incomplete transactions or redoing completed ones.
Major
Read MoreArray-Based Java Queue Implementation with Example
Array-Based Java Queue Example
Corrected Java Queue Code
The following Java classes implement a simple array-based queue and a tester. Spelling, grammar, and capitalization in comments and output strings have been corrected while preserving all original code logic and content.
class Queue {
private int front; // Front is the index of the first element in the queue
private int rear; // Rear is the index of the last element in the queue
private int maxSize; // maxSize represents the maximum number Read More
Data Structures and Algorithms: Core Concepts and Comparisons
Graph and Tree Structures Fundamentals
Difference between Tree and Graph
The fundamental differences between trees and graphs are summarized below:
| Feature | Tree | Graph |
|---|---|---|
| Structure | A tree is a hierarchical structure containing a root and several levels of child nodes. | A graph is a network structure containing vertices and edges without any fixed hierarchical arrangement. |
| Cycles | A tree never contains cycles because it maintains a strict parent-child relationship across all nodes. | A graph can freely contain cycles |
C++ Data Structures: Circular List, AVL Rotations, DFS & Palindrome
Create and Display a Circular Singly Linked List
In a circular singly linked list, the last node’s next pointer points back to the head instead of NULL.
C++
// struct definition
struct Node {
int data;
Node* next;
};
// Function to insert a node (Creating the list)
void insertEnd(Node*& head, int value) {
Node* newNode = new Node();
newNode->data = value;
if (head == NULL) {
head = newNode;
newNode->next = head; // Points to itself
Read More
