0% found this document useful (0 votes)
9 views24 pages

DSA UNIT 1

The document provides an overview of data structures in C, categorizing them into primitive and non-primitive types, with further classifications into linear and non-linear structures. It explains Abstract Data Types (ADTs) such as List, Stack, and Queue, detailing their functions and features, as well as the concepts of algorithm analysis including time and space complexity. Additionally, it covers asymptotic notation for measuring algorithm efficiency, including Big O, Omega, and Theta notations.

Uploaded by

jeevayogi S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views24 pages

DSA UNIT 1

The document provides an overview of data structures in C, categorizing them into primitive and non-primitive types, with further classifications into linear and non-linear structures. It explains Abstract Data Types (ADTs) such as List, Stack, and Queue, detailing their functions and features, as well as the concepts of algorithm analysis including time and space complexity. Additionally, it covers asymptotic notation for measuring algorithm efficiency, including Big O, Omega, and Theta notations.

Uploaded by

jeevayogi S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Data Structure Definition:

Data structures in C is a way of storing and organizing data in the computer memory so
that it can be processed efficiently. Data structures can be broadly classified into two categories -
Primtive and Non-Primitive. Non-primitive data structures can be further classified into two
categories - Linear and Non-linear.

Abstract Data type (ADT)


Abstract Data type (ADT) is a type (or class) for objects whose behavior is defined by a set of values
and a set of operations. The definition of ADT only mentions what operations are to be performed
but not how these operations will be implemented. It does not specify how data will be organized
in memory and what algorithms will be used for implementing the operations. It is called
“abstract” because it gives an implementation-independent view.
The process of providing only the essentials and hiding the details is known as abstraction.

ADTs namely List ADT, Stack ADT, Queue ADT.


List ADT
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
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.


Queue ADT

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:
Abstraction
Better Conceptualization
Robust
Encapsulation
Data Abstraction
Data Structure Independence:
Information Hiding
Modularity

Disadvantages:
Overhead
Complexity
Learning
Limited Flexibility
Cost
Mathematical Notation

ANALYSIS OF BEST ,WORST AND AVERAGE CASE

Algorithm Analysis An algorithm is said to be efficient and fast, if it takes less time to
execute consumes less memory space.

The performance of an algorithm is measured on the basis of 1. Time Complexity 2. Space


Complexity

Space Complexity

The amount of memory space required by the algorithm in its life cycle. A fixed part : For
example simple variables & constant used and program size etc. A variable part : For
example dynamic memory allocation, recursion stacks space etc.

Space complexity S(P) of any algorithm P is S(P) = C + SP(I) Where C is the fixed part S(I) is
the variable part of the algorithm
Time Complexity - T(n)

The amount of time required by the algorithm to run to completion. T(n) can be measured as the number of steps, provided each step consumes
constant time.

ALGORITHM ANALYSIS

The worst-case complexity of the algorithm is the function defined by the maximum number of steps taken on any instance of size n.

The best-case complexity of the algorithm is the function defined by the minimum number of steps taken on any instance of size n.

Finally, the average-case complexity of the algorithm is the function defined by the average number of steps taken on any instance of size n.

ASYMPTOTIC NOTATION BASED ON GROWTH FUNCTIONS

Growth of Functions Growth of the function is one where it analyses if the input has increased , or how quickly the running time goes up. One easiest
way of comparing different running times is to plot them and see the natures of the graph Another way of checking if a function f(n) goes faster or
slower is by:
Order of Growth Function
Value of growth-rate function
ASYMPTOTIC NOTATION

Asymptotic analysis refers to computing the running time of any operation in mathematical units of
computation.

Ο Notation
Ω Notation
θ Notation
There are 3 types of asymptotic notations:

• Big O notation
• Ω notation
• θ notation
Big Oh Notation, Ο It measures the worst case time complexity or longest amount of time an algorithm can possibly
take to complete.

O(g(n)) = { f(n): there exist positive constants c and n0 such that 0 <= f(n) <= cg(n) for all n >= n0}
BIG Ω NOTATION(Ω ): Ω notation provides an asymptotic lower bound. Ω(g(n)) = { f(n): there exist positive
constants c and n0 such that 0 ≤ cg(n) ≤ f(n) for all n≥ n0}
Θ NOTATION: Θ((g(n)) = {f(n): there exist positive constants c1, c2 and n0 such that 0 ≤ c1*g(n) ≤
f(n) ≤ c2*g(n) for all n≥n0}

You might also like