Skip to main content

Posts

Tree

  Tree Definition of Tree:  Tree is finite set of nodes with one specially designated node called the root   and the remaining nodes are partitioned into n>=0 disjoint sets T1 & Tn which are called the sub-root trees of the root. Types of Trees: Binary Tree :-  It's finite set of nodes, with one special node called root and the other nodes are partitioned into two disjoints sets, which are binary tree called its left and right subtree.  It is a tree where every nodes can have atmost two branches. Stritly  Binary Tree :-  Strictly binary tree is a where all no-leaf nodes have two branches. A Strictly binary tree may not be full. All leaf nodes may not be the same levels. Complete Binary Tree(Full Binary Tree):-  Full binary tree of depth d has 2d-1 nodes, In a full binary tree, all the levels are full and all leaf nodes are the same level. Full binary tree is a strictly binary tree. All leaf nodes are the same level Al-Most Complete Binary Tree : Binary tree with  d levels i
Recent posts

Heap-Sort(Program)

  Heap-Sort CODE 👇 #include<stdio.h> #include<stdlib.h> void heapsort(int a[], int n); void heapify(int a[], int  i, int last); void buildheap(int a[], int n); void display(int a[], int n); void heapsort(int a[10], int n) { int i,temp; buildheap(a,n); printf("\n   Initialize Heap"); display(a,n); printf("\n"); for(i=n-1; i>=1; i--) { temp=a[0]; a[0]=a[i]; a[i]=temp; printf("\nAfter %d Iteration-->", n-i); display(a,n); //printf("\n"); heapify(a, 0, i-1); } } void buildheap(int a[], int n) { //convert a[0] ... a[n-1] into heap int i; for(i=(n/2)-1; i>=0; i--) heapify(a,i, n-1); } void heapify(int a[], int i, int last) { int j, temp, key; key=a[i]; j=2*i+1; if((j<last )&&(a[j]<a[j+1])) j=j+1; if((j<=last)&&(key < a[j])) { temp = a[i]; a[i] = a[j]; a[j] = temp; heapify(a, j ,last);   } } void display(int a[

Level-Order Travsal BST(Program)

Level-Order Travsal CODE 👇 //Main File #include<stdio.h> #include<stdlib.h> #include "levelorder.h"   void main() {     NODE *root=NULL;     printf("\t>>First Create BST<<\n");     root = createbst(root);       display(root);      printf("\n\n\t>>Level order traversal<<\t");     levelorder(root); } //Header File    #define MAXSIZE 20     typedef struct node     {      int info;      struct node *left, *right;     }NODE;      //QUEUE FUNCTIONS     typedef struct     {      NODE *data[MAXSIZE];      int front, rear;     }QUEUE;     void initq(QUEUE *pq)     {      pq->front = pq->rear = -1;     }     void addq(QUEUE *pq, NODE *treenode)     {      pq->data[++pq->rear] = treenode;     }     NODE* removeq(QUEUE *pq)     {      return pq->data[++pq->front];     }     int isempty(QUEUE *pq)     {      return (pq->front == pq->rear);     }     int isfull(QUEUE

Binary Search Tree Operations(Program)

Binary Search Tree Operations MAIN FILE:- #include<stdio.h> #include<stdlib.h> #include "tree.h" NODE * create(NODE *root); NODE * insert(NODE *root,int n); NODE *search(NODE * root, int n); void display(); void preorder(NODE * root); void inorder(NODE * root); void postorder(NODE * root); NODE * deletebst(NODE *root, int n); int Node_count(NODE *root); int Leaf_count(NODE *root); NODE *treecopy(NODE *root); int comparebst(NODE *root, NODE *root1); int sumOdd(NODE *node); int sumEven(NODE *node1); void mirror(NODE *root); int smallest(NODE * root); int largest(NODE * root); void main() { NODE *root=NULL, *root1=NULL;     int n, num, osum, esum, choice; printf("\t\t>>Operations of Binary Search Tree<<\n\n");     printf("\t\t\t>>First Create BST<<\n");             //CREATE     root = create(root);     root1 = create(root1); do { printf("\n\n1.INSERT"); printf("\n2.SEARCH&

Operation On Binary Search Tree(BST)

 Operation On Binary Search Tree(BST) Create:- Create tree with 'n' nodes. Traverse:- Visit each & every node of tree. Search:- Searches for a specific element in the tree.  Insert:- The new element will be inserted according to its value. Delete:- Delete a specific node from the tree. Counting total nodes Counting leaf nodes Copying tree to another Mirror of tree Create:-          Some rules satisfy for create a nodes.  All keys in the left subtree < root. All keys in the right subtree >= root. The right & left subtree are also Binary Search Tree(BST).          Algorithm:-     Step 1:- Start     Step 2:- root=NULL     Step 3:- Read the value and create a newnode to store this value.     Step 4:- If root==NULL                       root=newnode                   goto Step 7     Step 5:- temp=root     Step 6:- If key<temp->info                           If temp doesn't have left child                                 attach newnode to temp->left       

Representation of Binary Tree

Representation of Binary Tree Types of Representation of Binary Tree Static Representation of Binary Tree. Dynamic Representation of Binary Tree.      ⩥ Static Representation of Binary Tree .      The element  are stroed in the array level-wise starting from the root. Since a full binary tree with total 'd' levels will have maximum of 2d-1 nodes, we can use an array od size 2d-1 to represrnt the binary tree. This representation allows random access to any node. The i th node is at location i where (0<=i<n). Find Parent of Node:- The parent of node is at location (i-1)/2. (i=0 is the root has no parent).             i=4 (E)                                                                        i=5 (F)               = (i-1)/2                                                                        = (i-1)/2               = (4-1)/2                                                                     = (5-1)/2               = 3/2