Skip to main content

Posts

Showing posts from November, 2016

print leaf nodes of binary search tree

Leaf nodes of binary tree are the nodes with no children or no subtrees. They have both left and right links as null. In the above image nodes 1,4 ,7 ,13 have no sub-trees hence they are the leaf nodes. Leaf nodes can be found easily by traversing the tree in inorder way and the printing the nodes that have no left or right subtrees. C++ Program Python Program C++ Program Python Program You might also be interested in Minimum & Maximum Element in BST Binary Search Tree in Python Binary Search Tree in C++ Insert ,Search and Display Binary Search Tree Height of Binary Search Tree Linked list in Python

height of binary search tree

Height of the binary search tree is defined as the number of nodes in the longest path from the root node to leaf node. In the above image one of the longest paths is 8 --> 10 --> 14 --> 13, containing 4 nodes hence the height of the binary search tree is 4. One thing that should be noted is that a tree with only root node has height 1 and not 0. In the following the height of the left and right subtree is compared and the larger value is returned. C++ Program Python Program C++ Program Python Program You might also be interested in Singly Linked List Binary Search Tree in Python Binary Search Tree in C++ Insert ,Search and Display Binary Search Tree Print Leaf nodes of Binary Search Tree Linked list in Python

Binary search tree in cpp

Binary Search Tree is a rooted binary tree. Its subtrees have certain properties. Each element of the binary tree is a node that has mainly 3 fields, data or element field left link  right link For each node in a binary search tree, the data of the left node is less than the parent node and data of the right node is greater than the parent node. It can be seen in the image above that the data in the left child node is less than the data of the parent node and data of the right child node is greater than the parent node. There are a lot of advantages of using the binary search tree data structure, they are related to searching, sorting, using them as priority queues, etc. To know more about binary search tree click  here . The following program has the following operations implemented isEmpty() : method that checks if the tree is empty. getRoot() :  method that returns the root element of the binary search tree. insert() : Insertion in ...

binary search tree in python

Binary Search Tree is a rooted binary tree. Its subtrees have certain properties. Each element of the binary tree is a node that has mainly 3 fields, data or element field left link  right link For each node in binary search tree , the data of the left node is less than the parent node and data of the right node is greater than the parent node. It can be seen in the image above that the data in the left child node is less than the data of the parent node and data of the right child node is greater than the parent node. There are a lot of advantages of using the binary search tree data structure, they are related to searching , sorting , using them as priority queues , etc. To know more about binary search tree click  here . The following program has the following operations implemented isEmpty() : method that checks if the tree is empty. getRoot() :  method that retuens the root element of the binary search tree. insert() : Insertion i...

binary search tree insert search and display

Binary Search Tree is a simple data structure which is very often used to solve a lot of different problems based on searching and sorting, and also it is a very popular topic for programming coding challenges and interview questions. Binary Search Tree is a rooted binary tree. It is basically a collection of nodes which are linked to each other. now, you may ask what is a node? Each element of the binary tree is a node that has mainly 3 fields, data or element field left link  right link Each node in the binary tree has the following properties Data of the left node is less than the parent node Data of the right node is greater than the parent node. Below is an example image for a binary search tree It can be seen in the image above that the data in the left child node is less than the data of the parent node and data of the right child node is greater than the parent node. For example, let us consider 8 as the parent node, then we can see t...

gcd using euclids algorithm

GCD stands for greatest common divisor. GCD of two numbers is the greatest number that divides both numbers without leaving a remainder. Euclidean algorithm for finding the gcd is based on the principle that the gcd of two numbers does not change if the larger number is replaced by its difference with the smaller number. Let us consider the example of 206 and 40, we find that 2 is the gcd of 206 and 40 also according to the above statement the gcd of 166 (206 - 40) and 40 is also 2. To know more about GCD click here . In the below program we follow the below steps Step 1: In each iteration calculate the quotient  Step 2: Then subtract the product of quotient and the smaller number from the bigger number Step 3: Replace the bigger number by the remainder.  Step 4: Repeat above steps until the smaller number becomes 0 C++ Program Java program Python Program C++ Program Java Program Python Program Sample input and output...

