Data Structures Tutorial

Data Structures Tutorial Asymptotic Notation Structure and Union Array Data Structure Linked list Data Structure Type of Linked list Advantages and Disadvantages of linked list Queue Data Structure Implementation of Queue Stack Data Structure Implementation of Stack Sorting Insertion sort Quick sort Selection sort Heap sort Merge sort Bucket sort Count sort Radix sort Shell sort Tree Traversal of the binary tree Binary search tree Graph Spanning tree Linear Search Binary Search Hashing Collision Resolution Techniques

Misc Topic:

Priority Queue in Data Structure Deque in Data Structure Difference Between Linear And Non Linear Data Structures Queue Operations In Data Structure About Data Structures Data Structures Algorithms Types of Data Structures Big O Notations Introduction to Arrays Introduction to 1D-Arrays Operations on 1D-Arrays Introduction to 2D-Arrays Operations on 2D-Arrays Strings in Data Structures String Operations Application of 2D array Bubble Sort Insertion Sort Sorting Algorithms What is DFS Algorithm What Is Graph Data Structure What is the difference between Tree and Graph What is the difference between DFS and BFS Bucket Sort Dijkstra’s vs Bellman-Ford Algorithm Linear Queue Data Structure in C Stack Using Array Stack Using Linked List Recursion in Fibonacci Stack vs Array What is Skewed Binary Tree Primitive Data Structure in C Dynamic memory allocation of structure in C Application of Stack in Data Structures Binary Tree in Data Structures Heap Data Structure Recursion - Factorial and Fibonacci What is B tree what is B+ tree Huffman tree in Data Structures Insertion Sort vs Bubble Sort Adding one to the number represented an array of digits Bitwise Operators and their Important Tricks Blowfish algorithm Bubble Sort vs Selection Sort Hashing and its Applications Heap Sort vs Merge Sort Insertion Sort vs Selection Sort Merge Conflicts and ways to handle them Difference between Stack and Queue AVL tree in data structure c++ Bubble sort algorithm using Javascript Buffer overflow attack with examples Find out the area between two concentric circles Lowest common ancestor in a binary search tree Number of visible boxes putting one inside another Program to calculate the area of the circumcircle of an equilateral triangle Red-black Tree in Data Structures Strictly binary tree in Data Structures 2-3 Trees and Basic Operations on them Asynchronous advantage actor-critic (A3C) Algorithm Bubble Sort vs Heap Sort Digital Search Tree in Data Structures Minimum Spanning Tree Permutation Sort or Bogo Sort Quick Sort vs Merge Sort Boruvkas algorithm Bubble Sort vs Quick Sort Common Operations on various Data Structures Detect and Remove Loop in a Linked List How to Start Learning DSA Print kth least significant bit number Why is Binary Heap Preferred over BST for Priority Queue Bin Packing Problem Binary Tree Inorder Traversal Burning binary tree Equal Sum What is a Threaded Binary Tree? What is a full Binary Tree? Bubble Sort vs Merge Sort B+ Tree Program in Q language Deletion Operation from A B Tree Deletion Operation of the binary search tree in C++ language Does Overloading Work with Inheritance Balanced Binary Tree Binary tree deletion Binary tree insertion Cocktail Sort Comb Sort FIFO approach Operations of B Tree in C++ Language Recaman’s Sequence Tim Sort Understanding Data Processing Applications of trees in data structures Binary Tree Implementation Using Arrays Convert a Binary Tree into a Binary Search Tree Create a binary search tree Horizontal and Vertical Scaling Invert binary tree LCA of binary tree Linked List Representation of Binary Tree Optimal binary search tree in DSA Serialize and Deserialize a Binary Tree Tree terminology in Data structures Vertical Order Traversal of Binary Tree What is a Height-Balanced Tree in Data Structure Convert binary tree to a doubly linked list Fundamental of Algorithms Introduction and Implementation of Bloom Filter Optimal binary search tree using dynamic programming Right side view of binary tree Symmetric binary tree Trim a binary search tree What is a Sparse Matrix in Data Structure What is a Tree in Terms of a Graph What is the Use of Segment Trees in Data Structure What Should We Learn First Trees or Graphs in Data Structures All About Minimum Cost Spanning Trees in Data Structure Convert Binary Tree into a Threaded Binary Tree Difference between Structured and Object-Oriented Analysis FLEX (Fast Lexical Analyzer Generator) Object-Oriented Analysis and Design Sum of Nodes in a Binary Tree What are the types of Trees in Data Structure What is a 2-3 Tree in Data Structure What is a Spanning Tree in Data Structure What is an AVL Tree in Data Structure Given a Binary Tree, Check if it's balanced

Recaman’s Sequence

Recamán's succession repeat connection in arithmetic and software engineering. Since its components are obviously connected with the past components, they are as often as possible characterized utilizing recursion.

It takes its name after its pioneer Bernardo Recaman Santos (Bogota, August 5, 1954), a Colombian mathematician.

Recaman's course of action was named after its trailblazer, Colombian mathematician Bernardo Recaman Santos, by Neil Sloane, creator of the On-Line Encyclopedia of Integer Sequences (OEIS).

The OEIS section for this grouping is A005132.

In any event, when Neil Sloane has gathered in excess of 325,000 arrangements starting around 1964, the Recamán's succession was referred to in his paper My #1 number sequences.

He moreover communicated that of the huge number of groupings in the OEIS, this one is his #1 to listen to[1] (you can hear it underneath).

Definition:

The Recaman's succession a0, a1, a2 is characterized as:

Recaman’s Sequence

Recaman's Sequence

The initial terms of the grouping are:

