You are on page 1of 17

:

Data Structures

: Thanks to Gowtham Raj..

Kongu engineering college B.E. CSE(2007-2011) PUBLISHED BY 1. ADT? Naveen Raj.B CSE(2007-2011)

ADT (abstract data type) is a mathematical abstraction and contains set of operations.Eg: set is an ADT with operations: union, insertion and complement. 2. list? List is an ADT with operations: insert, delete and find. Its a series of structures containing data and pointer to next structure. 2.1 Linear and non-linear data structures? The data structure is said to be a Linear data structure if its elements are in sequence and form a linear list.Ex. Arrays, Stacks, Queues, Linked Lists. If the elements of data structure do not form a sequence or a linear list then that type of data structure is called as Non-Linear data structure. Ex: Trees, BST (Binary Search Trees) etc. 3. Linked list?

Consist of series of structures which are not necessarily adjacent in memory. Doubly linked list helps to traverse the list backward with extra pointer field in the structure. Circular linked list, last cell keeps a pointer to first cell. 4. Application of Linked list? polynomial radix sort multi lists in course registration process. 5. Cursor implementation of linked list? If linked list are required and there is no pointer then we go for cursor implementation. To insert, first element after header is removed from free list. To free, we place the cell at the front of free list.

5. Stack? Stack is a list with the restriction that insertion and deletion can be performed at the end of list called top. LIFO (last in first out). Operations: push and pop. 6. Application of stack? Balancing symbolpostfix expression 7. Queue? Queues are list with insertion at one end and deletion at another end.Operations: Enqueue and dequeue. 8. application of queue? graph theory algorithmsjob submitted to printers. 9. tree? Its a collection of nodes. It contains a root node with zero or more non-empty trees connected to the root with the edge. 9. Preorder traversal? Work at the node is performed before its children are processed. 10. Postorder traversal? Work at the node is performed after its children are processed. 11. Binary tree? Tree in which no node can have more than two children. Application: searching, Expression tree(in compiler design) 12. Expression tree? The leaves of expression tree are operands and the other nodes contain operators. It is build based on postfix evaluation. 13. Binary search tree? Its a binary tree with the condition that all the values to the left of a node should be smaller and the values to the right of the node should be greater. 14. AVL tree?

AVL tree is a balanced binary search tree. AVLAdelson Velskii and Landis. 15. Balanced condition? Left and the right subtree should have the same height.It is maintained by single or double rotation. 16. Splay tree? Data structure that guarantees that any M consecutive tree operations starting from an empty tree take atmost o(MlogN) time. 17. B tree? Its a popular non-binary search tree.Application: Database system, disk access is O(logN)base->M. 18. What is Heap data structure? The binary heap data structures is an array that can be viewed as a complete binary tree. Each node of the binary tree corresponds to an element of the array. The array is completely filled on all levels except possibly lowest. 19) What are the major data structures used in the following areas : RDBMS, Network data model & Hierarchical data model? 1. RDBMS Array (i.e. Array of structures) 2. Network data model Graph 3. Hierarchical data model Trees 20) Difference between calloc and malloc? malloc: allocate n bytes calloc: allocate m times n bytes initialized to 0 21) What is the difference bitween NULL AND VOID pointer? 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; Core Dimension is a Dimension table which is used dedicated for single fact table or Datamart. Conform Dimension is a Dimension table which is used across fact tables or Datamarts. 22) How can a node be inserted in the middle of a linked list? By repointing the previous and the next elements of existing nodes to the new node. You can insert a node in the middle of a linked list by repointing the previous and the next elements of existing nodes to the new node.

