Data Structures Unit-1 Chapter-1

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 17

Data Structures

Unit-1
Chapter-1
1.Introduction to Data Structures
1. Definition.
2. Classification of Data Structures.
3. Operations on Data Structures.
4. Abstract Data Types.
5. Preliminaries of Algorithms.
6. Time and Space Complexity.
1. Definition of Data Structures

A Data Structure is basically group of elements that are put together


under one name, and which defines a particular way of storing and
organizing data in a computer so that it can be used efficiently.
2. Classification of Data Structures

There are two types of data structure available for the programming purpose:
• Primitive data structure
• Non-primitive data structure
Primitive data structure is a fundamental type of data structure that stores the
data of only one type whereas the non-primitive data structure is a type of data
structure which is a user-defined that stores the data of different types in a single
entity.
Classification of Data Structures
• Array: An array is a data structure that can hold the elements of same
type. It cannot contain the elements of different types like integer with
character. The commonly used operation in an array is insertion,
deletion, traversing, searching.
Example:
Linked List
• Linked List can be defined as collection of objects called nodes that are randomly
stored in the memory.
• A node contains two fields i.e. data stored at that particular address and the
pointer which contains the address of the next node in the memory.
• The last node of the list contains pointer to the null.

Advantages of Linked List:


• Easier to insert or delete elements.
• list size is limited to the memory size and doesn't need to be declared in
advance.
• 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.

Standard Stack Operations:-


• push(): To insert element.
• pop(): To delete ana element.
• Queue:-
• 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.
• Queue is referred to be as First In First Out list.

Insertion and Deletion of element in Queues:-


• Trees:-
A tree is also one of the data structures that represent hierarchical data.

Root Node
Parent Node
Child Node
Sibling Node
Leaf Node

Binary Tree
The Binary tree means that the node can have maximum two children. Here, binary
name itself suggests that 'two'; therefore, each node can have either 0, 1 or 2 children.
Advantages:
Provides quick search, insert and delete operations.
• Graphs:-
A graph can be defined as group of vertices and edges, that are used to connect these vertices.
Directed and Undirected Graph:-

• Unlike trees, graphs do not have root nodes.


• When two nodes are connected via edge, two nodes are called neighbours.
3. Operations on Data Structures
Major Operations
The major or the common operations that can be performed on the data structures
are:
• Searching: We can search for any element in a data structure.
• Sorting: We can sort the elements of a data structure either in an ascending or
descending order.
• Insertion: We can also insert the new element in a data structure.
• Deletion: We can also perform the delete operation to remove the element from the
data structure.
• Traversing: We can access each data element exactly once so that it can be
processed.
• Merging: Lists of two sorted elements can be combined to form single linked list.
4.Abstract Data Types
• Data Type: The Data Type is basically a type of data that can be used in different
computer program. Eg: int, char,string.
• Abstract Data Type: The abstract datatype is special kind of datatype, whose behavior
is defined by a set of values and set of operations. Some examples of ADT are Stack,
Queue, List etc.
• An abstract data type (ADT), focus on what it does and ignoring how it does
its job.
5.Preliminaries Of Algorithms
Algorithm:-Algorithm is a step-by-step procedure, which defines a set of
instructions to be executed in a certain order to get the desired output.
Algorithms are generally created independent of underlying languages, i.e.
an algorithm can be implemented in more than one programming language.
From the data structure point of view, following are some important
categories of algorithms −
• Search − Algorithm to search an item in a data structure.
• Sort − Algorithm to sort items in a certain order.
• Insert − Algorithm to insert item in a data structure.
• Update − Algorithm to update an existing item in a data structure.
• Delete − Algorithm to delete an existing item from a data structure.
Characteristics of an Algorithm:-
Not all procedures can be called an algorithm. An algorithm should have the
following characteristics −
• Unambiguous − Algorithm should be clear and unambiguous. Each of its steps (or
phases), and their inputs/outputs should be clear and must lead to only one
meaning.
• Input − An algorithm should have 0 or more well-defined inputs.
• Output − An algorithm should have 1 or more well-defined outputs, and should
match the desired output.
• Finiteness − Algorithms must terminate after a finite number of steps.
• Feasibility − Should be feasible with the available resources.
• Independent − An algorithm should have step-by-step directions, which should
be independent of any programming code.
6.Time and Space Complexity
The efficiency of an algorithm can be computed by measuring the performance of
an algorithm. We can measure the performance of an algorithm in two ways:-

1. Time Complexity.
2. Space Complexity.

1. Time Complexity:-
• The time taken by an algorithm to complete its task.
• Eg:- Time taken to add an element first to an array and a linked list.
• The running time to perform any operation depends on the size of the
input. Eg:- Adding a 1st element to the array with a size of 100 takes less
time compared with adding 1st element to the array with the size of 1000.
2. Space Complexity:-
• Space Complexity can be defined as amount of memory (or) space required
by an Algorithm to run.
• To compute the space complexity we use 2 factors i. Constant ii. Instance
characteristics.
• The space requirement S(p) can be given as S(p) = C+Sp
where C- Constant, it denotes the space taken for input and output.
Sp – Amount of space taken by an instruction, variable and identifiers.

You might also like