Dsa Programs
Dsa Programs
class Node {
int data;
this.data = data;
if (head == null) {
head = newNode;
} else {
current = current.next;
current.next = newNode;
newNode.prev = current;
1. START
2. Create a node to store the data
3. Check if the list is empty
4. If the list is empty, add the data to the node and assign the head pointer to it.
5 If the list is not empty, add the data to a node and link to the current head. Assign the head to
the newly added node.
6. END
1 − START
2 – Check if the queue is full.
3 − If the queue is full, produce overflow error and exit.
4 − If the queue is not full, increment rear pointer to point the next empty space.
5 − Add data element to the queue location, where the rear is pointing.
6 − return success.
7 – END
Tree Implementation : tree needs to just explain whereas if ask about specific tree then
implementation and algo must write there
Binary tree implementation
class Node {
int key;
class BinaryTree {
// Constructors
BinaryTree(int key) { root = new Node(key); }
BinaryTree() { root = null; }
public static void main(String[] args)
{
BinaryTree tree = new BinaryTree();
// Create root
tree.root = new Node(1);
/* Following is the tree after above statement
1
/ \
null null
*/
1. START
2. Check whether the tree is empty or not
3. If the tree is empty, search is not possible
4. Otherwise, first search the root of the tree.
5. If the key does not match with the value in the root, search its subtrees.
6. If the value of the key is less than the root value, search the left subtree
7. If the value of the key is greater than the root value, search the right subtree.
8. If the key is not found in the tree, return unsuccessful search.
9. END
AVL Tree
Algo :