0% found this document useful (0 votes)
57 views142 pages

Data Structure Unit1

The document outlines the syllabus and course details for a Data Structures course at the Noida Institute of Engineering and Technology, taught by Mrs. Nidhi Sharma. It covers various topics including arrays, linked lists, stacks, queues, trees, graphs, searching, and sorting algorithms, along with their applications and evaluation schemes. The course aims to familiarize students with time and space complexity, algorithm efficiency, and data structure implementations in programming.

Uploaded by

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

Data Structure Unit1

The document outlines the syllabus and course details for a Data Structures course at the Noida Institute of Engineering and Technology, taught by Mrs. Nidhi Sharma. It covers various topics including arrays, linked lists, stacks, queues, trees, graphs, searching, and sorting algorithms, along with their applications and evaluation schemes. The course aims to familiarize students with time and space complexity, algorithm efficiency, and data structure implementations in programming.

Uploaded by

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

Noida Institute of Engineering and Technology,

Greater Noida

Introduction to data structures, Arrays and


Linked lists

Unit: 01

Subject Name
Data Structures Mrs. Nidhi Sharma
(AOE0662) NIET, Greater Noida.
Electronics and
Course Details
(B Tech 4th Sem) Communication
Engineering.

Nidhi Sharma AOE0662 Data Structures Unit 1


Brief Introduction

Ms. Nidhi Sharma

• PhD Amity University, Pursuing


• M.Tech AKTU, Lucknow, India
• B.Tech. Kurukshetra University, Kkr. , Haryana

Research Interests
VLSI Design, Communication System, Internet of Things.

Industrial Experiance: (2.5 Years)


Academic Experience: (17+ years)

Publication : 08 (Peer Reviewed journals), 05(International Conference), 01 National


conference.
05/12/2025
Ms. Nidhi Sharma AOE0662 Data Stuctures Unit1
NOIDA INSTITUTE OF ENGINEERING AND
TECHNOLOGY, GREATER NOIDA
Evaluation Scheme

Ms. Nidhi Sharma AOE0662 Data Stuctures Unit1


NOIDA INSTITUTE OF ENGINEERING AND
TECHNOLOGY, GREATER NOIDA
Course Contents / Syllabus
UNIT-I: Introduction: Basic Terminology, Elementary Data Organization, Built in Data Types in C/python. Algorithm, Efficiency of an
Algorithm, Time and Space Complexity, Asymptotic notations: Big Oh, Big Theta and Big Omega, Abstract Data Types (ADT) Arrays: Single
and Multidimensional Arrays, Representation of Arrays: Row Major Order, and Column Major Order, Index Formulae for 1-D,2-D,3-D and n-D
Array Application of arrays, Sparse Matrices and their representations. Linked lists: Array Implementation of Singly Linked Lists, Doubly Linked
List, Circularly Linked List, Operations on a Linked List. Insertion, Deletion, Traversal. Polynomial Representation and Addition Subtraction &
Multiplications of Single variable. .
UNIT II : Stacks: Abstract Data Type, Primitive Stack operations: Push & Pop, Array and Linked Implementation of Stack, Application of stack:
Prefix and Postfix Expressions, Evaluation of postfix expression, Iteration and Recursion- Principles of recursion, Tail recursion, Removal of
recursion Problem solving using iteration and recursion with examples of binary search, Fibonacci numbers, and Hanoi towers. Tradeoffs between
iteration and recursion.Queues: Operations on Queue: Create, Add, Delete, Full and Empty, Circular queues, Dequeue and Priority Queue.

UNIT III: Basic terminology used with Tree, Binary Trees, Binary Tree Representation: Array Representation and Pointer (Linked List)
Representation, Binary Search Tree, Strictly Binary Tree, Complete Binary Tree, An Extended Binary Trees. Tree Traversal algorithms: In-order,
Pre-order and Post-order. Constructing Binary Tree from given Tree Traversal, Operation of Insertion, Deletion, Searching & Modification of data
in Binary Search tree, Introduction of Binary Heaps, Threaded Binary trees, Traversing Threaded Binary trees, AVL Tree, B-Tree.

UNIT IV: Graphs: Terminology used with Graph, Data Structure for Graph Representations: Adjacency
matrices, Adjacency List. Graph Traversal: Depth First Search and Breadth First Search. Connected
Component, Spanning Trees, Minimum Cost Spanning Trees: Prim’ s and Kruskal’s algorithm. Shortest Path
algorithms: Dijkstra Algorithm.
UNIT-V: Searching: Concept of Searching, Sequential search, Index Sequential Search, Binary Search. Concept of
Hashing. Sorting: Insertion Sort, Selection, Bubble Sort, Quick Sort, Merge Sort, Heap Sort and Radix Sort. File Structure:
Concepts of files, records and files, Sequential, Indexed and Random File Organization, indexing structure for index files,
multi-Key file organization and Access Methods.
Ms. Nidhi Sharma AOE0662 Data Stuctures Unit1
BRANCH WISE APPLICATION
When we talked about it is very vast majority
used today’s and the biggest example of it is
social media. People all around the world
connect with each other through social media.
From the origin of the primary programming
languages to the fashionable programming
languages presently in use, computer
programing has evolved quite lot. it’s currently
become additional powerful, efficient, and
advanced. However, the basic ideas and use of
information structure and algorithms in laptop
programming haven’t changed. It must be the
core of computer programming from the
beginning. you may have detectedAOE0662 Data
StucturesA getting used in the main within the
field of computer science. However, the
employment ofAOE0662 Data StucturesA isn’t
restricted to the sector of computing. we will
conjointly notice the construct ofAOE0662 Data
StucturesA being used in day to day life.
Nidhi Sharma AOE0662(DS) Unit-1
Course Objective

 Students will be familiar with the concept of time and space


complexity and demonstrate linear data structure array and linked
lists.
 Students will be able to understand the concept of stack and queue
with there memory representations.
 Students will be able to know the non linear data structures- trees.
 Students will be able to know the non linear data structures- graphs
with their different traversal ways.
 Students will be able to analyze the concepts of searching and
sorting.

05/12/2025 Nidhi Sharma AOE0662(DS) UNIT-4


Course Outcome

Course COURSE OUTCOMES Bloom’s


Outcome At the end of the semester, Knowledge
no. the students will be able to: Level (KL)
Understand and analyze the time and space K4, K2
AOE0662.1
complexity of an algorithm
Understand and implement fundamental K2, K3
AOE0662.2 algorithms(including sorting algorithms, graph
algorithms, and dynamic programming)
Discuss various algorithm design techniques for K1, K2
AOE0662.3
developing algorithms
Discuss various searching, sorting and graph K2, K3
AOE0662.4
traversal Algorithms
Understand operation on Queue, Priority Queue, K2
AOE0662.5
D-Queue.

05/12/2025 Nidhi Sharma AOE0662(DS) UNIT- 1


CO-PO Mapping

CO PO PO PO PO PO PO PO PO PO PO1 PO1 PO1


1 2 3 4 5 6 7 8 9 0 1 2
AOE06 3 3 3 3 2 1 1 2 2 1 2 2
62.1
AOE06 3 3 3 2 2 1 1 1 2 2 1 2
62.2
AOE06 3 3 3 3 2 1 - 2 1 1 1 2
62.3
AOE06 3 3 2 3 2 1 1 2 2 1 1 2
62.4
AOE06 3 3 3 3 2 1 1 2 2 1 1 2
62.5
Avg 3 3 2.8 2.8 2 1 0.8 1.8 1.8 1.2 1.2 2

