You are on page 1of 4

Notes on Data Structure

Q. 1: What is data structure? Describe the different types of data structure. Or Describe data structure with its classifications. Ans: Data Structure: Data may be organized in many different ways; the logical or mathematical model of a particular organization of data is called a data structure. Different types of data structure: 1. Arrays: The simplest type of data structure is a linear array. A linear array is a list of a finite number n of homogeneous data elements such that: The elements of the array are referenced respectively by an index set consisting of n consecutive numbers. The elements of the array are stored respectively in successive memory locations. Linear arrays are called one dimensional array. A two dimensional array is a collection of similar data elements where each elements is referenced by two subscripts and multidimensional arrays are defined analogously. Example: A linear array STUDENT consisting of names of six students where STUDENT[1] denotes John Brown, STUDENT[2] denotes Sandra Gold and so on is pictured in fig bellow: STUDENT 1 John Brown 2 Sandra Gold 3 Tom Jones 4 June Kelly 5 Mary Reed 6 Alan Smith Records: A record is a collection of related data items, each of which is called a field or attribute and a file is a collection of similar records. Example: A hospital record on each new born baby: New born Name Sex Birthday i. Month ii. Day iii. Year Father i. Name ii. Age Mother i. Name ii. Age Link lists: A linked list or one way list is a linear collection of data elements, called nodes, where the linear order is given by means of pointers. Each node is divided into two parts: the

2.

1. a. b. c.

d.

e.

3.

first part contains the information of the element, and the second part called the link field or next pointer field contains the address of the next node in the list. Example:

Next pointer field of first node Information part of first node Fig: Linked list with 6 nodes. 4. Stacks: A stack is a list of elements in which an element may be inserted or deleted only at one end, called the top of the stack. This means that elements are removed from a stack in the reverse order of that in which they were inserted into the stack. Stacks are called last in first out (LIFO) system. Special terminology is used for two basic operations associated with stacks: Push is the term used to insert an element into a stack. Pop is the term used to delete an element from a stack. Example: The following 6 elements are pushed in order onto an empty stack AAA, BBB, CCC, DDD, EEE, FFF. AAA BBB CCC DDD EEE FFF 1 2 3 4 5 6 7 N -1 N Fig: Diagram of stacks. 5. Queues: A queue is a linear list of elements in which deletion can take place only at one end, called the front and insertions can take place only at the other end, called the rear. The terms front and rear are used in describing a linear list only when it is implemented as a queue. Queues are called first in first out (FIFO) lists. Example: [AAA] [BBB] [CCC] [DDD] [BBB] [CCC] [DDD] [BBB] [CCC] [DDD] [EEE] Fig: Queues

6.

Trees: Tree is a non-linear data structure. Tree is used to represent data containing a hierarchical relationship between elements, e.g. records, family trees and table of contents. Binary tree is a special kind of tree, which can be sassily maintained in the computer. Example:

Fig: Trees

7.

Graphs: Data sometimes contain a relationship between pairs of elements which is not necessarily hierarchical in nature. The data structure which reflects this type of relationship is called a graph.

Q. 2: Define different types of data structure operations. Ans: Data structure operations: The following four operations play a major role in data structure operation: 1. Traversing: Traversing means accessing each record exactly once, so that certain items in the record may be processed. 2. Searching: Searching refers to the operation of Finding the location of the record with a given key value, or finding the locations of all records which satisfy one or more conditions. 3. Inserting: Inserting refers to the operation of Adding a new record to the structure. 4. Deleting: Deleting refers to the operation of removing a record from the structure. The following two operations, which are used in special situations of data structure operation: 1. 2. Sorting: Sorting means arranging the records in some logical order. Merging: Merging means combining the records in two different sorted files into a single sorted file. Q.3: What is time space trade off? Or Define time space tradeoff for algorithm design. Ans: Time space trade off: The time space trade off refers to a choice between algorithmic solutions of a data processing problem that allows one to decrease the running time of an algorithm solution by increasing the space to store the data and vice versa. Q.4: What is algorithm complexity? Or what do you mean by complexity of algorithms. Ans: Algorithm complexity: Complexity of an algorithm M is the function f(n) which gives the running time and / or storage space requirement of the algorithm in terms of the size n of the input data.

You might also like