2. Chapter 01 introduction and overview
• Content
• Data/group data
• Entity / attribute
• Filed /record / file
• Data structure
3. What is Data Structure:
A data structure is a storage that is used to store and organize
data. It is a way of arranging efficiently.
data on a computer so that it can be accessed and updated A data
structure is not only used for organizing the data. It is also used for
processing, retrieving, and storing data.
There are different basic and advanced types of data structures
that are used in almost every program
or software system that has been developed. So we must have
good knowledge about data structures.
4. What is definition of data?
• In computing, data is information that has been translated into a form
that is efficient for movement or processing. Relative to today's
computers and transmission media, data is information converted
into binary digital form. It is acceptable for data to be used as a
singular subject or a plural subject.
Example:
• Data can come in the form of text, observations, figures, images,
numbers, graphs, or symbols. For example, data might include
individual prices, weights, addresses, ages, names, temperatures,
dates, or distances. Data is a raw form of knowledge and, on its own,
doesn't carry any significance or purpose
5. • Data are simply value or set of values. a data item refers to the single
unit of value . Data item that are divided into subitems are called
group items that those are not elementary items
E.G employee name may b
divided
Into three subitems like first name
,middle name , last name
But the social
security number
would normally
treated as a single
item
7. Entity
An entity is something that has certain attribute or properties which
may be assigned values . The values themselves may be either numeric
or non numeric
• Example :
Following are possible attributes and their corresponding values for an
entity an employee of a given organization
• Attributes
name :age : social security number
• Values
ABC : 25 : 1234-5403-45
8. • Entities with similar ( e.g. all employees in an organization )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
particular attribute
9. The way the data are organized in to the hierarchy of field , record , and its
file reflect the relationship between attributes , entities, and entity set,
• Field
Is a single elementary unit of information representing an attribute of a
entity
• Record
A record is the collection of fields values of a given entity
• File
File is a collection of records of the entities in a given entity set . Each record
in a file ma contain many fields items , but the value in a certain filed may
uniquely determine the record in the file
10. Example
• Suppose an organization maintain a membership file where each
record contain the following data
• Name, Address, Telephone num , Dues
• Here is the name field is a primary key . Note that the address and
telephone filed may not serve as primary key , since some members
may also belong to same family and have same address and
telephone number
11. Record classification
• Record may also be classified according to its length, A file can have
• Fixed-length record
Or
• variable –length record
• Fixed-length record :
All the record contain the same data items with the same amount of space
assigned to each data item
variable –length record
File record may contain different length
e.g. students record usually have variable length since each students take
different number of courses it has a minimum and a maximum length
12. Data structure
• Data may be organized in many different ways Logically or
mathematically model of a particular organization of data is called
data structure . The choice of particular data model depends on two
consideration
First , it must be rich enough in structure to mirror the actual
relationship of data in the real world
Secondly , the structure should be simple enough that one can
effectively process the data when necessary
13. What is Array in Data Structure?
• An array is a data structure for storing more than one data item that
has a similar data type. The items of an array are allocated at adjacent
memory locations. These memory locations are called elements of
that array. The total number of elements in an array is called length.
• The details of an array are accessed about its position. This reference
is called index or subscript.
14. Arrays
• Arrays are defined as the collection of similar types of data
items stored at contiguous memory locations. It is one of the
simplest data structures where each data element can be
randomly accessed by using its index number.
• Following are the important terms to understand the concept of
Array.
• Element − Each item stored in an array is called an element.
• Index − Each location of an element in an array has a numerical
index, which is used to identify the element.
15. Why are arrays required?
• Arrays are useful because -
• Sorting and searching a value in an array is easier.
• Arrays are best to process multiple values quickly and easily.
• Arrays are good for storing multiple values in a single
variable - In computer programming, most cases require
storing a large number of data of a similar type. To store such
an amount of data, we need to define a large number of
variables. It would be very difficult to remember the names of all
the variables while writing the programs. Instead of naming all
the variables with a different name, it is better to define an array
and store all the elements into it.
16. Representation of an array
• We can represent an array in various ways in different programming languages.
As an illustration, let's see the declaration of array in C language –
• as per the above illustration, there are some of the following important
points -
• Index starts with 0.
• The array's length is 10, which means we can store 10 elements.
• Each element in the array can be accessed via its index.
17. What Are the Types of Arrays?
• There are majorly two types of arrays, they are:
• One-Dimensional Arrays:
• You can imagine a 1d array as a row, where elements are stored one after
another.
19. How Do You Declare an Array?
Arrays are typically defined with square brackets with the size
of the arrays as its argument.
Here is the syntax for arrays:
• 1D Arrays: int arr[n];
• 2D Arrays: int arr[m][n];
20. Linked list
• Linked list is a linear data structure that includes a series of
connected nodes. Linked list can be defined as the nodes that
are randomly stored in the memory. A node in the linked list
contains two parts, i.e., first is the data part and second is the
address part. The last node of the list contains a pointer to the
null. After array, linked list is the second most used data
structure. In a linked list, every link contains a connection to
another link.
21. Representation of a Linked list
• Linked list can be represented as the connection of nodes in which
each node points to the next node of the list. The representation of
the linked list is shown below –
• Till now, we have been using array data structure to organize
the group of elements that are to be stored individually in the
memory. However, Array has several advantages and
disadvantages that must be known to decide the data structure
that will be used throughout the program.
22. Now, the question arises why we should use
linked list over array?
• Linked list is a data structure that overcomes the limitations of
arrays. Let's first see some of the limitations of arrays -
• The size of the array must be known in advance before using it
in the program.
• Increasing the size of the array is a time taking process. It is
almost impossible to expand the size of the array at run time.
• All the elements in the array need to be contiguously stored in
the memory. Inserting an element in the array needs shifting of
all its predecessors.
• Linked list is useful because -
23. • to allocates the memory dynamically. All the nodes of the linked list
are non-contiguously stored in the memory and linked together with
the help of pointers.
• In linked list, size is no longer a problem since we do not need to
define its size at the time of declaration. List grows as per the
program's demand and limited to the available memory space.
24. • We read the linear data structures like an array, linked list, stack and
queue in which all the elements are arranged in a sequential manner.
The different data structures are used for different kinds of data.
25. Some factors are considered for choosing the data
structure:
• What type of data needs to be stored?: It might be a possibility that
a certain data structure can be the best fit for some kind of data.
• Cost of operations: If we want to minimize the cost for the operations
for the most frequently performed operations. For example, we have
a simple list on which we have to perform the search operation; then,
we can create an array in which elements are stored in sorted order
to perform the binary search. The binary search works very fast for
the simple list as it divides the search space into half.
• Memory usage: Sometimes, we want a data structure that utilizes
less memory.
26. Let's understand some key points of the Tree data
structure.
• A tree data structure is defined as a collection of objects or entities known
as nodes that are linked together to represent or simulate hierarchy.
• A tree data structure is a non-linear data structure because it does not
store in a sequential manner. It is a hierarchical structure as elements in a
Tree are arranged in multiple levels.
• In the Tree data structure, the top most node is known as a root node. Each
node contains some data, and data can be of any type. In the above tree
structure, the node contains the name of the employee, so the type of data
would be a string.
• Each node contains some data and the link or reference of other nodes
that can be called children.
27. A tree is also one of the data
structures that represent
hierarchical data. Suppose we
want to show the employees
and their positions in the
hierarchical form then it can be
represented as shown below:
• the above tree shows the organization
hierarchy of some company. In the above
structure, john is the CEO of the company,
and John has two direct reports named as
Steve and Rohan. Steve has three direct
reports named Lee, Bob, Ella where Steve is
a manager. Bob has two direct reports
named Sal and Emma. Emma has two direct
reports named Tom and Raj. Tom has one
direct report named Bill. This particular
logical structure is known as a Tree. Its
structure is similar to the real tree, so it is
named a Tree. In this structure, the root is at
the top, and its branches are moving in a
downward direction. Therefore, we can say
that the Tree data structure is an efficient
way of storing the data in a hierarchical way.
28. What is a Stack?
• A Stack is a linear data structure that follows the LIFO (Last-In-
First-Out) principle. Stack has one end, whereas the Queue
has two ends (front and rear). It contains only one pointer top
pointer pointing to the topmost element of the stack. Whenever
an element is added in the stack, it is added on the top of the
stack, and the element can be deleted only from the stack. In
other words, a stack can be defined as a container in which
insertion and deletion can be done from the one end known
as the top of the stack.
29. Some key points related to stack
• It is called as stack because it behaves like a real-world stack, piles of
books, etc.
• A Stack is an abstract data type with a pre-defined capacity, which
means that it can store the elements of a limited size.
• It is a data structure that follows some order to insert and delete the
elements, and that order can be LIFO or FILO.
30. Working of Stack
• Stack works on the LIFO pattern. As we can
observe in the below figure there are five
memory blocks in the stack; therefore, the
size of the stack is 5.
• Suppose we want to store the elements in a
stack and let's assume that stack is empty.
We have taken the stack of size 5 as shown
below in which we are pushing the elements
one by one until the stack becomes full.
• Since our stack is full as the size of the stack
is 5. In the above cases, we can observe that
it goes from the top to the bottom when we
were entering the new element in the stack.
The stack gets filled up from the bottom to the
top.
31. Queue
• 1. A queue can be defined as an ordered list which enables
insert operations to be performed at one end called REAR
and delete operations to be performed at another end
called FRONT.
• 2. Queue is referred to be as First In First Out list.
• 3. For example, people waiting in line for a rail ticket form a
queue.
32. Applications of Queue
• Due to the fact that queue performs actions on first in first out basis
which is quite fair for the ordering of actions. There are various
applications of queues discussed as below.
1.Queues are widely used as waiting lists for a single shared resource
like printer, disk, CPU.
2.Queues are used in asynchronous transfer of data (where data is
not being transferred at the same rate between two processes) for
eg. pipes, file IO, sockets.
3.Queues are used as buffers in most of the applications like MP3
media player, CD player, etc.
4.Queue are used to maintain the play list in media players in order to
add and remove the songs from the play-list.
5.Queues are used in operating systems for handling interrupts.
33. Graph
• A graph can be defined as group of vertices and edges that are
used to connect these vertices. A graph can be seen as a cyclic
tree, where the vertices (Nodes) maintain any complex
relationship among them instead of having parent child
relationship.
34. Directed and Undirected Graph
• A graph can be directed or undirected.
However, in an undirected graph, edges are
not associated with the directions with them.
An undirected graph is shown in the above
figure since its edges are not attached with
any of the directions. If an edge exists
between vertex A and B then the vertices can
be traversed from B to A as well as A to B
• In a directed graph, edges form an ordered
pair. Edges represent a specific path from
some vertex A to another vertex B. Node A is
called initial node while node B is called
terminal node.
• A directed graph is shown in the following
figure.