05/12/2025 Nidhi Sharma AOE0662(DS) UNIT- 1


CO-PSO Mapping

CO PSO1 PSO2 PSO3


AOE0662.1 3 3 3
AOE0662.2 3 3 3
AOE0662.3 3 3 3
AOE0662.4 3 3 3
AOE0662.5 3 3 3
Avg 3 3 3

05/12/2025 Nidhi Sharma AOE0662(DS) UNIT- 1


RESULT ANALYSIS

OVERALL RESULT : 90.37%


SUBJECT RESULT : 90.37%
FACULTY RESULT : 91.37%

Nidhi Sharma AOE0662 Data Stuctures Unit-1


QUESTION PAPER TEMPLATE

Nidhi Sharma AOE0662 Data StucturesD Unit-1


Prerequisite and Recap

• Basic mathematical calculation skills and logical


skills
• Basic knowledge of C language
• In the previous units students were learn about the
array, stack, queue and linked list.
• Students were understand the algorithms and their
solving techniques.

05/12/2025 Nidhi Sharma AOE0662(DS) UNIT- 1


Brief subject Introduction withVideo

https://www.youtube.com/watch?v=ZAU5IlCQBls

05/12/2025 Nidhi Sharma AOE0662(DS) UNIT-4


Book referred

Nidhi Sharma AOE0662 Data Structures Unit 1


05/12/2025
Unit 1 Content

• Elementary data • Representation of • Linked lists


organization Arrays: Row Major • Array Implementation of Singly Linked
• Built in Data Types Order, and
Lists
in C/python. Column Major
Order • Doubly Linked List, Circularly Linked List, .
• Algorithm,
• Operations on a Linked List. Insertion,
Efficiency of an • Index Formulae
Algorithm, , for 1-D,2-D,3-D Deletion, Traversal.
Asymptotic and n-D Array • Polynomial Representation and
notations: Big Oh, • Application of • Addition Subtraction & Multiplications of
Big Theta and Big arrays, Single variable
OmegaTime and • Sparse Matrices • Video Links
Space Complexity and their

• Daily Quiz
Asymptotic representations.
notations: Big Oh, • Weekly Assignment
Big Theta and Big • MCQs
Omega • Old Question paper
• Abstract Data • Expected Questions for university Exam.
Types (ADT) • Recap
• Arrays: Single and
Multidimensional
Arrays

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Unit Objective

• Students will be familiar with the concept of time and space complexity.
• Students will be able to demonstrate linear data structure array.

Nidhi Sharma AOE0662 Data Structures Unit 1


05/12/2025
Prerequisite and Recap

What is data structures?


The logical or mathematical model of a particular organization of data is called data
structure.
What is an Algorithm?
An algorithm is a well-defined list of steps for solving a particular problem.
For Example: Algorithm To add Two numbers :

1. Ask User to enter two integer numbers.


2. Add both the integer numbers.
3. Print the final sum value of two numbers.

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Prerequisite and Recap

The study of data structure, includes the following three steps/ characteristics:

(1) Logical or mathematical description of the structure.

(2) Implementation of the structure on a computer.

(3) Quantitative analysis of the structure, which include determining the amount
of memory needed to store the structure and the time required to process the
structure.

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Topic Objective

 After studying Basic Terminology, Elementary Data Organization students


will understand the concept of various terms used in Data Structure.

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Elementary data organization

1. Data
Data can be defined as a representation of facts, concepts or instructions in a
formalized manner suitable for communication, interpretation or processing by
human or electric machines. Data is represented with the help of characters like
alphabets (A-Z,a-z), digits (0-9) and special characters (+,-,*,<, >, =, ^ etc.).

2. Data Item (Field)


A set of characters which are used together to represent a specific data element
e.g. name of a student in a class is represented by the data item, say NAME.
The data items can be classified into two types depending on the usage:
1.Elementary Data Items: These data items can’t be further sub-divided. For
e.g. ROLL NUMBER.
2.Group Data Items: These data items can be further sub-divided into
elementary data items. For example: DATE may be divided into Days, Months
and Years.

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Elementary data organization

3. Record
Record is a collection of related data items. E.g. a student record for a
student’s contains data fields such as name, age,class etc.

4. File (Data File)


File is collection of logically related records. E.g. a payroll file might consist
of the employee pay records for a company.

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Elementary data organization

5. Entity:
An entity is a person, place, thing, event or concept about which information
recorded.

6. Attribute:
Attributes gives the characteristics or properties of the entity.

7. Data Value:
A data value is the actual data or information contained in each attribute.

Example:
Entity : Employee
Attributes: Id, Name, Age
Value: 1, ABC, 18

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Elementary data organization

8.Entity Set
Entities with similar attributes form an entity set. For example, All the
employees in an organization form an entity set.

9. Primary and Secondary Keys:

Primary Key: A field or collection of fields in a record which identifies a record


uniquely is called a primary key or simply key. In a student file: ID is primary
key.

Secondary Key: A field in a record which identifies the records but not
uniquely is called a secondary key. For Example, NAME and MARKS are the
secondary keys in Student file.[2]

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Elementary data organization

• https://video.search.yahoo.com/search/video?fr=mcafee&p=elementary+
data+organization+video#id=1&vid=5a74b11f053de91ba9baa46c6a762b3
b&action=click

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Topic Objective

 After studying Built in Data Types in C/python students will understand the
concept of various types of data types.

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Built in Data Types in C/python

Built-in Data Types


Variables can store data of different types, and different types can do different
things.

Python has the following data types built-in by default, in these categories:

Text Type: str


Numeric Types: int, float, complex
Sequence Types: list, tuple, range
Mapping Type: dict
Set Types: set, frozenset
Boolean Type: bool
Binary Types: bytes, bytearray, memoryview

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Built in Data Types in C/python
Each variable in C has an associated data type. Each data type requires different
amounts of memory and has some specific operations which can be performed over
it. It specifies the type of data that the variable can store like integer, character,
floating, double, etc. The data type is a collection of data with values having fixed
values, meaning as well as its characteristics.
The data types in C can be classified as follows:
Types Description
Primitive Data Types Arithmetic types can be further classified into integer and
floating data types.
Void Types The data type has no value or operator and it does not
provide a result to its caller. But void comes under Primitive data types.
User Defined DataTypes It is mainly used to assign names to integral constants,
which make a program easy to read and maintain
Derived types The data types that are derived from the primitive or
built-in datatypes are referred to as Derived Data Types.

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Built in Data Types in C/python
Data Types in C
Different data types also have different ranges up to which they can store numbers.
These ranges may vary from compiler to compiler. Below is a list of ranges along with
the memory requirement and format specifiers on the 32-bit GCC compiler.

Data Type
Memory (bytes)
Range
Format Specifier
short int
2
-32,768 to 32,767
%hd
unsigned short int
2
0 to 65,535
%hu
05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1
Built in Data Types in C/python
unsigned int
4
0 to 4,294,967,295
%u
int
4
-2,147,483,648 to 2,147,483,647
%d
long int
4
-2,147,483,648 to 2,147,483,647
%ld
unsigned long int
4
0 to 4,294,967,295
%lu
long long int
8
-(2^63) to (2^63)-1
%lld
05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1
Built in Data Types in C/python
unsigned long long int
8
0 to 18,446,744,073,709,551,615
%llu
signed char
1
-128 to 127
%c
unsigned char
1
0 to 255
%c
float
4
1.2E-38 to 3.4E+38 %f
double
8
1.7E-308 to 1.7E+308 %lf
long double
16
05/12/2025 3.4E-4932 to 1.1E+4932
Nidhi Sharma AOE0662 Data Structures
%Lf Unit 1
Built in Data Types in C/python
Integer Types
The integer data type in C is used to store the whole numbers without decimal
values. Octal values, hexadecimal values, and decimal values can be stored in
int data type in C. We can determine the size of the int data type by using the
sizeof operator in C. Unsigned int data type in C is used to store the data
values from zero to positive numbers but it can’t store negative values like
signed int. Unsigned int is larger in size than signed int and it uses “%u” as a
format specifier in C programming language. Below is the programming
implementation of the int data type in C.

