0% found this document useful (0 votes)
11 views26 pages

Intro of DS

The document discusses data structures, defining them as organized formats for storing and managing data efficiently in computer systems. It differentiates between primitive and non-primitive data types, outlines operations like searching and sorting, and explains algorithms such as linear and binary search, including their complexities and applications. Understanding data structures is essential for optimizing code and improving program performance.

Uploaded by

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

Intro of DS

The document discusses data structures, defining them as organized formats for storing and managing data efficiently in computer systems. It differentiates between primitive and non-primitive data types, outlines operations like searching and sorting, and explains algorithms such as linear and binary search, including their complexities and applications. Understanding data structures is essential for optimizing code and improving program performance.

Uploaded by

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

Data Structure(CS-6301)

Presented By:-
Dr Suraj Srivastava
Data Structure
• A Data Structure is a particular way of
organizing and storing data in a computer so
that it can be accessed and modified
efficiently.
Data Structure
• In Computer Science, A data structures is a data organization, management , and storage
format that enables efficient access and modification.

• Data Structure is a means of arranging information systematically. With its help, we


convert any data into information. Due to which the systematic form of that group of
information is called Data Structure.

• In simple words, Data Structure (DS) is the systematization of data in memory. Under this,
any raw data is converted into some information. It serves to organize the data in a
sequence. The meaning of data structure is to save different types and groups of data in a
systematic way in the computer, that is, to manage it. You can also call it a type of
mathematical model, using which data is saved, so that it can be easily accessed when the
data is in a systematic form.

• Data Structure is the organized form of an Algorithm that works to organize a data. With
the help of this, we can define any information in its meaning or we can divide that
information according to some parameters.
Continue..
• Data structure is a way to store and organize data in a computer system.
So that we can use the data easily . That is, data is stored and organized
in such a way that it can be easily accessed at any time later.
• Data Structure is not a programming language like C, C++, Java, but it
is a set of algorithms that we use to structure data in programming
languages.
• Data structure is a main part of many computer science algorithms by
which programmers can handle data properly. It plays a very important
role in improving the performance of the program or software .
Why DS?
• This makes the processing of data very easy.
• If the programmer uses the right data structure, then he saves a
lot of his time and along with this he is able to save storage and
processing time as well.
• The data structure that is specified by an abstract data type
(ADT) provides abstraction. Due to which the client cannot see
the internal working of the data structure, so it does not need to
worry about the working part. The client can only see the
interface.
• Data structure provides reusability which means that many
clients can use the data structure.
Operation of DS
• Searching - The process of finding an element is called searching. There are
two algorithms to complete the search, first binary search and second linear
search.
• Sorting - The process of arranging the data structure in a particular order is
called sorting. There are many algorithms to perform sorting such as -
insertion sort, selection sort, bubble sort, radix sort etc.
• Insertion - The process of adding elements to a location is called insertion. If
the size of a data structure is n, then we can insert only n-1 elements in it.
• Deletion - The process of removing an element is called deletion. We can
delete data from any location.
• Traversing - Traversing means traversing each element of the data structure
to perform a particular task.
• Merging - Merging is the process of joining two lists containing similar data
elements together. From which we get a third list.
Explain what are the primary uses of
data structures?
Data structure is a way to store and organize
data in a computer system so that we can use the
data easily, that is, data is stored and organized
in such a way. that after that it can be easily
accessed at any time
Types of DS
• Data structures are closely linked with
primitive and non-primitive data types. Data
structures provide a way for programmers to
organize and manage data efficiently, by
choosing the appropriate data structure for the
task at hand. This can help optimize the code
and improve the performance of the
application.
Continue..
Continue..
Primitive Data Type
Primitive Data Type
These are basic data types that are built into a programming language and are generally considered the most basic data types. They
are called primitive because they are not composed of any other data types. Examples of primitive data types include integers, float,
characters, and boolean values.
Integer: It is a whole number that can be positive, negative, or zero. These are represented by the "int" data type.
Example of primitive data type:
C++:
int num = 10;

Float: It is a number with a decimal point that can be positive, negative, or zero. Floats are represented by the "float" or "double"
data type.
Example:
C++:
float num = 3.14;

Character: It is a single symbol, letter, or digit. These are represented by the "char" data type.
Example:
C++:
char letter = 'a';
Boolean: It is a data type that can have one of two values: true or false. These are represented by the "bool" data type.
Example:
C++:
bool isTrue = true;
Non-Primitive Data Type

• These are more complex data types that are composed of primitive data types or
other non-primitive data types. They are also referred to as composite data types or
reference data types. Examples of non-primitive data types include arrays, stacks,
queues, and trees.
Here, are some examples of non-primitive data types:
• Array: An array is a collection of elements of the same data type stored in
contiguous memory locations. Elements in an array can be accessed using their
index value.

• Example of Non-primitive data type:


