INTRODUCTION TO DATA STRUCTURES

DATA TYPE :
Data type of a variable is the set of values that the variable may assume.

Basic Data Types in C :
int , char , float , double
Basic Data Types in PASCAL :
integer , real , char , boolean
ABSTRACT DATA TYPE :
An ADT is a set of elements with a collection of well defined operations.
1)The operations can take operands from not only the instances of the ADT but other types of operands or instances of other ADTs.
2)Similarly results need not be instances of the ADT.
3)At least one operand or the result is of the ADT type in question.

Object Oriented languages such as C++ and Java provide explicite support for expressing ADTs by means of Classes.

DATA STRUCTURE :
A Data Structure is an implementation of an ADT.That is it is a translation of ADT into statements of a programming language.It consists of
1)The declarations that define a variable to be of that ADT type.
2)The operations defined on the ADT(using procedures of the programming language).

An ADT implementation chooses a data structure to represent the ADT.
Each data structure is built up from the basic data types of the underlying programming language using the available data structuring facilities , such as
arrays ,records (structures in C) , pointers , files , sets , etc.

Example:
A ” Queue ” is an abstract data type which can be defined as a sequence of elements with operations such as ENQUEUE(x,Q),DEQUEUE(Q) .
This can be implemented using data structures such as
1)Array
2)Singly linked list
3)Doubly linked list
4)Circular array

