[ DATA STRUCTURES] to Data Structures

Similar documents
[ DATA STRUCTURES ] Fig. (1) : A Tree

Data Structure. IBPS SO (IT- Officer) Exam 2017

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

Data Abstractions. National Chiao Tung University Chun-Jen Tsai 05/23/2012

Representation Techniques for Logical Spaces

MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct.

Chapter 8: Data Abstractions

CS301 - Data Structures Glossary By

The time and space are the two measure for efficiency of an algorithm.

CHARUTAR VIDYA MANDAL S SEMCOM Vallabh Vidyanagar

Binary Trees. Height 1

Organizing Spatial Data

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305

MIDTERM EXAMINATION Spring 2010 CS301- Data Structures

An array is a collection of data that holds fixed number of values of same type. It is also known as a set. An array is a data type.

Chapter 8: Data Abstractions

Objective Questions for Online Practical Exams under CBCS Scheme Subject: Data Structure-I (CS-113)

12 Abstract Data Types

Linked List. April 2, 2007 Programming and Data Structure 1

Fundamentals of Programming. Lecture 12: C Structures, Unions, Bit Manipulations and Enumerations

How to declare an array in C?

DDS Dynamic Search Trees

Programming and Data Structure Solved. MCQs- Part 2

Topology and Boundary Representation. The ACIS boundary representation (B-rep) of a model is a hierarchical decomposition of the model s topology:

( ) D. Θ ( ) ( ) Ο f ( n) ( ) Ω. C. T n C. Θ. B. n logn Ο

1. Two main measures for the efficiency of an algorithm are a. Processor and memory b. Complexity and capacity c. Time and space d.

CSCE 110 PROGRAMMING FUNDAMENTALS. Prof. Amr Goneid AUC

1. INTRODUCTION TO DATA STRUCTURE

Arrays. Defining arrays, declaration and initialization of arrays. Designed by Parul Khurana, LIECA.

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING B.E SECOND SEMESTER CS 6202 PROGRAMMING AND DATA STRUCTURES I TWO MARKS UNIT I- 2 MARKS

Computer Science 210 Data Structures Siena College Fall Topic Notes: Trees

Types of Data Structures

CS6702 GRAPH THEORY AND APPLICATIONS 2 MARKS QUESTIONS AND ANSWERS

Functions BCA-105. Few Facts About Functions:

Data Structure using C++ Lecture 04. Data Structures and algorithm analysis in C++ Chapter , 3.2, 3.2.1

NCS 301 DATA STRUCTURE USING C

S.E. Sem. III [CMPN] Data Structures. Primitive Linear Non Linear

Algorithms and Data Structures

S.E. Sem. III [INFT] Data Structures & Analysis. Primitive Linear Non Linear

ONE MARKS QUESTION AND ANSWERS

INSTITUTE OF AERONAUTICAL ENGINEERING

Cpt S 122 Data Structures. Course Review Midterm Exam # 1

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

Introduction to Data Structure

CS DATA STRUCTURES AND ALGORITHMS

Name CPTR246 Spring '17 (100 total points) Exam 3

DC54 DATA STRUCTURES DEC 2014

Computer Systems Lecture 9

LIFO : Last In First Out

MCA SEM-II Data Structure

1 P age DS & OOPS / UNIT II

Advanced C Programming and Introduction to Data Structures

C Data Structures Stacks. Stack. push Adds a new node to the top of the stack

Revision Statement while return growth rate asymptotic notation complexity Compare algorithms Linear search Binary search Preconditions: sorted,

Computer Science 385 Analysis of Algorithms Siena College Spring Topic Notes: Introduction and Overview

Introduction to C++ Introduction to C++ Dr Alex Martin 2013 Slide 1

a) State the need of data structure. Write the operations performed using data structures.

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

DEEPIKA KAMBOJ UNIT 2. What is Stack?

CSC 553 Operating Systems

Object Oriented Methods : Deeper Look Lecture Three

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard

Arrays in C. Rab Nawaz Jadoon DCS. Assistant Professor. Department of Computer Science. COMSATS IIT, Abbottabad Pakistan

ONE DIMENSIONAL ARRAYS

Algorithms and Data Structures

