Java
code
Given two sorted arrays, X[] and Y[] of size m and n each, merge elements of X[] with elements of array Y[] by maintaining the sorted order, i.e., fill X[] with the first m smallest elements and fill Y[] with remaining elements.
#Data_structure
#Data_structure
The idea is to traverse both trees and compare values at their root node. If the value matches, recursively check if the first tree’s left subtree is identical to the left subtree of the second tree and the right subtree of the first tree is identical to the right subtree of the second tree. If the value at their root node differs, the trees violate data property. If at any point in the recursion, the first tree is empty and the second tree is non-empty, or the second tree is empty and the first tree is non-empty, the trees violate structural property, and they cannot be identical.
#Data_structure
#Source_code
#Data_structure
#Source_code
Check if a string is a rotated palindrome or not
A naive solution is to consider all rotations of the given string and check if any rotation is a palindrome or not. If we have found a rotation that is a palindrome, return true; otherwise, return false.
#Source_code
#Data_structure
A naive solution is to consider all rotations of the given string and check if any rotation is a palindrome or not. If we have found a rotation that is a palindrome, return true; otherwise, return false.
#Source_code
#Data_structure
code.png
563.4 KB
Determine whether a string matches with a given pattern.
Given a string and a pattern, determine whether a string matches with a given pattern. The solution should not use any regex.
#Source_code
#Data_structure
#84
Given a string and a pattern, determine whether a string matches with a given pattern. The solution should not use any regex.
#Source_code
#Data_structure
#84
Java
code.png
#Data_structure
#Output
#84
Example inputs for a given Data Structure:
Input:
string: codesleepcode
pattern: XYX
Output:
X: code
Y: sleep
Input:
string: codecodecode
pattern: XXX
Output:
X: code
#Output
#84
Example inputs for a given Data Structure:
Input:
string: codesleepcode
pattern: XYX
Output:
X: code
Y: sleep
Input:
string: codecodecode
pattern: XXX
Output:
X: code
code.png
686.8 KB
Java program to find the maximum and minimum value node from a doubly linked list.
#Source_code
#Doubly_linked_list
#Data_structure
#Source_code
#Doubly_linked_list
#Data_structure
Find the missing term in a sequence in logarithmic time
Given the missing term in a sequence in logarithmic time
#Source_code
#Data_structure
#132
Given the missing term in a sequence in logarithmic time
#Source_code
#Data_structure
#132
code.png
479.9 KB
When looking for a place to insert a new key, traverse the tree from root-to-leaf, making comparisons to keys stored in the tree’s nodes and deciding based on the comparison to continue searching in the left or right subtrees. In other words, we examine the root and recursively insert the new node to the left subtree if its key is less than that of the root or the right subtree if its key is greater than or equal to the root.
#Source_code
#Data_structure
#Recursion_Version
#135
#Source_code
#Data_structure
#Recursion_Version
#135