The border of a string is a substring which is both a proper prefix and proper suffix of the string — "proper" meaning that the whole string does not count as a substring. The longest border of x is "ab". The longest border of y is "abab" (the prefix and suffix can overlap). More de
We can use level order traversal for solving this problem. The only change required in level order traversal is, instead of printing the date we just need to check whether the root data is equal to the element we want to search. source: Data Structures and Algorithms Made Easy in Jav
We could have used either PreOrder, InOrder or PostOrder traversal to find the maximum in a Tree but as it is mentioned that we need to find the maximum without using Recursion. Using Level Order Traversal we can find the Maximum element. We just need to observe the elements data while de
Trees can also be traversed in level-order, where we visit every node on a level before going to a lower level. This search is referred to as a breadth-first search (BFS), as the search tree is broadened as much as possible on each depth before going to the next depth. Java implementation
PostOrder Traversal is different from InOrder Traversal and PreOrder Traversal. In this Traversal approach we first traverse through left and then right and at the end, we traverse to the node data. In PostOrder traversal, the root is visited after both subtrees. PostOrder traversal is de
The Technique for traversal in an Inorder is slightly different from what we were doing in PreOrder Traversal. Here we go through left node, then data and then the right node. In an InOrder traversal, the root is visited between the subtrees. InOrder traversal is defined as follows:
In pre-order traversal, each node is processed before (pre) either of it's sub-trees. This is the simplest traversal to understand. However, even though each node is processed before the subtrees, it still requires that some information must be maintained while moving down the tree. Preor
A tree is a data structure similar to a linked list but instead of each node pointing simply to the next node in a linear fashion, each node points to a number of nodes. A tree is an example of non-linear data structures. A Tree structure is a way of representing the hierarchical nature of a stru
A queue is a data structure used for storing data (similar to Linked Lists and Stacks). In a queue, the order in which data arrives is important. In general, a queue is a line of people or things waiting to be served in sequential order starting at the beginning of the line or sequence. A
It is required to create a method getMinimum() which will give us the minimum in the current stack in O(1) time complexity. we will be using another stack for this to store the minimum at any particular point in time. We will take an auxiliary stack that maintains the minimum of all value
A stack is a simple data structure used for storing data (similar to Linked Lists). In stack the order in which the data arrives is important. The pile of plates of a cafeteria is a good example of a stack. The plates are added to the stack as they are cleaned. They are placed on the top. When a
A linked list is a data structure used for storing collections of data. A linked list has the following properties. - Successive elements are connected by pointers - The last element points to NULL - Can grow or shrink in size during execution of a program - Can be