DS Notes Unit 1 - Part 1
DS Notes Unit 1 - Part 1
Data Structure is a way to store and organize data so that it can be used efficiently.
A data structure is not only used for organizing the data. It is also used for processing,
retrieving, and storing data. (or) The organized collection of data is called a ‘Data
Structure’.
Data Structure involves two complementary goals. The first goal is to identify and
develop useful, mathematical entities and operations and to determine what class of
problems can be solved by using these entities and operations. The second goal is to
determine representation for those abstract entities to implement abstract operations
on this concrete representation.
Classification of Data Structure:
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. It
is a collection of data of same data type but the data items need not be stored in
consecutive.
Stack: Stack is a linear list in which insertion and deletions are allowed only at one
end, called top. It is a Last-In-First-Out linear data structure.
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.
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 a First-In-First-Out
Linear data structure.
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.
Operations applied on Linear Data Structure:
The following list of operations applied on linear data structures
Insert an element
Delete an element
LIST ADT :
List is basically the collection of elements arranged in a sequential manner. In
memory we can store the list in two ways: one way is we can store the elements in
sequential memory locations. That means we can store the list in arrays. The other
way is we can use pointers or links to associate elements sequentially. This is
known as linked list.
Stack ADT
A stack is a linear data structure that only allows data to be accessed from the top.
It simply has two operations: push (to insert data to the top of the stack) and pop
(to remove data from the stack). (used to remove data from the stack top).
top(): returns the value of the node present at the top of the stack.
push(int val): creates a node with value = val and puts it at the stack top.
pop(): removes the node from the top of the stack.
empty(): returns true if the stack is empty, otherwise returns false.
size(): returns the number of nodes that are present in the stack.
Queue ADT
A queue is a linear data structure that allows data to be accessed from both ends.
There are two main operations in the queue: push (this operation inserts data to
the back of the queue) and pop (this operation is used to remove data from the
front of the queue).
Some of the most essential operations defined in Queue ADT are listed below.
front(): returns the value of the node present at the front of the queue.
back(): returns the value of the node present at the back of the queue.
push(int val): creates a node with value = val and puts it at the front of the
queue.
pop(): removes the node from the rear of the queue.
empty(): returns true if the queue is empty, otherwise returns false.
size(): returns the number of nodes that are present in the queue.
Overhead: Using ADTs may result in additional overhead due to the need for
abstraction and encapsulation.
Limited control: ADTs can limit the level of control that a programmer has
over the data structure, which can be a disadvantage in certain scenarios.
Performance impact: Depending on the specific implementation, the
performance of an ADT may be lower than that of a custom data structure
designed for a specific application.
θ(f(n)) = { g(n) if and only if g(n) = Ο(f(n)) and g(n) = Ω(f(n)) for all n > n0 }
Time Complexity:
Notation Description
Complexity
Constant number of
operations, not
Constant O(1)
depending on the input
data size.
Number of operations
proportional of log(n)
Logarithmic O(logn)
where n is the size of
the input data.
Number of operations
Linear O(n) proportional to the
input data size.
Number of operations
proportional to the
Quadratic O(n²)
square of the size of
the input data.
Number of operations
proportional to the
Cubic O(n³)
cube of the size of the
input data.
Exponential number of
Exponential operations, fast
O(n!), O(kn),O(2n)
growing.