UNIT- 1 (IQ)
UNIT- 1 (IQ)
2 MARKS:
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.
Types of ADTs:
List ADT
Stack ADT
Queue ADT
Traversal
Search
Insertion
Deletion
Sorting
Merge
Create
Selection
Update
Splitting
16 MARKS:
A data structure that preserves a linear connection among its data elements
is known as a Linear Data Structure.
The following is the list of Linear Data Structures that we generally use:
1. Arrays
2. Linked Lists
Stack is a Linear Data Structure that follows Last In First Out (LIFO)
principle.
Insertion and deletion can be do neat only one end of the stack called
TOP of the stack.
Example:-Pile of coins, stack of trays.
Non-Linear Data Structures are data structures where the data elements are
not arranged in sequential order. Here, the insertion and removal of data are
not feasible in a linear manner. There exists a hierarchical relationship
between the individual data items.
The following is the list of Non-Linear Data Structures that we generally use:
Trees:
Figure 9. A Tree
2. Graphs
G = (V,E)
Big-O notation
Omega notation
Theta notation
Theta notation encloses the function from above and below. Since it
represents the upper and the lower bound of the running time of an
algorithm, it is used for analyzing the average-case complexity of an
algorithm.
LIST ADT:
If the element at position i is Ai, then its successor is Ai+1 and its
predecessor is Ai-1
Array:
A set of data elements of same data type is called array. Array is a static
data structure i.e., the memory should be allocated in advance and the size
is fixed. This will waste the memory space when used space is less than the
allocated space. An array implementation allows the following operations
a. Creation of a List.
Create Operation:
Create operation is used to create the list with „ n „ number of elements .If
„ n „ exceeds the arrays max size, then elements cannot be inserted into the
list. Otherwise the array elements are stored in the consecutive array
locations (i.e.) list [0], list [1] and so on.
void Create ( )
int i;
for(i=0;i<n; i++)
scanf ("%d",& list[i]);
20 10 30 40 50 60
Insert Operation:
void Insert( )
{
int i,data,pos;
printf("\nEnter the data to be inserted:\t");
scanf("%d",&data);
printf("\nEnter the position at which element to be inserted:\t");
scanf("%d",&pos);
if (pos==n)
printf (“Array overflow”);
for(i = n-1 ; i >= pos-1 ; i--)
list[i+1] = list[i];
list[pos-1] = data;
n=n+1;
Display();
}
Consider an array with 5 elements [ max elements = 10 ]
10 15 20 30 40 50
void Delete( )
{
int i, pos ;
printf("\nEnter the position of the data to be deleted:\t");
scanf("%d",&pos);
printf("\nThe data deleted is:\t %d", list[pos-1]);
for(i=pos-1;i<n-1;i++)
list[i]=list[i+1];
n=n-1;
Display();
}
10 20 30 40 50
10 30 40 50
Search Operation:
Search ( ) operation is used to determine whether a particular element is
present in the list or not. Input the search element to be checked in the list.
#include <stdio.h>
int main() {
// Define an array
printf("\n");
arr[i + 1] = arr[i];
arr[2] = insertElement;
printf("\n");
printf("\n");
arr[2] = updateElement;
printf("\n");
int searchElement = 3;
int found = 0;
if (arr[i] == searchElement) {
found = 1;
break;
if (found) {
printf("Element found\n");
} else {
arr[i] = arr[j];
arr[j] = temp;
printf("\n");
return 0;
Output:
Original Array: 1 2 3 4 5
Sorted array: 1 2 4 5 20
--------------------------------
Polynomials Definition
Types of Polynomials:
Polynomials are classified based on the number of terms they contain, and
they can be divided into the following categories:
Monomial: A polynomial with only one term is called a Monomial, and it
must not be zero.
Examples: 2x, 5x3, 10
Binomial: A polynomial with two terms is called a binomial. It can be
expressed as the sum or difference of two or more monomials.
Examples: 3x4 + 4x, 5y3 + 3x, xy3 + 3y
Trinomial: A polynomial with three terms is referred to as a trinomial.
Examples: 5x2 + 4x + 10, 10y4 + 4x4 + 2x2, 7y2 + 3y + 10
Quadronomial: Polynomial containing 4 terms is called the Quadronomial.
Example: 3x2 + 2x + y3 – 11y, 13x3 – x + y2 – 4y, etc.
Operations on Polynomials:
There are four main polynomial operations which are:
Addition of Polynomials
Subtraction of Polynomials
Multiplication of Polynomials
Division of Polynomials
Addition of Polynomials
When adding polynomials, it is important to combine the like terms,
which means adding the terms that have the same variable and
exponent. Adding polynomials will always yield a polynomial of the
same degree as the original polynomials being added.
Subtraction of Polynomials
Multiplication of Polynomials
Division of Polynomials
It is an arithmetic operation by which a polynomial is divided by
another polynomial in a known as polynomial division. For this
operation to succeed, the divisor polynomial must have a degree that
is less than or equal to the dividend polynomial.
There are several ways to divide polynomials, some of which include:
Long Division
Synthetic Division
Polynomial Division Using Factors
printf("Polynomial 1: ");
printPoly(poly1);
printf("Polynomial 2: ");
printPoly(poly2);
return 0;
}