Data Structures. COMS W1007 Introduction to Computer Science. Christopher Conway 1 July 2003

logn D. Θ C. Θ n 2 ( ) ( ) f n B. nlogn Ο n2 n 2 D. Ο & % ( C. Θ # ( D. Θ n ( ) Ω f ( n)

Data Structures. Outline. Introduction Linked Lists Stacks Queues Trees Deitel & Associates, Inc. All rights reserved.

Lecture 9 Stacks & Queues

Lecture Notes. char myarray [ ] = {0, 0, 0, 0, 0 } ; The memory diagram associated with the array can be drawn like this

2.2 Syntax Definition

CSCI 171 Chapter Outlines

MAHARASHTRASTATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

1) What is the primary purpose of template functions? 2) Suppose bag is a template class, what is the syntax for declaring a bag b of integers?

Principles of Programming. Chapter 6: Arrays

Unit 3 Decision making, Looping and Arrays

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

DATA STRUCTURE. Exclusive for IACE Students iacehyd.blogspot.in Ph: /422 Page 1

CS-301 Data Structure. Tariq Hanif

Programming and Data Structures Prof. N.S. Narayanaswamy Department of Computer Science and Engineering Indian Institute of Technology, Madras

CHAPTER 5 GENERATING TEST SCENARIOS AND TEST CASES FROM AN EVENT-FLOW MODEL

Data Structures and Algorithms in Java. Second Year Software Engineering

Data Structures and Algorithms

Fundamentals of Data Structure

Data Structure with C. List

Lesson 3: Understanding General Software Development

CS/ENGRD 2110 FALL Lecture 7: Interfaces and Abstract Classes

( ) n 3. n 2 ( ) D. Ο

AE52/AC52/AT52 C & Data Structures JUNE 2014

UNIT III TREES. A tree is a non-linear data structure that is used to represents hierarchical relationships between individual data items.

Function Call Stack and Activation Records

Department of Computer Science and Technology

.:: UNIT 4 ::. STACK AND QUEUE

3. Priority Queues. ADT Stack : LIFO. ADT Queue : FIFO. ADT Priority Queue : pick the element with the lowest (or highest) priority.

Q1: /20 Q2: /30 Q3: /24 Q4: /26. Total: /100

Constructing a Cycle Basis for a Planar Graph

Test 1 Last 4 Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. 2 points each t 1

(i) Describe in detail about the classification of computers with their features and limitations(10)

CSE 230 Intermediate Programming in C and C++

1. Stack overflow & underflow 2. Implementation: partially filled array & linked list 3. Applications: reverse string, backtracking

Transcription:

[ DATA STRUCTURES] Chapter - 01 : Introduction to Data Structures INTRODUCTION TO DATA STRUCTURES A Data type refers to a named group of data which share similar properties or characteristics and which have common behavior among them. Three fundamental data types used in C programming are int for integer values, float for floating-point numbers and char for character values. But, sometimes a need arises to treat a group of different data types as a single unit. For example, a record in a file can have several fields of different data types and entire record may be required to be processed in one unit. In such a case, Data structures can be beneficial as data structures let you combine data of different types and process them together. Def : A Data structure is a named group of data of different data types which can be processed as a single unit. Data structure is representation of the logical relationship existing between individual elements of data. In other words, a Data structure is a way of organizing all data items that considers not only the elements stored but also their relationship to each other. Data structures are the building blocks of a program. And hence the selection of particular data structure stresses on the following two things : 1. The data structures must be rich enough in structure to reflect the relationship existing between the data. 2. And the structure should be simple so that we can process data effectively whenever required. The identification of the inbuilt data structure is very important in nature. And the structure of input and output data can be use to derive the structure of a program. Data structures affects the design of both structural and functional aspects of a program. Algorithm + Data structure = Program We know that an algorithm is a step-by-step procedure to solve a particular function i.e., it is a set of instructions written to carry out certain tasks and the data structure is the way of organizing the data with their logical relationship maintained. To develop a program of an algorithm, we should select an appropriate data structure for that algorithm. Therefore, algorithm and its associated data structures form a program.