23) What are the various kinds of sorting techniques? Which is has best case? Bubble sort Quick sort Insertion sort Selection sort Merge sort Heap sort Among the sorting algorithms quick sort is the best one 24) Which one is faster? A binary search of an orderd set of elements in an array or a sequential search of the elements. Binary search is faster because we traverse the elements by using the policy of Divide and Conquer. we compare the key element with the approximately center element, if it is smaller than it search is applied in the smaller elements only otherwise the search is applied in the larger set of elements. its complexity is as we all know is log n as compared to the sequential one whose complexity is n. 26)What is hashing? Hashing is a way retrieving records from memory in faster way. Record is inserted into memory by using hash function(division, midsqure,folding,digit analysis)and also records are retrieved using same hash function. 27)What is almost complete binary tree? An almost complete binary tree is a tree in which each nodethat has a right child also has a left child. Having a left child does not require a node to have a right child. Stated alternately, an almost complete binary tree is a tree where for a right child, there is always a left child, but for a left child there may not be a right child. 28)Explain about the types of linked lists? Their are three linked lists 1)linear or simple linked lists2)doubly linked lists3)circular linked lists simple linked list :This contains a node which has two parts, see that a node is a STRUCTURE.one is data and other one is a pointer which is called self reference pointers, so we must make it to point to the next location of second node created dynamically. double linked lists :A node will consists of previous node address , a data & next node address which can move backwards to the very first address. circular linked list :Here we will have the node consists of same thing but default when it finishes the last node and come to the first node. 29))What are the parts of root node?

A root node contains data part and has link part. i.e links to its child. If it is binary tree it has two links i.e left child and right child. 30)What is mean by d-queue? D-queue stands for double ended queue. It is a abstract data structure that implements a queue for which elements can be added to front or rear and the elements can be removed from the rear or front. It is also called head-tail linked list 31)Which one is faster? A binary search of an orderd set of elements in an array or a sequential search of the elements. Binary search is faster because we traverse the elements by using the policy of Divide and Conquer. we compare the key element with the approximately center element, if it is smaller than it search is applied in the smaller elements only otherwise the search is applied in the larger set of elements. its complexity is as we all know is log n as compared to the sequential one whose complexity is n. 32)What is B+ tree? A B+ tree is a type of tree which represents sorted data in a way that allows for efficient insertion, retrieval and removal of records, each of which is identified by a key. It is a dynamic, multilevel index, with maximum and minimum bounds on the number of keys in each index segment (usually called a 'block' or 'node'). In a B+ tree, in contrast to a B-tree, all records are stored at the lowest level of the tree; only keys are stored in interior blocks. The primary value of a B+ tree is in storing data for efficient retrieval in a block-oriented storage context. Given a storage system with a block size of b, a B+ tree which stores a number of keys equal to a multiple of b will be very efficient when compared to a binary search tree 33)What data structure would you mostly likely see in a non recursive implementation of a recursive algorithm? Stack 34)What is a spanning Tree? 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 edge weight between nodes is minimized. 35)Does the minimum spanning tree of a graph give the shortest distance between any 2 specified nodes? No. 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-spanning tree is

minimum. 36) Which is the simplest file structure? (a) Sequential (b) Indexed (c) Random Sequential 37)Whether Linked List is linear or Non-linear data structure? According to Access strategies Linked list is a linear one. According to Storage Linked List is a Non-linear one. 38)What are the types of Collision Resolution Techniques and the methods used in each of the type? Open addressing (closed hashing), The methods used include: Overflow block, Closed addressing (open hashing) The methods used include: Linked list, Binary tree 39)In RDBMS, what is the efficient data structure used in the internal storage representation? B+ tree. Because in B+ tree, all the data is stored only in leaf nodes, that makes searching easier. This corresponds to the records that shall be stored in leaf nodes. 40)List out few of the Application of tree data-structure? The manipulation of Arithmetic expression, Symbol Table construction, Syntax analysis. 41) List out few of the applications that make use of Multilinked Structures? Sparse matrix, Index generation. 42) In tree construction which is the suitable efficient data structure? (a) Array (b) Linked list (c) Stack (d) Queue (e) none (b) Linked list

