Data Structures and Algorithms

Data Structures and Algorithms

DATA STRUCTURES AND ALGORITHMS For COMPUTER SCIENCE DATA STRUCTURES & . ALGORITHMS SYLLABUS Programming and Data Structures: Programming in C. Recursion. Arrays, stacks, queues, linked lists, trees, binary search trees, binary heaps, graphs. Algorithms: Searching, sorting, hashing. Asymptotic worst case time and space complexity. Algorithm design techniques: greedy, dynamic spanning trees, shortest paths. ANALYSIS OF GATE PAPERS Data Structures Algorithms 1 Mark 2 Mark 1 Mark 2 Mark Exam Year Ques. Ques. Total Exam Year Ques. Ques. Total 2003 5 7 19 2003 3 5 13 2004 7 10 27 2004 1 7 15 2005 5 6 17 2005 2 7 16 2006 1 7 15 2006 7 5 17 2007 2 7 16 2007 2 8 18 2008 3 7 17 2008 - 11 22 2009 1 4 9 2009 3 5 13 2010 1 5 11 2010 1 3 7 2011 1 3 7 2011 1 3 7 2012 1 4 9 2012 3 3 9 2013 - 3 6 2013 4 3 10 2014 Set-1 3 3 9 2014 Set-1 2 2 6 2014 Set-2 3 3 9 2014 Set-2 2 2 6 2014 Set-3 3 3 9 2014 Set-3 1 3 5 2015 Set-1 3 3 6 2015 Set-1 3 3 9 2015 Set-2 3 2 4 2015 Set-2 3 3 9 2015 Set-3 4 6 16 2015 Set-3 2 3 8 2016 Set-1 3 5 13 2016 Set-1 2 3 8 2016 Set-2 3 6 15 2016 Set-2 2 2 6 2017 Set-1 4 3 10 2017 Set-1 2 1 4 2017 Set-2 2 4 10 2017 Set-2 1 3 7 2018 4 3 10 2018 1 3 7 © Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission CONTENTS Topics Page No 1. INTRODUCTION TO DATA STRUCTURES 1.1 Introduction 0 1.2 Linked Lists 0 1 2. STACK AND QUEUE 1 2.1 Stack 0 2.2 Queues 2.3 Deque 16 2.4 Abstract Data Types 109 2.5 Performance Analysis 12 2.6 Asymptotic Notation (o, Ω, ϴ) 12 2 3. SORTING & SEARCHING 3 3.1 Sorting 1 3.2 Sorting, Algorithms 1 3.3 Searching 25 5 4. TREE 5 4.1 Binary Tree 4.2 Header Nodes: Threads 4.3 Binary Search Trees 29 36 5. HEAP & HEIGHT BALANCED TREE 38 5.1 Heap 4 5.2 Tree Searching 4 5.3 Optimum Search Trees 42 5.4 General Search Trees 4 5.5 Multiday Search Trees 6 5.6 B– Tree and B+ Tree 549 5.7 Digital Search Tree 549 0 6. INTRODUCTION TO GRAPH THEORY 2 6.1 Graph Theory Terminology 5 6.2 Direct Graph 5 57 © Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission 6.3 In Degrees and Out Degrees 6.4 Null Graph 6.5 Finite Graphs Of Vertices of a Diagram 58 6.6 Trivial Graphs 58 6.7 Sub Graphs 58 6.8 Sequential Representation of Graphs, Adjacency Matrix, 58 Path Matrix 58 6.9 Shortest Path Algorithm 6 6.10 Linked Representation of a Graph 658 6.11 Graph Traversal 60 6.12 Spanning Forests 60 6.13 Undirected Graphs and Their Traversals 62 6.14 Minimum Spanning Trees 72 3 7. DESIGN TECHNIQUES 6 7.1 A Greedy Algorithm 7. lgorithm 7 7. 769 7. 2 Divide and Conquer A 720 3 Dynamic Programming 1 4 Backtracking 8. GATE QUESTIONS (DATA STRUCTURES) 9. GATE QUESTIONS (ALGORITHMS) 175 10. ASSIGNMENT QUESTIONS (DATA STRUCTURES) 136 11. ASSIGNMENT QUESTIONS (ALGORITHMS) 84 200 © Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission 1 INTRODUCTION TO DATA STRUCTURES 1.1 INTRODUCTION i) A fixed amount of storage remains allocated to the stack or queue even A computer is a machine that processes when the structure is actually using information and data. The study of data a smaller amount or possibly no structures includes how this information storage at all. and data is related and how to use this data efficiently for various applications. ii) Only fixed amount of storage may be allocated, making overflow a possibility. In a sequential representation, the items of a stack or a queue are implicitly ordered by the sequential order of storage. If q[x] represents an element of a queue, the next element will be q [(x+1) % MAXQUEUE] i.e. if x equals MAXQUEUE -1 then next element is q [0]. Suppose that the items of a stack or a queue are explicitly ordered i. e. each Fig 1: Value and Operator Definition item contain the address of the next item within itself. Such an explicit A logical property of a data type is ordering gives rise to a data structure specified by abstract data type, or ADT. known as a Linear linked list as shown A data type definition consist of: in the figure 2. (i) Value definition i.e. values and (ii)Operator definition i.e. set of operations on these values. These values and the operations on them form a mathematical construct that can be implemented using Fig 2: Linked List hardware or software data structures. Note: ADT is not concerned with Each item in the list is called a node and implementation details. it contains two fields. i) Information field: It holds the actual Any two values in an ADT are equal if and only if the values of their element on the list. components are equal. ii) The next address field: It contains the address of the next node in the 1.2 LINKED LISTS list. Such an address, which is used to access a particular node, is known There are certain drawbacks of using as a pointer. sequential storage to represent stacks The entire linked list is accessed from and queue. an external pointer (list) that points to (contains the address of) the first node in the list. © Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission The next address field of the last node in the linked list contains a special value called as null. This is not a valid address and used to signal the end of a list. Fig 3: Adding an element to front of The linked list with no nodes is called linked list the empty list or the null list. The value of the external pointer, list, to such a For example: linked list is the null. The list can be Suppose that we are given a list of integers initialized to form the empty list by the as illustrated in fig 3(a) and we have to add operation list = null. the integer 6 to the front of that linked list. 1.2.1 INSERTING AND REMOVING NODES Assume the existence of mechanism for FROM A LIST obtaining empty nodes as P = getNode ( ); 1.2.1.1 Insertion The operation obtains an empty node and sets the contents of a variable A list is a dynamic data structure, the named P to the address of that node. number of nodes on a list may vary as The value of P is then a pointer to this elements are inserted and removed. The newly allocated node. dynamic nature of a list may be contrasted fig 3(b), shows the list and the new with the static nature of an array, whose node after performing the get node size remains constant. operation. The next step is to insert the integer 6 into the info portion of the newly allocated node. This is done by info (P) = 6; (The result is shown in fig. 3(c)) After setting the info portion of node (P), it is necessary to set the next portion of that node. Since node (P) is to be inserted at the front of the list, the node that follows should be the first node of the current list. Since the variable list contains the address of that first node, node (P) can be added to the list by performing the operation next (P) = list; [This operation places the value of list (which is the address of first node fn the list) into the next field of node(P)] At this point, P points to the list with the additional item included. However, since list is the external pointer to the desired list, its value must be modified to the address of the new first node of the list. This can be done by performing the operation – list = P; © Copyright Reserved by Gateflix.in No part of this material should be copied or reproduced without permission Which changes the value of list to the Note: The process is exactly opposite to the value of P. Fig 3(e) illustrates the result process of adding a node of this operation. During the process of removing the first Generalized Algorithm node from the list, the variable p is used as 1. P=getNode ( ); //Allocate an auxiliary variable. The starting and memory for new node ending configuration of the list make no 2. Info (P) =x; reference to P. But once the value of p is 3. Next (P) =list; changed there is no way to access the node 4. List=P; at all, since neither an external pointer nor a next field contains its address. Therefore 1.2.1.2 Deletion the node is currently useless and cannot be reused. The get node creates a new node, The following figure 4 shows the process of whereas free node destroys a node.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    218 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us