Range: -2,147,483,648 to 2,147,483,647


Size: 2 bytes or 4 bytes
Format Specifier: %d
Note: The size of an integer data type is compiler-dependent, when processors
are 16-bit systems, then it shows the output of int as 2 bytes. And when
processors are 32-bit then it shows 2 bytes as well as 4 bytes.

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Topic Objective

 After studying Algorithm, Efficiency of an Algorithm students will understand


the concept of efficient algorithm.

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Algorithm, Efficiency of an Algorithm

What is an Algorithm?
An algorithm is a well-defined list of steps for solving a particular problem.
For Example: Algorithm To add Two numbers :

1. Ask User to enter two integer numbers.


2. Add both the integer numbers.
3. Print the final sum value of two numbers.

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Algorithm, Efficiency of an Algorithm

Performance analysis of an algorithm depends upon two factors i.e. amount


of memory used and amount of computing time consumed by any CPU.
Formally they are notified as complexities in terms of:
• Space Complexity.

• Time Complexity.

Space Complexity of an algorithm is the amount of memory it needs to run to


completion i.e. from start of execution to its termination.
Time Complexity
Time Complexity of an algorithm(basically when converted to program) is the
amount of computer time it needs to run to completion.

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Algorithm, Efficiency of an Algorithm

Complexity of Algorithms:
In order to compare algorithms, we must have some criteria to measure the
efficiency of our algorithms.

Suppose M is an algorithm, and


Suppose n is the size of the input data.
The time and space used by the algorithm M are two main measures for the
efficiency of M.
The Time is measured by counting the number of key operations. E.g.in
searching and sorting algorithms – number of comparisons.
The Space is measured by counting the maximum of memory needed by the
algorithm.

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Topic Objective

 After studying ‘Time and Space Complexity’ students will come to know
how much is the importance of (run time) time while writing efficient
algorithms.

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Time and Space Complexity

Time Complexity
Time Complexity of an algorithm(basically when converted to program) is the
amount of computer time it needs to run to completion. The time taken by a
program is the sum of the compile time and the run/execution time . The
compile time is independent of the instance(problem specific) characteristics.
following factors effect the time complexity:
• Characteristics of compiler used to compile the program.
• Computer Machine on which the program is executed and physically
clocked.
• Multiuser execution system.
• Number of program steps.

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Topic Objective

 After studying ‘Asymptotic notations: Big Oh, Big Theta and Big Omega’
students will be capable of quantifying the complexity of an algorithm.

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Asymptotic notations: Big Oh, Big Theta and Big
Omega
• Whenever we work with algorithms, the most critical factor considered for them is
their efficiency. And for this we are interested in analyzing how the running time
increases when input size increases. when two algorithms are compared with
respect to their behavior for large input size, the measure is know as Order of
growth.
• In Asymptotic analysis it is considered that an algorithm 'A1' is better than
algorithm 'A2' if the order of growth of the running time of the 'A1' is lower than
that of 'A2’.
• Therefore asymptotic efficiency of algorithms are concerned with how the
running time of an algorithm increases with the size of the input in the limit, as
the size of the input increases without bound.
• Asymptotic Notations: For every algorithm corresponding to efficiency analysis,
we have three basic cases :
 Best Case
 Average Case
 Worst Case
• There are 5 Asymptotic notations.

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Asymptotic notations: Big Oh, Big Theta and Big
Omega
Suppose f(n) and g(n) are functions defined on the positive integers with the
property that f(n) is bounded by some multiple of g(n) for almost all n. That
is, suppose there exist a positive integer n0 and a positive number M such
that, for all n> n0 , we have
ǀ f(n)ǀ < M ǀ g(n)ǀ
Then we may write
f(n)=O(g(n))
Which is read as ‘f(n) is of order g(n)’
E.g. 8n3-576n2+832n-248= O(n3)
Complexity of certain well-known searching and sorting algorithms:
1. Linear search: O(n)
2. Binary search: O(log n)
3. Bubble Sort: O(n2)
4. Merge Sort: O(n log n)

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Asymptotic notations: Big Oh, Big Theta and Big
Omega
Asymptotic
Symbol
Notation Efficiency Case Examples
S.No Used
Name Resemblance

Theta Average Case Θ(1), Θ(n), Θ(n 2 ), Θ(n 3 ),


1 notation Θ (Tightly Bound) Θ(n n ), Θ(log n), Θ(n log n)

Worst Case (Tightly


2 Big oh O Bound) O(1), O(n), O(n 2
), O(n 3
),
notation O(n ), O(log n), O(n log n)
n

Best Case (Tightly


Omega Ω(1), Ω(n), Ω(n 2 ), Ω(n 3 ),
3 Ω Bound)
notation Ω(n n ), Ω(log n), Ω(n log n)

Worst Case (Loosely


4 Little oh o Bound) o(1), o(n), o(n 2
), o(n 3
), o(n n
),
notation o(log n), o(n log n)

Little Best Case (Loosely


5 omega ω Bound) ω(1), ω(n), ω(n 2 ), ω(n 3 ),
notation ω(n n ), ω(log n), ω(n log n)
05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1
Asymptotic notations: Big Oh, Big Theta and Big
Omega

https://video.search.yahoo.com/search/video?fr=mcafee&p=big+oh+notation
+data+structure+video#id=2&vid=0da5ae6151918fd479169873ccb78a6b&act
ion=click

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Daily Quiz

Q1: If time taken by an algorithm to run is more then that algorithm is ………………
Efficient/inefficient.

Q2: In case of Big Oh notation worst case is ………………… tightly Bound/ Loosly bound/
Efficient case.

Q3: Performance of an algorithm depends on:


a) Time Complexity.
b) Space Complexity.
c) Both a and b.
d) None.

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


FAQs

Q1: What do you mean by performance analysis of an algorithm?


Q2: How time complexity is related to the performance of an algorithm?
Q3: Define Big Oh notation. Give Example.

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Recap

Performance analysis of an algorithm depends upon two factors i.e. amount


of memory used and amount of compute time consumed on any CPU. Space
Complexity and Time Complexity.

Time Complexity
Time Complexity of an algorithm(basically when converted to program) is the
amount of computer time it needs to run to completion. The time taken by a
program is the sum of the compile time and the run/execution time .

Big oh notation (O)- Worst Case (Tightly Bound) – e.g. O(1), O(n), O(n 2 ),
O(n 3 ), O(n n ), O(log n), O(n log n)

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Objective of topic

 After studying ‘Abstract Data Types (ADT)’ students will come to know
about ADTs.

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Abstract Data Types (ADT)
Data types such as int, float, double, long, etc. are considered to be in-built
data types and we can perform basic operations with them such as addition,
subtraction, division, multiplication, etc. Now there might be a situation when
we need operations for our user-defined data type which have to be defined.
These operations can be defined only as and when we require them. So, in
order to simplify the process of solving problems, we can create data
structures along with their operations, and such data structures that are not in-
built are known as 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.
05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1
Abstract Data Types (ADT)

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Daily Quiz

Q1:Fibbonaci series is a …………….. Function.


