• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Short dec
 

Short dec

on

  • 585 views

data structure importants notes

data structure importants notes

Statistics

Views

Total Views
585
Views on SlideShare
584
Embed Views
1

Actions

Likes
0
Downloads
7
Comments
0

1 Embed 1

http://www.slashdocs.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft Word

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Short dec Short dec Document Transcript

    • ARRAYan array data structure or simply an array is a data structure consisting of a collectionof elements (values orvariables), each identified by at least one array index or key.ApplicationsArrays are used to implement mathematical vectors and matrices, as well as other kinds ofrectangular tables.One-dimensional arraysA one-dimensional array (or single dimension array) is a type of linear array. Accessing itselements involves a single subscript which can either represent a row or column index.As an example consider the C declaration int anArrayName[10];Multidimensional arraysFor a two-dimensional array, the element with indices i,j would have address B + c · i + d · j,where the coefficients c and d are the rowand column address increments, respectively.For example: int a[3][2];STACK::A stack is a list in which insertion and deletion take place at the same endThis end is called topThe other end is called bottomStacks are known as LIFO (Last In, First Out) lists.The last element inserted will be the first to be retrievedPrimary operations: Push and PopPushAdd an element to the top of the stackPopRemove the element at the top of the stackImplementation of StacksAny list implementation could be used to implement a stackArrays (static: the size of stack is given initially)Linked lists (dynamic: never become full)CODE)CHECK ITLB=O;TOP=LB; INSEERTIONWHILE TOP!= 4READ XNUM[TOP]=XTOP=TOP+1TOP=TOP-1WHILE TOP!= -1 DELETION {TOP= TOP -1}QEUEE
    • Like a stack, a queue is also a list. However, with a queue, insertion is done at one end, whiledeletion is performed at the other end.Accessing the elements of queues follows a First In, First Out (FIFO) order.Like customers standing in a check-out line in a store, the first customer in is the first customerserved.Enqueue and DequeuePrimary queue operations: Enqueue and DequeueLike check-out lines in a store, a queue has a front and a rear.Enqueue – insert an element at the rear of the queueDequeue – remove an element from the front of the queueImplementation of QueueJust as stacks can be implemented as arrays or linked lists, so with queues.Dynamic queues have the same advantages over static queues as dynamic stacks have over staticstacksQueue Implementation of ArrayThere are several different algorithms to implement Enqueue and DequeueNaïve wayWhen enqueuing, the front index is always fixed and the rear index moves forward in the array. rear rear rear 3 3 6 3 6 9 front front front Enqueue(3) Enqueue(6) Enqueue(9)Naïve way (cont’d)When dequeuing, the front index is fixed, and the element at the front the queue is removed.Move all the elements after it by one position. (Inefficient!!!)
    • rear rear rear = -1 6 9 9 front front front Dequeue() Dequeue() Dequeue()Delete ( ):Description: Here QUEUE is an array with N locations. FRONT and REAR points to the frontand rear ofthe QUEUE.1. If (FRONT == 0) Then [Check for underflow]2. Print: Underflow3. Else4. ITEM = QUEUE[FRONT]5. If (FRONT == REAR) Then [Check if only one element is left](a) Set FRONT = 0(b) Set REAR = 06. Else7. Set FRONT = FRONT + 1 [Increment FRONT by 1][End of Step 5 If]8. Print: ITEM deleted[End ofInsert ( ):Description: Here QUEUE is an array with N locations. FRONT and REAR points to the frontand rear ofthe QUEUE. ITEM is the value to be inserted.1. If (REAR == N) Then [Check for overflow]2. Print: Overflow3. Else4. If (FRONT and REAR == 0) Then [Check if QUEUE is empty](a) Set FRONT = 1(b) Set REAR = 15. Else6. Set REAR = REAR + 1 [Increment REAR by 1][End of Step 4 If]7. QUEUE[REAR] = ITEM8. Print: ITEM inserted[End of Step 1 If]9. ExitLINKLIST A linked list or one way list is a linear collection of data elements called nodes where the linearorder is given by means of pointers. That is each node is divided into two parts the first part
    • contains the address of the element and the second part called the link field or next pointer fieldcontains the address of the next node in the list.The linked list can be of following types:1. Linear Linked List or One Way List or Singly Linked List.2. Doubly Linked List or Two Way List.3. Circular Linked List.4. Header Linked List.5. Two Way Header Linked List.6. Circular Header Linked List.7. Two Way Circular Header Linked List • Types of linked lists: – Singly linked list • Begins with a pointer to the first node • Terminates with a null pointer • Only traversed in one direction – Circular, singly linked • Pointer in the last node points back to the first node – Doubly linked list • Two “start pointers” – first element and last element • Each node has a forward pointer and a backward pointer • Allows traversals both forwards and backwards – Circular, doubly linked list • Forward pointer of the last node points to the first node and backward pointer of the first node points to the last nodeHeader Linked List.Header Linked List: A header linked list which always contains a special node, called the header node, atthe beginning of the list. The following are two kinds of widely used header list: 1. A grounded header list is a header list where the last node contains the null pointer. 2. A circular header list is a header list where the last node points back to the header node. Unless otherwise stated or implied, our header list will always be circular list. Accordingly, in such a case, the header node also acts as a sentinel indicating the end of the list.Header Linked List. Two Way Header Linked List.The two-way list is a linear collection of data elements called nodes where each node is divided into threeparts: 1. An information field INFO which contains the data of N 2. A pointer field FORW which contains the location of the next node in the list. 3. A pointer field BACK which contains the location of the preceding node in the list.
    • The list also requires two list pointer variables: FIRST, which points to the first node in the list, and LAST,which points to the last node in the list. Observe that the null pointer appears in the FORW field of the lastnode in the list and also in the BACK fieldof the first node in the list.TREE (inorder, preorder, postfix, memory representation byarray and link list) • Tree nodes contain two or more links – All other data structures we have discussed only contain one • Binary trees – All nodes contain two links • None, one, or both of which may be NULL – The root node is the first node in a tree. – Each link in the root node refers to a child – A node with no children is called a leaf node • Binary search tree – Values in left sub tree less than parent – Values in right sub tree greater than parent – Facilitates duplicate elimination – Fast searches - for a balanced tree, maximum of log n comparisons
    • 4 7 2 7 5 7 1 4 6 93 1 3 57 17 3 44 6 1 8 • Tree traversals: – In order traversal – prints the node values in ascending order1. Traverse the left sub tree with an in order traversal2. Process the value in the node (i.e., print the node value)3. Traverse the right sub tree with an in order traversal – Preorder traversal1. Process the value in the node2. Traverse the left sub tree with a preorder traversal3. Traverse the right sub tree with a preorder traversal – Post order traversal1. Traverse the left subtree with a postorder traversal2. Traverse the right subtree with a postorder traversal3. Process the value in the nodeFor examplecan be represented by the arraySuppose we would like to represent the following tree in memory, using only lists (which arecreated by chaining conses). You should already know how acons is created and what partsconstitute one. If not, go back to an introductory book on Common Lisp.
    • This tree can be represented as a set of linked lists, like in the following diagram:The natural way to represent the previous tree as a Common Lisp list is like the following:(1 (2 6 7 8) 3 (4 (9 12)) (5 10 11))The first element of a list is the root of that tree (or a node) and the rest of the elements arethe subtrees (more nodes). For example, the subtree (2 6 7 8)is a tree with “2” at its rootand the elements “6 7 8” as its children.Graph definitionA graph is a collection of nodes called vertices, and the connections between them, called edges.An exampleThe following diagram shows a graph with 5 vertices and 7 edges. The edges between A and Dand B and C are pairs that make a bidirectional connection, represented here by a double-headedarrow.
    • disjkstra algorithm to find shortest path The indented lines under a given line are done under the condition that line. Once that conditionis no longer met you move on in the algorithm. The first part of the algorithm is an initializationof the graph into the setup described earlier; the rest is concerned with searching through thegraph to find distances. To illustrate the algorithm we provide an example below.In the above picture o is marked by a double circle. The Unburned node with the smallest &deltavalue is orange. It will be burned at the next step in the algorithm. The yellow vertex is the onethat is currently burning. Gray vertices have been labeled as Burned by the algorithm. Neighborsif the burning vertex whose &delta is being updated have their edges marked in orange. Thishappens when δ(u) + w(u,n) < &delta(n). Edges corresponding to sources are marked in blue.Note that the algorithm will occasionally overwrite the source of a vertex with a closer source.Once all the vertices are Burned the algorithm is burned.Now that weve run the algorithm how do we find the shortest path from o to another vertex? Wesimply follow thesource edges (blue in the example) from the destination until we reach o, andthe distance we have travelled corresponds to the label &delta on the destination. We also knowthat we have actually found the shortest path (it is possible to have more than one path tied forbeing the shortest) since our fire has always chosen to take the shortest steps possible whenmoving to a new location.You might have already noticed that the blue subgraph doesnt contain any loops, and this is whatmathematicians call a tree. In fact this is a very special kind of tree called a minimal spanningtree because it grows from the root o to all of its leaves, the other vertices in G, in the shortestway possible. Minimal spanning trees are very useful. For instance, if a cable company needs towire all the houses in a neighborhood using as little wire as possible, a minimal spanning tree ofthe neighborhood provides them with the most efficient way to do so.
    • Game tree (definiton)games) game tree - A tree representing contingencies in a game. Each node in a game tree represents a possible position (e.g., possible configuration of pieces on a chessboard) in the game, and each branching ("edge" in graph terms) represents a possible move.A constructor gets called automatically when you create an object of a class; if you define yourown constructor, by default a constructor is called which is the Default Constructor. A class canhave more than one constructor. It has the same name as the class itself.Destructors are again methods of a class that enable the destruction of an object after its use;destructors also provide the means of memory clean up after usage. Destructors are always calledin the reverse order of Constructors. There can only be one destructor per class and they neithertake an input parameter nor do they return anything. Destructors need not be called explicitly.Code:class Vehicle{ Int Registration = 0; public: Vehicle(int regis) // constructor { Registration = regis; } Virtual void GetRegistration() = 0; ~Vehicle() // destructor { }ATTRIBUTE FUNCTION In GNU C, you declare certain things about functions called in yourprogram which help the compiler optimize function calls and check yourcode more carefully. The keyword `__attribute__ allows you to specify special attributeswhen making a declaration. This keyword is followed by an attributespecification inside double parentheses. void fatal () __attribute__ ((noreturn)); void fatal (...) { ... /* Print error message. */ ... exit (1); }Attribute Member The member attribute is a multi-value attribute that contains the list of distinguished names for the user, group, and contact objects that are members of the group. Each item in the list is a linked
    • reference to the object that represents the member; therefore, the Active Directory server automaticallyupdates the distinguished names in the member property when a member object is moved or renamed.