• Stack: It defines the Last-In-First-Out (LIFO) principle. Elements are inserted and
removed from the top of the stack. Common operations on stacks include push
(insertion), pop (remove), peek (accessing the top element without removing it),
and checking if the stack is empty.
• Example:
Continue..
• Queue: It follows the First-In-First-Out (FIFO)
principle. Elements are inserted at the back of
the queue and removed from the front.
Common operations on queues include
enqueue (insertion), dequeue (removal), peek
(accessing the front element without
removing it), and checking if the queue is
empty.
• Example:
Continue..
• Tree: A tree is a collection of nodes, where each node has a value and
a set of zero or more child nodes. The topmost node in the tree is
called the root node, and every other node is connected to the root
node by a unique path. To represent hierarchical relationships
between data elements in a tree, they are:
• Root node: The topmost node in a tree.
• Child node: A node directly connected to another node when moving
away from the root.
• Parent node: A node directly connected to another node when
moving toward the root.
• Leaf node: A node without any children.
• Subtree: A smaller tree that is part of a larger tree.
• Example:
Key Difference between Primitive and Non Primitive Data Structure
Here, is the difference between primitive and non primitive data structure:

Primitive Data Non-Primitive Data


Structures Structures

1. These are complex


1. It has basic data types
data types composed of
in programming
one or more primitive
languages
data types

2. These are used to 2. These are used to


represent simple values represent more complex
such as integers, data objects such as
booleans, and arrays, queues, trees,
characters and stacks

3. It has a fixed size and 3. They can be resized or


range of values modified during runtime

4. These are defined by 4. These are defined by


the language the programmer

5. It is Immutable 5. It is mutable

6. These are stored in 6. These are stored in


the stack the heap
Conclusion

In conclusion, the difference between primitive and


non primitive data structure serve different purposes
in programming. Primitive data structures are
basically used to represent simple values, while non-
primitive data structures are used to represent more
complex data objects. Understanding the difference
between primitive and non primitive data structure
is essential for building efficient and effective
programs.
Linear Search
• Linear Search is defined as a sequential search algorithm that starts at one
end and goes through each element of a list until the desired element is
found, otherwise the search continues till the end of the data set

• How Does Linear Search Algorithm Work?


• In Linear Search Algorithm,
• Every element is considered as a potential match for the key and checked
for the same.
• If any element is found equal to the key, the search is successful and the
index of that element is returned.
• If no element is found equal to the key, the search yields “No match found”.
Algorithm
• LSEARCH(A,N,item)
1-LOC=-1
2-i=1
3-Repeat while i<=N and A[i]≠ item
i=i+1
4-If A[i]=item then
loc=I
5-Return loc
Complexity Analysis of Linear Search

• Time Complexity:
• Best Case: In the best case, the key might be present
at the first index. So the best case complexity is O(1)
• Worst Case: In the worst case, the key might be
present at the last index i.e., opposite to the end from
which the search has started in the list. So the worst-
case complexity is O(N) where N is the size of the list.
• Average Case: O(N)
• Auxiliary Space: O(1) as except for the variable to
iterate through the list, no other variable is used.
• Advantages of Linear Search:
• Linear search can be used irrespective of whether the array is sorted or not. It
can be used on arrays of any data type.
• Does not require any additional memory.
• It is a well-suited algorithm for small datasets.
• Drawbacks of Linear Search:
• Linear search has a time complexity of O(N), which in turn makes it slow for
large datasets.
• Not suitable for large arrays.
• When to use Linear Search?
• When we are dealing with a small dataset.
• When you are searching for a dataset stored in contiguous memory.
Binary Search

• Binary Search is defined as a searching algorithm used in a sorted array


by repeatedly dividing the search interval in half. The idea of binary search is to
use the information that the array is sorted and reduce the time complexity to
O(log N).

• Conditions for when to apply Binary Search in a Data Structure:


• To apply Binary Search algorithm:
• The data structure must be sorted.
• Access to any element of the data structure takes constant time.
Binary Search Algorithm:

• In this algorithm,
• Divide the search space into two halves by finding the middle index “mid”.

• Compare the middle element of the search space with the key.
• If the key is found at middle element, the process is terminated.
• If the key is not found at middle element, choose which half will be used as the next search space.
– If the key is smaller than the middle element, then the left side is used for next search.
– If the key is larger than the middle element, then the right side is used for next search.
• This process is continued until the key is found or the total search space is exhausted.

Algorithm:
• B SEARCH(A,N,item)
1- LOC=-1
2-B=1,E=N
3-while B<=E
4- mid=[(B+E)/2]
5-if item=A[mid] then
Loc=mid[exit loop]
Else if item>A[mid]
B=mid+1
Else
E=mid-1
6- Return Loc
Complexity Analysis of Binary Search:

• Time Complexity:
– Best Case: O(1)
– Average Case: O(log N)
– Worst Case: O(log N)
• Auxiliary Space: O(1), If the recursive call
stack is considered then the auxiliary space
will be O(logN).
• Advantages of Binary Search:
• Binary search is faster than linear search, especially for large arrays.
• More efficient than other searching algorithms with a similar time
complexity, such as interpolation search or exponential search.
• Binary search is well-suited for searching large datasets that are
stored in external memory, such as on a hard drive or in the cloud.
• Drawbacks of Binary Search:
• The array should be sorted.
• Binary search requires that the data structure being searched be
stored in contiguous memory locations.
• Binary search requires that the elements of the array be
comparable, meaning that they must be able to be ordered.
• Applications of Binary Search:
• Binary search can be used as a building block for
more complex algorithms used in machine learning,
such as algorithms for training neural networks or
finding the optimal hyperparameters for a model.
• It can be used for searching in computer graphics
such as algorithms for ray tracing or texture
mapping.
• It can be used for searching a database.

You might also like