FAQ’s during Campus Placement Data Structures About Technical Interviews A technical interview is a type of interview that typically features questions that are specific to the role you have applied for. Technical interviews are generally used to assess candidates for technical or specialist graduate job positions (such as jobs in IT, Engineering and Science) rather than general graduate schemes. In a technical interview candidates are likely to be asked questions that relate to specific knowledge about the company's technical activities relate to understanding the technical work required to be completed as part of the job applied for relate to work completed as part of a degree course (if this relates to the job applied for) require candidates to solve actual technical problems that they would be likely to face if employed. Data Structure Interview Questions-Interview Questions and Answers 1.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. 2.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. 3.What are the notations used in Evaluation of Arithmetic Expressions using prefix and postfix forms? Polish and Reverse Polish notations. 4.List out few of the Application of tree data-structure? i)The manipulation of Arithmetic expression ii)Symbol Table construction iii)Syntax analysis. 5.What is the type of the algorithm used in solving the 8 Queens problem? Backtracking 6.In RDBMS, what is the efficient data structure used in the internal storage representation? 1 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. 7. 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. 8. List out the areas in which data structures are applied extensively? Compiler Design, Operating System, Database Management System, Statistical analysis package, Numerical Analysis, Graphics, Artificial Intelligence, Simulation 9. Translate infix expression into its equivalent post fix expression: (A-B)*(D/E) (A-B)*(D/E) = [AB-]*[DE/] = AB-DE/* 10. What are priority queues? A priority queue is a collection of elements such that each element has been assigned a priority. 11. What is a string? A sequential array of characters is called a string. 12. What is Brute Force algorithm? Algorithm used to search the contents by comparing each element of array is called Brute Force algorithm. 13. What are the limitations of arrays? i)Arrays are of fixed size. ii)Data elements are stored in continuous memory locations which may not be available always. iii)Adding and removing of elements is problematic because of shifting the locations. 14. How can you overcome the limitations of arrays? Limitations of arrays can be solved by using the linked list. 15. What is a linked list? Linked list is a data structure which store same kind of data elements but not in continuous memory locations and size is not fixed. The linked lists are related logically. 16. What is a node? The data element of a linked list is called a node. 17. What does node consist of? Node consists of two fields:data field to store the element and link field to store the address of the next node. 2 18. What is a queue ? A Queue is a sequential organization of data. A queue is a first in first out type of data structure. An element is inserted at the last position and an element is always taken out from the first position. 19. 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 20. What are the methods available in storing sequential files ? Straight merging, Natural merging, Polyphase sort, Distribution of Initial runs. 21. Mention some of the problem solving strategies? The most widely strategies are listed below i)Divide and conquer ii)Binary doubling strategy iii)Dynamic programming 22. What is divide and conquer method? The basic idea is to divide the problem into several sub problems beyond which cannot be further subdivided. Then solve the sub problems efficiently and join then together to get the solution for the main problem. 23. What is the need for the header? Header of the linked list is the first element in the list and it stores the number of elements in the list. It points to the first data element of the list. 24. Define leaf? In a directed tree any node which has out degree o is called a terminal node or a leaf. 25. What are the applications of binary tree? Binary tree is used in data processing. 26. What are the different types of traversing? The different types of traversing are i)Pre-order traversal-yields prefix from of expression. ii)In-order traversal-yields infix form of expression. iii)Post-order traversal-yields postfix from of expression. 27. Define pre-order traversal? i)Process the root node ii)Process the left subtree iii)Process the right subtree 28. Define post-order traversal? 3 i)Process the left subtree ii)Process the right subtree iii)Process the root node 29. Define in -order traversal? i)Process the left subtree ii)Process the root node iii)Process the right subtree 30. What is meant by sorting? Ordering the data in an increasing or decreasing fashion according to some relationship among the data item is called sorting. 31. What's the major distinction in between Storage structure and file structure and how? The expression of an specific data structure inside memory of a computer system is termed storage structure in contrast to a storage structure expression in auxiliary memory is normally known as a file structure. 32. Stack can be described as a pointer. Explain? Because stack will contain a head pointer which will always point to the top of the Stack.All Stack Operations are done using Head Pointer. Hence Stack can be Described as a Pointer 33. What do you mean by: Syntax Error, Logical Error, Run time Error? Syntax Error-Syntax Error is due to lack of knowledge in a specific language. It is due to somebody does not know how to use the features of a language.We can know the errors at the time of compilation. logical Error-It is due to the poor understanding of the requirement or problem. Run time Error-The exceptions like divide a number by 0,overflow and underflow comes under this. 34. 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 35. What is AVL tree? Avl tree is self binary tree in which balancing factor lie between the -1 to 1.It is also known as self balancing tree. 36. what is binary tree? Binary tree is a tree which has maximum no. of childrens either 0 or 1 or 2. i.e., there is at the most 2 branches in every node. 37. What is the difference between a stack and a Queue? Stack – Represents the collection of elements in Last In First Out order. 4 Operations includes testing null stack, finding the top element in the stack, removal of top most element and adding elements on the top of the stack. Queue - Represents the collection of elements in First In First Out order.Operations include testing null queue, finding the next element, removal of elements and inserting the elements from the queue. Insertion of elements is at the end of the queue.Deletion of elements is from the beginning of the queue 38. What actions are performed when a function is called? i)arguments are passed ii)local variables are allocated and initialized iii)transferring control to the function 39. What is precision? Precision refers the accuracy of the decimal portion of a value. Precision is the number of digits allowed after the decimal point. 40. What do you mean by overflow and underflow? When new data is to be inserted into the data structure but there is no available space i.e.free storage list is empty this situation is called overflow.When we want to delete data from a data structure that is empty this situation is called underflow. Data Structure Advanced-Interview Questions and Answers 1. Is it possible to find a loop in a Linked list ? a. Possilbe at O(n) b. Not possible c. Possible at O(n^2) only d. Depends on the position of loop Solution: a. Possible at O(n) Have two pointers say P1 and P2 pointing to the first node of the list. Start a loop and Increment P1 once and P2 twice in each iteration. At any point of time if P1==P2 then there is a loop in that linked list. If P2 reaches NULL (end of linked list) then no loop exists. 2. Two linked lists L1 and L2 intersects at a particular node N1 and from there all other nodes till the end are common. The length of the lists are not same. What are the possibilities to find N1?. a. Solution exist for certain cases only b. No linear solution exist c. Linear solution is possible d Only Non-linear solution exist. Solution: c. Linear solution is possible Have two pointers say P1 pointing to the first node of L1 and P2 to that of L2. 5 Traverse through both the lists. If P1 reaches L1’s last node, point it to the first node of L2 and continue traversing. Do the same thing for P2 when it reaches L2’s last node. (By doing this, we are balancing the difference in the length between the linked lists. The shorter one will get over soon and by redirecting to longer list’s head, it will traverse the extra nodes also.) Finally they will Meet at the Intersection node. 3. void PrintTree (Tree T) { if (T != NULL) { PrintTree (T-> Left); PrintElement (T-> Element); PrintTree (T->Right); } } The above method ‘PrintTree’ results in which of the following traversal a Inorder b. Preorder c. Postorder d. None of the above Solution: a. Inorder Inorder: void PrintTree (Tree T) { if (T != NULL) { PrintTree (T-> Left); PrintElement (T-> Element); PrintTree (T->Right); } } For preorder use this order PrintElement (T-> Element); PrintTree (T-> Left); PrintTree (T->Right); For postorder use this order PrintTree (T-> Left); PrintTree (T->Right); PrintElement (T-> Element); 4. Given a Binary Search Tree (BST), print its values in ascending order. a. b. c. d. Perform Perform Perform Perform Depth first traversal Breadth first traversal Postorder traversal Inorder traversal 6 Solution: d. Perform Inorder traversal It is the properfy of BST and Inorder traversal. 5. Is it possible to implement a queue using Linked List ?. Enqueue & Dequeue should be O(1). a. Not possible to implement. b Only Enqueue is possible at O(1). c. Only Dequeue is possible at O(1). d. Both Enqueue and Dequeue is possible at O(1) Solution: d. Both Enqueue and Dequeue is possible at O(1) Have two pointers H pointing to the Head and T pointing to the Tail of the linked list. Perform enqueue at T and perform dequeue at H. Update the pointers after each operations accordingly. 6. Given a Tree, is it possible to find the greatest and least among leaves in linear time?. a. Solution depends on the tree structure b.Linear solution exist c. Only Non-linear solution exist. d. No linear solution exist Solution: b. Linear solution exist Have two variables Min and Max. Perform any tree traversal.Assign the first traversed leaf element to Min and Max for all other leaf elements check with these variables and update it accordingly. If a current element is < Min then update Min with that element. If it is > Min then check with Max. Note: If you want to find the greatest and least among all nodes perform the checks for each node traversed. 7. Is it possible to find find the greatest and least value among the nodes in a given BST without using any extra variables? a. No solution exist. b. Solution need 2 extra variables c. Solution exist without any extra variables d Solution need 1 extra variable Solution:c Solution exist without any extra variables As per BST property, the left most node should be the least one and the rightmost node should be the greatest. In other words, the first and last node of an Inorder traversal are the least and greatest among the nodes respectively. 8. Is it possible to implement 2 stack in an array? Condition: None of the stack should indicate an overflow until every slot of an array is used. a. Only 1 stack can be implemented for the given condition b. Stacks can not be implemented in array c. 2 stacks can be implemented for the given condition. 7 d. 2 stacks can be implemented if the given condition is applied only for 1 stack. Solution:c. 2 stacks can be implemented for the given condition Start 1st stack from left (1st position of an array) and 2nd from right (last position say n). Move 1st stack towards right( i.e 1,2,3 ...n) and 2nd towards left (i.e n,n-1,n-2...1). 9. Given two keys K1 & K2, write an algorithm to print all the elements between them with K1<=K2 in a BST. a. Solution need 2 extra spaces b. Linear solution is possible without using any extra space c No linear solution exist d Solution need 1 extra space Solution:b. Linear solution is possible without using any extra space Perform an inorder traversal. Once you find K1 print it and continue traversal now, print all other traversed elements until you reach K2. Note: If K1 == K2 stop once you find K1. 10. How many stacks are required to implement a Queue. a. One b. Two c. Three d. Two + one extra space. Solution:b Two Have two stacks S1 and S2. For Enqueue, perform push on S1. For Dequeue, if S2 is empty pop all the elements from S1 and push it to S2. The last element you popped from S1 is an element to be dequeued. If S2 is not empty, then pop the top element in it. Data structure interview questions 1. What is Data Structure? - Data structure is a group of data elements grouped together under one name. - These data elements are called members. They can have different types and different lengths. - Some of them store the data of same type while others store different types of data. 2. Which data structure is used to perform recursion? - The data structure used for recursion is Stack. - Its LIFO property helps it remembers its 'caller'. This helps it know the data which is to be returned when the function has to return. - System stack is used for storing the return addresses of the function calls. 3. Does the Minimal Spanning tree of a graph give the shortest distance between any 2 specified nodes? - No, it doesn’t. - It assures that the total weight of the tree is kept to minimum. 8 - It doesn't imply that the distance between any two nodes involved in the minimum-spanning tree is minimum. 4. If you are using C language to implement the heterogeneous linked list, what pointer type will you use? - A heterogeneous linked list contains different data types in its nodes. We can not use ordinary pointer to connect them. - The pointer that we use in such a case is void pointer as it is a generic pointer type and capable of storing pointer to any type. 5. Differentiate between PUSH and POP? - Pushing and popping refers to the way data is stored into and retrieved from a stack. - PUSH – Data being pushed/ added to the stack. - POP - Data being retrieved from the stack, particularly the topmost data. 6. When is a binary search algorithm best applied? - It is best applied to search a list when the elements are already in order or sorted. - The list here is searched starting in the middle. If that middle value is not the correct one, the lower or the upper half is searched in the similar way. 7. How do you reference all the elements in a one-dimension array? - This is done using an indexed loop. - The counter runs from 0 to the array size minus one. - Using the loop counter as the array subscript helps in referencing all the elements in one-dimensional array. 8. What is Huffman’s algorithm? - It is used in creating extended binary trees that have minimum weighted path lengths from the given weights. - It makes use of a table that contains frequency of occurrence for each data element. 9. What is Fibonacci search? - It is a search algorithm that applies to a sorted array. - It uses divide-and-conquer approach that reduces the time needed to reach the target element. 10. Which data structure is applied when dealing with a recursive function? - A recursive function is a function that calls itself based on a terminating condition. - It uses stack. - Using LIFO, a call to a recursive function saves the return address. This tells the return address to the calling function after the call terminates. 11. How does dynamic memory allocation help in managing data? 9 - Dynamic memory allocation helps to store simple structured data types. - It can combine separately allocated structured blocks to form composite structures that expand and contract as required. 12. What is a bubble sort and how do you perform it? - Bubble sort is a sorting technique which can be applied to data structures like arrays. - Here, the adjacent values are compared and their positions are exchanged if they are out of order. - The smaller value bubbles up to the top of the list, while the larger value sinks to the bottom. 13. How does variable declaration affect memory allocation? - The amount of memory to be allocated depends on the data type of the variable. - An integer type variable is needs 32 bits of memory storage to be reserved. 14. You want to insert a new item in a binary search tree. How would you do it? - Let us assume that the you want to insert is unique. - First of all, check if the tree is empty. - If it is empty, you can insert the new item in the root node. - If it is not empty, refer to the new item’s key. - If the data to be entered is smaller than the root’s key, insert it into the root’s left subtree. - Otherwise, insert it into the root’s right subtree. 15. Why is the isEmpty() member method called? - The isEmpty() member method is called during the dequeue process. It helps in ascertaining if there exists any item in the queue which needs to be removed. - This method is called by the dequeue() method before returning the front element. 16. What is a queue ? - A Queue refers to a sequential organization of data. - It is a FIFO type data structure in which an element is always inserted at the last position and any element is always removed from the first position. 17. What is adequeue? - A dequeue is a double-ended queue. - The elements here can be inserted or removed from either end. 18. What is a postfix expression? - It is an expression in which each operator follows its operands. - Here, there is no need to group sub-expressions in parentheses or to consider operator precedence.. 1.What is a data structure? What are the types of data structures? 10 The scheme of organizing related information is known as ‘data structure’. The types of data structure are: Lists: A group of similar items with connectivity to the previous or/and next data item 2.Define a linear and non linear data structure. Linear data structure: A linear data structure traverses the data elements sequentially, in which only one data element can directly be reached. Ex: Arrays, Linked Lists............... 3.Define in brief an array. What are the types of array operations? An array is a set of homogeneous elements. Every element is referred by an index. Arrays are used for storing the data until the application expires in the main memory of the computer system. So that, the elements can be accessed at any time. The operations are: 4.What is a matrix? Explain its uses with an example A matrix is a representation of certain rows and columns, to persist homogeneous data. It can also be called as double-dimensioned array................. 5.Define an algorithm. What are the properties of an algorithm? What are the types of algorithms? Algorithm: A step by step process to get the solution for a well defined problem.............. 6.What is an iterative algorithm? The process of attempting for solving a problem which finds successive approximations for solution, starting from an initial .. 7.What is an recursive algorithm? Recursive algorithm is a method of simplification that divides the problem into sub-problems of the same nature. The result of one recursion is the input for the next recursion............... 8.What is the Huffman algorithm? In Huffman Algorithm, a set of nodes assigned with values if fed to the algorithm................ 9.Explain quick sort and merge sort algorithms. Quick sort employs the ‘divide and conquer’ concept by dividing the list of elements into two sub elements............ 9.What is Bubble Sort and Quick sort? Bubble Sort: The simplest sorting algorithm. It involves the sorting the list in a repetitive fashion. It compares two adjacent elements in the list.............. 10.What is the difference between a stack and a Queue? 11 Stack – Represents the collection of elements in Last In First Out order. Operations includes testing null stack, finding the top element in the stack, removal of top most element and adding elements on the top of the stack.............. 11.Can a stack be described as a pointer? Explain A stack is represented as a pointer. The reason is that, it has a head pointer which points to the top of the stack.............. 12.What is the recursion? Recursion is an approach in which a function calls itself with an argument. Upon reaching a termination condition, the control returns to the calling function............... 13.Is it possible to insert different type of elements in a stack? How? Different elements can be inserted into a stack. This is possible by implementing union / structure data type............ 14.Explain in brief a linked list. A linked list is a dynamic data structure. It consists of a sequence of data elements and a reference to the next record in the sequence. Stacks, queues, hash tables, linear equations, prefix and post fix operations.................. 15.Explain the types of linked lists. The types of linked lists are: Singly linked list: It has only head part and corresponding references to the next nodes............... 16.How would you sort a linked list? 1: Compare the current node in the unsorted list with every element in the rest of the list. If the current element is more than any other element go to step 2 otherwise go to step 3.............. 17.What is sequential search? What is the average number of comparisons in a sequential search? Sequential search: Searching an element in an array, the search starts from the first element till the last element.............. 18.What is binary searching and Fibonacci search? Binary Search: Binary search is the process of locating an element in a sorted list. The search starts by dividing the list into two parts............... 19. What is a data structure? What are the types of data structures? Briefly explain them The scheme of organizing related information is known as ‘data structure’. The types of data structure are: 12 Lists: A group of similar items with connectivity to the previous or/and next data items. Arrays: A set of homogeneous values Records: A set of fields, where each field consists of data belongs to one data type. Trees: A data structure where the data is organized in a hierarchical structure. This type of data structure follows the sorted order of insertion, deletion and modification of data items. Tables: Data is persisted in the form of rows and columns. These are similar to records, where the result or manipulation of data is reflected for the whole table. 20. Define a linear and non linear data structure. Linear data structure: A linear data structure traverses the data elements sequentially, in which only one data element can directly be reached. Ex: Arrays, Linked Lists Non-Linear data structure: Every data item is attached to several other data items in a way that is specific for reflecting relationships. The data items are not arranged in a sequential structure. Ex: Trees, Graphs 21. Define in brief an array. What are the types of array operations? An array is a set of homogeneous elements. Every element is referred by an index. Arrays are used for storing the data until the application expires in the main memory of the computer system. So that, the elements can be accessed at any time. The operations are: - Adding elements Sorting elements Searching elements Re-arranging the elements Performing matrix operations Pre-fix and post-fix operations 22. What is a matrix? Explain its uses with an example A matrix is a representation of certain rows and columns, to persist homogeneous data. It can also be called as double-dimensioned array. Uses: - To represent class hierarchy using Boolean square matrix For data encryption and decryption To represent traffic flow and plumbing in a network To implement graph theory of node representation 23. Define an algorithm. What are the properties of an algorithm? What are the types of algorithms? Algorithm: A step by step process to get the solution for a well defined problem. 13 Properties of an algorithm: - Should be written in simple English - Should be unambiguous, precise and lucid - Should provide the correct solutions - Should have an end point - The output statements should follow input, process instructions - The initial statements should be of input statements - Should have finite number of steps - Every statement should be definitive Types of algorithms: - Simple recursive algorithms. Ex: Searching an element in a list – Backtracking algorithms Ex: Depth-first recursive search in a tree – Divide and conquer algorithms. Ex: Quick sort and merge sort – Dynamic programming algorithms. Ex: Generation of Fibonacci series – Greedy algorithms Ex: Counting currency – Branch and bound algorithms. Ex: Travelling salesman (visiting each city once and minimize the total distance travelled) – Brute force algorithms. Ex: Finding the best path for a travelling salesman – Randomized algorithms. Ex. Using a random number to choose a pivot in quick sort). 24. What is an iterative algorithm? The process of attempting for solving a problem which finds successive approximations for solution, starting from an initial guess. The result of repeated calculations is a sequence of approximate values for the quantities of interest. 25. What is an recursive algorithm? Recursive algorithm is a method of simplification that divides the problem into sub-problems of the same nature. The result of one recursion is the input for the next recursion. The repletion is in the self-similar fashion. The algorithm calls itself with smaller input values and obtains the results by simply performing the operations on these smaller values. Generation of factorial, Fibonacci number series are the examples of recursive algorithms. 26. Explain quick sort and merge sort algorithms. Quick sort employs the ‘divide and conquer’ concept by dividing the list of elements into two sub elements. The process is as follows: 1. Select an element, pivot, from the list. 2. Rearrange the elements in the list, so that all elements those are less than the pivot are arranged before the pivot and all elements those are greater than the pivot are arranged after the pivot. Now the pivot is in its position. 3. Sort the both sub lists – sub list of the elements which are less than the pivot and the list of elements which are more than the pivot recursively. 14 Merge Sort: A comparison based sorting algorithm. The input order is preserved in the sorted output. Merge Sort algorithm is as follows: 1. The length of the list is 0 or 1, and then it is considered as sorted. 2. Other wise, divide the unsorted list into 2 lists each about half the size. 3. Sort each sub list recursively. Implement the step 2 until the two sub lists are sorted. 4. As a final step, combine (merge) both the lists back into one sorted list. 27. What is Bubble Sort and Quick sort? Bubble Sort: The simplest sorting algorithm. It involves the sorting the list in a repetitive fashion. It compares two adjacent elements in the list, and swaps them if they are not in the designated order. It continues until there are no swaps needed. This is the signal for the list that is sorted. It is also called as comparison sort as it uses comparisons. Quick Sort: The best sorting algorithm which implements the ‘divide and conquer’ concept. It first divides the list into two parts by picking an element a ’pivot’. It then arranges the elements those are smaller than pivot into one sub list and the elements those are greater than pivot into one sub list by keeping the pivot in its original place. 28. What are the difference between a stack and a Queue? Stack – Represents the collection of elements in Last In First Out order. Operations includes testing null stack, finding the top element in the stack, removal of top most element and adding elements on the top of the stack. Queue - Represents the collection of elements in First In First Out order. Operations include testing null queue, finding the next element, removal of elements and inserting the elements from the queue. Insertion of elements is at the end of the queue Deletion of elements is from the beginning of the queue. 29. Can a stack be described as a pointer? Explain. A stack is represented as a pointer. The reason is that, it has a head pointer which points to the top of the stack. The stack operations are performed using the head pointer. Hence, the stack can be described as a pointer. 30. Explain the terms Base case, Recursive case, Binding Time, RunTime Stack and Tail Recursion. 15 Base case: A case in recursion, in which the answer is known when the termination for a recursive condition is to unwind back. Recursive Case: A case which returns to the answer which is closer. Run-time Stack: A run time stack used for saving the frame stack of a function when every recursion or every call occurs. Tail Recursion: It is a situation where a single recursive call is consisted by a function, and it is the final statement to be executed. It can be replaced by iteration. 31. Is it possible to insert different type of elements in a stack? How? Different elements can be inserted into a stack. This is possible by implementing union / structure data type. It is efficient to use union rather than structure, as only one item’s memory is used at a time. 32. Explain in brief a linked list. A linked list is a dynamic data structure. It consists of a sequence of data elements and a reference to the next record in the sequence. Stacks, queues, hash tables, linear equations, prefix and post fix operations. The order of linked items is different that of arrays. The insertion or deletion operations are constant in number. 33. Explain the types of linked lists. The types of linked lists are: Singly linked list: It has only head part and corresponding references to the next nodes. Doubly linked list: A linked list which both head and tail parts, thus allowing the traversal in bi-directional fashion. Except the first node, the head node refers to the previous node. Circular linked list: A linked list whose last node has reference to the first node. 34. How would you sort a linked list? Step 1: Compare the current node in the unsorted list with every element in the rest of the list. If the current element is more than any other element go to step 2 otherwise go to step 3. Step 2: Position the element with higher value after the position of the current element. Compare the next element. Go to step1 if an element exists, else stop the process. Step 3: If the list is already in sorted order, insert the current node at the end of the list. Compare the next element, if any and go to step 1 or quit. 16 35. What is sequential search? What is the average number of comparisons in a sequential search? Sequential search: Searching an element in an array, the search starts from the first element till the last element. The average number of comparisons in a sequential search is (N+1)/2 where N is the size of the array. If the element is in the 1st position, the number of comparisons will be 1 and if the element is in the last position, the number of comparisons will be N. 36. What are binary search and Fibonacci search? Binary Search: Binary search is the process of locating an element in a sorted list. The search starts by dividing the list into two parts. The algorithm compares the median value. If the search element is less than the median value, the top list only will be searched, after finding the middle element of that list. The process continues until the element is found or the search in the top list is completed. The same process is continued for the bottom list, until the element is found or the search in the bottom list is completed. If an element is found that must be the median value. Fibonacci Search: Fibonacci search is a process of searching a sorted array by utilizing divide and conquer algorithm. Fibonacci search examines locations whose addresses have lower dispersion. When the search element has non-uniform access memory storage, the Fibonacci search algorithm reduces the average time needed for accessing a storage location. 1)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. 2)List out the areas in which data structures are applied extensively? Compiler Design, Operating System, Database Management System, Statistical analysis package, Numerical Analysis, Graphics, Artificial Intelligence, Simulation 3) 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. 4) 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. 17 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. 5)What are the methods available in storing sequential files ? Straight merging, Natural merging, Polyphase sort, Distribution of Initial runs. 6) List out few of the Application of tree data-structure? The manipulation of Arithmetic expression, Symbol Table construction, Syntax analysis. 7) 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. 8) 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. 9) Does the minimum spanning tree of a graph give the shortest distance between any 2 specified nodes? Minimal spanning tree assures that the total weight of the tree is kept at its minimum. But it doesn't mean that the distance between any two nodes involved in the minimum-spanning tree is minimum. 10) 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. 11) What is the quickest sorting method to use? The answer depends on what you mean by quickest. For most sorting problems, it just doesn't 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 is no 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 author's toolbox that are all very fast and that are useful in different situations. Those methods are quick sort, merge sort, and radix sort. The Quick Sort The quick sort algorithm is of the divide and conquer type. That means it works by reducing a sorting problem into several easier sorting problems and solving each of them. A dividing value is chosen from the input data, and the data is partitioned into three sets: elements that belong before the dividing value, the value itself, and elements that come after the dividing value. The partitioning is performed by 18 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 the dividing element can be put in any of the three sets the algorithm will still work properly. The Merge Sort The merge sort is a divide and conquer sort as well. It works by considering the data to be sorted as a sequence of already-sorted lists (in the worst case, each list is one element long). Adjacent sorted lists are merged into larger sorted lists until there is a single sorted list containing all the elements. The merge sort is good at sorting lists and other data structures that are not in arrays, and it can be used to sort things that don't fit into memory. It also can be implemented as a stable sort. 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, and the process is repeated for each more significant byte until the list is sorted. The radix sort is simpler to implement on fixed-length data such as ints. How can I search for data in a linked list? Unfortunately, the only way to search a linked list is with a linear search, because the only way a linked list's members can be accessed is sequentially. Sometimes it is quicker to take the data from a linked list and store it in a different data structure so that searches can be more efficient. 12) What is the heap? The heap is where malloc(), calloc(), and realloc() get memory. 13 )What is the easiest sorting method to use? The answer is the standard library function qsort(). It's the easiest sort by far for several reasons: It is already written. It is already debugged. 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)); 14) What is the bucket size, when the overlapping and collision occur at same time? One. If there is only one entry possible in the bucket, when the collision occurs, there is no way to accommodate the colliding value. This results in the overlapping of values. 15)In an AVL tree, at what condition the balancing is to be done? 19 If the pivotal value (or the Height factor) is greater than 1 or less than 1. 16) 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. 17)How many different trees are possible with 10 nodes ? 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. 18) What is a node class? A node class is a class that, relies on the base class for services and implementation, provides a wider interface to users than its base class, relies primarily on virtual functions in its public interface depends on all its direct and indirect base class can be understood only in the context of the base class can be used as base for further derivation can be used to create objects. A node class is a class that has added new services or functionality beyond the services inherited from its base class. 19)When can you tell that a memory leak will occur? A memory leak occurs when a program loses the ability to free a block of dynamically allocated memory. 20) What is placement new? When you want to call a constructor directly, you use the placement new. Sometimes you have some raw memory that’s already been allocated, and you need to construct an object in the memory you have. Operator new’s special version placement new allows you to do it. 21)List out the areas in which data structures are applied extensively ? Compiler Design, Operating System, Database Management System, Statistical analysis package, Numerical Analysis, Graphics, Artificial Intelligence, Simulation 22)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. 23)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 20 iterative (non-recursive) function. Even when such equivalent iterative procedures are written, explicit stack is to be used. 24)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 25) What is the difference between ARRAY and STACK? STACK follows LIFO. Thus the item that is first entered would be the last removed. In array the items can be entered or removed in any order. Basically each member access is done using index. No strict order is to be followed here to remove a particular element. 26) What is the difference between 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; 27) What is precision? Precision refers the accuracy of the decimal portion of a value. Precision is the number of digits allowed after the decimal point. What is impact of signed numbers on the memory? Sign of the number is the first bit of the storage allocated for that number. So you get one 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 the sign. So the range is -128 to +127. 28)How memory is reserved using a declaration statement ? Memory is reserved using data type in the variable declaration. A programming language implementation has predefined sizes for its data types. For example, in C# the declaration int i; will reserve 32 bits for variable i. A pointer declaration reserves memory for the address or the pointer variable, but not for the data that it will point to. The memory for the data pointed by a pointer has to be allocated at runtime. The memory reserved by the compiler for simple variables and for storing pointer address is allocated on the stack, while the memory allocated for pointer referenced data at runtime is allocated on the heap. 29) How many parts are there in a declaration statement? There are two main parts, variable identifier and data type and the third type is optional which is type qualifier like signed/unsigned. 21 30) Is Pointer a variable? Yes, a pointer is a variable and can be used as an element of a structure and as an attribute of a class in some programming languages such as C++, but not Java. However, the contents of a pointer is a memory address of another location of memory, which is usually the memory address of another variable, element of a structure, or attribute of a class. 31)What is Data Structure? 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. Some are used to store the data of same type and some are used to store different types of data. 32)What is significance of ” * ” ? 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. 33) Why do we Use a Multidimensional Array? 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 store memory addresses of data in a pointer array and an array of pointers. Multidimensional arrays are used to store information in a matrix form. e.g. a railway timetable, schedule cannot be stored as a single dimensional array. One can use a 3-D array for storing height, width and length of each room on each floor of a building. 34) How do you assign an address to an element of a pointer array ? We can assign a memory address to an element of a pointer array by using the address operator, which is the ampersand (&), in an assignment statement such as ptemployee[0] = &projects[2]; 35)Run Time Memory Allocation is known as ? 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, 22 for example : int grades[] = new int[10]; 36)What method is used to place a value onto the top of a stack? 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. 37) What method removes the value from the top of a stack? The pop() member method removes the value from the top of a stack, which is then returned by the pop() member method to the statement that calls the pop() member method. 38) What does isEmpty() member method determines? isEmpty() checks if the stack has at least one element. This method is called by Pop() before retrieving and returning the top element. 39) What is a queue ? A Queue is a sequential organization of data. A queue is a first in first out type of data structure. An element is inserted at the last position and an element is always taken out from the first position. What is the relationship between a queue and its underlying array? Data stored in a queue is actually stored in an array. Two indexes, front and end will be used to identify the start and end of the queue. 40) Why is the isEmpty() member method called? The isEmpty() member method is called within the dequeue process to determine if there is an item in the queue to be removed i.e. isEmpty() is called to decide whether the queue has at least one element. This method is called by the dequeue() method before returning the front element. 41) How is the front of the queue calculated ? The front of the queue is calculated by front = (front+1) % size. 42 )What does each entry in the Link List called? Each entry in a linked list is called a node. Think of a node as an entry that has three sub 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 new item on a linked list, you allocate the new node and then set the pointers to previous and next nodes. 43) What is Linked List ? Linked List is one of the fundamental data structures. It consists of a sequence of? nodes, each containing arbitrary data fields and one or two (”links”) pointing to the next and/or previous 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 in the list in constant time, but do not allow random access. 23 44) What member function places a new node at the end of the linked list? 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. 45 )How is any Data Structure application is classified among files? A linked list application can be organized into a header file, source file and main application file. The first file is the header file that contains the definition of the NODE structure and the LinkedList class definition. The second file is a source code file containing the implementation of member functions of the LinkedList class. The last file is the application file that contains code that creates and uses the LinkedList class. 46) Which file contains the definition of member functions? Definitions of member functions for the Linked List class are contained in the LinkedList.cpp file. 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. 47 ) Difference between calloc and malloc ? malloc: allocate n bytes calloc: allocate m times n bytes initialized to 0 1. What is data structure? The logical and mathematical model of a particular organization of data is called data structure. There are two types of data structure Linear Nonlinear 2. What is a linked list? A linked list is a linear collection of data elements, called nodes, where the linear order is given by pointers. Each node has two parts first part contain the information of the element second part contains the address of the next node in the list. 3. What is a queue? A queue is an ordered collection of items from which items may be deleted at one end (front end) and items inserted at the other end (rear end). It obeys FIFO rule there is no limit to the number of elements a queue contains. 4. What is a spanning Tree? 24 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. 5. What is precision? Precision refers the accuracy of the decimal portion of a value. Precision is the number of digits allowed after the decimal point. 6. What are the goals of Data Structure? It must rich enough in structure to reflect the actual relationship of data in real world. The structure should be simple enough for efficient processing of data. 7. What is the difference between a Stack and an Array? Stack Stack is a dynamic object whose size is constantly changing as items are pushed and popped . Stack may contain different data types. Stack is declared as a structure containing an array to hold the element of the stack, and an integer to indicate the current stack top within the array. Stack is a ordered collection of items. Array Array is an ordered collection of items. Array is a static object. It contains same data types. Array can be home of a stack i.e. array can be declared large enough for maximum size of the stack. 8. What is sequential search? In sequential search each item in the array is compared with the item being searched until a match occurs. It is applicable to a table organized either as an array or as a linked list. 9. What are the disadvantages array implementations of linked list? The no of nodes needed can’t be predicted when the program is written. The no of nodes declared must remain allocated throughout its execution. 10. What is a priority queue? The priority queue is a data structure in which the intrinsic ordering of the elements. 11. What are the disadvantages of sequential storage? Fixed amount of storage remains allocated to the data structure even if it contains less element.No more than fixed amount of storage is allocated causing overflow. 12. Define circular list? 25 In linear list the next field of the last node contain a null pointer, when a next field in the last node contain a pointer back to the first node it is called circular list. 13. What does abstract Data Type Mean? Data type is a collection of values and a set of operations on these values. Abstract data type refer to the mathematical concept that define the data type. 14. What do you mean by recursive definition? The definition which defines an object in terms of simpler cases of itself is called recursive definition. 15. What actions are performed when a function is called? When a function is called arguments are passed local variables are allocated and initialized transferring control to the function 16. Define double linked list? It is a collection of data elements called nodes, where each node is divided into three parts An info field that contains the information stored in the node. Left field that contain pointer to node on left side. Right field that contain pointer to node on right side. 17. What do you mean by overflow and underflow? When new data is to be inserted into the data structure but there is no available space i.e.free storage list is empty this situation is called overflow. When we want to delete data from a data structure that is empty this situation is called underflow. 18. 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. 19. What do you mean by free pool? Pool is a list consisting of unused memory cells which has its own pointer. 20. What are the methods available in storing sequential files ? Straight merging Natural merging Polyphase sort Distribution of Initial runs 21. What is a node class? A node class is a class that has added new services or functionality beyond the services inherited from its base class. 22. what is binary tree? 26 A binary tree is a tree data structure in which each node has at most two child nodes, usually distinguished as left and right. ****** 27