Q2: When a function calls itself then it is called …….. Function.
Q3: Accessing each record exactly once so that it can be processed is called …………

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


FAQs

Q1: Define traversing ,searching, sorting operations .


Q2: What is recurrence? Explain with the help of example.

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Weekly Assignment

Q1: What is the difference between elementary data item and grouped data
item?
Q2: What is primary Key and Secondary key? Give example of each.
Q3: Define Entity and Attribute with example.
Q4: Define traversing ,searching, sorting operations .
Q5: What is recurrence? Explain with the help of example.
Q6: What is the Abstract data type?
Q7: What is time space trade off?
Q8: Explain the concept of field, record and file.

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Objective of topic

 After studying ‘Arrays’ students will understand the concept of one of the
linear data structure which stores similar data items – Array.

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Arrays: Single and Multidimensional Arrays

Linear array:
A linear array is a list of a finite number n of homogeneous data elements.(i.e.
data elements of same type) such that:
1. The elements of the array are referenced respectively by an index set
consisting of consecutive numbers.
2. The elements of the array are stored respectively in successive memory
locations.

Representation of elements of an array:


A1,A2,A3,………
A(1),A(2),A(3),……………
A[1],A[2],A[3],……………

Length of an array:
The number n of elements is called the length or Size of the array.
Length= UB-LB+1
05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1
Arrays: Single and Multidimensional Arrays

• An array is a collection of items stored at contiguous memory locations.


The idea is to store multiple items of the same type together.

• To calculate the position of each element by simply adding an offset to a


base value, i.e., the memory location of the first element of the array
(generally denoted by the name of the array).

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Objective of topic

 After studying ‘Single dimensional array and multi dimensional array’


students will come to know the Types of arrays .

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Single dimensional and multidimensional arrays

Single dimensional array

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Single dimensional and multidimensional arrays
Multidimensional arrays.

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Objective of topic

 After studying ‘Array operations’ students will understand different


operations of Array e.g. Insertion, Traversal and Deletion etc.

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Operation on arrays

Basic Operations
Following are the basic operations supported by an array.

• Traverse − print all the array elements one by one.


• Insertion − Adds an element at the given index.
• Deletion − Deletes an element at the given index.
• Search − Searches an element using the given index or by the value.
• Update − Updates an element at the given index.

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Operation on arrays
Array traversal
In traversing operation of an array, each element of an array is accessed
exactly for once for processing. This is also called visiting of an array.

//Write a Program which perform traversing operation.


#include <stdio.h>
void main()
{
int LA[] = {2,4,6,8,9};
int i, n = 5;
printf("The array elements are:\n");
for(i = 0; i < n; i++)
{
printf("LA[%d] = %d \n", i, LA[i]);
}
}
05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1
Operation on arrays

Traversing in Linear Array Algorithm: Here LA is a linear array with


lower bound LB and upper bound UB. This algorithm traverses LA
applying an operation PROCESS to each element of LA.

Step 1 : [Initialization] Set K := LB

Step 2 : Repeat Step 3 and Step 4 while K < = UB.

step 3 : [ Visit element ] Apply PROCESS to LA[K].

Step 4 : [ Increment the counter ] K:= K + 1.


[ End of the loop of step 2 ]

Step 5: Exit

(Here LB is lower Bound and UB is Upper Bound LA[ ] is linear array )

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Operation on arrays

Traversing in Linear Array Algorithm:

Step 1 : [Initialization] Set K := LB. K=0

Step 2 : Repeat Step 3 and Step 4 while K < = UB. K ≤ 6

step 3 : [ Visit element ] Apply PROCESS to LA[K].


LA[0],LA[1],LA[2],LA[3],LA[4], LA[5],LA[6]

Step 4 : [ Increment the counter ] K:= K + 1.


K:= 0+1, K:= 1+1, K:= 2+1, K:= 3+1…..,K:=5+1
[ End of the loop of step 2 ]

Step 5: Exit .

(Here LB is lower Bound and UB is Upper Bound LA[ ] is linear array )


05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1
Operation on arrays

Insertion Algorithm:
We have to insert a name- Rahul at index no. 3
NAME NAME NAME
1 Amit 1 Amit 1 Amit
2 Manish 2 Manish 2 Manish
3 Sumit 3 3 Rahul
4 Ram 4 Sumit 4 Sumit
5 Ramesh 5 Ram 5 Ram
6 6 Ramesh 6 Ramesh
7 7 7
8 8 8

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Operation on arrays
Insertion Algorithm In Linear Array
INSERT(LA, N, K, ITEM)
Here LA is a linear array with N elements and k is the positive integer such that K≤ N.
This algorithm inserts an element ITEM into the Kth position in LA.

Step 1 : [Initialization] Set J := N


Step 2 : [ Loop ] Repeat Step 3 and Step 4 while J ≥ K.

step 3 : [ Moving Jth Element downward ] Set LA [J+ 1] := LA[J].

Step 4 : [Decrement counter ] Set J := J – 1.

[End of loop ]

Step 5: [ Insertion Element ] Set LA[ K ] :=ITEM.


Step 6 : [Reset N ]Set N :=N+1
Step 7 : Exit

(P is position ; N is number of Element ; A[i] is Array)


05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1
Operation on arrays
Approach to insert an element into the array:

Here’s how to do it.


• First get the element to be inserted, say x
• Then get the position at which this element is to be inserted, say pos
• Then shift the array elements from this position to one position forward, and do
this for all the other elements next to pos.
• Insert the element x now at the position pos, as this is now empty.
Below is the implementation of the above approach:

// C Program to Insert an element


// at a specific position in an Array

#include <stdio.h>

int main()
{
int arr[100] = { 0 };
int i, x, pos, n = 10;
05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1
Operation on arrays

// initial array of size 10


for (i = 0; i < 10; i++)
arr[i] = i + 1;

// print the original array


for (i = 0; i < n; i++)
printf("%d ", arr[i]);
printf("\n");
// element to be inserted
x = 50;

// position at which element


// is to be inserted
pos = 5;
// increase the size by 1
n++;

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Operation on arrays

// shift elements forward


for (i = n; i >= pos; i--)
arr[i] = arr[i - 1];

// insert x at pos
arr[pos - 1] = x;

// print the updated array


for (i = 0; i < n; i++)
printf("%d ", arr[i]);
printf("\n");

return 0;
}
05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1
Operation on arrays

Deletion Algorithm:
We have to delete a name- Ram.

NAME NAME NAME


1 Amit 1 Amit 1 Amit
2 Manish 2 Manish 2 Manish
3 Sumit 3 Sumit 3 Sumit
4 Ram 4 4 Ramesh
ITEM
5 Ramesh 5 Ramesh 5
6 6 6
7 7 7
8 8 8

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Operation on arrays

Deletion Algorithm In Linear Array:


DELETE(LA, N, K, ITEM)
Here LA is a linear array with N elements and K is a Positive integer such that
K ≤ N. This algorithm deletes the Kth element from LA.

Step 1 : [Deletion of element] Set ITEM := LA [ K ].


Step 2 : [ Loop ] Repeat for J = K to N – 1.
Step 3 : [ Moving (J + 1)th element upwards ] Set LA[ J ] :=LA[ J+1 ].
[ End of Loop ]
Step 4 : [ Reset the number N ] Set N := N – 1.
Step 5 : Exit .

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Operation on arrays
#include <stdio.h>
int main()
{
int array[100], position, c, n;
printf("Enter number of elements in array\n");
scanf("%d", &n);
printf("Enter %d elements\n", n);
for (c = 0; c < n; c++)
scanf("%d", &array[c]);
printf("Enter the location where you wish to delete element\n");
scanf("%d", &position);
if (position >= n+1)
printf("Deletion not possible.\n");
else
{
for (c = position - 1; c < n - 1; c++)
array[c] = array[c+1];
printf("Resultant array:\n");
05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1
Operation on arrays

for (c = 0; c < n - 1; c++)


printf("%d\n", array[c]);
}
return 0;
}

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Operation on arrays

