- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 546 Articles for Algorithms
331 Views
In this section we will see the post-order traversal technique (recursive) for binary search tree.Suppose we have one tree like this −The traversal sequence will be like: 8, 5, 15, 23, 20, 16, 10AlgorithmpostorderTraverse(root): Begin if root is not empty, then postorderTraversal(left of root) postorderTraversal(right of root) print the value of root end if EndExample Live Demo#include using namespace std; class node{ public: int h_left, h_right, bf, value; node *left, *right; }; class tree{ private: node *get_node(int key); ... Read More
302 Views
In this section we will see the level-order traversal technique for binary search tree.Suppose we have one tree like this −The traversal sequence will be like: 10, 5, 16, 8, 15, 20, 23AlgorithmlevelOrderTraverse(root): Begin define queue que to store nodes insert root into the que. while que is not empty, do item := item present at front position of queue print the value of item if left of the item is not null, then insert left of item into que end ... Read More
743 Views
In this section we will see different traversal algorithms to traverse keys present in binary search tree. These traversals are Inorder traversal, Preorder traversal, Postorder traversal and the level order traversal.Suppose we have one tree like this −The Inorder traversal sequence will be like − 5 8 10 15 16 20 23The Preorder traversal sequence will be like − 10 5 8 16 15 20 23The Postorder traversal sequence will be like − 8 5 15 23 20 16 10The Level-order traversal sequence will be like − 10, 5, 16, 8, 15, 20, 23AlgorithminorderTraverse(root): Begin if root is not ... Read More
4K+ Views
In this section we will see some important properties of one binary tree data structure. Suppose we have a binary tree like this.Some properties are −The maximum number of nodes at level ‘l’ will be $2^{l-1}$ . Here level is the number of nodes on path from root to the node, including the root itself. We are considering the level of root is 1.Maximum number of nodes present in binary tree of height h is $2^{h}-1$ . Here height is the max number of nodes on root to leaf path. Here we are considering height of a tree with one ... Read More
14K+ Views
Here we will see how to represent a binary tree in computers memory. There are two different methods for representing. These are using array and using linked list.Suppose we have one tree like this −The array representation stores the tree data by scanning elements using level order fashion. So it stores nodes level by level. If some element is missing, it left blank spaces for it. The representation of the above tree is like below −12345678910111213141510516-81520-------23The index 1 is holding the root, it has two children 5 and 16, they are placed at location 2 and 3. Some children are ... Read More
531 Views
Here we will see some basic operations of array data structure. These operations are −TraverseInsertionDeletionSearchUpdateThe traverse is scanning all elements of an array. The insert operation is adding some elements at given position in an array, delete is deleting element from an array and update the respective positions of other elements after deleting. The searching is to find some element that is present in an array, and update is updating the value of element at given position. Let us see one C++ example code to get better idea.Example Live Demo#include #include using namespace std; main(){ vector arr; //insert elements ... Read More
738 Views
Amortize AnalysisThis analysis is used when the occasional operation is very slow, but most of the operations which are executing very frequently are faster. In Data structures we need amortized analysis for Hash Tables, Disjoint Sets etc.In the Hash-table, the most of the time the searching time complexity is O(1), but sometimes it executes O(n) operations. When we want to search or insert an element in a hash table for most of the cases it is constant time taking the task, but when a collision occurs, it needs O(n) times operations for collision resolution.Aggregate MethodThe aggregate method is used to ... Read More
18K+ Views
In this section we will see how to multiply two matrices. The matrix multiplication can only be performed, if it satisfies this condition. Suppose two matrices are A and B, and their dimensions are A (m x n) and B (p x q) the resultant matrix can be found if and only if n = p. Then the order of the resultant matrix C will be (m x q).AlgorithmmatrixMultiply(A, B): Assume dimension of A is (m x n), dimension of B is (p x q) Begin if n is not same as p, then exit otherwise define C ... Read More
8K+ Views
The step count method is one of the method to analyze the algorithm. In this method, we count number of times one instruction is executing. From that we will try to find the complexity of the algorithm.Suppose we have one algorithm to perform sequential search. Suppose each instruction will take c1, c2, …. amount of time to execute, then we will try to find out the time complexity of this algorithmAlgorithmNumber of timesCostseqSearch(arr, n, key)i := 0while i < n, do if arr[i] = key, then break end ifdonereturn i1n+1n0/11c1c2c3c4c5Now if we add the cost by multiplying the ... Read More
489 Views
Queue is First In First Out data structure. The queue is used in different area for graph traversal algorithms Breadth First Search etc. The queue has some primitive operations. Here we will see those operations of queue, and see one example using the queue ADT.The ADT (abstract datatype) is special kind of datatype, whose behavior is defined by a set of values and set of operations. The keyword “Abstract” is used as we can use these datatypes, we can perform different operations. But how those operations are working that is totally hidden from the user. The ADT is made of ... Read More
To Continue Learning Please Login
Login with Google