guide to data structures

Upload: abhishek-dixit

Post on 24-Feb-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/25/2019 Guide to Data Structures

    1/29

    dreamMAKERS Guide to Data Structures

    dreamMAKERS

    dreamMAKERSGuide to

    Data Structures

    dreamMAKERS Quick Tip:

    Data Structures forms an integral part of all IT Interviews for freshers irrespective of your branch orstream. In the following dreamMAKERS guide an attempt has been made to give a quick snapsolution for interview preparation purposes. Go through the basics first to brush your ownknowledge and then jump on to the questions.

    Go get it!

    Data Structures Basics

    Dynamic data structures Data structures that grow and shrink during execution

    Linked lists Allow insertions and removals anywhere

    Stacks Allow insertions and removals only at top of stack

    Queues Allow insertions at the back and removals from the front

    Binary trees High-speed searching and sorting of data and efficient elimination of duplicate data

    items Self-referential structures

    Structure that contains a pointer to a structure of the same type Can be linked together to form useful data structures such as lists, queues, stacks

    and trees Terminated with a NULLpointer (0)

    Diagram of two self-referential structure objects linked together.

  • 7/25/2019 Guide to Data Structures

    2/29

    dreamMAKERS Guide to Data Structures

    Dynamic memory allocation

    1015

    NULLpointer (points to nothing)Data member

    and pointer

    Obtain and release memory during execution malloc

    o Takes number of bytes to allocate Use sizeofto determine the size of an object

    o Returns pointer of type void * A void *pointer may be assigned to any pointer If no memory available, returns NULL

    o ExamplenewPtr = malloc( sizeof( struc t node ) );

    free Deallocates memory allocated by malloc Takes a pointer as an argument free ( newPtr ); Linked list

    A linked listis a series of connected nodes Each node contains at least A piece of data (any type) Pointer to the next node in the list

    Head:pointer to the first node The last node points to NULL Ar ray vs Linked L is to Array has a fixed size

    Data must be shifted during insertions and deletionso Linked list is able to grow in size as needed

    Does not require the shifting of items during insertions and deletions Types of linked lists:o Singly linked list

    Begins with a pointer to the first node Terminates with a null pointer Only traversed in one direction

    o Circular, singly linked Pointer in the last node points back to the first node

    o Doubly linked list Two start pointers first element and last element Each node has a forward pointer and a backward pointer Allows traversals both forwards and backwards

    o Circular, doubly linked list Forward pointer of the last node points to the first node and backward

    pointer of the first node points to the last node

    dreamMAKERS

  • 7/25/2019 Guide to Data Structures

    3/29

    dreamMAKERS Guide to Data Structures

    Operations in a simple linked list:A. Insert ion:1. Insert to Empty List:Case 1: Insert to Empty List:Cur ==Head, means we are adding to an empty list, OR at the beginning of a

    listCur ==NULL, means the list is emptynewPtr ->next = Head;

    Head = newPtrCase 2: Insert to head of non-empty Lis t:Cur! =NULL, means the list is not empty. And we are adding at the beginningof the List.newPtr->next = Head;Head = newPtr ;Case 3: Insert to middle:prev!= NULL ANDCur! = NULL, so we are adding at the middle of the list

    newPtr->next = cur;prev->next = newPtrCase 4: Insert to end:

    prev != NULL ANDCur == NULL, so we are adding at the end of the listnewPtr->next = cur;prev->next = newPtr

    B. Deletion :Case 1: head node:Cur! =NULL &&Cur == Head &&Cur->data == deldata Delete first node

    Head = Head->next; delete cur;Case 2: Delete non head node:

    Cur! =Head && cur->data ==deldata && cur !=NULLprev->next = cur->next;delete cur;

    Double-Ended Lists Similar to an ordinary list with the addition that a link to the last item is

    maintained along with that to the first. The reference to the last link permits to insert a new link directly at the

    end of the list as well as at the beginning. This could not be done in the ordinary linked list without traversing the

    whole list. This technique is useful in implementing the Queue where insertions

    are made at end and deletions from the front.

    dreamMAKERS

  • 7/25/2019 Guide to Data Structures

    4/29

    dreamMAKERS Guide to Data Structures

    dreamMAKERS

    Circular Linked Lists

    o Last node references the first nodeo Every node has a successoro No node in a circular linked list contains NULL

    Circular doubly linked list Precede pointer of the dummy head node points to the last node Next reference of the last node points to the dummy head node No special cases for insertions and deletions

    STACK: New nodes can be added and removed only at the top Similar to a pile of dishes Last-in, first-out (LIFO) Bottom of stack indicated by a link member to NULL Constrained version of a linked list

    push Adds a new node to the top of the stack

    pop Removes a node from the top Stores the popped value Returns trueif popwas successful

    IsEmpty: Checks if the Stack is empty

    TOP

    BOTTOM

    exitenter

    IsFull: checks if the Stack is full Run-time procedure information

  • 7/25/2019 Guide to Data Structures

    5/29

    dreamMAKERS Guide to Data Structures

    Ar ithmetic computations Convert the infix expression to postfix form

    ted by first being

    h respect

    move only to the right with respect

    re removed

    a t the postfix expression

    the calculator

    he calculator

    n the stack

    Queue Similar to a supermarket checkout line

    from the head

    sert an object at the end of the queue

    move and return from the queue the object at the front

    ueue is empty

    BACK

    FRONT

    o An infix expression can be evaluaconverted into an equivalent postfix expression

    o Facts about converting from infix to postfixo Operands always stay in the same order wit

    to one anothero An operator will

    to the operandso All parentheses a

    Ev lua eo Requires you to enter postfix expressions

    Example: 2, 3, 4, +, *o When an operand is entered,

    Pushes it onto a stacko When an operator is entered, t

    Applies it to the top two operands of the stack

    Pops the operands from the stack Pushes the result of the operation o

    First-in, first-out (FIFO) Nodes are removed only Nodes are inserted only at the tail Enqueue

    o in Dequeue:

    o re Other methods supported are:

    o isEmpty: checks if the qo isFull: checks if the queue is full

    enter

    exit

    dreamMAKERS

  • 7/25/2019 Guide to Data Structures

    6/29

    dreamMAKERS Guide to Data Structures

    dreamMAKERS

    Circ e

    Basic Operations on a Queue: Removes all the elements from the

    the queue is empty.

    ueue is full. If the

    (first) element of the queue; the

    front (first) element of the queue; the

    a new element to the rear of the

    ty

    Tree The boxes on the tree are called nodes

    and right of) a given

    e a given node is called its parent

    d to be siblingsndant

    a binary tree that is either empty or one

    ular Queu

    destroyQueuequeue, leaving the queue empty

    isEmptyQueue: Checks whetherIf the queue is empty, it returns the value true;otherwise, it returns the value false

    isFullQueue: Checks whether the qqueue is full, it returns the value true; otherwise, itreturns the value false

    front: Returns the frontqueue must exist

    back: Returns thequeue must exist

    addQueue: Addsqueue; the queue must exist and must not be full

    deleteQueue: Removes the front element of thequeue; the queue must exist and must not be emp

    The nodes immediately below (to the leftnode are called its children

    The node immediately abov The (unique) node without a parent is called the root

    A node with no children is called a leaf Two children of the same parent are sai A node can be an ancestor (e.g. grandparent) or a desce

    (e.g. great-grandchild) A binary search treeis

    in which each node contains a key that satisfies the followingconditions:

  • 7/25/2019 Guide to Data Structures

    7/29

    dreamMAKERS Guide to Data Structures

    o All keys (if any) in the left sub-tree of the root precede thekey in the root we will not consider the case withrepeating keys

    o The key in the root precedes all keys (if any) in its right sub-tree

    o The left and right sub-trees of the root are again binarysearch trees (a recursivedefinition, but here implemented asTreeNode elements)

    4

    2 7

    Binary trees

    4 6 9

    6

    1

    7 17 3 4

    All nodes contain two links None, one, or both of which may be NULL The root node is the first node in a tree. Each link in the root node refers to a child A node with no children is called a leaf node

    B

    A D

    C

    Tree traversals:

    dreamMAKERS

  • 7/25/2019 Guide to Data Structures

    8/29

    dreamMAKERS Guide to Data Structures

    Inordertraversal prints the node values in ascending order Traverse the left subtree with an inorder traversal Process the value in the node (i.e., print the node

    value) Traverse the right subtree with an inorder traversal

    Preorder traversal Process the value in the node Traverse the left subtree with a preorder traversal Traverse the right subtree with a preorder traversal

    Postorder traversal Traverse the left subtree with a postorder

    traversal Traverse the right subtree with a postorder

    traversal Process the value in the node

    A binary tree is balanced if there is no binary tree of lesser height thatcan have the same number of nodes

    For example, the maximum number ofnodes in a tree of height 1 is 3, so this

    tree is balanced:

    A Unbalanced tree

    Efficiency: Assume number of nodes N and number of levels L. N = 2L -1 N+1 = 2L L = log(N+1) The time needed to carry out the common tree

    operations is proportional to the base 2 log of N O(log N)time is required for these operations.

    dreamMAKERS

  • 7/25/2019 Guide to Data Structures

    9/29

    dreamMAKERS Guide to Data Structures

    dreamMAKERS

    SEARCHING & SORTING: Search Algorithms:

    o Sequential Search:

    for ( i = 0 ; i

  • 7/25/2019 Guide to Data Structures

    10/29

    dreamMAKERS Guide to Data Structures

    for a list of length n, a binary search makesapproximately 2*log2(n + 1) keycomparisons

    Successful search: for a list of length n, on average, a binary

    search makes 2*log2n 4 key comparisonso Hashing

    Main objectives to choosing hash functions: Choose a hash function that is easy to

    compute Minimize the number of collisions Mid-Square

    Hash function, h, computed bysquaring the identifier

    Using appropriate number of bits fromthe middle of the square to obtain thebucket address

    Middle bits of a square usually dependon all the characters, it is expectedthat different keys will yield differenthash addresses with high probability,even if some of the characters are thesame

    Folding Key X is partitioned into parts such

    that all the parts, except possibly thelast parts, are of equal length

    Parts then added, in convenient way,to obtain hash address

    Division(Modular arithmetic) Key X is converted into an integer iX This integer divided by size of hash

    table to get remainder, giving addressof X in HT

    Sorting:

    The objective is to take an unordered set ofcomparable data items and arrange them inorder.

    We will usually sort the data into ascendingorder sorting into descending order issimilar

    We will concentrate on sorting data that isstored in an array, but other ADTs can beused to store the data; in fact, we have

    dreamMAKERS

  • 7/25/2019 Guide to Data Structures

    11/29

    dreamMAKERS Guide to Data Structures

    already seen a sorting algorithm in which abinary search tree is used

    There are two main sorting themes: address-based sorting and comparison-based sorting

    A. Bubble sor t [t ranspos it ion sor ting]:

    A p ret ty dreadful type of sort ! However, the code is small:

    f or ( i nt i =arr . l ength; i >0; i - - ) {f or ( i nt j =1; j ar r [ j ] ) {temp = arr [ j - 1] ;ar r [ j - 1] = ar r [ j ] ;

    arr [ j ] = t emp; }}}

    B. SelectionSort [priority queue sorting]:

    o SelectionSort uses an arrayimplementation of the Priority Queue

    ADT (not the heap implementation westudied)

    o The elements are inserted intothearray as they arrive and thenextracted in descending order intoanother array

    o The major disadvantage is theperformance overhead of finding thelargest element at each step; we haveto traverse over the entire array tofind it

    o The dominant operation (time-wise)gives the overall time complexity, i.e.,O(n2)

    o Although this is an O(n2) algorithm,its advantage overO(nlog n)sorts is its simplicity

    C. Shell sort :o Shell sort aims to reduce the work done

    by insertion sort (i.e. scanning a list andinserting into the right position

    o It can be shown that this approach willsort a list with a time complexity ofO(N1.25

    D. Merge Sort :

    dreamMAKERS

  • 7/25/2019 Guide to Data Structures

    12/29

    dreamMAKERS Guide to Data Structures

    MergeSort an initial array is repeatedlydivided into halves (usually each is aseparate array), until arrays of just oneelement remain

    At each level of recombination, twosorted arrays are merged into one This is done by copying the smaller of

    the two elements from the sorted arraysinto the new array, and then movingalong the arrays

    if (left < right) // terminating condition {int centre = (left + right)/2;mergeSort (a, temp, left, centre);mergeSort (a, temp, center + 1, right);merge (a, temp, left, center + 1, right); }

    Time complexity of merge sort is O(nlog n)

    E. Quick Sort: Its average running time is O(n log n)

    and it is very fast It has worst-case performance of O(n2)

    but this can be made very unlikely withlittle effort

    The idea is as follows:1. If the number of elements to be sorted

    is 0 or 1, then return2. Pick any element, v(this is called thepivot)

    3. Partition the other elements into twodisjoint sets, S1 of elements v, and S2 ofelements > v

    4. Return QuickSort (S1) followed by vfollowed by QuickSort (S2)

    dreamMAKERS

  • 7/25/2019 Guide to Data Structures

    13/29

    dreamMAKERS Guide to Data Structures

    Some frequently asked Questions

    1. What is Data Structure?

    Answer : A data structure is a group of data elements grouped together under one name.

    These data elements, known as members, can have different types and different lengths. Someare used to store the data of same type and some are used to store different types of data.

    2. What is a queue?

    Answer :A Queue is a sequential organization of data. A queue is a first in first out type of datastructure. An element is inserted at the last position and an element is always taken out from thefirst position.

    3. What is a spanning Tree?

    Answer :A spanning tree is a tree associated with a network. All the nodes of the graph appear

    on the tree once. A minimum spanning tree is a spanning tree organized so that the total edgeweight between nodes is minimized.

    4. How can I search for data in a linked list?

    Answer : Unfortunately, the only way to search a linked list is with a linear search, because theonly way a linked lists members can be accessed is sequentially. Sometimes it is quicker totake the data from a linked list and store it in a different data structure so that searches can bemore efficient.

    5. What is the data structures used to perform recursion?

    Answer : Stack. Because of its LIFO (Last In First Out) property it remembers its caller soknows whom to return when the function has to return. Recursion makes use of system stackfor storing the return addresses of the function calls. Every recursive function has its equivalentiterative (non-recursive) function. Even when such equivalent iterative procedures are written,explicit stack is to be used.

    6. What is the difference between ARRAY and STACK?

    Answer :STACK follows LIFO. Thus the item that is first entered would be the last removed. Inarray the items can be entered or removed in any order. Basically each member access is doneusing index. No strict order is to be followed here to remove a particular element.

    7. What is the difference between procedural and object-oriented programs?

    Answer : 1. In procedural program, programming logic follows certain procedures and theinstructions are executed one after another. In OOP program, unit of program is object, which isnothing but combination of data and code.2. In procedural program, data is exposed to the whole program whereas in OOPs program, it isaccessible with in the object and which in turn assures the security of the code.

    8. What is the difference between NULL AND VOID poin ter?

    dreamMAKERS

    http://www.kyapoocha.com/data-structure-interview-questions/what-is-data-structure-2/http://www.kyapoocha.com/data-structure-interview-questions/what-is-a-queue/http://www.kyapoocha.com/data-structure-interview-questions/what-is-a-spanning-tree/http://www.kyapoocha.com/data-structure-interview-questions/what-is-the-data-structures-used-to-perform-recursion-2/http://www.kyapoocha.com/data-structure-interview-questions/what-is-the-difference-between-array-and-stack/http://www.kyapoocha.com/object-oriented-interview-questions/what-is-the-difference-between-procedural-and-object-oriented-programs/http://www.kyapoocha.com/data-structure-interview-questions/what-is-the-difference-bitween-null-and-void-pointer/http://www.kyapoocha.com/data-structure-interview-questions/what-is-the-difference-bitween-null-and-void-pointer/http://www.kyapoocha.com/object-oriented-interview-questions/what-is-the-difference-between-procedural-and-object-oriented-programs/http://www.kyapoocha.com/data-structure-interview-questions/what-is-the-difference-between-array-and-stack/http://www.kyapoocha.com/data-structure-interview-questions/what-is-the-data-structures-used-to-perform-recursion-2/http://www.kyapoocha.com/data-structure-interview-questions/what-is-a-spanning-tree/http://www.kyapoocha.com/data-structure-interview-questions/what-is-a-queue/http://www.kyapoocha.com/data-structure-interview-questions/what-is-data-structure-2/
  • 7/25/2019 Guide to Data Structures

    14/29

    dreamMAKERS Guide to Data Structures

    Answer :NULL can be value for pointer type variables.VOID is a type identifier which has not size.NULL and void are not same. Example: void* ptr = NULL;

    9. Does the minimum spanning tree of a graph give the shortest distance between any 2

    specified nodes?

    Answer :Minimal spanning tree assures that the total weight of the tree is kept at its minimum.But it doesnt mean that the distance between any two nodes involved in the minimum-spanningtree is minimum.

    10. How do you assign an address to an element of a pointer array?

    Answer : We can assign a memory address to an element of a pointer array by using theaddress operator, which is the ampersand (&), in an assignment statement such asptemployee[0] = &projects[2];

    11. How is any Data Structure application is c lassified among files?

    Answer : A linked list application can be organized into a header file, source file and mainapplication file. The first file is the header file that contains the definition of the NODE structureand the LinkedList class definition. The second file is a source code file containing theimplementation of member functions of the LinkedList class. The last file is the application filethat contains code that creates and uses the LinkedList class.

    12. What is the quickest sorting method to use?

    Answer :The answer depends on what you mean by quickest. For most sorting problems, itjust doesnt matter how quick the sort is because it is done infrequently or other operations take

    significantly more time anyway. Even in cases in which sorting speed is of the essence, there isno one answer. It depends on not only the size and nature of the data, but also the likely order.No algorithm is best in all cases.There are three sorting methods in this authors toolbox thatare all very fast and that are useful in different situations. Those methods are quick sort, mergesort, and radix sort.

    The Quick Sort: The quick sort algorithm is of the divide and conquer type. That means itworks by reducing a sortingproblem into several easier sorting problems and solving each of them. A dividing value ischosen from the input data, and the data is partitioned into three sets: elements that belongbefore the dividing value, the value itself, and elements that come after the dividing value. Thepartitioning is performed by exchanging elements that are in the first set but belong in the third

    with elements that are in the third set but belong in the first Elements that are equal to thedividing element can be put in any of the three setsthe algorithm will still work properly.

    The Merge Sort: The merge sort is a divide and conquer sort as well. It works by consideringthe data to be sorted as a sequence of already-sorted lists (in the worst case, each list is oneelement long). Adjacent sorted lists are merged into larger sorted lists until there is a singlesorted list containing all the elements. The merge sort is good at sorting lists and other datastructures that are not in arrays, and it can be used to sort things that dont fit into memory. Italso can be implemented as a stable sort.

    dreamMAKERS

    http://www.kyapoocha.com/data-structure-interview-questions/does-the-minimum-spanning-tree-of-a-graph-give-the-shortest-distance-between-any-2-specified-nodes/http://www.kyapoocha.com/data-structure-interview-questions/does-the-minimum-spanning-tree-of-a-graph-give-the-shortest-distance-between-any-2-specified-nodes/http://www.kyapoocha.com/data-structure-interview-questions/how-do-you-assign-an-address-to-an-element-of-a-pointer-array/http://www.kyapoocha.com/data-structure-interview-questions/how-is-any-data-structure-application-is-classified-among-files/http://www.kyapoocha.com/data-structure-interview-questions/how-is-any-data-structure-application-is-classified-among-files/http://www.kyapoocha.com/data-structure-interview-questions/what-is-the-quickest-sorting-method-to-use/http://www.kyapoocha.com/data-structure-interview-questions/what-is-the-quickest-sorting-method-to-use/http://www.kyapoocha.com/data-structure-interview-questions/how-is-any-data-structure-application-is-classified-among-files/http://www.kyapoocha.com/data-structure-interview-questions/how-do-you-assign-an-address-to-an-element-of-a-pointer-array/http://www.kyapoocha.com/data-structure-interview-questions/does-the-minimum-spanning-tree-of-a-graph-give-the-shortest-distance-between-any-2-specified-nodes/http://www.kyapoocha.com/data-structure-interview-questions/does-the-minimum-spanning-tree-of-a-graph-give-the-shortest-distance-between-any-2-specified-nodes/
  • 7/25/2019 Guide to Data Structures

    15/29

    dreamMAKERS Guide to Data Structures

    dreamMAKERS

    The Radix Sort:The radix sort takes a list of integers and puts each element on a smaller list,depending on the value of its least significant byte. Then the small lists are concatenated, andthe process is repeated for each more significant byte until the list is sorted. The radix sort issimpler to implement on fixed-length data such as ints.

    13. What method removes the value from the top of a stack?

    Answer :The pop() member method removes the value from the top of a stack, which is thenreturned by the pop() member method to the statement that calls the pop() member method.

    14. How is the front of the queue calculated?

    Answer :The front of the queue is calculated by front = (front+1) % size.

    15. How many di fferent trees are possible with 10 nodes?

    Answer : 1014 - For example, consider a tree with 3 nodes(n=3), it will have the maximum

    combination of 5 different (ie, 23 - 3 = 5) trees.

    i) ii) iii) iv) v)In general: If there are n nodes, there exist 2n-n different trees.

    16. How many parts are there in a declaration statement?

    Answer : There are two main parts, variable identifier and data type and the third type isoptional which is type qualifier like signed/unsigned.

    17. How many ways can an argument be passed to a subrou tine?

    Answer :An argument can be passed in two ways. They are Pass by Valueand Passing byReference. Passing by value: This method copies the value of an argument into the formalparameter of the subroutine. Passing by reference: In this method, a reference to an argument(not the value of the argument) is passed to the parameter

    18. How memory i s reserved using a declaration statement?

    Answer : Memory is reserved using data type in the variable declaration. A programminglanguage implementation has predefined sizes for its data types. For example, in C# thedeclaration int i; will reserve 32 bits for variable i. A pointer declaration reserves memory for theaddress or the pointer variable, but not for the data that it will point to. The memory for the datapointed by a pointer has to be allocated at runtime. The memory reserved by the compiler forsimple variables and for storing pointer address is allocated on the stack, while the memoryallocated for pointer referenced data at runtime is allocated on the heap.

    http://www.kyapoocha.com/data-structure-interview-questions/what-method-removes-the-value-from-the-top-of-a-stack/http://www.kyapoocha.com/data-structure-interview-questions/how-is-the-front-of-the-queue-calculated/http://www.kyapoocha.com/data-structure-interview-questions/how-many-parts-are-there-in-a-declaration-statement/http://www.kyapoocha.com/java-interview-questions/how-many-ways-can-an-argument-be-passed-to-a-subroutine-and-explain-them/http://www.kyapoocha.com/java-interview-questions/how-many-ways-can-an-argument-be-passed-to-a-subroutine-and-explain-them/http://www.kyapoocha.com/data-structure-interview-questions/how-memory-is-reserved-using-a-declaration-statement/http://www.kyapoocha.com/data-structure-interview-questions/how-memory-is-reserved-using-a-declaration-statement/http://www.kyapoocha.com/java-interview-questions/how-many-ways-can-an-argument-be-passed-to-a-subroutine-and-explain-them/http://www.kyapoocha.com/data-structure-interview-questions/how-many-parts-are-there-in-a-declaration-statement/http://www.kyapoocha.com/data-structure-interview-questions/how-is-the-front-of-the-queue-calculated/http://www.kyapoocha.com/data-structure-interview-questions/what-method-removes-the-value-from-the-top-of-a-stack/
  • 7/25/2019 Guide to Data Structures

    16/29

    dreamMAKERS Guide to Data Structures

    19. If you are using C language to implement the heterogeneous linked lis t, what pointertype will you use?

    Answer :The heterogeneous linked list contains different data types in its nodes and we need alink, pointer to connect them. It is not possible to use ordinary pointers for this. So we go for voidpointer. Void pointer is capable of storing pointer to any type as it is a generic pointer type.

    20. In an AVL tree, at what condition the balancing i s to be done?

    Answer :If the pivotal value (or the Height factor) is greater than 1 or less than 1.

    21. In RDBMS, what is the efficient data structure used in the internal storagerepresentation?

    Answer : B+ tree. Because in B+ tree, all the data is stored only in leaf nodes, that makessearching easier. This corresponds to the records that shall be stored in leaf nodes.

    22. Is Pointer a variable?

    Answer :Yes, a pointer is a variable and can be used as an element of a structure and as anattribute of a class in some programming languages such as C++, but not Java. However, thecontents of a pointer is a memory address of another location of memory, which is usually thememory address of another variable, element of a structure, or attribute of a class.

    23. List out few of the Application of t ree data-structu re?

    Answer : The manipulation of Arithmetic expression, Symbol Table construction, Syntaxanalysis.

    24. List out the areas in which data structures are applied extensively?

    Answer: 1.Compiler Design, 2.Operating System, 3.Database Management System,4.Statistical analysis package, 5. Numerical Analysis, 6.Graphics, 7.Artificial Intelligence,8. Simulation.

    .25. Minimum number of queues needed to imp lement the priority queue?

    Answer : Two. One queue is used for actual storing of data and another for storing priorities.

    26. Run Time Memory Allocation is known as.

    Answer :Allocating memory at runtime is called a dynamically allocating memory. In this,you

    dynamically allocate memory by using the new operator when declaring the array, forexample:int grades[] = new int[10];

    27. Tell how to check whether a linked list is circular.

    Answer :Create two pointers, each set to the start of the list. Update each as follows:while (pointer1) {pointer1 = pointer1->next;pointer2 = pointer2->next; if (pointer2) pointer2=pointer2->next;

    dreamMAKERS

    http://www.kyapoocha.com/data-structure-interview-questions/if-you-are-using-c-language-to-implement-the-heterogeneous-linked-list-what-pointer-type-will-you-use-2/http://www.kyapoocha.com/data-structure-interview-questions/if-you-are-using-c-language-to-implement-the-heterogeneous-linked-list-what-pointer-type-will-you-use-2/http://www.kyapoocha.com/data-structure-interview-questions/in-an-avl-tree-at-what-condition-the-balancing-is-to-be-done/http://www.kyapoocha.com/data-structure-interview-questions/in-rdbms-what-is-the-efficient-data-structure-used-in-the-internal-storage-representation/http://www.kyapoocha.com/data-structure-interview-questions/in-rdbms-what-is-the-efficient-data-structure-used-in-the-internal-storage-representation/http://www.kyapoocha.com/data-structure-interview-questions/is-pointer-a-variable/http://www.kyapoocha.com/data-structure-interview-questions/is-pointer-a-variable/http://www.kyapoocha.com/data-structure-interview-questions/list-out-few-of-the-application-of-tree-data-structure/http://www.kyapoocha.com/data-structure-interview-questions/list-out-the-areas-in-which-data-structures-are-applied-extensively-2/http://www.kyapoocha.com/data-structure-interview-questions/minimum-number-of-queues-needed-to-implement-the-priority-queue/http://www.kyapoocha.com/data-structure-interview-questions/run-time-memory-allocation-is-known-as/http://www.kyapoocha.com/c-interview-questions/tell-how-to-check-whether-a-linked-list-is-circular/http://www.kyapoocha.com/c-interview-questions/tell-how-to-check-whether-a-linked-list-is-circular/http://www.kyapoocha.com/data-structure-interview-questions/run-time-memory-allocation-is-known-as/http://www.kyapoocha.com/data-structure-interview-questions/minimum-number-of-queues-needed-to-implement-the-priority-queue/http://www.kyapoocha.com/data-structure-interview-questions/list-out-the-areas-in-which-data-structures-are-applied-extensively-2/http://www.kyapoocha.com/data-structure-interview-questions/list-out-few-of-the-application-of-tree-data-structure/http://www.kyapoocha.com/data-structure-interview-questions/is-pointer-a-variable/http://www.kyapoocha.com/data-structure-interview-questions/in-rdbms-what-is-the-efficient-data-structure-used-in-the-internal-storage-representation/http://www.kyapoocha.com/data-structure-interview-questions/in-rdbms-what-is-the-efficient-data-structure-used-in-the-internal-storage-representation/http://www.kyapoocha.com/data-structure-interview-questions/in-an-avl-tree-at-what-condition-the-balancing-is-to-be-done/http://www.kyapoocha.com/data-structure-interview-questions/if-you-are-using-c-language-to-implement-the-heterogeneous-linked-list-what-pointer-type-will-you-use-2/http://www.kyapoocha.com/data-structure-interview-questions/if-you-are-using-c-language-to-implement-the-heterogeneous-linked-list-what-pointer-type-will-you-use-2/
  • 7/25/2019 Guide to Data Structures

    17/29

    dreamMAKERS Guide to Data Structures

    if (pointer1 == pointer2) {print (\circular\n\);}}

    28. What are the methods available in storing sequential fi les?

    Answer :Straight merging,Natural merging,Polyphase sort,Distribution of Initial runs.

    29. What does each entry in the Link List called?

    Answer :Each entry in a linked list is called a node. Think of a node as an entry that has threesub entries. One sub entry contains the data, which may be one attribute or many attributes.Another points to the previous node, and the last points to the next node. When you enter a newitem on a linked list, you allocate the new node and then set the pointers to previous and nextnodes.

    30. What does isEmpty() member method determines?

    Answer : isEmpty() checks if the stack has at least one element. This method is called byPop() before retrieving and returning the top element.

    31. What is a node class?

    Answer : A node class is a class that, relies on the base class for services and implementation,provides a wider interface to te users than its base class, relies primarily on virtual functions inits public interface depends on all its direct and indirect base class can be understood only inthe context of the base class can be used as base for further derivationcan be used to create objects. A node class is a class that has added new services orfunctionality beyond the services inherited from its base class.

    32. What is impact of signed numbers on the memory?

    Answer :Sign of the number is the first bit of the storage allocated for that number. So you getone bit less for storing the number. For example if you are storing an 8-bit number, without sign,the range is 0-255. If you decide to store sign you get 7 bits for the number plus one bit for thesign. So the range is -128 to +127

    33. What is Linked List?

    Answer :Linked List is one of the fundamental data structures. It consists of a sequence ofnodes, each containing arbitrary data fields and one or two (links) pointing to the next and/orprevious nodes. A linked list is a self-referential datatype because it contains a pointer or link to

    another data of the same type. Linked lists permit insertion and removal of nodes at any point inthe list in constant time, but do not allow random access.

    34. What is precision?

    Answer :Precision refers the accuracy of the decimal portion of a value. Precision is thenumber of digits allowed after the decimal point.

    dreamMAKERS

    http://www.kyapoocha.com/data-structure-interview-questions/what-is-a-node-class/http://www.kyapoocha.com/data-structure-interview-questions/what-is-impact-of-signed-numbers-on-the-memory/http://www.kyapoocha.com/data-structure-interview-questions/what-is-linked-list/http://www.kyapoocha.com/data-structure-interview-questions/what-is-precision/http://www.kyapoocha.com/data-structure-interview-questions/what-is-precision/http://www.kyapoocha.com/data-structure-interview-questions/what-is-linked-list/http://www.kyapoocha.com/data-structure-interview-questions/what-is-impact-of-signed-numbers-on-the-memory/http://www.kyapoocha.com/data-structure-interview-questions/what-is-a-node-class/
  • 7/25/2019 Guide to Data Structures

    18/29

    dreamMAKERS Guide to Data Structures

    35. What is significance of * ?

    Answer :The symbol * tells the computer that you are declaring a pointer.Actually it depends on context.In a statement like int *ptr; the * tells that you are declaring a pointer.In a statement like int i = *ptr;it tells that you want to assign value pointed to by ptr to variable i.

    The symbol * is also called as Indirection Operator/ Dereferencing Operator.

    36. What is the bucket size, when the overlapping and coll ision occur at same time?

    Answer :One. If there is only one entry possible in the bucket, when the collision occurs, thereis no way to accommodate the colliding value. This results in the overlapping of values.

    37. What is the easiest sorting method to use?

    Answer :The answer is the standard library function qsort(). Its the easiest sort by far forseveral reasons: 1. It is already written. 2. It is already debugged. 3. It has been optimized as

    much as possible (usually).Void qsort(void *buf, size_t num, size_t size, int (*comp)(const void *ele1, const void *ele2));

    38. What is the heap?

    Answer :The heap is where malloc(), calloc(), and realloc() get memory.Getting memory fromthe heap is much slower than getting it from the stack. On the other hand, the heap is muchmore flexible than the stack. Memory can be allocated at any time and deallocated in any order.Such memory isnt deallocated automatically; you have to call free().Recursive data structuresare almost always implemented with memory from the heap. Strings often come from there too,especially strings that could be very long at runtime. If you can keep data in a local variable (andallocate it from the stack), your code will run faster than if you put the data on the heap.

    Sometimes you can use a better algorithm if you use the heapfaster, or more robust, or moreflexible. Its a tradeoff.If memory is allocated from the heap, its available until the program ends. Thats great if youremember to deallocate it when youre done. If you forget, its a problem. A memory leak issome allocated memory thats no longer needed but isnt deallocated. If you have a memoryleak inside a loop, you can use up all the memory on the heap and not be able to get any more.(When that happens, the allocation functions return a null pointer.) In some environments, if aprogram doesnt deallocate everything it allocated, memory stays unavailable even after theprogram ends.

    39. What is the relationship between a queue and its underlying array?

    Answer :Data stored in a queue is actually stored in an array. Two indexes, front and end willbe used to identify the start and end of the queue. When an element is removed front will beincremented by 1. In case it reaches past the last index available it will be reset to 0. Then it willbe checked with end. If it is greater than end queue is empty.When an element is added end willbe incremented by 1. In case it reaches past the last index available it will be reset to 0. Afterincrementing it will be checked with front. If they are equal queue is full.

    dreamMAKERS

    http://www.kyapoocha.com/data-structure-interview-questions/what-is-significance-of/http://www.kyapoocha.com/data-structure-interview-questions/what-is-the-bucket-size-when-the-overlapping-and-collision-occur-at-same-time/http://www.kyapoocha.com/data-structure-interview-questions/what-is-the-heap/http://www.kyapoocha.com/data-structure-interview-questions/what-is-the-relationship-between-a-queue-and-its-underlying-array/http://www.kyapoocha.com/data-structure-interview-questions/what-is-the-relationship-between-a-queue-and-its-underlying-array/http://www.kyapoocha.com/data-structure-interview-questions/what-is-the-heap/http://www.kyapoocha.com/data-structure-interview-questions/what-is-the-bucket-size-when-the-overlapping-and-collision-occur-at-same-time/http://www.kyapoocha.com/data-structure-interview-questions/what-is-significance-of/
  • 7/25/2019 Guide to Data Structures

    19/29

    dreamMAKERS Guide to Data Structures

    40. What member funct ion places a new node at the end of the linked list?

    Answer :The appendNode() member function places a new node at the end of the linked list.The appendNode() requires an integer representing the current data of the node.

    41. What method is used to place a value onto the top of a stack?

    Answer :push() method, Push is the direction that data is being added to the stack. push()member method places a value onto the top of a stack.

    42. What method removes the value from the top of a stack?

    Answer :The pop() member method removes the value from the top of a stack, which is thenreturned by the pop() member method to the statement that calls the pop() member method.

    43. When can you tell that a memory leak will occur?

    Answer :A memory leak occurs when a program loses the ability to free a block of dynamically

    allocated memory.

    44. Whether Linked List is linear or Non-linear data structure?

    Answer :According to Access strategies Linked list is a linear one. According to Storage LinkedList is a Non-linear one.

    45. Which file contains the definition o f member functions?

    Answer : Definitions of member functions for the Linked List class are contained in theLinkedList.cpp file.

    46. Which process places data at the back of the queue?

    Answer : Enqueueis the process that places data at the back of the queue.

    47. Why do we Use a Multidimensional Array?

    Answer :A multidimensional array can be useful to organize subgroups of data within an array.In addition to organizing data stored in elements of an array, a multidimensional array can storememory addresses of data in a pointer array and an array of pointers. Multidimensional arraysare used to store information in a matrix form. e.g. a railway timetable, schedule cannot bestored as a single dimensional array. One can use a 3-D array for storing height, width andlength of each room on each floor of a building.

    48. Why is the isEmpty() member method called?

    Answer :The isEmpty() member method is called within the dequeue process to determine ifthere is an item in the queue to be removed i.e. isEmpty() is called to decide whether the queuehas at least one element. This method is called by the dequeue() method before returning thefront element.

    dreamMAKERS

    http://www.kyapoocha.com/data-structure-interview-questions/what-member-function-places-a-new-node-at-the-end-of-the-linked-list/http://www.kyapoocha.com/data-structure-interview-questions/what-method-is-used-to-place-a-value-onto-the-top-of-a-stack/http://www.kyapoocha.com/data-structure-interview-questions/what-method-removes-the-value-from-the-top-of-a-stack/http://www.kyapoocha.com/data-structure-interview-questions/when-can-you-tell-that-a-memory-leak-will-occur/http://www.kyapoocha.com/data-structure-interview-questions/whether-linked-list-is-linear-or-non-linear-data-structure-2/http://www.kyapoocha.com/data-structure-interview-questions/which-file-contains-the-definition-of-member-functions/http://www.kyapoocha.com/data-structure-interview-questions/which-process-places-data-at-the-back-of-the-queue/http://www.kyapoocha.com/data-structure-interview-questions/why-do-we-use-a-multidimensional-array/http://www.kyapoocha.com/data-structure-interview-questions/why-is-the-isempty-member-method-called/http://www.kyapoocha.com/data-structure-interview-questions/why-is-the-isempty-member-method-called/http://www.kyapoocha.com/data-structure-interview-questions/why-do-we-use-a-multidimensional-array/http://www.kyapoocha.com/data-structure-interview-questions/which-process-places-data-at-the-back-of-the-queue/http://www.kyapoocha.com/data-structure-interview-questions/which-file-contains-the-definition-of-member-functions/http://www.kyapoocha.com/data-structure-interview-questions/whether-linked-list-is-linear-or-non-linear-data-structure-2/http://www.kyapoocha.com/data-structure-interview-questions/when-can-you-tell-that-a-memory-leak-will-occur/http://www.kyapoocha.com/data-structure-interview-questions/what-method-removes-the-value-from-the-top-of-a-stack/http://www.kyapoocha.com/data-structure-interview-questions/what-method-is-used-to-place-a-value-onto-the-top-of-a-stack/http://www.kyapoocha.com/data-structure-interview-questions/what-member-function-places-a-new-node-at-the-end-of-the-linked-list/
  • 7/25/2019 Guide to Data Structures

    20/29

    dreamMAKERS Guide to Data Structures

    dreamMAKERS

    49. Draw a binary tree for the expression: A* B-(C+D)*(P/Q)

    Answer:

    50. Convert the given graph with weighted edges to minimal spanning tree:.

    51. Answer: The equivalent minimal spanning tree is:

    52. Of the following tree structure, which is, efficient considering space and timecomplexities?

    (a) Incomplete Binary Tree (b) Complete Binary Tree (c) Full Binary Tree

    Answer: (b) Complete Binary Tree. By the method of elimination: Full binary tree loses itsnature when operations of insertions and deletions are done. For incomplete binary trees, extrastorage is required and overhead of NULL node checking takes place. So complete binary tree

    is the better one since the property of complete binary tree is maintained even after operationslike additions and deletions are done on it.

    1 3

    2 4

    5410

    600

    200

    400

    310

    1421

    2985

    1

    2

    3

    4 5

    410 612

    200

    310

    -

    **

    A +B /

    C D P

  • 7/25/2019 Guide to Data Structures

    21/29

    dreamMAKERS Guide to Data Structures

    dreamMAKERS

    53. Draw the B-tree of order 3 created by inserting the following data arriv ing in sequence 92 24 6 7 11 8 22 4 5 16 19 20 78:

    Answer:

    11 -

    5 7 19 24

    4 - 6

    54. What are the types of Collision Resolution Techniques and the methods used in eachof the type?

    Answer: 1. Open addressing (closed hashing),The methods used include:Overflow

    block, 2.Closed addressing (open hashing),The methods used include: Linked list,Binary tree

    55. Classify the Hashing Functions based on the various methods by wh ich the key valueis found:

    Answer: Direct method, Subtraction method, Modulo-Division method, Digit-Extraction method,Mid-Square method, Folding method, Pseudo-random method.

    56. Sort the given values using Quick Sort?

    65 70 75 80 85 60 55 50 45

    Answer: Sorting takes place from the pivot value, which is the first value of the givenelements, this is marked bold. The values at the left pointer and right pointer are indicatedusing L and R respectively.

    65 70L 75 80 85 60 55 50 45RSince pivot is not yet changed the same process is continued after interchanging the valuesat L and R positions

    65 45 75 L 80 85 60 55 50 R 70

    65 45 50 80 L 85 60 55 R 75 70

    65 45 50 55 85 L 60 R 80 75 70

    65 45 50 55 60 R 85 L 80 75 70When the L and R pointers cross each other the pivot value is interchanged with the

    value at right pointer. If the pivot is changed it means that the pivot has occupied its originalposition in the sorted order (shown in bold italics) and hence two different arrays are formed,one from start of the original array to the pivot position-1 and the other from pivot position+1to end.

    60 L 45 50 55 R 65 85 L 80 75 70 R

    55 L 45 50 R 60 65 70 R 80 L 75 85

    - 8 - 16 22- 20 78 92

  • 7/25/2019 Guide to Data Structures

    22/29

    dreamMAKERS Guide to Data Structures

    dreamMAKERS

    50 L 45 R 55 60 65 70 80 L 75 R 85In the next pass we get the sorted form of the array.

    45 50 55 60 65 70 75 80 85

    57. In the given binary tree, using array you can store the node 4 at which location?

    Answer: At location 6

    1

    1 2 3 - - 4 - - 5

    Root LC1 RC1 LC2 RC2 LC3 RC3 LC4 RC4

    where LCn means Left Child of node n and RCn means Right Child of node n

    58. Traverse the given t ree using Inorder, Preorder and Postorder traversals.

    Answer:Inorder : D H B E A F C I G JPreorder: A B D H E C F G I JPostorder: H D E B F I J G C A

    2 3

    4

    5

    A

    CB

    D GE F

    JH I

  • 7/25/2019 Guide to Data Structures

    23/29

    dreamMAKERS Guide to Data Structures

    59. There are 8, 15, 13, 14 nodes were there in 4 different trees. Which of them could haveformed a full binary tree?

    Answer: 15. In general: There are 2n-1 nodes in a full binary tree.By the method of elimination:Full binary trees contain odd number of nodes. So there cannot be full binary trees with 8 or 14nodes, so rejected. With 13 nodes you can form a complete binary tree but not a full binary tree.

    So the correct answer is 15.

    60. List out few of the applications that make use of Multilinked Structures?

    Answer: Sparse matrix, Index generation

    61. What are the notations used in Evaluation of Arithmetic Expressions using prefix andpostfix forms?

    Answer: Polish and Reverse Polish notations

    62. Convert the expression ((A + B) * C (D E) ^ (F + G)) to equivalent Prefix and

    Postfix notations.

    Answer: Prefix Notation:^ - * +ABC - DE + FG

    Postfix Notation:AB + C * DE - - FG + ^

    63. Convert infix to post fix us ing C:

    Answer: #include#include#include

    void main() {char *p,*q;int n,i,j=0;clrscr();printf("Enter the Infix Expression= ");gets(p);*(--p)='(';

    n=strlen(p);p[n]=')';p[n+1]='\0';puts(p);for(i=0;i=65 && p[i]=97 && p[i]

  • 7/25/2019 Guide to Data Structures

    24/29

    dreamMAKERS Guide to Data Structures

    while(q[j-1]=='*' || q[j-1]=='/')printf("%c",q[--j]);

    q[j++]=p[i]; }else if(p[i]=='+' ||p[i]=='-') {

    while(q[j-1]=='+' || q[j-1]=='-'||q[j-1]=='*'||q[j-1]=='/')printf("%c",q[--j]);

    q[j++]=p[i]; }Else {

    q[j]=p[i];j++; }}}

    getch(); }

    64. What is done for a Push operation?

    Answer: Stack pointer is decremented and then the value is stored.

    65. What is the time complexity of merge sort , quick sort?

    Answer: QUICK SORT: The running time of quick sort is equal to the running time of the two recursivecalls & the linear time spent the partition. In worst case analysis the time complexity is O(n^2).In best case analysis, the time complexity is O(n log (n)).MERGE SORT: The worst case & average case complexity of merge sort is O(n log(n)).

    66. Write a function to insertion & display in double linked list:

    Answer: INSERTION:void add(int a) {node *t;

    t=(node *) malloc(sizeof(node));t->a=a;if(start==NULL) {

    t->next=NULL;t->back=NULL;start=t;end=t; }else if(start==end) {

    start->next=t;t->next=NULL;end=t;t->back=start; }

    else {end->next=t;t->next=NULL;t->back=end;end=t; }}

    DISPLAY:void disp(void) {node *t;int b;

    dreamMAKERS

  • 7/25/2019 Guide to Data Structures

    25/29

    dreamMAKERS Guide to Data Structures

    t=start;printf("Present Position Of The List..\n");printf("Printing From Front To Back..\n");while(t!=NULL) {

    b=t->a;printf("%d ",b);

    t=t->next; }t=end;printf("\nPrinting From Back To Front..\n");while(t!=NULL) {b=t->a;printf("%d ",b);t=t->back; }printf("\n"); }

    67. Write a program to insert a node, deletion a node in a linked list?

    Answer: INSERT:

    void insert(void){int x=0,N,p,y=1;node *t=start,*newnode;while(t!=NULL) {

    x++;t=t->next; }

    printf("Total No. Of Elementes Present= %d\n",x);printf("Enter The Position: ");scanf("%d",&p);while(p(x+1)) {

    printf("Position Not Found..\n");disp();

    printf("\nPlease Enter The Position Again= ");scanf("%d",&p); }

    printf("Enter The Number To Be Inserted= ");scanf("%d",&N);newnode=(node *)malloc(sizeof(node));newnode->a=N;if(p==0) {

    newnode->next=start;start=newnode; }

    else {t=start;while(ynext;y++; }

    newnode->next=t->next;t->next=newnode; }}

    DELETION:void del(void) {

    node *t;

    dreamMAKERS

  • 7/25/2019 Guide to Data Structures

    26/29

    dreamMAKERS Guide to Data Structures

    int x=0,n,p=1;t=start;while(t!=NULL) {

    x++;t=t->next; }disp();

    t=start;printf("No. Of Elements Present In The List= %d\n",x);printf("Enter Serial No. Of The No. To Be Deleted= ");scanf("%d",&n);if(nx)

    printf("The Index No. Does Not Exist...\n");else {

    if(n==1) {t=t->next;start=t; }

    else if(n==x) {while(t->next->next!=NULL)

    t=t->next;t->next=NULL; }

    else {while(pnext;p++; }

    t->next=t->next->next; }printf("After Deletion The Present Position Of The List Is...\n");disp(); }}

    68. Write a program to reverse a linked lis t.

    Answer:void reverse(void) {

    node *s1,*t,*t1,*t2;t=start;while(t!=NULL)

    t=t->next;t2=s1=t;while(t2!=start) {

    t1=start;t=(node *)malloc(sizeof(node));t->next=NULL;while(t1->next!=t2)

    t1=t1->next;t2=t1;t->n=t1->n;t1=s1;if(s1==NULL)

    s1=t;else {

    while(t1->next!=NULL)t1=t1->next;

    dreamMAKERS

  • 7/25/2019 Guide to Data Structures

    27/29

    dreamMAKERS Guide to Data Structures

    t1->next=t; } }t=s1;while(t!=NULL) {

    printf("%d ",t->n);t=t->next; }

    printf("\n");

    start=s1;printf("End Of Computation\n");}

    69. Describe the following st ructures as LIFO/FILO/FIFO/LILO:(a) Stack (b) Queue

    Answer: STACK: Stack is described as LIFO. It is an ordered collection of items into whichnew items may be inserted & from which items may be deleted at one end.

    QUEUE: Queue is described as FIFO. It is an ordered collection of items into whichnew items may be inserted & from which items may be deleted at other end.

    70. How is li nked list implemented?

    Answer: By referential structures.

    71. In binary search t ree which t raversal is used for getting ascending order values--Inorder, post order or preorder?

    Answer: Inorder

    72. Write an algorithm to insert a node into sorted linked list. After inserting, the listmust be sorted

    Answer : void sort(void) {node *t1,*t2;

    int temp;t1=start;while(t1->next!=NULL) {t2=t1->next;

    while(t2!=NULL) {if(t1->n>t2->n) {

    temp=t1->n;t1->n=t2->n;t2->n=temp; }

    t2=t2->next; }t1=t1->next; }

    t1=start;

    printf("\nThe Sorted List Is...\n");while(t1!=NULL){

    printf("%d ",t1->n);t1=t1->next;}}

    73. The sorting method which don't generally use recursion(a)heap sort (b)bubble sort (c)quick sort (d)bubble sort

    Answer: b) Bubble sort

    dreamMAKERS

  • 7/25/2019 Guide to Data Structures

    28/29

    dreamMAKERS Guide to Data Structures

    74. Which of the following sorting algorithm has average sorting behavior Bubble sort,merge sort, heap sort, exchange sort ?

    Answer: Heap sort

    75. Quick sort uses which algorithm?

    Answer : Divide & Conquer Algorithm.

    76. If we delete a node from a balanced binary tree, how can we retain the properties ofbalanced binary tree?

    Answer :By rotation at the nodes

    77. No. of comparisons in a merge sort?

    Answer: (2*n+1)

    78. Sorting o f N elements how many comparisons are required?

    Answer: (n-1)

    79. When quick sort gives worst performance?

    Answer :When elements are in order.

    80. If there are n nodes and K edges in a graph then what is the order of traversing ?

    Answer: O(n^2)

    81. A graph is represented as an adjacency list w ith n vertices and e edges What is itstime complexity?

    Answer: O(n + e)

    82. If a set of numbers are in sorted order then which of the following sorting method isbest?

    Answer :Bubble Sort

    83. A magnetic tape is similar to which of the following structu res?

    Answer :List

    84. For a linked lis t imp lementation which searching technique is not applicable?a)linear search b)none c)quick sort d)binary search

    Answer: Binary search

    dreamMAKERS

  • 7/25/2019 Guide to Data Structures

    29/29

    dreamMAKERS Guide to Data Structures

    85. Which one of the following data structures is best suited for searching?a) Arrays b) Singly Linked List c) Doubly Linked Lis t d) Hash Table

    Answer: Hash Table

    86. Which o f the following data structures is best suited for Deletion?

    a) Arrays b) Singly Linked List c) Doubly Linked List d) Hash Table

    Answer: Doubly linked list

    87. If the number of in ternal nodes in a binary tree is n, then what is the number ofexternal nodes ?a) n -1 b) n c) n + 1 d) 2n

    Answer :n+1

    88. If i/p in a stack are in o rder 1,2,3,4,5 the order of o/p is?

    Answer : 5, 4,3, 2,1

    89. A tree in which every node(value) which exceeds parent node is placed on right whilenode lacking than parent is placed on left Is called?

    Answer: Binary tree.

    Al l the Best from Team dreamMAKERS!