• https://video.search.yahoo.com/search/video?fr=mcafee&p=algorithm+fo
r+traversing+a+linear+array#id=1&vid=5b42cd22970b6591707cad125d98
2dbf&action=click-

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Daily Quiz
Q1: All the elements of an array are of …………………… type.
a) Same
a) Homogeneous
b) Heterogeneous
c) Both a and b.
Q2: When element is inserted into the array
d) Blank location is needed
e) No Blank location needed
f) One element is to be removed from the array
g) None of the Above.
Q3: An array elements are always stored in ________ memory locations.
h) Sequential
i) Random
j) Both a and b
k) None

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


FAQs

Q1: How index number is affected by insertion and deletion operation into
the array?
Q2: What is row major and column major order?
Q3: How the LOC is found in a linear array?

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Recap

Array
An array is a collection of items stored at contiguous memory locations.

Array Operations
Traverse − print all the array elements one by one.
Insertion − Adds an element at the given index.
Deletion − Deletes an element at the given index.

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Topic Objective

 After studying ‘Representation of Arrays: Row Major Order, and Column


Major Order’ students will see how the elements of an array are stored in
memory.

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Representation of Arrays: Row Major Order, and
Column Major Order
Representation of Linear Arrays in Memory:
In linear array the declaration statements tell how many cells are
needed to store the array.
 to calculate the number of cells needed and
 to find the location or address of any element of the array.
We need:
1. The upper bound (UB) of the index range-- Largest index value.
2. The lower bound (LB) of the index range– Lowest index value. In
C/C++, LB is zero.
3. The location in memory of the first byte of the array, called base
address of the array (Base).
4. The number of memory bytes needed for each cell containing one
data element of the array (size, denoted by W).
cell -a unit of memory bytes that will be assigned to hold a value of
respective data element.
05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1
Representation of Arrays: Row Major Order, and
Column Major Order

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Representation of Arrays: Row Major Order, and
Column Major Order
Finding the LOC in Linear Array:
• The elements of linear array are stored in consecutive memory locations.
• The computer does not keep track of address of each element of array. It only
keeps track of the base address of the array and on the basis of this base address,
the address or location of any element can be found.

LOC (LA[K]) = Base(LA) + W(K-LB)

LOC (LA [K]) is the location of the Kth element of LA.


Base (LA) is the base address of LA.
w is the number of bytes taken by one element.
K is the Kth element.
LB is the lower bound.

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Representation of Arrays: Row Major Order, and
Column Major Order

Example of finding LOC in Linear array:

Suppose we want to find out Loc (A [3]). For it, we have:


Base (A) = 1000
w = 2 bytes (Because an integer takes two bytes in the memory).
K=3
LB = 1

After putting these values in the given formula, we get:


LOC (A [3]) = 1000 + 2 (3 – 1)
= 1000 + 2 (2)
= 1000 + 4
= 1004

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Representation of Arrays: Row Major Order, and
Column Major Order

Column Major order

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Representation of Arrays: Row Major Order, and
Column Major Order

Column Major Order:


The formula is:
LOC (A [J, K]) = Base (A) + w [M (K-1) + (J-1)]
LOC (A [J, K]) = the location of the element in the Jth row and Kth column.
Base (A) = the base address of the array A.
W= is the number of bytes required to store single element of the array
A.
M = The total number of rows in the array.
J = The row number of the element.
K =The column number of the element.

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Representation of Arrays: Row Major Order, and
Column Major Order

Column Major Order:


Address of A[J][K] = B + W * ((K – LC) * M + (J – LR))
J = Row Subset of an element whose address to be found,
K = Column Subset of an element whose address to be found,
B = Base address,
W = Storage size of one element store in any array(in byte),
LR = Lower Limit of row/start row index of matrix(If not given
assume it as zero),
LC = Lower Limit of column/start column index of matrix(If not
given assume it as zero),
M = Number of rows given in the matrix.

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Representation of Arrays: Row Major Order, and
Column Major Order

Example of Column Major Order:


Suppose we have to find the location of A [3, 2]. The required values are:
Base (A) = 1000
W = 2 (because an integer takes 2 bytes in memory)
M=3
J=3
K=2
Now put these values in the given formula as below:
LOC (A [3, 2]) = 1000 + 2 [3 (2-1) + (3-1)]
= 1000 + 2 [3 (1) + 2]
= 1000 + 2 [3 + 2]
= 1000 + 2 [5]
= 1000 + 10
= 1010

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Representation of Arrays: Row Major Order, and
Column Major Order

Row Major order

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Representation of Arrays: Row Major Order, and
Column Major Order

Row Major Order

The formula is:


LOC (A [J, K]) = Base (A) + w [N (J-1) + (K-1)]

LOC (A [J, K]) = The location of the element in the Jth row and Kth
column.
Base (A) = The base address of the array A.
W = The number of bytes required to store single element of the array A.
N = The total number of columns in the array.
J = The row number of the element.
K = The column number of the element.

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Representation of Arrays: Row Major Order, and
Column Major Order

Row major order:

Address of A[J][K] = B + W * ((J – LR) * N + (K –


LC))
J = Row Subset of an element whose address to be found,
K = Column Subset of an element whose address to be found,
B = Base address,
W = Storage size of one element store in an array(in byte),
LR = Lower Limit of row/start row index of the matrix(If not given assume it
as zero),
LC = Lower Limit of column/start column index of the matrix(If not given
assume it as zero),
N = Number of column given in the matrix.

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Representation of Arrays: Row Major Order, and
Column Major Order

Example of Row Major Order:

Suppose we have to find the location of A [3, 2]. The required values are:
Base (A) = 1000
w = 2 (because an integer takes 2 bytes in memory)
N=4
J=3
K=2
Now put these values in the given formula as below:
LOC (A [3, 2]) = 1000 + 2 [4 (3-1) + (2-1)]
= 1000 + 2 [4 (2) + 1]
= 1000 + 2 [8 + 1]
= 1000 + 2 [9]
= 1000 + 18
= 1018
05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1
Representation of Arrays: Row Major Order, and
Column Major Order

INTEGER NUMB(2:5,-3:1)
• It is a 2D array
• No. of rows=5-2+1=4
• No. of Columns= 1-(-3)+1=5

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Representation of Arrays: Row Major Order, and
Column Major Order

• https://video.search.yahoo.com/search/video?fr=mcafee&p=Representati
on+of+arrays+in+memory#id=2&vid=c91f7715bd3ec193dc18f0af08d5980
a&action=click

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Daily Quiz

Q1: LOC (LA[K]) = ………………….+ W(K-LB) .


Q2: Find the location of A [2, 3]. The required values are:
Base (A) = 1000
W = 2 (because an integer takes 2 bytes in memory)
M=3
J=3
K=2

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


FAQs

Q1: What is row major and column major order?


Q2: How the LOC is found in a linear array?

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Recap

Representation of Linear Arrays in Memory:


In linear array the declaration statements tell how many cells are needed to
store the array.
 to calculate the number of cells needed and
 to find the location or address of any element of the array.

For Linear array


