0% found this document useful (0 votes)
8 views6 pages

UNIT 1 Ds

The document discusses asymptotic notations used for analyzing algorithm complexity, including Big Oh (O), Big Omega (Ω), Big Theta (Θ), and little o notation. It also explains the structure and implementation of a Doubly Linked List (DLL) in C, detailing insertion methods at the beginning, end, and middle of the list. Additionally, it provides code snippets for these operations.
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)
8 views6 pages

UNIT 1 Ds

The document discusses asymptotic notations used for analyzing algorithm complexity, including Big Oh (O), Big Omega (Ω), Big Theta (Θ), and little o notation. It also explains the structure and implementation of a Doubly Linked List (DLL) in C, detailing insertion methods at the beginning, end, and middle of the list. Additionally, it provides code snippets for these operations.
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/ 6

UNIT 1 )

Q1) all types of notations ( theta, 0 , big 0) – 100%


Ans) Asymptatic notation are used to represent the
complexity for an algorithm for asymptotic analysis. These
notations are mathematical tools to represent the
complexity
Following notations are used to calculate the running time
complexity of an algorithm.
- 1 ) Big Oh (0) – notation –
The 0-notation gives an upper bound for a function
within a constant factor i.e when we have only an
asymptotic upper bound, we use 0 notation
f(n)=O(g(n)) means that for large enough n, the
function f(n) grows at most as fast as g(n) up to a
constant factor.
- 0 - notation is used for worst case complexity
- The value of f(n) always lies on below (g(n) after no.

- Example: If f(n)=3n2+5n+7 , we can say f(n)=O(n2)


2) Big omega (Ω) -
Describes a lower bound on the time or space
complexity of an algorithm. It gives the best-case
scenario. f(n)=Ω(g(n)) means that for large enough n,
the function f(n) grows at least as fast as g(n) up to a
constant factor

Example: If f(n)=n2+2n , we can say f(n)=Ω(n2)


- Big theta (Θ) notation –
Θ bounds a function to within constant factors
For given g(n) functions we have
f(n)=Θ(g(n)) means that for large enough n, the
function f(n) grows at the same rate as g(n) up to
constant factors (i.e., f(n) is bounded both above and
below by g(n).

- Little o Notation (o)-


Describes an upper bound that is not tight. It means
that the function grows strictly slower than the
function it is compared to.
(n)=o(g(n)) means that for large enough n, the
function f(n) grows strictly slower than g(n)
Example: If f(n)= n we can say f(n)=o(n^2) because n
grows strictly slower than n^2.

Ques – IMPLEMENTAION OF DOUBLY LINKED LIST


INSERTION, DELETION, AND ALL OPERATIONS.
(101%)
ANS- A Doubly Linked List (DLL) is a type of linked
list where each node has two pointers: one pointing
to the next node and one pointing to the previous
node. This allows for traversal in both directions
(forward and backward).
Basic Structure of a Node in a Doubly Linked List:
Each node in a doubly linked list typically contains:

Data: The value stored in the node.


Next Pointer: A pointer to the next node in the list.
Prev Pointer: A pointer to the previous node in the list.
BASIC STUCTURE OF THE CODE

#include <stdio.h>
#include <stdlib.h>

// Define the structure of a node in a doubly linked list

struct Node {

int data; // Data in the node


struct Node* next; // Pointer to the next node
struct Node* prev; // Pointer to the previous node
};

// Define the doubly linked list


struct DoublyLinkedList {
struct Node* head; // Head of the list
};

INSTERTION –
We will create different insertion functions for:

Insert at the beginning


Insert at the end
Insert after a given node.
a)instertion at beginning

C IMPLEMENTAION –

Struct node * newnode * ptr;

newnode = (struct node *)malloc(sizeof(struct node));

ptr = start;

printf(“enter the value=”);

scanf(“%d”,&newnode ->info);

newnode ànext = NULL;

newnodeàprev = NULL;

newnode àNEXT = start;

ptr àprev = newnode;

start = newnode;

b) instertion at end:-

C IMPLEMENTATION

Struct node * newnode * ptr;

newnode = (struct node *)malloc(sizeof(struct node));

printf(“enter the value=”);

scanf(“%d”,&newnode ->info);

newnode ànext = NULL;

newnodeàprev = NULL;

ptr = start;

while(ptr ànext ! = NULL)

Ptr = ptr ànext;

Ptr à next = newnode;

Newnode àprev = ptr;


c) insertion at middle ;-

struct node* newnode * temp;

int pos i ;

newnode = (struct node*)malloc(sizeof(struct node));

printf(“enter the value=”);

scanf(“%d”, &newnode à info);

newnode -> next = NULL;

newnode à prev = NULL;

printf(“enter the postion = “);

scanf(“%d”,%pos);

temp= start;

for ( I = 2, I < pos; I ++)

If ( temp à next ! = NULL)

Temp = temp à next;

Temp à next à prev = newnode

Newnode à next = temp à next;

Temp à next = newnode;

Newnode à prev = temp;


DELETION
FROM BEGINNING –
Struct node

You might also like