Found 345 Articles for Data Structure Algorithms

Conversion of Binary to Gray Code

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

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

378 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

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

Ternary Search

Rishi Raj
Updated on 15-Jun-2020 14:50:10

3K+ Views

Like the binary search, it also separates the lists into sub-lists. This procedure divides the list into three parts using two intermediate mid values. As the lists are divided into more subdivisions, so it reduces the time to search a key value.The complexity of Ternary Search TechniqueTime Complexity: O(log3 n)Space Complexity: O(1)Input and OutputInput: A sorted list of data: 12 25 48 52 67 79 88 93 The search key 52 Output: Item found at location: 3AlgorithmternarySearch(array, start, end, key)Input − An sorted array, start and end location, and the search keyOutput − location of the key (if found), otherwise wrong ... Read More

Exponential Search

Paul Richard
Updated on 15-Jun-2020 14:10:42

4K+ Views

Exponential search is also known as doubling or galloping search. This mechanism is used to find the range where the search key may present. If L and U are the upper and lower bound of the list, then L and U both are the power of 2. For the last section, the U is the last position of the list. For that reason, it is known as exponential.After finding the specific range, it uses the binary search technique to find the exact location of the search key.The complexity of Exponential Search TechniqueTime Complexity: O(1) for the best case. O(log2 i) ... Read More

Advertisements