Singly Linked List

A linked list is a simple linear data structure formed by a collection of data elements called nodes. Each node consists of a data element and link field. There is a head node that points to the starting of the linked list. this diagram shows a simple representation of the linked list. A linked list can be used to implement stacks, queues, list, associative arrays, etc.  Unlike arrays linked lists are not stored in contagious memory locations rather they are stored at any empty place in memory and the address of the next node is stored in the link field. Also, you don't need to declare the size of the linked list at the time of initialization you can dynamically keep adding elements to the linked list. Click for complete information on  Linked List  The following implementation of the linked list has the following methods implemented : Method to add an element at the start of the List Method to add an element at the end of the ...

Home Page

List of All Programs The Following is the List of all the programs on my Blog Math Programs Square Root of a number using Babylonian Method Finding The Next Smallest Palindrome Finding the Armstrong Numbers Factorial of a number GCD using Euclid's Algorithm Check if a number is Fibonacci Number or not LCM of 2 numbers Trailing Zeros in factorial of a number Sorting Algorithms Bubble Sort Algorithm Selection Sort Algorithm Insertion Sort Algorithm Shell Sort Algorithm Counting Sort Algorithm Linked List Programs Simple Singly Linked List Linked List in C++ Linked List in Python Linked List in Java Doubly Linked List Finding Kth element from the end of Linked List Delete a node from Linked List Delete Kth element from the end of Linked List Rotate Linked List in an Anti-clockwise direction Reversing first K nodes of a Linked List Binary Search Tree Left View of Binary Tree Righ...

Stack implementation using array

A stack is a data structure it serves as a collection of elements. It has 2 principle operation push and pop. The push operation pushes the element on the top and the pop operation removes the element on the top. This can be seen in the below image. Stack works on the principle of  Last In First Out or LIFO i.e the element that is entered last is removed first. Stacks can be implemented using arrays as well as linked list. There are a lot of applications of Stacks like Recursion Backtracking  Memory management  Activation records etc To know more about Stacks click here  The following program is to implement a stack using an array with maximum size of 20. C Program C++ Program Java program Python Program C Program C++ Program Java Program Python Program You might also be interested in  Linked List in python Linked List in C++ Finding the next Smallest Palindrome Finding facto...

bar graph in c using dda algorithm

DDA line generation algorithm is used to draw lines by finding the points of the line using arithmetic operations on integers and floating point numbers. The following program is to draw a bar graph using dda line algorithm. To know all about the algorithm click here C Program C Program OUTPUT You might also be interested in Linked List in Python Linked List in Java Program to find Armstrong Numbers Program to find next smallest Palindrome finding square root of a number using Babylonian method

factorial of a number

Factorial of a number is equal to the product of the number and all the positive numbers below it. Factorial of a number is denoted as n!. for example Factorial of 7 is denoted as 7!. 7! = 7*6*5*4*3*2*1 7! = 5040 also 0! is 1 according to the convention of empty product. To know more about factorials click here C Program C++ Program Java program Python Program C Program C++ Program Java Program Python Program Sample input and output to check the program You might also be interested in Linked List in Python Linked List in Java Program to find Armstrong Numbers Program to find next smallest Palindrome finding square root of a number using Babylonian method

Program to find Armstrong numbers

Armstrong numbers are numbers such that if we take sum of all the digits of the number raised to 3 it equal to the original number. Armstrong numbers can also be called as 3-narcissistic numbers,   as we raise all the digits to 3. Let us take a quick example  C++ Program Java program Python Program C++ Program Java Program Python Program Sample input and output to check the program You might also be interested in  Singly Linked List Double Linked List Linked List in Python Infix to Prefix Conversion Infix to Postfix Conversion Binary Search Tree