LOC (LA[K]) = Base(LA) + W(K-LB)
For 2D array
Column Major order
LOC (A [J, K]) = Base (A) + w [M (K-1) + (J-1)]
Row Major Order
LOC (A [J, K]) = Base (A) + w [N (J-1) + (K-1)]

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Topic Objective

 After studying ‘Sparse Matrices and their representations.’ students will


analyze how the memory space is efficiently used while storing an array
element called sparse matrix.

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Sparse Matrices and their representations.

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Linked list

Linked list:
A Linked List or One Way List, is a linear collection of data
elements , called nodes, where the linear order is given by
means of pointers. That is, each node is divided into two parts:
the first part contains the information of the element, and the
second part, called the link field or nextpointer field, contains
the address of the next node in the list.

05/12/2025 Nidhi Sharma AOE0662 Data Stuctures Unit1


Singly linked list

Singly linked list


• Singly linked list is a basic linked list type.
• Singly linked list is a collection of nodes linked together in a sequential way
where each node of singly linked list contains a data field and an address
field which contains the reference of the next node.
• Singly linked list can contain at least single address field pointing to its
connected next node.

05/12/2025 Nidhi Sharma AOE0662 Data Stuctures Unit1


Circular linked list

Circular linked list


• A linked list in which the last node points to the first node instead of
containing null pointer will be termed as circularly linked list or simply
circular list

05/12/2025 Nidhi Sharma AOE0662 Data Stuctures Unit1


Two way(Doubly) Linked lists

A Two way list is a linear collection of data elements, called nodes, where each
node N is divided into three parts:
1 An information field INFO which contains the data of N.
2 A pointer field FORW which contains the location of the next node in the list.
3 A pointer field BACK which contains the location of the preceding node in
the list.

05/12/2025 Nidhi Sharma AOE0662 Data Stuctures Unit1


Array Implementation of Singly Linked Lists, Doubly
Linked List, Circularly Linked List
Linked List Implementation using Array

• This means that how the data in the INFO field of all the nodes is stored in
the form of an array.

05/12/2025 Nidhi Sharma AOE0662 Data Stuctures Unit1


Array Implementation of Singly Linked Lists, Doubly
Linked List, Circularly Linked List

Linked List Implementation using Array

05/12/2025 Nidhi Sharma AOE0662 Data Stuctures Unit1


Operations on a Linked List. Insertion, Deletion,
Traversal

Traversal of a Linked list:


Let LIST be a linked list in memory stored in linear arrays INFO
and LINK with START pointing to the first element and NULL
indicating the end of LIST.
Suppose we want to traverse LIST in order to process each node
exactly once.

PTR:= LINK[PTR]

05/12/2025 Nidhi Sharma AOE0662 Data Stuctures Unit1


Traversal operation: Linked List
Traversing a Linked List:
Let LIST be a linked list in memory. This algorithm traverses LIST, Applying an
operation PROCESS to each element of LIST. The variable PTR points to the
node currently being processed.
1. Set PTR:=START.
2. Repeat Steps 3 and 4 while PTR not=NULL.
3. Apply PROCESS to INFO[PTR].
4. Set PTR:= LINK[PTR.]
5. Exit.

05/12/2025 Nidhi Sharma AOE0662 Data Stuctures Unit1


Inserting after a given node: Linked List
INSLOC(INFO, LINK,START,AVAIL,LOC,ITEM)
This algorithm inserts ITEM so that ITEM Follows the node with location LOC
or insert ITEM as the first node when LOC= NULL.
1. If AVAIL=NULL, Then : Write: OVERFLOW, and Exit.
2. Set NEW:=AVAIL and AVAIL:=LINK[AVAIL].
3. Set INFO[NEW]:= ITEM.
4. If LOC=NULL, Then :
Set LINK[NEW]:= START and START:=NEW.
Else :
Set LINK[NEW]:= LINK[LOC] and LINK[LOC] := NEW.
5. Exit.

05/12/2025 Nidhi Sharma AOE0662 Data Stuctures Unit1


Inserting after a given node: Linked List

05/12/2025 Nidhi Sharma AOE0662 Data Stuctures Unit1


Inserting after a given node: Linked List

05/12/2025 Nidhi Sharma AOE0662 Data Stuctures Unit1


Inserting after a given node: Linked List

05/12/2025 Nidhi Sharma AOE0662 Data Stuctures Unit1


Deleting the node following a given node: Linked List
DEL(INFO, LINK, START,AVAIL, LOC, LOCP)
This algorithm deletes the node N with location LOC, LOCP is the location of
the node precedes N or, when N is the first node , LOCP= NULL.
1. If LOCP=NULL, Then :
Set START:= LINK[START].
Else:
Set LINK[LOCP]:= LINK[LOC].
2. Set LINK[LOC] := AVAIL and AVAIL := LOC.
3. Exit.

05/12/2025 Nidhi Sharma AOE0662 Data Stuctures Unit1


Deleting the node following a given node: Linked List

05/12/2025 Nidhi Sharma AOE0662 Data Stuctures Unit1


Deleting the node following a given node: Linked List

05/12/2025 Nidhi Sharma AOE0662 Data Stuctures Unit1


Deleting the node following a given node: Linked List

05/12/2025 Nidhi Sharma AOE0662 Data Stuctures Unit1


Header Linked lists

A header linked list is a linked list which always contains a special node,
called the header node, at the beginning of the list.
Two types of header lists:
1. A grounded header list is a header list where the last node contains the
null pointer.
2. A circular header list is a header list where the last node points back to
the header node.

05/12/2025 Nidhi Sharma AOE0662 Data Stuctures Unit1


Polynomial Representation and Addition Subtraction
& Multiplications of Single variable.
Adding two polynomials using Linked List
Given two polynomial numbers represented by a linked list. Write a function
that add these lists means add the coefficients who have same variable powers.
Example:

Input:
1st number = 5x2 + 4x1 + 2x0
2nd number = -5x1 - 5x0
Output:
5x2-1x1-3x0
Input:
1st number = 5x3 + 4x2 + 2x0
2nd number = 5x^1 - 5x^0
Output:
5x3 + 4x2 + 5x1 - 3x0
Addition-of-two-polynomial

05/12/2025 Nidhi Sharma AOE0662 Data Stuctures Unit1


Polynomial Representation and Addition Subtraction
& Multiplications of Single variable.
Multiplication of two polynomials using Linked list
Given two polynomials in the form of linked list. The task is to find the
multiplication of both polynomials.

Examples:

Input: Poly1: 3x^2 + 5x^1 + 6, Poly2: 6x^1 + 8


Output: 18x^3 + 54x^2 + 76x^1 + 48
On multiplying each element of 1st polynomial
with elements of 2nd polynomial, we get
18x^3 + 24x^2 + 30x^2 + 40x^1 + 36x^1 + 48
On adding values with same power of x,
18x^3 + 54x^2 + 76x^1 + 48

Input: Poly1: 3x^3 + 6x^1 - 9, Poly2: 9x^3 - 8x^2 + 7x^1 + 2


Output: 27x^6 - 24x^5 + 75x^4 - 123x^3 + 114x^2 - 51x^1 - 18
05/12/2025 Nidhi Sharma AOE0662 Data Stuctures Unit1
Polynomial Representation and Addition Subtraction
& Multiplications of Single variable.
Approach:

• In this approach we will multiply the 2nd polynomial with each term of 1st
polynomial.
• Store the multiplied value in a new linked list.
• Then we will add the coefficients of elements having the same power in
resultant polynomial.

05/12/2025 Nidhi Sharma AOE0662 Data Stuctures Unit1


