Found 282 Articles for Data Structure Algorithms

Amortized time complexity in Data Structures

Arnab Chakraborty
Updated on 27-Aug-2019 09:15:10

1K+ 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

Matrix multiplication algorithm

Arnab Chakraborty
Updated on 27-Aug-2019 08:14:18

26K+ 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

Step Count Method in Algorithm

Arnab Chakraborty
Updated on 27-Aug-2019 08:02:11

10K+ 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

Operations on Queue in Data Structures

Arnab Chakraborty
Updated on 27-Aug-2019 07:51:59

685 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

Tail Recursion in Data Structures

Arnab Chakraborty
Updated on 27-Aug-2019 07:45:44

4K+ Views

Here we will see what is tail recursion. The tail recursion is basically using the recursive function as the last statement of the function. So when nothing is left to do after coming back from the recursive call, that is called tail recursion. We will see one example of tail recursion.Example Live Demo#include using namespace std; void printN(int n){    if(n < 0){       return;    }    cout

Data Structures Stack Primitive Operations

Arnab Chakraborty
Updated on 27-Aug-2019 07:38:16

8K+ Views

Stack is Last In First Out data structure. The stack is used in different area for evaluating expressions, call and recursion strategy etc. The stack has some primitive operations. Here we will see those operations of stack, and see one example using the stack 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

Abstract Data Type in Data Structures

Arnab Chakraborty
Updated on 05-Oct-2023 01:03:30

37K+ Views

The Data Type is basically a type of data that can be used in different computer program. It signifies the type like integer, float etc, the space like integer will take 4-bytes, character will take 1-byte of space etc.The 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 with primitive datatypes, but operation logics are ... Read More

Conversion of Binary to Gray Code

Ankith Reddy
Updated on 31-Oct-2023 13:38:45

79K+ Views

The reflected binary code or Gray code is an ordering of the binary numeral system such that two successive values differ in only one bit (binary digit). Gray codes are very useful in the normal sequence of binary numbers generated by the hardware that may cause an error or ambiguity during the transition from one number to the next. So, the Gray code can eliminate this problem easily since only one bit changes its value during any transition between two numbers.Conversion of Binary to Gray CodeGray codes are used in rotary and optical encoders, Karnaugh maps, and error detection. The ... Read More

The Fibonacci sequence in Javascript

karthikeya Boyini
Updated on 22-Jun-2020 15:00:49

505 Views

Fibonacci numbers are the numbers such that every number in the series after the first two is the sum of the two preceding ones. The series starts with 1, 1. Example −1, 1, 2, 3, 5, 8, 13, 21, 34, ….We can write a program to generate nth as follows −functionfibNaive(n) {    if (n

Dynamic Programming in JavaScript

Samual Sam
Updated on 30-Jul-2019 22:30:23

3K+ Views

Dynamic programming breaks down the problem into smaller and yet smaller possible sub-problems. These sub-problems are not solved independently. Rather, results of these smaller sub-problems are remembered and used for similar or overlapping sub-problems. Dynamic programming is used where we have problems, which can be divided into similar sub-problems so that their results can be re-used. Mostly, these algorithms are used for optimization. Before solving the in-hand sub-problem, the dynamic algorithm will try to examine the results of the previously solved sub-problems. The solutions of sub-problems are combined in order to achieve the best solution. For a problem to be ... Read More

Advertisements