43)In an AVL tree, at what condition the balancing is to be done? If the pivotal value (or the Height factor) is greater than 1 or less than 1. 44)What are the notations used in Evaluation of Arithmetic Expressions using prefix and postfix forms? Polish and Reverse Polish notations. 45) Convert the expression ((A + B) * C (D E) ^ (F + G)) to equivalent Prefix and Postfix notations. Prefix Notation: ^ - * +ABC - DE + FG Postfix Notation: AB + C * DE - - FG + ^ 43)What are the methods available in storing sequential files ? merging, Polyphase sort, Distribution of Initial runs. 44)What is data structure? A data structure is a way of organizing data that considers not only the items stored, but also their relationship to each other. Advance knowledge about the relationship between data items allows designing of efficient algorithms for the manipulation of data. 45) List out the areas in which data structures are applied extensively? Compiler Design, Operating System, Database Management System, Statistical analysis package, Numerical Analysis. 46)What are the major data structures used in the following areas of RDBMS, Network data model & Hierarchical data model. RDBMS Array (i.e. Array of structures) Network data model Graph Hierarchical data model Trees 47) If you are using C language to implement the heterogeneous linked list, what pointer type will you use? The heterogeneous linked list contains different data types in its nodes and we need a link, pointer to connect them. It is not possible to use ordinary pointers for this. So we go for void pointer. Void pointer is capable of storing pointer to any type as it is a generic pointer type.

48) Minimum number of queues needed to implement the priority queue? Two. One queue is used for actual storing of data and another for storing priorities. 49) What is the data structures used to perform recursion? Stack. Because of its LIFO (Last In First Out) property it remembers its caller so knows whom to return when the function has to return. Recursion makes use of system stack for storing the return addresses of the function calls. Every recursive function has its equivalent iterative (non-recursive) function. Even when such equivalent iterative procedures are written, explicit stack is to be used. 50)sorting comparison sort bubble insertion heap merge quick average O(n^2) O(n^2) O(n*logn) O(n*logn) O(n*logn) best worst O(n^2) O(n^2) O(n) O(n^2) O(n*logn) O(n*logn) O(n*logn) O(n*logn) O(n*logn) O(n^2)

51) what is the difference between B-tree and B+ tree?


In a B- tree you can store both keys and data in the internal/leaf nodes. But in a B+ tree you have to store the data in the leaf nodes only B+Trees are much easier and higher performing to do a full scan, as in look at every piece of data that the tree indexes, since the terminal nodes form a linked list. To do a full scan with a B-Tree you need to do a full tree traversal to find all the data. B-Trees on the other hand can be faster when you do a seek (looking for a specific piece of data by key) especially when the tree resides in RAM or other non-block storage. Since you can elevate commonly used nodes in the tree there are less comparisons required to get to the data

52) The number of nodes in a binary tree can be found using this formula: n = 2^h Where n is the amount of nodes in the tree, and h is the height of the tree.

53)Types of Binary trees

A full binary tree (sometimes proper binary tree or 2-tree or strictly binary tree) is a tree in which every node other than the leaves has two children. A perfect binary tree is a full binary tree in which all leaves are at the same depth or same level. (This is ambiguously also called a complete binary tree.)

A complete binary tree is a binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible An almost complete binary tree is a tree in which each node that has a right child also has a left child. An Atmost complete binary tree is tree in which all nodes has at most two children.

Interview Questions:
HCL 1.What data structes you will use if you want to go to first record from the last and vice versa? ans.: doubly linked circular list

2. given a height balanced tree. If we add one more node , how many nodes gets unbalanced ? Ans. 3

3. Given a arbitrary pointer to an element in a singly linked list? what is the time complexity for its deletion . Ans. O(n)

4. S->S+S; s->s*s; s->a how many parse trees possible : a+a*a+a Ans. 5

5 A choclate of size nXn is given and is to be made into pices of size 1x1. At a time both horizontal and a vertical cut is done. Find the order of complexity a) 0(n2) b) o(nlogn) c) o(logn) Ans : a

HUGHES
8) No. of nodes of degree 2 in a binary tree with n leaf nodes. Ans. n-1

9. To sorting array of 10 elements which sorting is best a)slection b)bubble c)tree sort d).... ans:a