Polynomial Representation and Addition Subtraction
& Multiplications of Single variable.
Subtract Two Numbers represented as Linked Lists
Given two linked lists that represent two large positive numbers. Subtract the smaller
number from the larger one and return the difference as a linked list. Note that the input
lists may be in any order, but we always need to subtract smaller ones from larger ones.
Note: It may be assumed that there are no extra leading zeros in input lists.

Examples:

Input: l1 = 1 -> 0 -> 0 -> NULL, l2 = 1 -> NULL


Output: 0->9->9->NULL
Explanation: Number represented as
lists are 100 and 1, so 100 - 1 is 099

Input: l1 = 7-> 8 -> 6 -> NULL, l2 = 7 -> 8 -> 9 NULL


Output: 3->NULL
Explanation: Number represented as
lists are 786 and 789, so 789 - 786 is 3,
as the smaller value is subtracted from
the larger one.

05/12/2025 Nidhi Sharma AOE0662 Data Stuctures Unit1


Polynomial Representation and Addition Subtraction
& Multiplications of Single variable.
Subtraction two polynomials using Linked List

Approach: Following are the steps.

• Calculate sizes of given two linked lists.


• If sizes are not the same, then append zeros in the smaller linked list.
• If the size is the same, then follow the below steps:
• Find the smaller valued linked list.
• One by one subtract nodes of the smaller-sized linked list from the larger
size. Keep track of borrow while subtracting.

05/12/2025 Nidhi Sharma AOE0662 Data Stuctures Unit1


Singly linked list and Circular linked list, List
operations, List Implementation

• https://video.search.yahoo.com/search/video;_ylt=Awr9NVUptbxem0YA.
DL7w8QF;_ylu=X3oDMTBncGdyMzQ0BHNlYwNzZWFyY2gEdnRpZAM-;_yl
c=X1MDOTY3ODEzMDcEX3IDMgRhY3RuA2NsawRjc3JjcHZpZANsT3JOS3p
Fd0xqTFpsdlhHV3lqV1ZRQ1pNVEEyTGdBQUFBRHpUVUlwBGZyA21jYWZlZ
QRmcjIDc2EtZ3AEZ3ByaWQDSjg3TjdvazVSUS5CdllKd1hvQVJGQQRuX3Jzb
HQDNjAEbl9zdWdnAzEwBG9yaWdpbgN2aWRlby5zZWFyY2gueWFob28uY
29tBHBvcwMwBHBxc3RyAwRwcXN0cmwDBHFzdHJsAzIxBHF1ZXJ5A0xpb
mtlZCUyMGxpc3QlMjB2aWRlbwR0X3N0bXADMTU4OTQyODg5Mw--?p=Li
nked+list+video&ei=UTF-8&fr2=p%3As%2Cv%3Av%2Cm%3Asa&fr=mcafe
e#id=2&vid=801d07015208266e022a01875d6c2ba2&action=view
05/12/2025 Nidhi Sharma AOE0662 Data Stuctures Unit1
FAQs

Q1: What do you by linked list? State the types of linked lists.
Q2: Explain Circular linked list with neat diagram.
Q3: Explain how a node is inserted as first node in the linked list?
Q4: Write an algorithm to delete a node from the given location.
Q5: Write an algorithm to insert a node before the given location.

05/12/2025 Nidhi Sharma AOE0662 Data Stuctures Unit1


Recap

Singly linked list


Singly linked list is a collection of nodes linked together in a sequential way
where each node of singly linked list contains a data field and an address field
which contains the reference of the next node.

Circular linked list


A linked list in which the last node points to the first node instead of
containing null pointer will be termed as circularly linked list or simply circular
list.

List operations:
Insertion of a Node as First node
Insertion of a Node after a given location
Deletion of a node at given LOC.

05/12/2025 Nidhi Sharma AOE0662 Data Stuctures Unit1


Daily Quiz
Q1: When the Number of zero entries are more in a data matrix then it is called ………..
Q2: An array A[10] is a:
a) Linear array
b) Multi- dimensional array
c) 2 D array
d) 3 D array
Q3: An Array B[2,3] Is a:
e) Linear array
f) Multi- dimensional array
g) 2 D array
h) 3 D array
Q4: An Array C[1.3.2,5] is a:
i) Linear array
j) Multi- dimensional array
k) 2 D array
l) 3 D array

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Weekly Assignment

Q1: How index number is affected by insertion and deletion operation into
the array?
Q2: What is row major and column major order?
Q3: How the LOC is found in a linear array?
Q4: What are Character strings? Explain with suitable examples.
Q5: What do you mean by Sparse Matrix? Explain the types of Sparse
Matrices.
Q6: What do mean by linear array and multi-dimensional array?

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


MCQ s
Q1:An array elements are always stored in ________ memory locations.
a) Sequential
b) Random
c) Both a and b
d) None
Q2:What is the maximum number of dimensions an array in C may have?
e) 2
f) 8
g) 20
h) Theoretically no limit. The only practical limit is memory size and
compilers.
Q3: Which of these best describes an array?
a) A data structure that shows a hierarchical behaviour
b) Container of objects of similar types
c) Arrays are immutable once initialised
d) Array is not a data structure
05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1
MCQ s
Q4:How do you initialize an array in C?
a) int arr[3] = (1,2,3);
b) int arr(3) = {1,2,3};
c) int arr[3] = {1,2,3};
d) int arr(3) = (1,2,3);
Q5: When does the Array Index Out Of Bounds Exception occur?
a) Compile-time
b) Run-time
c) Not an error
d) Not an exception at all
Ans. ArrayIndexOutOfBoundsException is a run-time exception and the
compilation is error-free.
Q6: Which of the following concepts make extensive use of arrays?
a) Binary trees
b) Scheduling of processes
c) Caching
d) Spatial locality
05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1
MCQ s
Q7: What are the advantages of arrays?
a) Objects of mixed data types can be stored
b) Elements in an array cannot be sorted
c) Index of first element of an array is 1
d) Easier to store elements of same data type
Q8: What are the disadvantages of arrays?
a) Data structure like queue or stack cannot be implemented
b) There are chances of wastage of memory space if elements inserted in an
array are lesser than the allocated size
c) Index value of an array can be negative
d) Elements are sequentially accessed

Q9: Assuming int is of 4bytes, what is the size of int arr[15];?


a) 15
b) 19
c) 11
d) 60

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


MCQ s
Q10: In general, the index of the first element in an array is __________
a) 0
b) -1
c) 2
d) 1
Q11: Elements in an array are accessed _____________
a) randomly
b) sequentially
c) exponentially
d) logarithmically
Q12: If time taken by an algorithm to run is more then that algorithm is
………………
Efficient/inefficient.
Q13: In case of Big Oh notation worst case is ………………… tightly Bound/
Loosly bound/ Efficient case

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


MCQ s
Q14: Performance of an algorithm depends on:
a) Time Complexity.
b) Space Complexity.
c) Both a and b.
d) None.
Q15: Roll Number of a student is an example of (Primary Key/Secondary Key).
Q16: True / False
Field is a subset of Record.
Q17: Record is …………………. of file.
Q18: Name of a student is an example of …………………… Key.
Q19: All the elements of an array are of …………………… type.
a) Same
e) Homogeneous
f) Heterogeneous
g) Both a and b.
05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1
MCQ s
Q20: When element is inserted into the array
a) Blank location is needed
b) No Blank location needed
c) One element is to be removed from the array
d) None of the Above.
Q21: When the Number of zero entries are more in a data matrix then it is called
………..
Q22: An array A[10] is a:
e) Linear array
f) Multi- dimensional array
g) 2 D array
h) 3 D array
Q23: An Array B[2,3] Is a:
i) Linear array
j) Multi- dimensional array
k) 2 D array
l) 3 D array
05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1
MCQ s
Q24: An Array C[1.3.2,5] is a:
a) Linear array
b) Multi- dimensional array
c) 2 D array
d) 3 D array

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Glossary Questions
Fill in blanks using following Glossary words:

