You are on page 1of 3

Advanced Data Structure

1. What is a data structure? Discuss briefly on types of data structures. Answer 1: As we have seen previously the data structure represents the logical relationship of the particular data sets. In this section you are going to learn about some of the data structures which we will discuss in detail in further units. Data structures can be divided in to two types Linear data structure Non Linear data structure Linear data structure When the data is stored in the memory in linear or sequential form is called linear data structure. Examples of linear data structures include Array, Stack, Queue, Linked list. Non Linear data structure When the data is stored in the memory in dispersed or non sequential order is called non linear data structure. Example of non linear data structures includes trees, graphs, files etc. 2. Explain the insertion and deletion operation of linked list in detail. Answer 2: Insertion is the process of adding a new node to the linked list. It requires a new node and executing two next pointer maneuvers. Suppose consider a new node N is to be inserted into list between node A and B. We have algorithms for various situation of inserting an ITEM into linked list. In this section we will see two of them. The first one is inserting a node at the beginning of a list and the second one is inserting after the node with a given location. All over the algorithm ITEM contains the new data to be added to the list. Deletion is the process of removing a node from the linked list. The deletion of a node is made just by a pointer change. We have algorithms for deletion from linked list in various situations. In this section we will see two of them. The first one deletes the node following a given node and the second one deletes the node with a given ITEM of information. All of our deletion algorithms will return the memory space of the deleted node N to the beginning of the AVAIL list. Accordingly, all of our algorithms will include the following pair of assignments, where LOC is the location of the deleted node N: LINK [LOC]:= AVAIL and AVAIL := LOC 3. Discuss the process of Infix to postfix conversion. Also explain Postfix evaluation. Answer 3: Generally the expression we use for algebraic notations are in infix form, now we are going to discuss how to convert this infix to postfix, the following algorithm helps us to proceed with. Infix is the input string and the output what we get after the process is the postfix string. 1. Initialize a STACK as empty in the beginning. 2. Inspect the infix string from left to right. While reading character from a string we may encounter Operand - add with the postfix string. Operator if the stack is empty push the operator into stack, if any operator available with the stack compares the current operator precedence with the topStack if it has higher precedence over the current one pop the stack and add with the post string else push the current operator to the stack. Repeat this process until the stack is empty. Left Parenthesis: Push in to the STACK. Right Parenthesis: Pop everything until you get the left parenthesis or end of STACK. 3. Repeat Process with the infix string until all the characters are read. 4. Check for stack status if it is not empty add topStack to postfix string and repeat this process until the STACK is empty 5. Return the postfix string. 6. Exit.

Example for infix to postfix expression a+b*c-d Infix String Stack status Postfix string a + b * c - d Null Empty + b * c d Null a b*c-d+a * c - d + ab c-d* + ab -d* + abc d - abc*+ - abc*+d abc*+d 4. Explain the different types of traversal on binary tree. Answer 4: There are many operations that we often want to perform on trees. One notion that arises frequently is the idea of traversing a tree or visiting each node in the tree exactly once. A full traversal produces a linear order for the information in a tree. This linear order may be familiar and useful. When traversing a binary tree we want to treat each node and its subtrees in the same fashion. If we let L, D, R stand for moving left, printing the data, and moving right at a node then there are six possible combinations of traversal: LDR, LRD, DLR, DRL, RDL, and RLD If we adopt the convention that we traverse left before right then only three traversals remain: LDR, LRD and DLR . To these we assign the names inorder, postorder and preorder because there is a natural correspondence between these traversals and producing the infix, postfix and prefix forms of an expression. Inorder traversal helps to print the binary search tree in sorted order. Here the traversal starts with left most subtree then prints the parent node and then proceeds with the right subtree. 1) Traverse the left subtree 2) Visit the root node 3) Traverse the right subtree 5. Explain Breadth-first and depth-first search algorithm. Answer 5: This algorithm uses a queue data structure to perform the search. The effect of this is to process all nodes adjacent to the start node before we process the nodes adjacent to those nodes. If all of the edges in a graph are unweighted (or the same weight) then the first time a node is visited is the shortest path to that node from the source node. Algorithms for Breadth first search is also similar to the one that is mentioned in the previous unit. The concept of algorithm is same either it be in trees or in graph. There are other algorithms used to find the shortest path from one node to another like Dijkstra's algorithm . Dijkstras algorithm is described in the next unit. The shortest path from each node to every other node is also solved using the Floyd algorithm, Warshall algorithm and modified Warshall algorithms. The depth first search algorithm is used to visit all of the nodes in the graph for its examination and not always necessary to find the shortest path. Depth first search is done by taking a node, checking its neighbors, expanding the first node it finds among the neighbors, checking if that expanded node is our destination, and if not, continue exploring more nodes. In Depth First search it should be noted that same node is not visited more than once, otherwise possibility of infinite recursion may occur. Algorithms for Depth first search is similar to the one that is mentioned in the previous unit. The concept of algorithm is same either it be in trees or in graph.

6. Explain the meaning of dynamic storage management. Also explain the concept of storage release. Answer 6: Memory holds basically programs and their data. All the program need to manipulate the data in order to complete the task. These data should be stored in the memory for manipulation, so these data can be managed in two different ways. Like static storage management and dynamic storage management. Primitive and static natures of data structures like integer, real, or character variable has the characters that, their sizes are specified either explicitly or implicitly in their declarations and memory will be allotted during compilation and the sizes will not be changed during run time. For example while declaring an integer variable in of c or c++ , the complier may allocate 2 bytes for the variable. The programmer cannot change the size if he wants to make the variable to hold overflow situation also. This shows clearly, restrictions of static allocation are imposing limitations. These static allocations are manageable for primitive data structure for simple application. But we require dynamic data structures such as linked list in order to construct the advanced structures like queue and trees. The c++ language provides storage allocation by maintaining a separate memory area called free. Programs can request a block of contiguous memory for their dynamic use, after allocation this will be maintained in the allocated list. After the use allocated memory the same can be returned to the free pool. In many of the previous preceding sections we have made free use of structures that require a form of memory management in order to handle requests for storage and releases of storage. When we discussed about the tree data structure we simply requested the nodes, whenever we required without bothering when and how these nodes were to be released or when they were no longer needed. This makes the programmer work easy. Most of the dynamic storage management methods that are commonly used are variants of the technique presented here. concept of storage release. ,. Finally we highlighted the concept of garbage collection, which is the process of recovering unused objects or variable memory so that those can be used by the other programs. Garbage collection process can be triggered either manually or the appropriate functions can be called.

You might also like