Unit-1 - Introduction To Basic Terminology
Unit-1 - Introduction To Basic Terminology
DATA STRUCTURES
Data may be organized in many different ways. The logical or mathematical model of aparticular
organization of data is called a data structure.
The choice of a particular data model depends on the two considerations
1. It must be rich enough in structure to mirror the actual relationships of the data in thereal
world.
2. The structure should be simple enough that one can effectively process the data
whenever necessary.
Data items that are divided into sub-items are called Group items. Ex: An Employee Namemay
be divided into three subitems- first name, middle name, and last name.
Data items that are not able to divide into sub-items are called Elementary items.
Ex: SSN
Entity: An entity is something that has certain attributes or properties which may be assignedvalues.
The values may be either numeric or non-numeric.
Ex: Attributes- Names, Age, Sex, SSN
Values- Rohland Gail, 34, F, 134-34-5533
Entities with similar attributes form an entity set. Each attribute of an entity set has a range ofvalues,
the set of all possible values that could be assigned to the particular attribute.
The term “information” is sometimes used for data with given attributes, of, in other words
meaningful or processed data.
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 enough to maintain
and efficiently process certain collections of data. For this reason, data are also organized into more
complex types of structures.
The study of complex data structures includes the following three steps:
1. Logical or mathematical description of the structure
2. Implementation of the structure on a computer
3. Quantitative analysis of the structure, which includes determining the amount ofmemory
needed to store the structure and the time required to process the structure.
Adaptability: Developing software projects such as word processors, Web browsers and Internet search
engine involves large software systems that work or execute correctly and efficiently for many years.
Moreover, software evolves due to ever changing market conditions or due to emerging technologies.
Data Types
In C programming language, data types are used to define the type of data that a variable can hold.
Each data type has a specific size and range of values that it can represent.
• void - used to indicate an empty data type, usually used with pointers
These data types can be modified using different specifiers like signed, unsigned, short, and long to
provide additional variations.
For example, "short int" is used to store small integers, and "long double" is used to store floating-point
numbers with greater precision than the standard "double" type.
Example 1:
int age = 25;
The above example declares a variable named "age" of the "int" data type and assigns it a value of 25.
Example 2:
float price = 9.99;
The above example declares a variable named "price" of the "float" data type and assigns it a value of
9.99.
They include:
They include:
• Structures: A collection of variables of different data types grouped together under a single
name.
• Unions: A special type of structure that can store only one value at a time.
• Typedefs: A way to create a new name for an existing data type to improve code readability and
maintainability.
The range of all the C language data types are present in the table given below
CLASSIFICATION OF DATA STRUCTURES
1. Primitive data Structures: Primitive data structures are the fundamental data types which are
supported by a programming language. Basic data types such as integer, real, character and
Boolean are known as Primitive data Structures. These data types consists of characters that
cannot be divided and hence they also called simple data types.
2. Non- Primitive data Structures: Non-primitive data structures are those data structures which
are created using primitive data structures. Examples of non-primitive data structures is the
processing of complex numbers, linked lists, stacks, trees, and graphs.
Based on the structure and arrangement of data, non-primitive data structures is furtherclassified
into
1. Linear Data Structure
2. Non-linear Data Structure
The common examples of linear data structure are Arrays, Queues, Stacks, Linked list
Types of Linear Data Structures
1.Arrays:
The simplest type of data structure is a linear (or one dimensional) array. A list of a finite number n
of similar data referenced respectively by a set of n consecutive numbers, usually 1,2, 3 . . . . . . .
n. if A is chosen the name for the array, then the elements of A are denoted by subscript notation
a1, a2, a3….. an
or
by the parenthesis notation A (1), A (2), A (3) ............... A (n)
or
by the bracket notation A [1], A [2], A [3] ............... A [n]
Example 1: A linear array STUDENT consisting of the names of six students is pictured in
below figure. Here STUDENT [1] denotes John Brown, STUDENT [2] denotes Sandra Gold,
and so on.
Linear arrays are called one-dimensional arrays because each element in such an array is referenced
by one subscript. A two-dimensional array is a collection of similar data elements where each
element is referenced by two subscripts.
Example 2: A chain of 28 stores, each store having 4 departments, may list its weekly sales as in
below fig. Such data can be stored in the computer using a two-dimensional array in which the first
subscript denotes the store and the second subscript the department. If SALES is the name given to
the array, then
SALES [1, 1] = 2872, SALES [1, 2] - 805, SALES [1, 3] = 3211,…., SALES [28, 4] = 982
2. Stack: A stack, also called a fast-in first-out (LIFO) system, is a linear list in which insertions and
deletions can take place only at one end, called the top. This structure is similar in its operation to a
stack of dishes on a spring system as shown in fig.
Note that new 4 dishes are inserted only at the top of the stack and dishes can be deleted only from
the top of the Stack.
3.Queue: A queue, also called a first-in first-out (FIFO) system, is a linear list in which deletions can
take place only at one end of the list, the "from'' of the list, and insertions can take place only at the
other end of the list, the “rear” of the list.
This structure operates in much the same way as a line of people waiting at a bus stop, as pictured in
Fig. the first person in line is the first person to board the bus. Another analogy is with automobiles
waiting to pass through an intersection the first car in line is the first car through.
4.Linked Lists
A Linked List is another example of a linear data structure used to store a collection of data elements
dynamically. Data elements in this data structure are represented by the Nodes, connected using links or
pointers. Each node contains two fields, the information field consists of the actual data, and the pointer
field consists of the address of the subsequent nodes in the list. The pointer of the last node of the linked
list consists of a null pointer, as it points to nothing. Unlike the Arrays, the user can dynamically adjust
the size of a Linked List as per the requirements.
A Linked List
Figure: Tree
Some of the basic properties of tree are explained by means of examples
However, Name may be a group item with the sub-items Last, First and MI (middle initial). Also
Address may be a group item with the subitems Street address and Area address, where Area itself
may be a group item having subitems City, State and ZIP code number.
This hierarchical structure is pictured below
Another way of picturing such a tree structure is in terms of levels, as shown below
1. Graph: Data sometimes contain a relationship between pairs of elements which is not necessarily
hierarchical in nature. For example, suppose an airline flies only between the cities connected by lines
in Fig. The data structure which reflects this type of relationship is called a graph.
6. Selection: Selection means selecting a particular data from the available data. We can select
any particular data by specifying conditions inside the loop.
7. Update: The Update operation allows us to update or modify the data in the data structure. We
can also update any particular data by specifying some conditions inside the loop, like the
Selection operation.
8. Splitting: The Splitting operation allows us to divide data into various subparts decreasing the
overall process completion time.
The user of data type does not need to know how that data type is implemented, for example, we have
been using Primitive values like int, float, char data types only with the knowledge that these data type
can operate and be performed on without any idea of how they are implemented.
So a user only needs to know what a data type can do, but not how it will be implemented. Think of
ADT as a black box which hides the inner structure and design of the data type. Now we’ll define three
ADTs namely List ADT, Stack ADT, Queue ADT.
1. List ADT
View of list
• The data is generally stored in key sequence in a list which has a head structure consisting
of count, pointers and address of compare function needed to compare the data in the list.
• The data node contains the pointer to a data structure and a self-referential pointer which
points to the next node in the list.
• The List ADT Functions is given below:
• get() – Return an element from the list at any given position.
• insert() – Insert an element at any position of the list.
• remove() – Remove the first occurrence of any element from a non-empty list.
• removeAt() – Remove the element at a specified location from a non-empty list.
• replace() – Replace an element at any position by another element.
• size() – Return the number of elements in the list.
• isEmpty() – Return true if the list is empty, otherwise return false.
• isFull() – Return true if the list is full, otherwise return false.
2. Stack ADT
View of stack
• In Stack ADT Implementation instead of data being stored in each node, the pointer to data
is stored.
• The program allocates memory for the data and address is passed to the stack ADT.
• The head node and the data nodes are encapsulated in the ADT. The calling function can
only see the pointer to the stack.
• The stack head structure also contains a pointer to top and count of number of entries
currently in stack.
• push() – Insert an element at one end of the stack called top.
• pop() – Remove and return the element at the top of the stack, if it is not empty.
• peek() – Return the element at the top of the stack without removing it, if the stack is not
empty.
• size() – Return the number of elements in the stack.
• isEmpty() – Return true if the stack is empty, otherwise return false.
• isFull() – Return true if the stack is full, otherwise return false.
3. Queue ADT
View of Queue
• The queue abstract data type (ADT) follows the basic design of the stack abstract data type.
• Each node contains a void pointer to the data and the link pointer to the next element in the
queue. The program’s responsibility is to allocate memory for storing the data.
• enqueue() – Insert an element at the end of the queue.
• dequeue() – Remove and return the first element of the queue, if the queue is not empty.
• peek() – Return the element of the queue without removing it, if the queue is not empty.
• size() – Return the number of elements in the queue.
• isEmpty() – Return true if the queue is empty, otherwise return false.
• isFull() – Return true if the queue is full, otherwise return false.
•
Features of ADT:
Abstract data types (ADTs) are a way of encapsulating data and operations on that data into a
single unit. Some of the key features of ADTs include:
• Abstraction: The user does not need to know the implementation of the data structure only
essentials are provided.
• Better Conceptualization: ADT gives us a better conceptualization of the real world.
• Robust: The program is robust and has the ability to catch errors.
• Encapsulation: ADTs hide the internal details of the data and provide a public interface for
users to interact with the data. This allows for easier maintenance and modification of the
data structure.
• Data Abstraction: ADTs provide a level of abstraction from the implementation details of
the data. Users only need to know the operations that can be performed on the data, not how
those operations are implemented.
• Data Structure Independence: ADTs can be implemented using different data structures,
such as arrays or linked lists, without affecting the functionality of the ADT.
• Information Hiding: ADTs can protect the integrity of the data by allowing access only to
authorized users and operations. This helps prevent errors and misuse of the data.
• Modularity: ADTs can be combined with other ADTs to form larger, more complex data
structures. This allows for greater flexibility and modularity in programming.
Advantages:
• Encapsulation: ADTs provide a way to encapsulate data and operations into a single unit,
making it easier to manage and modify the data structure.
• Abstraction: ADTs allow users to work with data structures without having to know the
implementation details, which can simplify programming and reduce errors.
• Data Structure Independence: ADTs can be implemented using different data structures,
which can make it easier to adapt to changing needs and requirements.
• Information Hiding: ADTs can protect the integrity of data by controlling access and
preventing unauthorized modifications.
• Modularity: ADTs can be combined with other ADTs to form more complex data
structures, which can increase flexibility and modularity in programming.
Disadvantages:
• Overhead: Implementing ADTs can add overhead in terms of memory and processing,
which can affect performance.
• Complexity: ADTs can be complex to implement, especially for large and complex data
structures.
• Learning Curve: Using ADTs requires knowledge of their implementation and usage,
which can take time and effort to learn.
•Limited Flexibility: Some ADTs may be limited in their functionality or may not be
suitable for all types of data structures.
• Cost: Implementing ADTs may require additional resources and investment, which can
increase the cost of development
.
Some Applications of Data Structures