Sei sulla pagina 1di 11

1.

Singly Linked list:

A linked list is a data structure used for collecting a sequence of objects, which allows efficient addition, removal and retrieval of elements from any position in the sequence. It is implemented as nodes, each of which contains a reference (i.e., a link) to the next and/or previous node in the sequence.

A linked list whose nodes contain two fields: an integer value and a link to the next node

2.

Doubly Linked list


In it, each node has two links: one points to previous node and one points to next node. The previous link of first node in the list points to a Null and the next link of last node points to Null.

3.

Circularly Linked List:-

In it the last node does not contain NULL pointer. Instead the last node contains a pointer that has the address of first node and thus points back to the first node. It is shown below:

4. Generalized Linked List


Generalized Lists Generalized List A generalized list, A, is a finite sequence of n>= 0 elements, a0,,an-1, where ai is either

an atom or the list of atoms. It helps to represent a multi variable polynomial as well as list of elements. Flag: it tells whether Information/ Down pointer: it points Next pointer: it points to a GLL have a down data stored to the list following in next node of the list in pointer or not. the downward direction sequence of the current node. Eg we have 10 words in a list & each character is represented by a linked list.

5. Tree
A tree is a hierarchical non linear data structure which is an acyclic connected graph where each node has zero or more children nodes and at most one parent node. Eg.

6. Binary Tree
A binary tree is a tree data structures in which each node have at most two child nodes, termed as "left" and "right".

Node of a tree A node is a structure which may contain a value, a condition along with two pointers left pointer pointing to left subtree & right pointer pointing to right subtree. A node that has a child is called the child's parent node (or ancestor node, or superior). A node has at most one parent. Nodes that do not have any children are called leaf nodes. They are also referred to as terminal nodes. A free tree is a tree that is not rooted

The height of a node is the length of the longest downward path to a leaf from that node. The height of the root is the height of the tree. The depth of a node is the length of the path to its root (i.e., its root path). This is commonly needed in the manipulation of the various self balancing trees, AVL Trees in particular. Conventionally, the value 1 corresponds to a subtree with no nodes, whereas zero corresponds to a subtree with one node. The topmost node in a tree is called the root node. Being the topmost node, the root node will not have parents. It is the node at which operations on the tree commonly begin (although some algorithms begin with the leaf nodes and work up ending at the root). All other nodes can be reached from it by following edgesor links. (In the formal definition, each such path is also unique). In diagrams, it is typically drawn at the top. In some trees, such as heaps, the root node has special properties. Every node in a tree can be seen as the root node of the subtree rooted at that node. An internal node or inner node is any node of a tree that has child nodes and is thus not a leaf node. Similarly, an external node or outer node is any node that does not have child nodes and is thus a leaf. A subtree of a tree T is a tree consisting of a node in T and all of its descendants in T. (This is different from the formal definition of subtree used in graph theory.[1]) The subtree corresponding to the root node is the entire tree; the subtree corresponding to any other node is called a proper subtree (in analogy to the term proper subset). [edit]

7. Complete Binary Tree


A binary tree is an important type of structure which occurs very often. It is characterized by the fact that any node can have at most two branches, i.e.,there is no node with degree greater than two. For binary trees we distinguish between the subtree on the left and on the right, whereas for trees the order of the subtreewas irrelevant. Also a binary tree may have zero nodes. Thus a binary tree is really a different object than a tree. A binary tree is a finite set of nodes which is either empty or consists of a root and two disjoint binary trees called the left subtree and the right subtree.

8. Extended Binary Trees


An extended binary tree is a transformation of any binary tree into a complete binary tree. This transformation consists of replacing every null subtree of the original treewith ``special nodes.'' The nodes from the original tree are then internal nodes, while the ``special nodes'' are external nodes. For instance, consider the following binary tree.

The following tree is its extended binary tree. Empty circles represent internal nodes, and filled circles represent external nodes.

Every internal node in the extended tree has exactly two children, and every external node is a leaf. The result is a complete binary tree.

9. Threaded Binary trees


A threaded binary tree may be defined as follows: "A binary tree is threaded by making all right child pointers that would normally be null point to the inorder successor of the node, and all left child pointers that would normally be null point to the inorder predecessor of the node." A threaded binary tree makes it possible to traverse the values in the binary tree via a linear traversal that is more rapid than a recursive in-order traversal. It is also possible to discover the parent of a node from a threaded binary tree, without explicit use of parent pointers or a stack, albeit slowly. This can be useful where stack space is limited, or where a stack of parent pointers is unavailable (for finding the parent pointer via DFS). To see how this is possible, consider a node k that has a right child r. Then the left pointer of r must be either a child or a thread back to k. In the case that rhas a left child, that left child must in turn have either a left child of its own or a thread back to k, and so on for all successive left children. So by following the chain of left pointers from r, we will eventually find a thread pointing back to k. The situation is symmetrically similar when q is the left child of pwe can follow q's right children to a thread pointing ahead to p.

10. TreeTraversal:tree-traversal refers to the process of visiting (examining and/or updating) each node in a tree data structure, exactly once, in a systematic way. Such traversals are classified by the order in which the nodes are visited. The following algorithms are described for a binary tree, but they may be generalized to other trees as well. Compared to linear data structures like linked lists and one dimensional arrays, which have a canonical method of traversal, tree structures can be traversed in many different ways. Starting at the root of a binary tree, there are three main steps that can be performed and the order in which they are performed defines the traversal type. These steps (in no particular order) are: performing an action on the current node (referred to as "visiting" the node), traversing to the left child node, and traversing to the right child node. Thus the process is most easily described through recursion. The names given for particular style of traversal came from the position of root element with regard to the left and right nodes. Imagine that the left and right nodes are constant in space, then the root node could be placed to the left of the left node (pre-order), between the left and right node (in-order), or to the right of the right node (post-order). Depth-first Traversal Binary Tree

To traverse a non-empty binary tree in preorder, perform the following operations recursively at each node, starting with the root node: 1. 2. 3. Visit the root. Traverse the left subtree. Traverse the right subtree.

To traverse a non-empty binary tree in inorder (symmetric), perform the following operations recursively at each node: 1. 2. 3. Traverse the left subtree. Visit the root. Traverse the right subtree.

To traverse a non-empty binary tree in postorder, perform the following operations recursively at each node: 1. 2. 3. Traverse the left subtree. Traverse the right subtree. Visit the root.

Generic Tree To traverse a non-empty tree in depth-first order, perform the following operations recursively at each node: 1. 2. Perform pre-order operation for i=1 to n-1 do 1. 2. 3. 4. Visit child[i], if present Perform in-order operation

Visit child[n], if present Perform post-order operation

where n is the number of child nodes. Depending on the problem at hand, the pre-order, inorder or post-order operations may be void, or you may only want to visit a specific child node, so these operations should be considered optional. Also, in practice more than one of pre-order, in-order and post-order operations may be required. For example, when inserting into a ternary

tree, a pre-order operation is performed by comparing items. A post-order operation may be needed afterwards to rebalance the tree. Breadth-first Traversal Trees can also be traversed in level-order, where we visit every node on a level before going to a lower level. This is also called Breadth-first traversal. Binary search tree

Depth-first

Preorder traversal sequence: F, B, A, D, C, E, G, I, H (root, left, right) Inorder traversal sequence: A, B, C, D, E, F, G, H, I (left, root, right); note how this Postorder traversal sequence: A, C, E, D, B, H, I, G, F (left, right, root)

produces a sorted sequence

Breadth-first

Level-order traversal sequence: F, B, G, A, D, I, C, E, H

preorder

in-order

post-order level-order

push F pop F push G B pop B push D A pop A pop D

push F B A pop A pop B push D C pop C pop D push E

push F B A pop A push D C pop C push E pop E pop D

enqueue F dequeue F enqueue B G dequeue B enqueue A D dequeue G enqueue I

push E C pop C pop E pop G push I pop I push H pop H

pop E pop F push G pop G push I H pop H pop I

pop B push G I H pop H pop I pop G pop F

dequeue A dequeue D enqueue C E dequeue I enqueue H dequeue C dequeue E dequeue H

Inorder traversal It is particularly common to use an inorder traversal on a binary search tree because this will return values from the underlying set in order, according to the comparator that set up the binary search tree (hence the name). To see why this is the case, note that if n is a node in a binary search tree, then everything in n 's left subtree is less than n, and everything in n 's right subtree is greater than or equal to n. Thus, if we visit the left subtree in order, using a recursive call, and then visit n, and then visit the right subtree in order, we have visited the entire subtree rooted at n in order. We can assume the recursive calls correctly visit the subtrees in order using the mathematical principle of structural induction. Traversing in reverse inorder similarly gives the values in decreasing order. Preorder traversal Traversing a tree in preorder while inserting the values into a new tree is common way of making a complete copy of a binary search tree. One can also use preorder traversals to get a prefix expression (Polish notation) from expression trees: traverse the expression tree preorderly. To calculate the value of such an expression: scan from right to left, placing the elements in a stack. Each time we find an operator, we replace the two top symbols of the stack with the result of applying the operator to those elements. For instance, the expression + 2 3 4, which in infix notation is (2 + 3) 4, would be evaluated like this: Using prefix traversal to evaluate an expression tree Expression (remaining) +234 +23 Stack <empty> 4

+2 + Answer

34 234 54 20

11.

Graphs

a graph is an abstract representation of a set of objects where some pairs of the objects are connected by links. The interconnected objects are represented by mathematical abstractions called vertices, and the links that connect some pairs of vertices are called edges. Typically, a graph is depicted in diagrammatic form as a set of dots for the vertices, joined by lines or curves for the edge

12.

Edge

For an undirected graph, an unordered pair of nodes that specify a line joining these two nodes are said to form an edge. For a directed graph, the edge is an ordered pair of nodes. The terms "arc," "branch," "line," "link," and "1-simplex" are sometimes used instead of edge

13.

Node

A node may contain a value or a condition or represents a separate data structure or a tree of its own. Each node in a tree has zero or more child nodes, which are below it in the tree (by convention, trees grow down, not up as they do in nature). A node that has a child is called the child's parent node (or ancestor node, or superior). A node has at most one parent. The height of a node is the length of the longest downward path to a leaf from that node. The height of the root is the height of the tree. The depth of a node is the length of the path to its root (i.e., its root path). Root nodes The topmost node in a tree is called the root node. Being the topmost node, the root node will not have parents. It is the node at which operations on the tree commonly begin (although some algorithms begin with the leaf nodes and work up ending at the root). All other nodes can be reached from it by following edges or links. (In the formal definition, each such path is also unique). In diagrams, it is typically drawn at the top. In some trees, such as heaps, the root node has special properties. Every node in a tree can be seen as the root node of the subtree rooted at that node. Leaf nodes Nodes at the bottommost level of the tree are called leaf nodes. Since they are at the bottommost level, they do not have any children. Internal nodes An internal node or inner node is any node of a tree that has child nodes and is thus not a leaf node. A rooted tree is a tree with a countable number of nodes, in which a particular node is distinguished from the others and called the root:

Potrebbero piacerti anche