CLASSIFICATION OF DATA STRUCTURE Data structures are normally divided into two broad categories. (i) Primitive Data Structures(built-in) (ii) Non-Primitive Data Structures(user defined) DATA STRUCTURE Primitive Data Structure Non-Primitive Data Structure Integer Float Character Pointer Arrays Lists Files Linear Lists Non-Linear Lists Stacks Queues Graphs Trees Fig.(1) : Classification of Data structure. PRIMITIVE DATA STRUCTURES (BUILT-IN) : These are basic structures and are directly operated upon by the machine instructions. These, in general, have different representations on different computers. Integers, floating-point numbers, character constants, string constants, pointers etc. fall in this category.

NON-PRIMITIVE DATA STRUCTURES (USER-DEFINED) These are more complicated data structures. These are derived from the primitive data structures. The non-primitive data structures emphasize on structuring of a group of homogeneous (same type) or heterogeneous (different type) data items. Arrays, structures, lists and files are examples. The data appearing in our data structures are processed by means of certain operations. In fact, the particular data structure that one chooses for a given situation depends largely on the frequency with which specific operations are performed. OPERATIONS OF DATA STRUCTURES The basic operations that are performed on data structures are as follows : 1. Traversing : Accessing each record exactly once so that certain items in the record may be processed. (This accessing and processing is sometimes called visiting the record). 2. Searching : Searching operation finds the presence of the desired data item in the list of data item. It may also find the locations of all elements that satisfy certain conditions. 3. Inserting : Inserting means addition of a new data element in a data structure. 4. Deleting : Deleting means removal of a data element from a data structure. Sometimes, two or more of the operations may be used in a given situation. For e.g, we may want to delete a data element from a data structure, which may mean we first need to search for the location of the record. The following two operations, which are used in special situations, will also be considered : (1) Sorting : Sorting is the process of arranging all data items in a data structure in a particular order say for example, either in ascending order or in descending order. (2) Merging : Combining the records of two different sorted files into a single sorted file. EXAMPLES & REAL LIFE APPLICATIONS A company contains employee file in which each record contain the following data for a given employee : Name, Address, Telephone number, Employee age, sex, employ number. 1. Suppose the company wants to announce a meeting through a mailing. Then one would traverse the file to obtain employee name and address for each member.

2. Suppose one wants to find the name of all members living in a certain area. Again one would traverse the file to obtain the data. 3. Suppose one wants to obtain address for the given employee name. Then one would search the file for the record containing employee name. 4. Suppose a new person joins the company. Then one would insert his or her record into the file. 5. Suppose an employee dies. Then one would delete his or her record from the file. 6. Suppose an employee has moved and has a new address and telephone number. Given the name of the member, one would first need to search for the record in the file. Then one would perform the update - i..e., change items in the record with the new data. 7. Suppose one wants to find the number of members 65 or older. Again one would traverse the file, counting such members. DESCRIPTION OF VARIOUS DATA STRUCTURES 1. ARRAYS An array is defined as a set of finite number of homogeneous elements or data items. It means an array can contain one type of data only, either all integers, all floatingpoint numbers, or all characters. Declaration of arrays is as follows : int A[10]; where int specifies the data type or type of elements array stores. A is the name of the array, and the number specified inside the square brackets is the number of elements an array can store, this is also called size or length of array. Some important concepts of arrays are : (1) The individual element of an array can be accessed by specifying name of the array, followed by index or subscript (which is an integer number specifying the location of element in the array) inside square brackets. For example to access the fifth element of array a, we have to give the following statement : A[4]; (2) The first element of the array has index zero [0]. It means the first element and last element of the above array will be specified as : A[0], and A[9] respectively. (3) The elements of array will always be stored in consecutive memory locations. (4) The number of elements that can be stored in an array i.e., the size of array or its length is given by the following equation : (upperbound lowerbound) + 1

