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

NOTES

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

NOTES

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

strings are the sequence of characters

strings are non primitive data type


strings are immutable which cannot be changed
There are two classes of the string:
string buffer - s ="abc" or String Buffer sb = new String Buffer("abc");// memory
in the ram.
string builder - StringBuilder S = new StringBuilder("abc"); - string is passed to
the constructor of string builder.
Task -
methods of the stringbuilder.
STRING MATCHING ALGORITHM:

String matching algo are used to find the occurrence of a substring(pattern)


within another string(text).
Naive string matching algorithm.
here the pattern is compared is compared with each substring to the next.
Time complexity O(n-m+1)*m) where n is the length of the text and m is the length
of the pattern.

LINKEDLIST :
A LinkedList is a linear data structure where elements are stored in nodes with
each node pointing to the next.
TYPES:
1.Singly LinkedList - consist of data and address to the next node ,single
direction ,collection of data and next.
class Node{
int data;
Node next;
Node(int data){
this. data = data;//parameterised constructor.

this.next = null;
}
}

2.Doubly linkedlist - consist previous data and next. two direction traversal is
possible.

3.Circular linked list - we create the loop , at the last element next we store
the head node.
STACK:
Stack is a linear data structure that follows the Lifo principle.
Common operations: push(insert),pop(delete),peek ,isEmpty.
underflow - when the stack is empty and we perform the pop operation
overflow - if isFull is true and we try to push new data then the condition is
termed as overlflow.
class Stack{
private int maxSize;
private int[] stackArray;
private int top;
public satck(int size){
this.maxSize = size;
this.stackArray = new int[maxSize];
this.top = -1;
}
}
PUSH OPERATION:
adds an element to the top of the stack.
increases the top pointer.
public void push(int value){
if(top == maxsize -1){
System.out.println("stack is empty");
return -1;
} else
[
return stackArray[++top] = value;

}
}
TASK :
1. Practice stack problem.
QUEUE:
A queue is a linear data structure that follows the fifo principle.
common operation: enqueue,dequeue,front rear, isEmpty.
Use cases: Printer queue management ,cpu task scheduling, bfs in graphs.
TYPES OF QUEUE:
Simple queue. - linear queue ,follows the fifo, enqueue, dequeue,
front,rear,isEmpty,isFull.

circular queue - front and rear pointers wrap around when they reach the end of the
array.
overcome the limtations of unused space in a simple queue.
enqueue, dequeue, front,rear, isempty,isfull.
priority queue - elements are added in the priority.

double ended queue(deque). - elements can be added.


functions : addfirst,adddlast,removelast,peekfirst,peekalast.
TASK :
practice questions on queue.
GRAPH:
A graph is a collection of nodes and edges connecting pairs of nodes.
Applications : social networks, transportation ntworks we apge ranking.
types of graphs : directed , undirected,weighted,unweighted.

Vertex: Fundamental part of the graph.


node: connection between two vertices.
Adjacency : two vertices area adjacent if they are connected to a edge.

real world applications:


Social networks
routing algorithms
web page ranking (googles pagerank)
biology(protein interaction networks)
REPRESENTATION OF GRAPHS:
Adjacency matrix: a 2d array to represent edges.
Adjacency list : an array of lists to represent edges.
static class Edge{
char src;
cahr dest;
public Edge(char c,char d)
this.src = s;
this.dest = d;
this.wt = w;
ARRAYLIST:
ArrayList<Data-type>lst-new ArrayList<>();
get(i);
return(i);
add(i);
adds value to list.
BFS:
bfs explores all neighbours at the present depth before moving on to the nodes at
the next depth level.
uses a queue.
DFS:
dfs explores as afar as possible along each branch before backtracking
uses a stack .
Weighted Graph and Dijkstra algorithm:
a weighted graph or a network is a graph in which a number is assigned to each edge
DIJKSTRA ALGORITHM:
single source shortest path algorithm.
It is a greedy algorithm.
does not work on negative weights.
dist: 0 1 2 3 4 5
Priority Queue:
insertion from rear end and deletion from the front end.
highest element has the priority.
interfaces is used in java by using the implements keyword.
interface contain method declaration not its implementation.
@override - denotes the annotation
public int compareTo(pair o) - object class
task :
bellmanford algorithm
problems on graph
TREE:
A tree is also a graph which is a hierachical data structure consisting of nodes
with asingle node called the root.
Applications: File System , databases , HTML/XML parsing etc.
Properties : no cycles , connected graph , N nodes have n-1 edges.
Binary Tree:
each nide has atmost two children.
Binary search TREE: a binary tree where each node has a value greater than all
values in its left subtree and less than those in its right subtree
AVL tree: balanced binary tree.
Binary Tree:
class TreeNode{
int val;
Treenode left;
TreeNode right;
TreeNode(int x){
val = x;
}
}
TREE traversal
preorder:
root left right
inorder:
left root right
Binary Search Tree: O(1).
have atmost two children.
O(N). - BINARY TREE time complexity.
binary tree where each node has a value gretaer than all values in its left subtree
and less than the those in its right subtree.
operation: insertion , deletion, search
AVL TREE: time complexity o(h).

An avl tree is a self balaancing binary search tree where the difference in height
etween the left and right subtree of any is atmost one.
balancing the tree and amke it efficient.
balancing ensures that the tree remains balanced and maintains effiecient
operations.
class TreeNode{
int val;
TreeNode left;
Treenode right;
int height;
TreeNode(int x) {
val = x;
height = 1;
}

}
balancing factor : height of left subtree - height of right subtree.
range of balance factor = 0,1,-1.
disadvantages: hard to implement.
takes more processing time for balancing.
left rotation:
DIVIDE AND CONQUER:
CASE : 1 if arr[mid] == key
return mid+1;
case : 2 i f arr[mid] >key
if arr[mid] <key
return = mid+1;

adjacency list:
ArrayLidt<edge> graph[v].
Dynamic programmimng:
is a method for solving complws problems by breaking them doen into simpler
subproblems
it involves storing the results of the subproblems to avoid redundant calculations.
0/1 knapsack:

You might also like