0% found this document useful (0 votes)
36 views13 pages

Data Structures and Algorithms Overview

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

Data Structures and Algorithms Overview

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

Basic Terminology Description

Data is row facts and figures. It is a value or a set of


Data value.
Ex: Name = “Ram”, x = 60;
Data item is a single unit value.
Data Item Ex: Name = “Ram”. (Difference is that here is only one data no more
than one value like data)
The data item which can be divided in sub items is
called Group data item.
Group Data Item Ex: Date of birth of a student as it can be divided into
day, month and year.
The data item which can’t be divided in sub items
Elementary Data Item called Elementary Data Item.
Ex: Age of a Student
An entity is a specific thing which has attributes. Entity
Entity And Attributes has its own identity.
Ex: Student
Entities of similar attributes form an entity set.
Entity Set Ex: 2 Students of Similar attributes
Field Field is a single value of an attribute of entity.
Record is the collection of field, it represent a
Record complete row of a file.
File File is a collection of records.

Data Structure:
Data structure is a systematic way to organise data in order to use it
efficiently.
FOUNDATION TERM:
1. Interface
2. Implementation

Interface: Each data structure has an interface. Interface represents the


setup operation that a data structure support.
Implementation: Implementation provides the internal representation of
data structure. It also provides definition of the algorithms used in the
operation of the data structure.
Characteristics of Data Structure:
1. Correctness: Data structure implementation should implement it’ s
interface correctly.
2. Time Complexity: Running time or the execution time of an
algorithm of the data structure must be as small as possible.
3. Space Complexity: The memory usage of a data structure operation
should be as little as possible.
4. Linear or non-Linear: Whether data items are arranged in a specific
order or in unorder sequence.
5. Homogenous or Heterogenous: Whether all data items are of same
type or various type.

Operations On Data Structure:


1. Traversing: Traversing a data structure means to visit the element
stored in it. It visits data in systematic manner. (Going from one point to another
point in array)

2. Selection: Selection operation is used to select a data from


present data (available data).
3. Updation: This operation updates data in the data structure.
4. Merge: Merging data of two different table in a single table or
specific order presentation is performed by this operation.
5. Split-Data: This is the process to divide data into different sub
parts to make the process complete in less time.
6. Insertion: It is the operation we can apply on all data structure.
Insertion means to add a data element in the given data
structure.
7. Deletion: It is the operation applied in all data structure. Deletion
means delete a data item from the given data structure.
8. Sorting: Sorting is the operation to sort list of data items in a
specific order (ascending or descending).
9. Searching: Searching means to find a particular element in the
given data structure. It is considered as successful when the
required element is found.

Classification of Data-Structure

Primitive Non-Primitive
Integer Linear Non Linear
Float Array, Linkedlist, Stock, queue Tree, Graph, Hash

Character
Boolean

ALGORITHM:
An algorithm is a process or setup rules required to perform calculations
or some other problem solving operations specially via computer.
It contains the finite set of instructions which are being carried in a
specific order to perform the specific task.
Characteristics of Algorithm:
1. Input: An algorithm has some input values.
2. Output: We Will get one or more output at the end of the
algorithm.
3. Finiteness: Finiteness means that the algorithm should contain a
limited number of instructions.
4. Unambiguity: An algorithm should unambiguous which means that
the instructions in an algorithm should be clear and simple.
5. Effectiveness: An algorithm should be effective as each instruction
in an algorithm affects the overall process.
6. Language Independent: An algorithm must be language
independent so that the instructions in an algorithm can be
implemented in any of the program language.

Sub-Algorithm:
A sub algorithm is just an algorithm that is used as a part of another
algorithm. One of the most important strategy to solve a problem is
“Divide And Conquer” breaking down a problem into sub problems that
are easier to solve. Sub-Algorithm can solve a specific small problem.
It is independent defined algorithmic module. It is used by some main
algorithm or by other sub-algorithm. It can receive the value and gives the
result to the calling algorithms.

Control Structure Used In Algorithm:


An algorithm has finite number of steps, steps may involve following
control structure:
1. Sequence
2. Decision
3. Repetition

1. Sequence: It means that each step of an algorithm is executed in a


specified order.
Ex: Algorithm to add two numbers:
Step 1: Begin
Step 2: Input first number as A
Step 3: Input second number as B
Step 4: Set Sum = A+B
Step 5: Print Sum
Step 6: End
Above algorithm performs the steps in a purely sequential order.

2. Decision: decision statement are used when the execution of a


process depends on the outcome of some conditions.
Ex: Algorithm to check equality of two numbers:
Step 1: Begin
Step 2: Input First number as A
Step 3: Input Second number as B
Step 4: If A = B
Print “Equal”
Else
Print “Not Equal”
Step 5: End

3. Repetition: Repetition, which involves executing one or more steps


for a number of times, can be implemented using construct such as
for, while, Do-while loops.
Ex: algorithm to print the first 10 natural numbers:

Step 1: Begin
Step 2: Set I = 1 and N = 10
Step 3: Repeat Step 4 & 5 while I <= N
Step 4: print I
Step 5: Set I = I + 1
Step 6: End