10 To saving space point of view which sort is best a)selection b)insertion c)both a & b d)...

11Which statement is wrong on heap a)Any two childs should not same b).. c).. d)...

ans:a

12) cyclometric complexity..

13) how many null pointer are there in N number binary tree ans:N+1

14) Two sorted list of size n what are the maximum comparison in merge ANs:2n-1

15) two sorted lists of n elements will take at least fine the order of complexity? a. 2n b. n/2 c. square(n)

16)if there are n nodes in a binary tree, how many null pointers are there ans:n+1;

17). if heap sort contains n elements, no of comparsions required are a. log(n) b. height of heap sort c. d.

18) which of the following is efficient in terms of space a. insertion sort b. quick sort c. selection d. both a and c

19) in sorted table contains elements , which of the searching is false a. hash table b. binary searching

20) in associated memory for fast accessing which one is used a. single linked list b. double " c. hash table

21) for hashing which is best on terms of buckets a)100 b)50 c)21 d)32 ans 32

22) max and avg. height of sorted binary tree a. logn n b n logn

23) implementation of priority queue a. tree b linked list c doubly linked list

24) For a binary tree with n nodes, How many nodes are there which has got both a parent and a child?

25) Bubble sort : Given sequence of numbers what will be order of sequences after two iterations. Ans: very trivial, but you should know what bubble sort does.

26)Bubble sort : how many swap operations has been done in the above process?

27)What data structures you should use for dictionary searching and it should be capable of doing spell check also ? Ans: Hashing

28)Which is the best scheduling algo. (given five of them) Ans.: Shortest Job First with Pre-emption

29) Bubble sort is given ., No of times it executes ans . n(n-1)/2

30) The appriximate ratio for no of internal nodes to total no

31) precedence order from high to low ( ( ) ++ / )

32) preorder of A*(B+C)/D-G (*+ABC/-DG)

33) B-tree (failure nodes at same level) of nodes in k-ary tree of depth n. ans. 1/k

34) merge sort time complexity ( O(n log n) )

35) which sorting algorithm has average sorting behavior (heap sort )

36)in binary search tree which traversal is used for getting ascending order values (inorder )

37) fun(n) { if(n<=2) return (1); else return ((fun(n-1)*fun(n-2));

} find the order of complexity of the programme. possible answer ---- N(2^n)

39) a tree is given and ask to find its meaning (parse-tree) (expression tree) ans. ((a+b)-(c*d)) ( not confirmed)

40) Compute the complexity of Binary search. Ans : O(lg n) ( Answer in detail. This is not a multiple choice question. It carries more marks.)

41) A search procedure which assosiates an address with a key value and provides a mechanism for dealing with two or more values assigned to the same address to the same address is called. a) linear earch b) binary search * c) hash coded search d) radix search

42)which data struture is needed to convert infix notations to postfix notations? a. linear list b. queue c. tree

d. stack ans:d

43) recursive procedures are implemented by a.queues b.stacks c.linked lists d.strings

44) A linear list of elments in which deletion can be done from one end (front)and insertion can take place only at the other end(rear)is known as *a) queues b)stacks c)trees d)deque

45) A linear list in which elements can be added or removed at either end but not in the middle is known as a)queue *b)de queue c)stack d)tree

46)which of the following sorting procedure is slowest a)quick sort b)heap sort

c)shell sort *d)bubble sort

47) The complexity of bublle sort is0(a),then kequals ans:2

48) given a height balanced tree. If we add one more node , how many nodes gets unbalanced ? Ans. 3

49) Given a arbitrary pointer to an element in a singly linked list? what is the time complexity for its deletion . Ans. O(n)

50) S->S+S; s->s*s; s->a how many parse trees possible : a+a*a+a Ans. 5

51) A choclate of size nXn is given and is to be made into pices of size 1x1. At a time both horizontal and a vertical cut is done. Find the order of complexity a) 0(n2) b) o(nlogn) c) o(logn) Ans : a

You might also like