278 thoughts on “INTRODUCTION TO DATA STRUCTURES”

      1. : Provide a List ADT that keep record of student’s data. Interface of this ADT is provided below.
        class StudentList{
        public:
        StudentList(int s); //create a list of size s
        bool isEmpty(); //return true if list is empty and false otherwise.
        bool isFull(); //return true if list is full and false otherwise.
        void insert(StudentInfo s); //insert record s in the list. If list is full,
        double the list size.
        int find(int rn); //find record of student having roll_no rn in the list
        and return its index if found, or return -1 if not found.
        bool remove(int rn); //delete record of student having roll_no rn from list and return true if deleted, or return false if record not found in the list.
        void display(); //display all records of students in the list from beginning to end
        private:
        ……………
        };

        struct StudentInfo{

        int roll_no;
        string name;
        float cgpa;
        };

      2. bool BST::findit(node * & ptr, const T & x, int modify)
        {
        if(ptr == 0)
        {
        if(modify == 0)
        return false;

        if(modify == 1)
        {
        ptr = new node;
        ptr->data = x;
        return false;
        }

        if(modify == 2)
        return false;

        return false;
        }

        if(ptr->data == x)
        {
        if(modify == 0)
        return true;

        if(modify == 1)
        return true;

        if(modify == 2)
        {
        node *prev, *temp = ptr;
        if(ptr -> right == 0)
        ptr = ptr->left;
        else
        if(ptr -> left == 0)
        ptr = ptr -> right;
        if(ptr->left != 0 && ptr->right != 0)
        {
        temp = ptr -> left;
        prev = ptr;
        while (temp -> right != 0)
        {
        prev = temp;
        temp = temp -> right;
        }
        ptr->data = temp->data;
        if(prev == ptr)
        prev -> left = temp -> left;
        else prev -> right = temp -> left;
        }
        delete temp;
        return true;
        }
        }

        if(ptr->data right, x, modify);
        else
        return findit(ptr->left, x, modify);

        }

      1. *Program to insert an element in the array.

        #include
        #include
        void main()
        { clrscr();
        int a[20],n,i,k,item=0;
        cout<<"Enter size of array "<>n;
        cout<<"Enter array element"<<endl;
        for(i=0;i>a[i];
        cout<>item;
        cout<>k;
        for(i=n-1;i>=k;i–)
        a[i+1]=a[i];
        a[k]=item;
        n=n+1;
        for(i=0;i<n;i++)
        cout<<a[i]<<endl;
        getch();

    1. /* program to search an element from array */

      #include
      #include
      void main()
      {
      int a[20],n,item,i,k;
      cout<>n;
      cout<<endl<<"Enter the elements of array";
      for(i=0;i>a[i];
      }
      cout<>k;
      for(i=0;i<n;i++)
      {
      if(k==a[i])
      {
      cout<<"element ("<<k<< ") is present at loc"<<i+1;
      goto l1;
      }
      }
      cout<<endl<<"not preasent";
      l1:
      getch();
      }

  1. Very useful & informative on DS…

    1. Write a C program to simulate the working of a circular queue of integers using an array. Provide the following operations.
    a) Insert
    b) Delete
    c) Display

    5. Write a program to find minimum cost spanning tree of a given undirected graph using Prim’s

    Can you help me by sending this program ??

  2. i wanna do a program for 8 king on chess board….evry king moves but no one can cut otherz….how can i do that?plzz send it to my hotmail.

  3. i want the concept of simulating pointers in cpp using cpp concept as soon as possible as i have to prepare for my exam

  4. hey frnds cud u plz tell me the code to reverse a string using recursion and without using temporary variables

  5. Hi!I am unable to trace programs in ds which includes dynamic memory allocation as done thru—->{p=new node();}.what happens if node *link is declared in a class.how 2 declare classes without objects(if available)? & updating lptr and rptrs in double linked and single linked lists.How destructor will be invoked when objects are deleted .Plz Xplain about static variables in c++.I here by inform u that i am u’r svu’s friend kok’s brother (chandu 4m GPREC).If recommendations are not granted then u do as u’r wish.(its just a joke )..waiting 4 u’r reply.bye

    1. yes,i aggree your topics so i want to be one of the member in order to give me ideas to this course.
      thanks for your partens.

  6. please i need the complete source code of the simulation dijkstra algorithm using matlab, c language, qbasic. this is to help me in school

  7. hai iam mechanical student of RR ihave a paper pending for data structure through C plz help me give some easy tips to clear that paper.what should i read.sent me some important questions

  8. i need the struture of one node of linkedlist representing Address Book.Write a module to print alternative name from
    Address Book.

  9. I need a good book of Data Structure Through C Language containing programs and the changing of variable during program with the help of diagram.
    Please send if on my e-mail id

  10. Hey buddy m a beginner in DS .prep for my second sem exams .i want DS material which is easy for me to understand …Plz help me out … :(

  11. plz i need a help in ma project about linked list , queue and stack (push , pop, top) also including
    1- delete from the link
    2-add to the link at the top
    can i send u the project on mail its about a car agency
    plz reply

  12. i need program for warshall algorithm using c………………..with more explanations………….plz send to my id……..

  13. i need a program .
    6. write a c++ program to implement graph using adjacency matrix and perform the following operations
    b)breadth first search

  14. can you pls send me the program in c++ to Implement Kosaraju’s algorithm for finding the strongly connected components of a directed grpah using adjacency list to represent the directed graph

  15. #include
    #include
    #include
    struct node{
    int data;
    node *next;
    };
    void main(){
    clrscr();
    int i,get,hold;
    char opt=’T';
    node *h,*p,*q,*l,*c,*d,*r;
    cout<<"enter data"<>h->data;
    q=h;
    h->next=NULL;
    while((opt==’T’)||(opt==’t’)){
    cout<<"if you want to create more nodes than press t otherwise press any key…"<>opt;
    if((opt==’T’)||(opt==’t’)){
    p=new node;
    cout<<"enter data"<>p->data;
    p->next=NULL;
    q->next=p;
    q=p;
    } }
    cout<<endl<<endl<<"link list is"<next){ //display nodes
    cout<<endl<data<data=q->data;
    l=d;
    for(; p!=h;){
    for(q=h; q->next!=p; ){
    q=q->next;
    }
    p=q;
    c=new node;
    c->data=q->data;
    c->next=NULL;
    l->next=c;
    l=c;
    }
    cout<<endl<<endl<<"link list of copy is"<next){ //display nodes
    cout<<endl<data<<endl;
    }

    getch();
    }

    what is the problem in thiz program plzzzzzzzzzzzz inform me today……

      1. hi,
        use malloc function and use #include header file because new node will be created after giveing to it memory

  16. I don’t agree with everything in this blog, but you do make some very good points. Im very interested in this subject and I myself do alot of research as well. Either way it was a well thoughtout and nice read so I figured I would leave you a comment. Feel free to check out my website sometime and let me know what you think.

  17. PLEASE INTRODUCE WITH THE C++ CODING FOR GAME OF “CHESS” WITH WHITE(1KING ,1QUEEN,8PAUN. )
    & BLACK (1KING ,1QUEEN,8PAUN. ) WITH GRAPHICAL REPRESANTION.

  18. pls send me simple source codes for the following programs….

    1.BINARY SEARCH FOR STRINGS USING C …

    2.FINDING A WORD IN A PROGRAM USING C…

    3.ADDITION OF TWO SPARSE MATRIX USING C….

    4.IMPLEMENTATION OF TWO STACKS IN AN SINGLE ARRAY….

  19. pls send me a ebook which consists of all programs in data structures with c…..
    if u have pls mail to this id.. (siva.madurai@yahoo.co.in)

    pls someone help me im facing lots of problems with data structures……

    1. in sequential searching can be done to a sorted n unsorted array, both!..
      but the binary search can only be done when the array in in sorted manner..

    1. data structure using c- yashwant kanetkar..
      or u may prefer ds. baluja or dilip sultania is also gud..
      well… u will find the yashwant kanetkar’s book better 2 undrstnd the concepts…
      for algos…ds. baluja..

  20. sir i am a very week student of bca…….sir please help me my dear sir……..mera problem h ki mujhe main subject ka jo language hota h jaise c.c++,ds using c…….etc r language,bahut vast lagta hai hume…….sir kya aap mera help kr sakte h……..please sir …….i am requested to u my dear sirji………..aapke pas me bahut idea h sir aap meri madad kro n please sir……..bye takecare & good n9 my dear sir………..

  21. I m a student of A-level . i have already completed my 5 modules. i m very week in progarming.my next paper is data structure through c++(A6-r4). my c language conception is not good. Actually i dont understand the programing logic.pls help me for preparing my module.my conception is very bad about link list, array pls help me. thank u.

    1. hi Mira
      Iam a fresher and done my b.tech. I will help u because i am intrested in programming (in c, c++) so, ask any thing in c.

      Thanks,
      sandeep

  22. iam a beginner in DS i have an exam in the coming month so i need to prepare for will u plz help by giving the main points…

  23. i am the student of DIT.
    please send me the basic information about C++ and also send me some basic programs in C++.
    i will be very thankfull to you

  24. hi all,
    any one who is visiting this site need help about programming then just leave Q to me …..k

    Thanks,
    sandeep

  25. SEO| Internet Marketing| Website Designing

    Hi

    We are leading SEO service provider and web Development Company. We are expert in PHP,.NET, and many open sources like Joomla, Drupal, WordPress, Oscommerse ,Zencart and Blog Management. We offer best of quality work to our clients at the lowest possible prices. We can quickly promote your website.

    We can place your website on top of the Natural Listings on Google, Yahoo and MSN. We do not use “”link farms”” or “”black hat”” methods that Google and the other search engines frown upon and can use to de-list or ban your site. . Price is never a constraint with us because we take pride in handling challenging work.

    We would be happy to send you best fit proposal for web development and designing and if you have a SEO requirement we will send you a proposal using the top search phrases for your area of expertise.

    In order for us to respond to your request for information, please include your company’s website address (mandatory) and /or phone number.

    Sincerely,
    Gary Smith
    Garyinternetmarketing@gmail.com
    COMPLETE INTERNET MARKETING SOLUTION
    SEO – Link Building – Copyright – Web Designing – PHP

  26. Suppose that some application requires using two stacks whose elements are of the same type. A natural storage structure of such a two-stack data type would consist of two arrays and two top pointers. Explain why this may not be a spacewise efficient implementation.

  27. Assume tht ‘Stack’ is the class described in this section with ‘StackType’ set to int and STACK_CAPACITY or myCapacity set to 5. Give the value of ‘myTop’ and the contents of the array referred to by ‘myArray’ in the Stack s afer the code segment is executed, or indicate why an error occurs.
    Stack s;
    s.push(1);
    s.push(2);
    s.push(3);
    s.pop();
    s.push(4);
    s.push(5);
    s.pop();
    s.pop();

    1. this is the double stack program———-

      #include
      #include
      #include
      #define MAX 10
      #define TRUE 1
      #define FALSE 0
      struct stack
      {
      int arr[MAX];
      int top;
      } ;
      struct stack1
      {
      int arr[MAX];
      int top1;
      };
      int isfull(struct stack);
      int isfull1(struct stack1);
      void push(struct stack*,int);
      void push1(struct stack1*,int);
      int isempty(struct stack);
      int isempty1(struct stack1);
      int pop(struct stack*);
      int pop1(struct stack1*);
      int stacktop(struct stack);
      int stacktop1(struct stack1);
      void list(struct stack);
      void list1(struct stack1);

      void main()
      {
      struct stack s;
      struct stack1 s1;
      int ch,n,d;
      s.top=-1;
      s1.top1=MAX;
      while(1)
      {
      clrscr();
      printf(“\nmain menu”);
      printf(“\n 1.Push the element into stack”);
      printf(“\n 2.Pop the element from the stack”);
      printf(“\n 3.See the top element of the stack”);
      printf(“\n 4.List all element”);
      printf(“\n 5.Push the element into stack1″);
      printf(“\n 6.Pop the element from the stack1″);
      printf(“\n 7.See the top element of the stack1″);
      printf(“\n 8.List all element of stack1″);
      printf(“\n 9.Exit”);
      printf(“\n Enter your choice”);
      scanf(“%d”,&ch);
      switch(ch)
      {
      case 1:
      if(isfull(s)==TRUE)
      {
      printf(“stack over flow”);
      getch();
      }
      else
      {
      printf(“enter new element”);
      scanf(“%d”,&n);
      push(&s,n);
      }
      break;
      case 2:
      if(isempty(s)==TRUE)
      {
      printf(“stack underflow”);
      getch();
      }
      else
      {
      d=pop(&s);
      printf(“poped element %d”,d);
      getch();
      }
      break;
      case 3:
      if(isempty(s)==TRUE)
      {
      printf(“stack is empty”);
      getch();
      }
      else
      {
      d=stacktop(s);
      printf(“stack top %d “,d);
      getch();
      }
      break;
      case 4:
      if(isempty(s)==TRUE)
      {
      printf(“\n stack is empty”);
      getch();
      }
      else
      {
      list(s);
      getch();
      }
      break;
      case 5:
      if(isfull1(s1)==TRUE)
      {
      printf(“stack1 over flow”);
      getch();
      }
      else
      {
      printf(“enter new element”);
      scanf(“%d”,&n);
      push1(&s1,n);
      }
      break;
      case 6:
      if(isempty1(s1)==TRUE)
      {
      printf(“stack1 underflow”);
      getch();
      }
      else
      {
      d=pop1(&s1);
      printf(“poped element %d”,d);
      getch();
      }
      break;
      case 7:
      if(isempty1(s1)==TRUE)
      {
      printf(“stack1 is empty”);
      getch();
      }
      else
      {
      d=stacktop1(s1);
      printf(“stack top %d “,d);
      getch();
      }
      break;
      case 8:
      if(isempty1(s1)==TRUE)
      {
      printf(“\n stack1 is empty”);
      getch();
      }
      else
      {
      list1(s1);
      getch();
      }
      break;
      case 9:
      exit (0);
      break;
      default:
      printf(“wrong choice\n”);
      }
      }
      }
      int isfull(struct stack s)
      {
      if(s.top==MAX-1)
      return(TRUE);
      else
      {
      return(FALSE);
      }
      }
      void push(struct stack *s,int x)
      {
      s->top=s->top+1;
      s->arr[s->top]=x;
      }
      int isempty(struct stack s)
      {
      if(s.top==-1)
      return(TRUE);
      else
      return(FALSE);
      }
      int pop(struct stack *s)
      {
      int temp;
      temp=s->arr[s->top];
      s->top=s->top-1;
      return(temp);
      }
      int stacktop(struct stack s)
      {
      int temp;
      temp=s.arr[s.top];
      return(temp);
      }
      void list(struct stack s)
      {
      int i;
      for(i=0;itop1=s1->top1-1;
      s1->arr[s1->top1]=x;
      }
      int isempty1(struct stack1 s1)
      {
      if(s1.top1==MAX)
      return(TRUE);
      else
      return(FALSE);
      }
      int pop1(struct stack1 *s1)
      {
      int temp;
      temp=s1->arr[s1->top1];
      s1->top1=s1->top1+1;
      return(temp);
      }
      int stacktop1(struct stack1 s1)
      {
      int temp;
      temp=s1.arr[s1.top1];
      return(temp);
      }
      void list1(struct stack1 s1)
      {
      int i;
      for(i=MAX-1;i>=s1.top1;i–)
      {

      printf(“\n%d”,s1.arr[i]);
      }
      }

  28. 1. Algorithm to compute node in a link list

    2. Algorithm to calculate the average value of the real numbers in a link list

    3. Algorithm to add nodes at the end of a link list

    4. Algorithm to determine if any nodes that are not arranged in ascending (non-decreasing order) in a link list.

    5. Algorithm for finding an item in the link list.

    6. Algorithm to remove a node in a link list.

    – can give me a coding..coz i no understand how to write the coding

    1. data structure using c- yashwant kanetkar..
      or u may prefer ds. baluja or dilip sultania is also gud..
      well… u will find the yashwant kanetkar’s book better 2 undrstnd the concepts…
      for algos…ds. baluja..

  29. SEO| Internet Marketing| Website Designing

    Hi,

    We can fairly quickly promote your website to the top of the search rankings with no long term contracts!

    We can place your website on top of the Natural Listings on Google, Yahoo and MSN. Our Search Engine Optimization team delivers more top rankings then anyone else and we can prove it. We do not use “link farms” or “black hat” methods that Google and the other search engines frown upon and can use to de-list or ban your site. The techniques are proprietary, involving some valuable closely held trade secrets. Our prices are less then half of what other companies charge.

    We would be happy to send you a proposal using the top search phrases for your area of expertise. Please contact me at your convenience so we can start saving you some money.

    In order for us to respond to your request for information, please include your company’s website address (mandatory) and /or phone number.

    Sincerely,
    Deejay Colin
    deejayinternetmarketing@gmail.com
    COMPLETE INTERNET MARKETING SOLUTION
    SEO – Link Building – Copyright – Web Designing – PHP

  30. i myself prachi desai and have the exam of data structure management soon so i request the users to help me soon….. i want to learn how to write program using algorithms….. i can understand the algorithms easily but don’t understand how to do programming using algorithms……the topics included in my syllabus are arrays, stacks and queue, linked list….. and the basic introduction to data structure…….

    i hope for the reply soon…… please help me out…… its my request to the user of this site…… thank you……

  31. CREAT A PROGRRAM TO IMPLIMENT OF DBMS SET OPERATION(UNION,INTERSECT,EXCEPT)IN OOP
    TODAY OR TOMORRO

    Reply PLZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ

  32. hello!!
    i am intrested in learning data structures.. i am new to this subject although i know abt C.. could anyone help me in posting a material or illustrative so that i can learn data stuctures without anyones help..
    plz plz plz!!

  33. QUESTION:-

    Implement the course registration using the concept of single linked list.
    The data of students of a particular semester will be maintained in one linked list. Each node of the student linked list will point to another linked list of courses in which that particular student will get registered.

    The menu of the program should allow the following operations:
    1.Creation of linked list of students (Name, Reg.No and Batch No).
    2.Creation of linked list of offered courses.
    3.The function to register students in particular courses (Course Name and Course code).
    4.exat
    Allow the facility to view:
    The courses of only one student
    The courses of all the students
    Students in one particular course.

  34. pls give me a program of link list in data structure using c++ for the insertion of element after and before a given element in the link list

  35. Hi, guys I am preparing for c-dac entrance exam and don’t know data structures, please help me out and tell which book will be best for ds to start with as i have exam on 29th of this month, if anyone knows please tell me important topics to prepare for c-dac…
    my id is sadhnasharma89@gmail.com
    please help me guys….

  36. I am not known of any programming language.I have got data structure in our course using c. Any one who clears my concept…….. pzl plz plz plz rep

    1. hello sanjaya i don’t have link but i can mail you the book of data structure but in that book all the programs are shown with example but without theory

        1. you can ask me any thing about ds with c or c++. tell me that what are you doing currently. if you know c lang. then there is no problem about that so any time you can ask me

  37. sir,
    i am brushing up c and c++ for attending interviews for development job.i want to get good concepts and examples for datastructures in c,can u pl suggest some links and books.

    Thanks

  38. to use array of records and simulation methods to implement sparse matrix using a class ? can u help me making this program using C C++ . anything can be gratful . thanx a lot.. god bless you.

    1. You can easily learn data structure by reading books about it… One good book for begginers like you is “Book For Dummies”
      They have a lot of programming books which is easy to understand… try visit this site to find books that fits what you needed

      booksfordummies.weebly.com

  39. Sir m MCA student… B4 this i never liked this data structure sub
    But after seeing d articles in this site i got interest in this subject can u plz send me some of the algorithm to ma article thanking you

  40. Hai,guys i want need a program for in datastructure to creation of binarytree. i have a assignment guys.so plz help me

    1. hello dharshini send me ur email id i will mail u on it all ds programs that u want

      vishal lalwani
      computer programming faculty
      9026044257

  41. sir,i used sent mail for in my mobile.i dnt have pc.so that programs are not view in my mobile but ur msge i saw that,so dnt mistake me,sent it again in a these msg type,for this way.

  42. SEO| Internet Marketing| Website Designing

    Hi,

    We can fairly quickly promote your website to the top of the search rankings with no long term contracts!

    We can place your website on top of the Natural Listings on Google, Yahoo and MSN. Our Search Engine Optimization team delivers more top rankings then anyone else and we can prove it. We do not use “link farms” or “black hat” methods that Google and the other search engines frown upon and can use to de-list or ban your site. The techniques are proprietary, involving some valuable closely held trade secrets. Our prices are less then half of what other companies charge.

    We would be happy to send you a proposal using the top search phrases for your area of expertise. Please contact me at your convenience so we can start saving you some money.

    In order for us to respond to your request for information, please include your company’s website address (mandatory) and /or phone number.

    Sincerely,
    Jasmine Scott
    jasmineseomarketing@gmail.com
    COMPLETE INTERNET MARKETING SOLUTION
    SEO – Link Building – Copyright – Web Designing – PHP

  43. Write more, thats all I have to say. Literally, it seems as though you relied on the video to make your point.
    You clearly know what youre talking about, why throw away your intelligence on just posting videos to
    your site when you could be giving us something enlightening to
    read?

  44. Fantastic blog! Do you have any helpful hints for aspiring writers?

    I’m planning to start my own website soon but I’m a little lost on everything.
    Would you advise starting with a free platform like WordPress
    or go for a paid option? There are so many options out there that I’m totally confused .. Any tips? Thank you!

  45. Hi

    Hope you are well….

    I am Business Development Manager working with a reputable SEO and Web Development Company.

    I visited your website and found being having good design it’s not ranking well in search engines. When we search for any keyword pertaining to your domain, your website does not come on the first page of Google. So how would people come to know about your website? If you want your website to appear on first page of Google then please let me know. We can provide you guaranteed Top 10 Google rankings.

    Let me know if you are interested, I would happy to send you our company & price details etc…

    I look forward to your Mail.

    Thanks & Regards
    tom@topgooglerankings.net
    Tom Scott

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

If the code doesn't work, please replace the single quotes and double quotes(Actually these are not proper single and double quotes) in the code with single quotes and double quotes using your keyboard..

Follow

Get every new post delivered to your Inbox.

Join 110 other followers

%d bloggers like this: