iqa

This project contains Interview questions with solution and answers

This project is maintained by AshishNamdev

Data Structure Answers

<Back

A1-Data-Structure

A data structure is a way of organizing the data so that the data can be used efficiently. Different kinds of data structures are suited to different kinds of applications, and some are highly specialized to specific tasks. For example, B-trees are particularly well-suited for implementation of databases, while compiler implementations usually use hash tables to look up identifiers. (Source: Wiki Page)

A2-Data-Structure

Example:

A3-Data-Structure

A4-Data-Structure

A5-Data-Structure

Stack is a linear data structure which the order LIFO(Last In First Out) or FILO(First In Last Out) for accessing elements.

Basic operations of stack are:

Applications of Stack:

A6-Data-Structure

Queue is a linear structure which follows the order is First In First Out (FIFO) to access elements.

Basic operations on queue:

The difference between stacks and queues is in removing. In a stack we remove the item the most recently added; in a queue, we remove the item the least recently added. Both Queues and Stacks can be implemented using Arrays and Linked Lists.

A7-Data-Structure

A8-Data-Structure

A linked list is a linear data structure (like arrays) where each element is a separate object. Each element (that is node) of a list is comprising of two items – the data and a reference to the next node.

Types of Linked List:

  1. Singly Linked List: In this type of linked list, every node stores address or reference of next node in list and the last node has next address or reference as NULL.

    Example:

             1->2->3->4->NULL
    
  2. Doubly Linked List: Here, here are two references associated with each node, One of the reference points to the next node and one to the previous node.

    Example:

             NULL<-1<->2<->3->NULL
    
  3. Circular Linked List: Circular linked list is a linked list where all nodes are connected to form a circle. There is no NULL at the end. A circular linked list can be a singly circular linked list or doubly circular linked list.

    Example:

             1->2->3->1
             [The next pointer of last node is pointing to the first]
    

A9-Data-Structure

A10-Data-Structure

A stack can be implemented using two queues. Let stack to be implemented be ‘s’ and queues used to implement be ‘q1’ and ‘q2’. Stack ‘s’ can be implemented in two ways:

<Back