For the above array, it would be (9-0) + 1 = 10. Where 0 is the lower bound of array, and 9 is the upper bound of array. (5) Arrays can always be read or written through loop. If we read a one-dimensional array, it requires one loop for reading and other for writing (printing) the array. For example : (a) For reading the array for ( i = 0; i < = 9 ; i++) { scanf( %d, & A [ i ] ); } (b) For writing the array for ( i = 0; i < = 9 ; i++) { printf( %d, A [ i ] ); } If we are reading or writing two-dimensional array it would require two loops. And similarly the array of n dimension would required n loops. Some common operations performed on arrays are : 1. Creation of an array. 2. Traversing an array (accessing array elements). 3. Insertion of new elements. 4. Deletion of required element. 5. Modification of an element. 6. Merging of arrays. 2. LINKED LISTS A linked list is a linear collection of data elements, called node pointing to the next nodes by means of pointers. Each node is divided into two parts : the first part containing the information of the element, and the second part called the link or next pointer containing the address of the next node in the list. Technically, each such element is referred to as a node, therefore a list can be defined as a collection of nodes as shown in Fig. (2) below : START (START stores the address of first node)

1000 Node 1 Node 2 Node 3 Info Link Info Link Info Link 2 2000 4 3000 6 NULL 1000 2000 3000 3. STACKS Memory addresses of various nodes Fig. (2) Linked Lists A stack is a non-primitive linear data structure. It is an ordered list in which addition of new data item and deletion of already existing data item is done from only one end, known as Top of Stack (TOS). As all the deletion and insertion in a stack is done from top of the stack, the last added element will be the first to be removed from the stack. Due to this reason, the stack is also called Last-In-First-Out (LIFO) type of list. Consider some examples, A common model of a stack is plates in a marriage party. Fresh plates are pushed onto the top and popped off the top. Some of you may eat biscuits. If you assume only one side of the cover is torn and biscuits are taken off one by one. This is called popping and similarly, if you want to preserve some biscuits for some time later, you will put them back into the pack through the same torn end called pushing. 4. QUEUES Queue is a linear data structure that permits insertion of an element at one end and deletion of an element at the other end. The end at which the deletion of an element take place is called front, and the end at which insertion of a new element can take place is called rear. The deletion or insertion of elements can take place only at the front and rear end of the list respectively. The first element that gets added into the queue is the first one to get removed from the list. Hence, Queue is also referred to as First-In-First-Out (FIFO) list. The name Queue comes from the everyday use of the term. Consider a railway reservation booth, at which we have to get into the reservation queue. New customers got into the queue from the rear end, whereas the customers who get their seats reserved leave the queue from the front end. It means the customers are serviced in the order in which they arrive the service center (i.e. first come first serve type of service). The same characteristics apply to our Queue. Fig. (3) shows the pictorial representation of a Queue.

10 20 30 40 50 60 70 80 Front Rear Fig. (3) : Pictorial representation of a Queue In Fig (3), 10 is the first element and 80 is the last element added to the Queue. Similarly, 10 would be the first element to get removed and 80 would be the last element to get removed. 5. TREES A Tree can be defined as a finite set of data items (nodes). Tree is a non-linear type of data structure in which data items are arranged of stored in a sorted sequence. Trees represent the hierarchical relationship between various elements. In trees : 1. There is a special data item at the top of hierarchy called the Root of the Tree. 2. The remaining data items are partitioned into number of mutually exclusive (i.e. disjoint) subsets, each of which is itself, a tree, which is called the subtree. 3. The tree always grows in length towards bottom in data structures, unlike natural trees which grows upwards. The tree structure organizes the data into branches, which relate the information. A tree is shown in Fig. (4). A B C D E F G 6. GRAPHS Fig. (4) : A Tree Data sometimes contain a relationship between pairs of elements which is not necessarily hierarchical in nature. Geometrical arrangement are very important while working with real life projects. For example, let us suppose there are five villages separated by a river. Now we want to construct bridges to connect these villages as shown in Fig. (5)

Village 1 Village 2 Village 3 Village 4 Village 5 Fig. (5) We can reduce the landmass of villages to a dot and we can change the shape of bridges. This will not change geometric arrangement of paths to connect different villages. We can draw a similar geometry of our project as follows : v1 v2 v3 v4 Fig. (6) We have represented villages by dots (which are called vertex or node) and bridges by lines which are called edges. This type of drawing is called graph. Hence a graph can be defined as a ordered set (V,E), where V(G) represents the set of all elements called vertices and E(G) represents the edges between these vertices. Fig. (6) shows a graph, for which V(G)={ v1, v2, v3, v4, v5 } and E(G) = { b1, b2, b3, b4 }. v5