Ques:

1. Write an algorithm to find larger number among any two-given


number.
2. Write an algorithm to check whether a given number is prime or
not.
3. Write an algorithm to find Fibonacci series up to nth terms.

Complexity:
Complexity is a measure of how difficult a problem or solution is. In data
structure, algorithms of sorting, searching are measured to find it’ s
performance.
There are two types of complexities:
1. Time complexity
2. Space Complexity
Time complexity: It measures how long it take to execute an operation on
data structure. Such as inserting, deleting, searching or sorting.
Space complexity: It refers to the amount of memory space used by
algorithm including the space of input values for execution.

Performance analysis and measurement of


an algorithm:
An algorithm must be able to solve the problem in an efficient manner as
much as possible. Determining which algorithm is efficient than the other
depends upon the analysis of algorithms. Analysis of algorithm provides
Information that gives us a general idea of how long an algorithm will take
for solving a problem.

Complexity
Related to Cases
Space Complexity Time complexing Best case Average case Worst Case

Complexity
O (Big oh) Q(Theta) Ω(omega)
Asymptotic/mathematical notations are used to describe the time
complexity in numerical form.
Generally, three types of notations are used to describe complexities of an
algorithm
1. Theta Notation
2. Big oh Notation
3. Omega Notation

Theta(O) notation: For a given function g(n) we can denote it by


Theta(g(n)).

There exist positive constant c1, c2 and n0 such that 0 <= c1.g(n)<= f(n)<=
c2.g(n).
For all n > n0 f(n) = O(g(n)).

Big oh notation: For a given function g(n), we can denote it by O(g(n)) and
for set of functions
O(g(n)) = {f(n)}
There exist positive constants c & n0
For all n > n0
O <= f(n) <= g(n)
Ω (omega) notation: For a given function g(n) we can denote it by Ω(g(n))
and for set of functions
Ω(g(n)) = {f(n)}
There exist positive constants c and n0
For all n > n0
0 <= g(n) <= f(n)
f(n) = Ω(g(n))
UNIT 2

Searching:
Searching is the process to find a intended/specific data from a database.
Two types of searching algorithm is generally applied in data structure.
1. Linear search
2. Binary search

Linear Search:
Linear search is a very simple searching algorithm applied in ordered or
un-ordered / sorted or un-sorted list of data.
Algorithm of linear search:
Step 1: Begin
Step 2: Read ARRAY and NUM (variable).
Step 3: Declare variable I, LOC, N and FOUND.
Step 4: SET I = 0, LOC = 0 and FOUND = 0.
Step 5: Repeat step 6 while I < N (size of array) – 1.
Step 6: if NUM = ARRAY
Then SET FOUND = 1
And LOC = I
Break the loop.
Step 7: if FOUND = 1
Then print “Element NUM found at Position LOC”
Else print “Element NUM not found in the list”.
Step 8: END.
Que1: Write the occurrence of you searching data in your given data list.
Que2: For a given array. Find the first and last occurrence of your
searching data.
Array: 5, 8, 120, 60, 120, 120
Search: 120.

Binary Search:
It is a popular searching method of data structure, applied in ordered list.
It works on “divide and conquer” principle in which list is divided in two
parts in each step and process goes on until the intended data is found or
list is completely processed. This search is applied only on ordered list.

Algorithm of Binary Search:


Step 1: Begin
Step 2: Read arr and NUM.
Step 3: Declare variables: I, LOW, HIGH, MID
Step 4: Set LOW = 0, HIGH = N – 1
Step 5: Repeat the given process till I <= N – 1
If HIGH >= LOW: MID = (LOW + HIGH) / 2
If arr [MID] = NUM: print Data element Occur at LOC MID
Break.
Else if NUM < arr [MID]: Set HIGH = MID – 1
Else: Set LOW = MID + 1
Else: Data Element NUM doesn’t exist in the data list.
Break If – Else
Break loop
Step 6: End.
Time complexity:
N = 32
1st pass = n / 2 = 16
2nd pass = n / 22 = 8
3rd pass = n / 23 = 4
4th pass = n / 2k = 1
Or n = 2k
Take log both side
Log2n = log32k or log2n = k(log22).

Sorting:

Sorting is a process to arrange data elements of a list in a particular order

(ascending of descending). There are many algorithms generally

supported by data structures to sort the data elements, some of them are

given below:

1. Bubble Sort

2. Insertion sort
3. Selection sort

4. Quick sort

5. Merge sort

6. Heap sort

Bubble Sort:

Bubble sort is a sorting technique that is easy to implement but not very
efficient. In bubble sort, basic strategy is that each element is compared
with adjacent element. If first element is larger then second element then
interchange the locations of first and second elements, otherwise they
will not interchange. Then next element is compared with it’s adjacent
element and the same process is repeated for all the elements in the
array.
Node * insert(node * root, int value) {

If (value == NULL){return; }

If (root -> key < value) {

Root -> right = insert (root -> right, value);

} else {

Root -> left = insert(root-> left, val);

Return root;

You might also like