You are on page 1of 33

NAME : P SURYA NARAYANA

SUBJECT : SUMMER INTERNSHIP

SECTION : K18UW

REG NO : 11802507

COURSE CODE : CSE443

TOPIC : DSA SELF PACED


Course Completion Certificate
INTRODUCTION

TOPICS
Analysis of algorithm
RECURSION
Data structures
SEARCHING
SORTING
Data structures:

A data structure is a particular way of organizing data so that it can be


used effectively.

Algorithms:
Store and retrieve data in most efficient way.
Asymptotic Notations
Asymptotic notations are mathematical tools to represent the time complexity
of algorithms for asymptotic analysis.
There are mainly three asymptotic notations:
Theta notation
Omega notation
Big-O notation
Theta Notation (Θ-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.
Θ(g(n)) = { f(n): there exist positive constants c1, c2 and n0
such that 0 ≤ c1g(n) ≤ f(n) ≤ c2g(n) for all n ≥ n0 }
Big-O Notation (O-notation)
Big-O notation represents the upper bound of the running time of an
algorithm. Thus, it gives the worst case complexity of an algorithm.
O(g(n)) = { f(n): there exist positive constants c and n0
such that 0 ≤ f(n) ≤ cg(n) for all n ≥ n0 }
Omega Notation (Ω-notation)
Omega notation represents the lower bound of the running time of an
algorithm. Thus, it provides best case complexity of an algorithm.
Ω(g(n)) = { f(n): there exist positive constants c and n0
such that 0 ≤ cg(n) ≤ f(n) for all n ≥ n0 }
What is Recursion?
The process in which a function calls itself directly or indirectly is called
recursion and the corresponding function is called as recursive function. Using
recursive algorithm, certain problems can be solved quite easily.
Examples of such problems are Towers of Hanoi (TOH),
Inorder/Preorder/Postorder Tree Traversals, DFS of Graph, etc.
i
nt fact(int n)
{
if (n < = 1) // base case
return 1;
else
return n*fact(n-1);
}
Data structures
• Data structures has two types:
Linear
Non Linear
linear data structures
•Data structure where data elements are arranged sequentially
or linearly where the elements are attached to its previous and
next adjacent in what is called a linear data structure.
• Array
• Linked list
•Stack
•Queue
Array: An Array is a collection of data items having similar data
types.
Linked list
A Linked list is a collection of nodes, where each node has a data
element and a reference to the next node in the sequence.

Applications of linked list:


1) Polynomial addition
2)Polynomial multiplication
Types of Linked List
• Simple Linked List − Item navigation is forward only.

• Doubly Linked List − Items can be navigated forward and backward.


• Circular Linked List − Last item contains link of the first element as
next and the first element has a link to the last element as
previous.
Stack
A Stack is a FILO (First In Last Out) data structure where the element that
is added first will be deleted last.
push() − Pushing (storing) an element on the stack.
pop() − Removing (accessing) an element from the stack
Queue

A Queue is a FIFO (First in First Out) data structure where the


element that added is first will be deleted first.
enqueue() − add (store) an item to the queue.
dequeue() − remove (access) an item from the queue.
Non linear data structure
Data structures where data elements are not arranged sequentially or
linearly are called non-linear data structures.
Tree
A Tree is a collection of nodes where these nodes are arranged
hierarchically and form a parent-child relationship.
• Path − Path refers to the sequence of nodes along the edges of a tree.

• Root − The node at the top of the tree is called root. There is only one root per tree
and one path from the root node to any node.

• Parent − Any node except the root node has one edge upward to a node called parent.

• Child − The node below a given node connected by its edge downward is called its
child node.

• Leaf − The node which does not have any child node is called the leaf node.

• Subtree − Subtree represents the descendants of a node.


Graph
A Graph is a collection of a finite number of vertices and edges. Edges connect the
vertices and represent the relationship between the vertices that connect these vertices.

In the above graph,

V = {a, b, c, d, e}

E = {ab, ac, bd, cd, de}


SEARCHING
There are two types of searching
1)linear search
2)binary search

linear search
Linear search is a very simple search algorithm. In this type of search, a
sequential search is made over all items one by one. Every item is
checked and if a match is found then that particular item is returned,
otherwise the search continues till the end of the data collection.
Binary Search
Binary Search is a searching algorithm for searching an element in a
sorted list or array. Binary Search is efficient than Linear Search algorithm
and performs the search operation in logarithmic time complexity for
sorted arrays or lists.
compare key value to mid of the element
mid=(l+r)/2
low=mid+1
high=mid-1
SORTING
Sorting refers to arranging data in a particular format.

real-life scenarios

Telephone Directory − The telephone directory stores the telephone numbers


of people sorted by their names, so that the names can be searched easily.

Dictionary − The dictionary stores words in an alphabetical order so that


searching of any word becomes easy.
Sorting types
• Bubble sort
• Quick sort
• Insertion sort
• Selection sort
• Merge sort

Bubble sort
Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in wrong order.
• Example:
• First Pass:
• ( 5 1 4 2 8 ) –> ( 1 5 4 2 8 ), Here, algorithm compares the first two elements, and swaps since 5 > 1.
• ( 1 5 4 2 8 ) –> ( 1 4 5 2 8 ), Swap since 5 > 4
• ( 1 4 5 2 8 ) –> ( 1 4 2 5 8 ), Swap since 5 > 2
• ( 1 4 2 5 8 ) –> ( 1 4 2 5 8 ), Now, since these elements are already in order (8 > 5), algorithm does not swap them.

• Second Pass:
• ( 1 4 2 5 8 ) –> ( 1 4 2 5 8 )
• ( 1 4 2 5 8 ) –> ( 1 2 4 5 8 ), Swap since 4 > 2
• ( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )
• ( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )
• Now, the array is already sorted, but our algorithm does not know if it is completed. The algorithm needs one whole pass without
any swap to know it is sorted.

• Third Pass:
• ( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )
Insertion sort
Insertion sort is a simple sorting algorithm that works similar to
the way you sort playing cards in your hands. The array is
virtually split into a sorted and an unsorted part. Values from the
unsorted part are picked and placed at the correct position in the
sorted part.
Selection Sort
The selection sort algorithm sorts an array by repeatedly finding the
minimum element (considering ascending order) from unsorted part
and putting it at the beginning.
The algorithm maintains two subarrays in a given array.

1) The subarray which is already sorted.


2) Remaining subarray which is unsorted.
QuickSort

QuickSort is a Divide and Conquer algorithm.


It picks an element as pivot and partitions the given array around the
picked pivot.
There are many different versions of quickSort that pick pivot in
different ways.

Always pick last element as pivot (implemented below)


Merge Sort
Merge Sort is a Divide and Conquer algorithm.
It divides input array in two halves, calls itself for the two halves and then
merges them in a sorted manner.
.

THANK YOU

You might also like