basic , collection of nodes, sequential, data, address,single address

Singly linked list


• Singly linked list is a ...........linked list type.
• Singly linked list is a ............................... linked together in a ...................... way where
each node of singly linked list contains a ......... field and an ............. field which contains
the reference of the next node.
• Singly linked list can contain at least ............ field pointing to its connected next node.

Nidhi Sharma AOE0662 Data Structures Unit 1


UNIT 1 Updated Assignment
BLOOM’S
Q.N. Question Statement Marks CO
KNOWLEDGE LEVEL

Find the location of A [2, 3]. The required values are:Base (A) = 1000W = 2 (because
1 10 CO2 K1,K2
an integer takes 2 bytes in memory)M = 3J = 3K = 2

2 Distinguish between a linked list and a doubly linked list. 10 CO2 K1,K2

How do you find the complexity of an algorithm? What is the relation between the
3 10 CO2 K1,K2,K3
time and space complexities of an algorithm? Justify your answer with an example.

A 2D array is defined as BOOK[3:7,-1,4]required 4 words per memory cell.


4 Find the location of BOOK[5,2]if the array is implemented in row major 10 CO2 K1,K2
order. The base address is given as 200.

5 Describe Abstract Data Types. 10 CO2 K1,K2

Given a 2D array A[-100:100, -5:50]. Find the address of element A[99,49]


6 consideringBase address is 10 & each elements require 4 bytes for storage.a) 10 CO2 K1,K2
Row major method b) Column major method

Given the base address of an array B[1300…..1900] as 1020 and size of each
7 10 CO2 K1,K2
element is 2 bytes in the memory. Find the address of B[1700].

8 Write an algorithm to insert an node after a given node with diagram. 10 CO2 K1,K2

Find the base address of an array A[-15:65]. The size of each element is 2
9 10 CO2 K1,K2,K3
bytes in the memory and the location of A[37] is 4279.

An array X [-15……….10, 15……………40] requires one byte of storage. If


beginning location is 1500 determine the location of X [15][20].
10 10 CO2 K1,K2,K3

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Old Question Papers
Q1: How index number is affected by insertion and deletion operation into the
array?
Q2: What is row major and column major order?
Q3: How the LOC is found in a linear array?
Q4: What are Character strings? Explain with suitable examples.
Q5: What do you mean by Sparse Matrix? Explain the types of Sparse Matrices.
Q6: What do mean by linear array and multi-dimensional array?
Q7: What is the difference between elementary data item and grouped data item?
Q8: What is primary Key and Secondary key? Give example of each.
Q9: Define Entity and Attribute with example.
Q10: Define traversing ,searching, sorting operations .
Q11: What is recurrence? Explain with the help of example.
Q12:How the arrays are represented in the memory of a computer? Explain 1D and
2D memory representation of an array.
Q13: What do you mean by performance of an algorithm? Explain Big Oh notation.

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Old Question Papers
Q1: How index number is affected by insertion and deletion operation into the
array?
Q2: What is row major and column major order?
Q3: How the LOC is found in a linear array?
Q4: What are Character strings? Explain with suitable examples.
Q5: What do you mean by Sparse Matrix? Explain the types of Sparse Matrices.
Q6: What do mean by linear array and multi-dimensional array?
Q7: What is the difference between elementary data item and grouped data item?
Q8: What is primary Key and Secondary key? Give example of each.
Q9: Define Entity and Attribute with example.
Q10: Define traversing ,searching, sorting operations .
Q11: What is recurrence? Explain with the help of example.
Q12:How the arrays are represented in the memory of a computer? Explain 1D and
2D memory representation of an array.
Q13: What do you mean by performance of an algorithm? Explain Big Oh notation.

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Old Question Papers

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Old Question Paper

https://noidainstituteofengtech-
my.sharepoint.com/:b:/g/personal/
nidhisharma_niet_co_in/
EYRnv18D_TlNso22HXXGW3sBtHvazqQLJWEd7y
xtzwhrwA?e=RL0Vcs
05/12/2025Nidhi Sharma AOE0662 Data Structures Unit 1
Expected Questions for University Exam

Q1: What is row major and column major order?


Q2: What do you mean by Sparse Matrix? Explain the types of Sparse
Matrices.
Q3: How the arrays are represented in the memory of a computer? Explain
1D and 2D memory representation of an array.
Q4: What do you mean by performance of an algorithm? Explain Big Oh
notation.

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Recap
Performance analysis of an algorithm depends upon two factors i.e. amount of
memory used and amount of compute time consumed on any CPU. Space
Complexity and Time Complexity.

Time Complexity
Time Complexity of an algorithm(basically when converted to program) is the
amount of computer time it needs to run to completion. The time taken by a
program is the sum of the compile time and the run/execution time .

Big oh notation (O)- Worst Case (Tightly Bound) – e.g. O(1), O(n), O(n 2 ),
O(n 3 ), O(n n ), O(log n), O(n log n)

Data
Data can be defined as a representation of facts, concepts or instructions in a
formalized manner suitable for communication.

Data Item (Field)


A set of characters which are used together to represent a specific data element
05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1
Recap
Record
Record is a collection of related data items.

File (Data File)


File is collection of logically related records.

Entity:
An entity is a person, place, thing, event or concept about which information
recorded.

Attribute:
Attributes gives the characteristics or properties of the entity.

Data Value:
A data value is the actual data or information contained in each attribute.

Entity Set
Entities with similar attributes form an entity set.
05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1
Recap

Primary Key: A field or collection of fields in a record which identifies a record


uniquely is called a primary key or simply key.

Secondary Key: A field in a record which identifies the records but not
uniquely is called a secondary key.

Data Structure Operations


(1) Traversing: Accessing each records exactly once so that certain items in
the record may be processed.
(2) Searching: Finding the location of a particular record with a given key
value, or finding the location of all records which satisfy one or more
conditions.
(3) Inserting: Adding a new record to the structure.
(4) Deleting: Removing the record from the structure.
(5) Sorting: Managing the data or record in some logical order(Ascending or
descending order).
(6) Merging: Combining the record in two different sorted files into a single
sorted file.
05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1
Recap
Recurrence
A Recurrence is defined as a function by means of an expression that includes
one or more (smaller) instances of itself.

Array
An array is a collection of items stored at contiguous memory locations.

Array Operations
Traverse − print all the array elements one by one.
Insertion − Adds an element at the given index.
Deletion − Deletes an element at the given index.

Representation of Linear Arrays in Memory:


In linear array the declaration statements tell how many cells are needed to
store the array.
to calculate the number of cells needed and
to find the location or address of any element of the array.

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Recap
For Linear array
LOC (LA[K]) = Base(LA) + W(K-LB)

For 2D array
Column Major order
LOC (A [J, K]) = Base (A) + w [M (K-1) + (J-1)]

Row Major Order


LOC (A [J, K]) = Base (A) + w [N (J-1) + (K-1)]

Sparse Matrices
Sparse matrices are those matrices whose most of the entries are zero.
Character Strings.

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1


Noida Institute of Engineering and Technology,
Greater Noida

Thank You

05/12/2025 Nidhi Sharma AOE0662 Data Structures Unit 1

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy