Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 8

Arrays Array is a list or collection of data items which are stored in the form of a table and is given a common

name which is called array name or Subscript variable name. (Read the advantages of Array from the book) Pointers: Pointers are the special type of variable which point to another variable, structure, function or even a pointer. (Read the advantages of pointer from the book) Data Structure (Unit 2) A data structure is the organization of data in a computers memory or in a file. An ADT (Abstract Data type) defines a data structure with set of entities, their use in independent from a particular programming language and a set of operations on the entities. (Read Unit 2 carefully as it is the introductory part of the whole book). Stack: A stack is a data structure where we insert and delete the data from the same end known as Top. The insert operation in stack is known as Push and delete operation is know as Pop operation. Stack is based on LIFO basis. Normally stack has limited size but stack can be built with unlimited size using linked list. Queue: A queue is a data structure where data is inserted from one end and deleted from another end. The end from were we insert data is known as Rear end and the end from were we delete the data is known as Front end. The types of queues are : Ordinary Queue, Double ended queue, Circular queue and Priority queue.

Tree:
A tree a is a data structure which consists of a finite set of elements, called nodes and a finite set of directed lines, called branches that connect the nodes. The number of branches associated with a node is the degree of the node. The branch coming towards the node is the indegree of the node. Similarly the outgoing branches from the node means the outdegree of that node. The first node of the tree is known as root. When the tree is empty, then root is equals to null. In another case the indegree of the root is always 0. Elements of Tree: Leaf: Leaf is a node with no successors. Or Leaf is a node with outdegree equals to 0. Root: The unique node with no predecessor. Or the first node of the tree which has always indegree equals to 0. Non Leaf: A node which has both a parent and at least one child.

Children: The successors of a node Parent: The unique predecessor of a node. Siblings: Nodes that have the same parent. Internal Nodes: Nodes that are not root and not leaf are called as internal nodes.

Binary Tree: It is a directed tree in which outdegree of each node is less than or equal to two i.e, each node in a tree can not have more than two children. In a binary tree the two children are called left and right. In a complete binary tree of level 2 or more than 2, the degree of a root node is 2. The degree of internal nodes is 3 i.e. the indegree of internal node is 1 and the outdegree is 2. Binary Tree Traversal techniques: Pre-order Traversal (Algorithm: i. Process the node. (ii) Traverse the left subtree in Pre-order (iii) Traverse the right subtree in Pre-order.) Inorder Traversal (Algorithm: i. Traverse the left subtree in Inorder. (ii) Process the node (iii) Traverse the right subtree in inorder.) Post-order Traversal (Algorithm: i. Traverse the left subtree in postorder. (ii) Traverse the right subtree in postorder. (iii) Process the node.)

Example of the tree traversal:


P Q S W T R U V

Fig. 1

Preorder Traversal: P,Q,S,W,R,T,U,V Inorder Traversal: S, W, Q, P, T, R, U, V Postorder Traversal: W,S,Q,T,V,U,R,R,P

Splay trees

Splay trees, are a form of binary search tree on which the standard searchtree operations run in O(lg n) amortized time.

