Unit 1 Introduction & Array
Unit 1 Introduction & Array
2. Apart from Question No. 1, rest of the paper shall consist of four
units as per the syllabus. Every unit should have two questions to
evaluate analytical/technical skills of candidate. However, student may
be asked to attempt only 1 question from each unit. Each question
should be of 10 marks, including its subparts, if any.
LEARNING OBJECTIVES:
In this course, the learners will be provided expertise in 1.
Understanding of the basic concepts of data structures and their
operations like, insertion, deletion, searching and sorting 2. Design
algorithms and pseudo codes of various linear and non-linear data
structures.
PRE-REQUISITES:
1. C Programming Skills
2. Discrete Mathematics
COURSE OUTCOMES (COs):
UNIT – II
• Linear Data Structures-
Dynamic Introduction: Dynamic Memory Allocation, Dynamic Memory versus Static Memory Allocation.
Linked List Types: Singly Linked List, Circular Linked List, Doubly Linked List.
Operations: Creation, Insertion, Deletion, Modification, Searching, Sorting, Reversing, and Merging.
UNIT – III
• Abstract Data Types:
• Stacks: Introduction, Static and Dynamic Implementation, Operations, Applications- Evaluation and
Conversion between Polish and Reverse Polish Notations.
• Queues: Introduction, Static and Dynamic Implementation, Operations, Types- Linear Queue, Circular Queue,
Doubly Ended Queue.
UNIT – IV
Non-Linear Data Structures:
Introduction to Graphs: Notations & Terminologies, Representation of Graphs- Adjacency Matrix, Incidence
Matrix and Linked Representation.
Trees: Notations & Terminologies, Memory Representation, Binary Trees Types- Complete, Full, Strict,
Expression Binary Tree, Tree Traversals (Recursive), Binary Search Tree and Basic Operations
Introduction and Creation (Excluding Implementation): AVL Tree, Heap Tree, M- Way Tree, and B Tree.
Unit 1
Introduction
• Data: Collection of raw facts.
• Structure : Way of organizing information
• Data Object : A data object is a unique location in computer memory that contains the values
• Data Structure is a systematic way to organize data in order to use it efficiently.
Data Structure = Organized data + Allowed Operation
• Algorithm : Step by Step procedure to solve a particular function.
Program = Algorithm + Data Structure
Data Structure is a way of collecting and organising data in such a way that we can perform operations on
these data in an effective way. Data Structures is about rendering data elements in terms of some relationship,
for better organization and storage.
For example, we have some data which has player's name "Virat" and age 26. Here "Virat" is of String data
type and 26 is of integer data type.
In simple language, Data Structures are structures programmed to store ordered data, so that various operations
can be performed on it easily. It represents the knowledge of data to be organized in memory. It should be
designed and implemented in such a way that it reduces the complexity and increases the efficiency.
Characteristics of a Data Structure
• Correctness − Data structure implementation should implement its
interface correctly.
• Time Complexity − Running time or the execution time of operations
of data structure must be as small as possible.
• Space Complexity − Memory usage of a data structure operation
should be as little as possible.
Need of Data Structure
• As applications are getting complex and data rich, there are three common
problems that applications face now-a-days. • Data Search − Consider an
inventory of 1 million(106) items of a store. If the application is to search an
item, it has to search an item in 1 million(106) items every time slowing
down the search. As data grows, search will become slower. • Processor
speed − Processor speed although being very high, falls limited if the data
grows to billion records. • Multiple requests − As thousands of users can
search data simultaneously on a web server, even the fast server fails while
searching the data. To solve the above-mentioned problems, data
structures come to rescue. Data can be organized in a data structure in such
a way that all items may not be required to be searched, and the required
data can be searched almost instantly.
Advantages of Data Structures
• • Efficiency: Efficiency of a program depends upon the choice of data
structures. For example: suppose, we have some data and we need to perform
the search for a perticular record. In that case, if we organize our data in an
array, we will have to search sequentially element by element. hence, using
array may not be very efficient here. There are better data structures which can
make the search process efficient like ordered array, binary search tree or hash
tables. • Reusability: Data structures are reusable, i.e. once we have
implemented a particular data structure, we can use it at any other place.
Implementation of data structures can be compiled into libraries which can be
used by different clients. • Abstraction: Data structure is specified by the ADT
which provides a level of abstraction. The client program uses the data
structure through interface only, without getting into the implementation
details.
Execution Time Cases
• There are three cases which are usually used to compare various data structure's
execution time in a relative manner.
• Worst Case − This is the scenario where a particular data structure operation
takes maximum time it can take. If an operation's worst case time is ƒ(n) then this
operation will not take more than ƒ(n) time where ƒ(n) represents function of n.
• Average Case − This is the scenario depicting the average execution time of an
operation of a data structure. If an operation takes ƒ(n) time in execution, then m
operations will take mƒ(n) time.
• Best Case − This is the scenario depicting the least possible execution time of an
operation of a data structure. If an operation takes ƒ(n) time in execution, then the
actual operation may take time as the random number which would be maximum
as ƒ(n).
What you study in Data Structure?
• Logical or mathematical description of the structure.
• Implementation of structure on a computer using different computer
Languages, but here we use C for Implementation.
Basic Terminology: Elementary Data Organization
Data items that are divided into sub-items are called Group items.
Group items
Ex: An Employee Namemay be divided into three sub-items- first name, middle name, and last name.
Elementary items Data items that are not able to divide into sub-items are called Elementary items.
Ex: SSN
An entity is something that has certain attributes or properties which may be assignedvalues. The values may be either numeric or non-numeric.
Entities with similar attributes form an entity set. Each attribute of an entity set has a range of values, the set of all possible values that could be assigned to the
Entity Set: particular attribute.
Meaningful or processed data is called information. The collection of data is organized into the hierarchy of fields, records and files
File Each record in a file may contain many field items but the value in a certain field may uniquelydetermine the record in the file. Such a field K is called a primary
key and the values k1, k2, ….. in such a field are called keys or key values.
In fixed-length records, all the records contain the same data items with the same amountof space assigned to each data item.
Example: Student records have variable lengths, since different students take different numbers of courses. Variable-length records have a minimum and
a maximum length.
The above organization of data into fields, records and files may not be complex
Classification of Data Structure
Primitive Data Structure
Data Structures that are directly operated upon the machine – level
instructions are known as primitive data structures.
It is used to represent the Standard / Predefine / Built – in Data types in
anyone of the computer language.
It includes: Integer, Float / Double, Character, String, Pointers etc.
Non – Primitive Data Structure
There are more sophisticated data structures.
Characteristic Description
Linear In Linear data structures, the data items are arranged in a linear sequence. Ex: Array
Non-Linear In Non-Linear data structures, the data items are not in sequence. Ex: Tree, Graph
Homogeneous In homogeneous data structures, all the elements are of same type. Ex: Array
Non- Homogeneous In Non-Homogeneous data structure, the elements may or may not be of the same type. Ex: Structures
Static Static data structures are those whose sizes and structures associated memory locations are fixed, at compile time.
Ex: Array
Linear Data Structures:
• A data structure is called linear if all of its elements are arranged in the linear order. In linear data
structures, the elements are stored in non-hierarchical way where each element has the successors and
predecessors except the first and last element.
• It has Homogeneous Elements
• It is very easy to implement, since the memory of a computer is also organized in a linear fashion.
• Some commonly used Data Structures are:
• Array
• Linked List
• Stack
• Queue
Types of Linear Data Structures are given below:
1. Arrays: The elements of array share the same variable name but each one carries a different index number known as subscript. The array can
be one dimensional, two dimensional or multidimensional.
2. Linked List: Linked list is a linear data structure which is used to maintain a list in the memory. It can be seen as the collection of nodes stored
at non-contiguous memory locations. Each node of the list contains a pointer to its adjacent node.
3. Stack: Stack is a linear list in which insertion and deletions are allowed only at one end, called top.
• A stack is an abstract data type (ADT), can be implemented in most of the programming languages. It is named as stack because it
behaves like a real-world stack, for example: - piles of plates or deck of cards etc.
4. Queue: Queue is a linear list in which elements can be inserted only at one end called rear and deleted only at the other end called front.
• It is an abstract data structure, similar to stack. Queue is opened at both end therefore it follows First-In-First-Out (FIFO) methodology
for storing the data items.
Non Linear Data Structures:
This data structure does not form a sequence i.e. each item or element is connected with two or more other items in a non-linear arrangement.
1. Trees: Trees are multilevel data structures with a hierarchical relationship among its
elements known as nodes. The bottommost nodes in the hierarchy are called leaf node
while the topmost node is called root node. Each node contains pointers to point
adjacent nodes.
Tree data structure is based on the parent-child relationship among the nodes.
Each node in the tree can have more than one children except the leaf nodes whereas each
node can have atmost one parent except the root node. Trees can be classfied into many
categories which will be discussed later in this tutorial.
2. Graphs: Graphs can be defined as the pictorial representation of the set of elements
(represented by vertices) connected by the links known as edges.
• A graph is different from tree in the sense that a graph can have cycle while the
tree can not have the one.
Other Types of Data Structure are:
• Static Data Structure : (Array)
• 1. The size of the structure is fixed.
• The content of the data structure can be modified but without changing
the memory space allocated to it.
• The collection of data you work within a program have some kind of structure or organization.
• No matter how complex your data structures are, they can be broken down into two fundamental types:
• Contiguous
• Non-Contiguous.
• In contiguous structures, terms of data are kept together in memory (either RAM or in a file). An array is an
example of a contiguous structure. Since each element in the array is located next to one or two other
elements.
• In contrast, items in a non-contiguous structure and scattered in memory, but we linked to each other in
some way. A linked list is an example of a non- contiguous data structure. Here, the nodes of the list are
linked together using pointers stored in each node.
Contiguous structures:
The first kind is called the array. Figure 1.3(a. array) shows an example of an array of numbers. In an array, each
element is of the same type, and thus has the same size.
The second kind of contiguous structure is called structure, figure 1.3(b. struct) shows a simple structure consisting
of a person‘s name and age. In a struct, elements may be of different data types and thus may have different sizes.
For example, a person‘s age can be represented with a simple integer that occupies two bytes of memory. But his or her
• Non-contiguous structures:
• Non-contiguous structures are implemented as a collection of data-items, called nodes, where each node can
point to one or more other nodes in the collection.
• The simplest kind of non-contiguous structure is linked list. A linked list represents a linear, one- dimension
type of non-contiguous structure, where there is only the notation of backwards and forwards. as shown in
figure 1.4(a. Linked List)
• A tree such as shown in figure 1.4(b. Tree) is an example of a two-dimensional non-contiguous structure.
Here, there is the notion of up and down and left and right. In a tree each node has only one link that leads
into the node and links can only go do the tree. The most general type of non-contiguous structure, called a
graph has no such restrictions. Figure 1.4(c. Graph) is an example of a graph.
• Hybrid structures:
• If two basic types of structures are mixed then it is a hybrid form. Then one part contiguous and another part
non-contiguous. For example, figure 1.5 shows how to implement a double–linked list using three parallel
arrays, possibly stored a past from each other in memory.
The array D contains the data for the list, whereas the array P and N hold the previous andnext
―pointers‘‘. The pointers are actually nothing more than indexes into the D array. For instance, D[i] holds the
data for node i and p[i] holds the index to the node previous to i, where may or may not reside at position i–1.
Like wise, N[i] holds the index to the next node in the list.
ADT (Abstract Data Type)
THANKYOU