• Data Structure - Java - Tutorials

    Interview Series : Left View of Binary Tree

    Given a Binary Tree, print Left view of it. Left view of a Binary Tree is set of nodes visible when tree is visited from Left side. The task is to complete the function leftView(), which accepts root of the tree as argument. The problem is given in GeeksforGeeks Practice, which is useful for interview prepration as well as helps to learn basics of Data Structure. Left view of following tree is 1 2 4 8.           1       /     \     2        3   /     \    /    \  4     5   6    7   \     8    Example 1: Input:  1 /  \3   …

  • Data Structure - Tutorials

    Disjoint Sets Data Structure

    A Disjoint set which can be viewed as a collection of sets where in no element appears in more than one set. A disjoint set data structure is used to maintain a collection S = {S1, S2, S3, …, Sn} of disjoint dynamic set. We can identify each set by a representative, which is some member of the set. Disjoint set data structure is used to find the MST(Minimum Spanning Tree). Disjoint set is a partitioned set. Partitioned means union of any two sets is gives the original set while intersection of any two set gives a null set. Disjoint…

  • Data Structure - Tutorials

    Queue – Data Structure

    A queue is a simple data structure that allows elements to be inserted from one end, called the rear (also called tail), and deleted from the other end, called the front (also called head).This behavior is called FIFO (First in First Out). TerminologyThe process of adding new elements into the queue is called enqueue.The process of removal of an element from the queue is called dequeue. ApplicationsQueues are used whenever we need to manage objects in order starting with the first one in.Scenarios include printing documents on a printer, call center systems answering people on hold people, and so on.…

  • Data Structure - Tutorials

    Stack – Data Structure

    A stack is a simple data structure that adds and removes elements in a particular order.Every time an element is added, it goes on the “top” of the stack. Only an element at the top of the stack can be removed, just like a stack of plates. This behavior is called LIFO (Last In, First Out). TerminologyAdding a new element onto the stack is called push.Removing an element from the stack is called pop. ApplicationsStacks can be used to create undo-redo functionalities, parsing expressions (infix to postfix/prefix conversion), and much more. A stack can be implemented using an array or…

  • Data Structure - Tutorials

    ALGORITHM

    ALGORITHM  An Algorithm is a finite set of instruction that perform a particular task. An Algorithm should satisfy following criteria. Input: Zero or more quantities are supplied externally. Output: At least one quantity is produced. Definiteness: Each instruction is clear and unambiguous. Finiteness: Algorithm must terminate after few steps. Effectiveness: Every instruction must be very basic. ANALYSIS: It means determining amount of resources (such as time and space) needed to execute it. TIME COMPLEXITY: Time complexity of an algorithm is basically the execution time of a program. Time complexity of an algorithm depends on the number of machine instruction. SPACE…

  • Data Structure - Tutorials

    Introduction Of Linear And Non Linear Data Structure

    Linear data structure: A data structure is said to be linear if its data item form a linear sequence. Examples of the linear data structure are: (a) Array (b) Linked List (c) Stack (d) Queue Array: An array is a collection of data elements of same datatype. The elements of the array are stored in consecutive memory locations. Arrays are declared using the following syntax: type name[size]; memory representation: Stack: A stack is a linear list in which insertion and deletion operations are performed at only one end of the list.  It follows LIFO structure. Queue: A queue is a…

  • Data Structure - Tutorials

    Basic Introduction Of Data Structures

    Data structures: A data structure is a way of organizing data items such that data items can be accessed efficiently. Or A data structure is a way of organizing data items that considers not only the items stored, but also their relationship to each other. Types of data Structure: Primitive data structure: The data structures that are directly operated by machine level instructions are known as primitive data structures. Following are the primitive data structure: (a) Integer : – Integer is a represent numbers. – The set of integer is: {…………-(n+1), -n,…,-2,-1,0,1,2,……..,n,n+1,………} (b) Real: – The number having decimal point…

  • Data Structure

    Stack Push And Pop Operation

    Here, We are performing push and pop operation of stack. #include<stdio.h> #include<conio.h> void push(); void pop(); void main() { int ch,c; clrscr(); do { printf("\n***SELECT OPERATION OF STACK**\n"); printf("\n1.PUSH OPERATION\n2.POP OPERATION\n"); printf("\nEnter you choice::"); scanf("%d",&ch); switch(ch) { case 1: push(); break; case 2: pop(); break; default: printf("\n**INVALID CHOICE**\n"); } printf("\nDOU YOU WANT TO QUIT(0 or 1)::"); scanf("%d",&c); }while(c==0); } void push() { int a[10],n,i,top=-1,no; printf("\n***PUSH OPERATION**\n"); printf("\nEnter the size of array::"); scanf("%d",&n); printf("\n**Enter array elements**\n"); for(i=0;i<n;i++) { scanf("%d",&a[i]); top++; } printf("\nEnter element to insert::"); scanf("%d",&no); if(top>=n) { printf("\n**STACK IS OVERFLOW**\n"); } else { top++; a[top]=no; } printf("\n***AFTER POUSH OPERATION**\n"); for(i=0;i<=top;i++)…