Every time the accessed node is moved to the root in splay tree. We continue to apply the three rules until x is at the root of the tree and the rules are : Zig, Zig-zag and Zig-zig. The zig-zig rule is the one that distinguishes splaying from just rotating z to the root of the tree. Doing a rotation between a pair of nodes x and y only effects the ranks of the nodes x and y and no other nodes in the tree. The join operation on two splay tree A and B takes O(log n). Deletion of a node x in splay tree is also done in O(log n) amortized cost. The balance theorem has sequence of m splays in a tree of n nodes and takes time O(m log (n) + n log(n)). Insertion operation in splay trees takes O(log(n+1) i.e. the amortized cost. File Structure Records are collected into logical units called files.

File structure which is also called as data structure is the logical organization of records in a file.

Logical structure of the data is the relationship that will exist between data items independenty. Some examples of file structures are sequential files, inverted files, index-sequential files and multi-list files. Sequential file structure is easy to implement. It provides fast access to the next record using lexicographic order. It is difficult to update, for example inserting a new record may require moving a large proportion of the file. Random access is extremely slow. An inverted file is a file structure in which every list contains only one record. The and and OR operations can be performed with one pass through both list in and inverted file. An index-sequential file is an inverted file with a hierarchy of indices. A multi-list is a slightly modified inverted file. The multi-list is designed to overcome the difficulties of updating an inverted file.

Cellular multi-list is again the modified form of the multi-list. The K-lists are limited in cellular multi-list so that they will not cross the page(cell) boundaries of the storage media. A ring structure is a linear list that closes upon itself i.e. the beginning and the end of the list are the same record. A ring structure is particularly useful to show classification of data.

Hash addressing is the technique by which the file structures are implemented. Tree structure can be used to organize the files. Hash addressing is the technique by which the file structures are implemented. The advantages of hashing are: (i) It is simple (ii) Insertion and search strategies are identical. (iii) The search time is independent of the number of keys to be inserted. Graph:
A graph is a collection of vertices V and a collection of edges E consisting of pairs of vertices. The graph is normally represented using that analogy. Vertices are points or circles, edges are lines between them. In this example graph: V = {1, 2, 3, 4, 5, 6} E = { (1,3), (1,6), (2,5), (3,4), (3,6)}. Each vertex is a member of the set V. A vertex is sometimes called a node. Each edge is a member of the set E. Note that some vertices might not be the end point of any edge. Such vertices are termed ``isolated''. Sometimes, numerical values are associated with edges, specifying lengths or costs; such graphs are called edge-weighted graphs (or weighted graphs). The value associated with an edge is called the weight of the edge. A similar definition holds for node-weighted graphs.

Minimum Spanning Tree:


In the mathematical field of graph theory, a spanning tree T of a connected, undirected graph G is a tree composed of all the vertices and minimum number of the edges of G. Informally, a spanning tree of G is a selection of edges of G that form a tree spanning every vertex. That is, every vertex lies in the tree, but no cycles (or loops) are formed. On the other hand, every bridge of G must belong to T.

A spanning tree of a connected graph G can also be defined as a maximal set of edges of G that contains no cycle, or as a minimal set of edges that connect all vertices. We can find out the Minimum Spanning Tree using Kruskals and Prims Algorithm. We go on selecting the minimum cost edge one after another in ascending order of the weights in Kruskals algorithm. In Prims Algorithm we go on selecting the minimum cost edge adjacent to the already selected edges. Kruskals algorithm is also known as Greedy algorithm. Djikstra's algorithm solves the problem of finding the shortest path from a point in a graph (the source) to a destination. It turns out that one can find the shortest paths from a given source to all points in a graph in the same time, hence this problem is sometimes called the single-source shortest paths problem. Relaxation The relaxation process updates the costs of all the vertices, v, connected to a vertex, u, if we could improve the best estimate of the shortest path to v by including (u,v) in the path to v. Bellman-Ford algorithm: An efficient algorithm to solve the single-source shortest-path problem. Weights may be negative. The algorithm initializes the distance to the source vertex to 0 and all other vertices to . It then does V-1 passes (V is the number of vertices) over all edges relaxing, or updating, the distance to the destination of each edge. Finally it checks each edge again to detect negative weight cycles, in which case it returns false. The time complexity is O(VE), where E is the number of edges.
Graph Transpose Graph Transpose problem Input: directed graph G = (V,E) Output: graph GT = (V,ET), where ET = {(v,u) in VxV : (u,v) in E}. i.e. GT is G with all its edges reversed. Describe efficient algorithms for computing GT from G, for both the adjacency-list and adjacencymatrix representations of G. Analyze the running times of your algorithms.

==>
Using Adjacency List representation, array B is the new array of Adjacency List GT for (i=1;i<=p;i++) B[i] = nil; for (i=1;i<=p;i++) repeat { append i to the end of linked list B[A[i]]; get next A[i]; } until A[i] = nil; Total Time = O(V+E) Using Adjacency Matrix representation, D[][] is the new adj matrix for GT for (i=1;i<=p;i++) for (j=1;j<=p;j++) D[j][i] = C[i][j]; Total time = O(V2) Eulerian Cycle & Eulerian Path Euler Cycle Input: Connected, directed graph G = (V,E) Output: A cycle that traverses every edge of G exactly once, although it may visit a vertex more than once. Theorem: A directed graph possesses an Eulerian cycle iff 1) It is connected 2) For all {v} in {V} indegree(v) = outdegree(v) Euler Path Input: Connected, directed graph G = (V,E) Output: A path from v1 to v2, that traverses every edge of G exactly once, although it may visit a vertex more than once. Theorem: A directed graph possesses an Eulerian path iff 1) It is connected 2) For all {v} in {V} indegree(v) = outdegree(v) with the possible exception of two vertices v1,v2 in which case,

a) indegree(v1) = outdegree(v2) + 1 b) indegree(v2) = outdegree(v1) - 1 Topological Sort Topological Sort problem Input: A directed acyclic graph (DAG) G = (V,E) Output: A linear ordering of all vertices in V such that if G contains an edge (u,v), then u appears before v in the ordering. If drawn on a diagram, Topological Sort can be seen as a vertices along horizontal line, where all directed edges go from left to right. Note: A directed graph G is acylic if and only if a DFS of G yields no back edge.

Big O Notation It is the formal method of expressing the upper bound of an algorithms running time. Its a measure of the longest amount of time it could possibly take for algorithm to complete. More formally, for non-negative functions, f(n) and g(n), if there exists an integer n0 and a constant c>0 such that for all integers n>n0, f(n) cg(n), then f(n) is Big O of g(n). This is denoted as f(n) = O(g(n)). If graphed, g(n) serves as an upper bound to the curve you are analyzing, f(n). Some Examples: O(n) : printing a list of n items to the screen, looking at each item once.

O(log n) or O(ln n) : taking a list of items, cutting it in half repeatedly until theres only on item left. O(n2): taking a list of n items, and comparing every item to every other item.

Big- Omega Notation For non-negative functions, f(n) and g(n), if there exists an integer n0 and a constant c>0 such that for all integers n>n0, f(n) cg(n), then f(n) is omega of g(n). This is denoted as f(n) = (g(n)). This is almost the same definition as Big O, except that f(n) cg(n), this makes g(n) a lower bound function, instead of an upper bound function. It describes the best that can happen for a given data size.

Theta Notation: For non-negative functions, f(n) and g(n), f(n) is theta of g(n) if and only if f(n) = O(g(n)) and f(n) = (g(n)). This is denoted as f(n) = (g(n)). This is basically saying that the function, f(n) is bounded both from top and bottom by the same function, g(n).

Little o Notation For non-negative functions, f(n) and g(n), f(n) is little o of g(n) if and only if f(n) = O(g(n)), but f(n) (g(n)). This is denoted as f(n) = o(g(n)). This represents a loose bounding version of Big O. g(n) bounds from the top, but it does not bound the bottom.

Little Omega Notation For non-negative functions, f(n) and g(n), f(n) is little omega of g(n) if and only if f(n) = (g(n)), but f(n) (g(n)). This is denoted as f(n) = (g(n)). This represents a loose bounding version of Big Omega. g(n) bounds from the bottom, but it does not bound the top.

Note: Dont forget to read the Summary given after each chapters.

You might also like