0, 1, 3, 6, 2, 7, 13, 20, 12, 21, 11, 22, 10, 23, 9, 24, 8, 25, 43, 62, 42, 63, 41, 18, 42, 17, 43, 16, 44, 15, 45, 14, 46, 79, 113, 78, 114, 77, 39, 78, 38, 79, 37, 80, 36, 81, 35, 82, 34, 83, 33, 84, 32, 85, 31, 86, 30, 87, 29, 88, 28, 89, 27, 90, 26, 91, 157, 224, 156, 225, 155, ...

//printing first n elements

Input: n=7
Output: 0,1,3,6,2,7,13
Input: n=4
Output: 0,1,3,6

It is basically a capability with domain and co-domain as regular numbers and 0 separately. It is characterized recursively as follows:

Make a(n) to signify the (n+1)- th term. (0 is as of now present).

As indicated by Rules:

a(0) = 0,
on the off chance that n > 0 and the number isn't
   currently remembered for the grouping,
     a(n) = a(n - 1) - n
else
     a(n) = a(n-1) + n.

A straightforward execution is displayed beneath, in which we store all n Recaman Sequence numbers in an exhibit. Utilizing the recursive recipe referenced above, we process the following number.

  • Time Complexity : O(n)
  • Space Complexity : O(n)

Advantages:

Recamán's grouping, not with standing its numerical and tasteful properties, can be utilized to scramble 2D pictures utilizing steganography.

// Java programm to print nth number in Recaman's arrangement
import java.io.*;


class  Rsequence {
           // Prints first n terms of Recaman arrangement
	static void recaman(int n)
	{
		// Make an exhibit to store terms
		int arr[] = new int[n];
                      // Initial term of the succession is generally 0
		arr[0] = 0;
		System.out.print(arr[0]+" ,");


		// Fill remaining terms utilizing recursive
		// equation.
		for (int j = 1; j< n; j++)
		{
			int curr = arr[j - 1] - i;
			int k;
			for (k = 0; k < i; k++)
			{
				// In the event that arr[j-1] - i is negative or
				// as of now exists.
				if ((arr[k] == curr) || curr < 0)
				{
					curr = arr[j - 1] + i;
					break;
				}
			}


			arr[j] = curr;
			System.out.print(arr[j]+", ");


		}
	}


	// Driver code
	public static void principal (String[] args)
	{
		int n = 19;
		recaman(n);


	}
}

Visual Presentation:

Recaman’s Sequence

Using Array:

Given a set of n positive whole numbers addressing lengths.

Decide the most extreme conceivable region whose four sides are browsed the given exhibit.

 It ought to be noticed that a square shape must be framed assuming the given exhibit contains two sets of equivalent qualities.

Method1(Sorting):

The errand fundamentally decreases to finding two sets of equivalent qualities in cluster.

On the off chance that there are multiple matches, pick the two sets with greatest qualities.

A straightforward arrangement is to do following.

Sort the given cluster.

Navigate exhibit from biggest to littlest worth and return two sets with most extreme qualities

// CPP program for tracking down most extreme region conceivable
// of a square shape
#incorporate <bits/stdc++.h>
utilizing namespace sexually transmitted disease;


// capability for tracking down max region
int findArea(int array[], int n1)
{
    // sort cluster in non-expanding request
    sort(arr, array + n1, greater<int>());


    // Introduce different sides of square shape
    int dimension[2] = { 0, 0 };


    // navigate through exhibit
    for (int i = 0, j = 0; i < n1 - 1 && j < 2; i++)


        // assuming any component happens two times
        // store that as aspect
        if (array[i] == array[i + 1])
            dimension[j++] = arr[i++];


    // return the result of aspects
    return (dimension[0] * dimension[1]);
}


// driver capability
int primary()
{
    int arr[] = { 4, 2, 1, 4, 6, 6, 2, 5 };
    int n1 = sizeof(array)/sizeof(array[0]);
    cout << findArea(array, n1);
    bring 0 back;
}

Method2(Hashing):

In a hash set, all first events of components are embedded.

Monitor something like two qualities for second events

// CPP program for tracking down greatest region conceivable
// of a square shape
#incorporate <bits/stdc++.h>
utilizing namespace sexually transmitted disease;


// capability for tracking down max region
int findArea(int arr[], int n)
{
    unordered_set<int> s1;


    // cross through exhibit
    int firstt= 0, secondd = 0;
    for (int i = 0; i < n; i++) {


        // In the event that this is first event of arr[i],
        // basically supplement and proceed
        if (s1.find(array[i]) == s1.end()) {
            s1.insert(array[i]);
            proceed;
        }


        // Assuming that this is second (or more) event,
        // update first and second greatest qualities.
        if (array[i] > firstt) {
            secondd = firstt;
            firstt = array[i];
        } else if (array[i] > secondd)
            secondd = array[i];
    }


    // return the result of aspects
    return (firstt * secondd);
}


// driver capability
int fundamental()
{
    int arr[] = { 4, 2, 1, 4, 6, 6, 2, 5 };
    int n1 = sizeof(array)/sizeof(array[0]);
    cout << findArea(array, n1);
    bring 0 back;
}
# Python 3 program to print n-th
# numbering in Recaman's grouping


# Prints first n terms of Recaman
# group
def recaman(n1):


    # Make a cluster to store terms
    array = [0] * n1


    # Initial term of the succession
    # is always generally 0
    array[0] = 0
    print(array[0], end=", ")


    # Fill remaining terms utilizing
    # recursive 
    for i in range(1, n1):


        current = array[i-1] - i
        for j in range(0, i):


            # If array[i-1] - I is
            # negative or as of now
            # exists.
            if ((array[j] == current) or current < 0):
                current = arr[i-1] + I
                break


        array[i] = current
        print(array[i], end=", ")


# Driver code
n1 = 15


recaman(n1)



ADVERTISEMENT
ADVERTISEMENT