Class 01
Class 01
Algorithms is about how to solve different problems, often by searching through and manipulating data structures.
Theory about Data Structures and Algorithms (DSA) helps us to use large amounts of data to solve problems efficiently.
Family tree
First, let's consider an example without computers in mind, just to get the idea.
If we want to store data about people we are related to, we use a family tree as the data structure. We choose a family tree as the data
structure because we have information about people we are related to and how they are related, and we want an overview so that we can
easily find a specific family member, several generations back.
With such a family tree data structure visually in front of you, it is easy to see, for example, who my mother's mother is—it is 'Emma,' right?
But without the links from child to parents that this data structure provides, it would be difficult to determine how the individuals are related.
Data structures give us the possibility to manage large amounts of data efficiently for uses such as large databases and internet indexing
services.
Data structures are essential ingredients in creating fast and powerful algorithms. They help in managing and organizing data, reduce
complexity, and increase efficiency.
When we talk about algorithms in Computer Science, the step-by-step instructions are written in a programming language, and instead of
food ingredients, an algorithm uses data structures. Algorithms are fundamental to computer programming as they provide step-by-step
instructions for executing tasks. An efficient algorithm can help us to find the solution we are looking for, and to transform a slow program
into a faster one.
Class 01 Page 1
into a faster one.
Step 1: Start
Step 2: Declare variables num1, num2 and sum.
Step 3: Read values num1 and num2.
Step 4: Add num1 and num2 and assign the result to sum.
sum←num1+num2
Step 5: Display sum
Step 6: Stop
Algorithm examples:
○ Finding the fastest route in a GPS navigation system
○ Navigating an airplane or a car (cruise control)
○ Finding what users search for (search engine)
○ Sorting, for example sorting movies by rating
Class 01 Page 2
Page 02
26 November 2024 6:51 AM
Data structure is a storage that is used to store and organize data. It is a way of
arranging data on a computer so that it can be accessed and updated efficiently.
Depending on your requirement and project, it is important to choose the right data
structure for your project. For example, if you want to store data sequentially in the
memory, then you can go for the Array data structure.
Primitive Data Structures are basic data structures provided by programming languages to represent single values, such as integers, floating-
point numbers, characters, and booleans.
Non-primitive or Abstract Data Structures are higher-level data structures that are built using primitive data types and provide more complex
and specialized operations. Some common examples of abstract data structures include arrays, linked lists, stacks, queues, trees, and graphs.
In linear data structures, the elements are arranged in sequence one after the other. Since elements are arranged in particular order, they are easy
to implement.
However, when the complexity of the program increases, the linear data structures might not be the best choice because of operational
complexities.
Class 01 Page 3
An array with each element represented by an index
It works just like a pile of plates where the last plate kept on the pile will be removed first.
It works just like a queue of people in the ticket counter where first person on the queue will get the ticket first.
Unlike linear data structures, elements in non-linear data structures are not in any sequence. Instead they are arranged in a hierarchical manner
where one element will be connected to one or more elements.
Non-linear data structures are further divided into graph and tree based data structures.
Class 01 Page 4
Graph data structure example
Popular Graph Based Data Structures:
• Spanning Tree and Minimum Spanning Tree
• Strongly Connected Components
• Adjacency Matrix
• Adjacency List
• Binary Tree
• Binary Search Tree
• AVL Tree
• B-Tree
• B+ Tree
• Red-Black Tree
Class 01 Page 5
Page 03
26 November 2024 7:08 AM
1. Traversal: Traversing a data structure means accessing each data element exactly once so it can be administered. For example, traversing
is required while printing the names of all the employees in a department.
2. Search: Search is another data structure operation which means to find the location of one or more data elements that meet certain
constraints. Such a data element may or may not be present in the given set of data elements. For example, we can use the search
operation to find the names of all the employees who have the experience of more than 5 years.
3. Insertion: Insertion means inserting or adding new data elements to the collection. For example, we can use the insertion operation to
add the details of a new employee the company has recently hired.
4. Deletion: Deletion means to remove or delete a specific data element from the given list of data elements. For example, we can use the
deleting operation to delete the name of an employee who has left the job.
5. Sorting: Sorting means to arrange the data elements in either Ascending or Descending order depending on the type of application. For
example, we can use the sorting operation to arrange the names of employees in a department in alphabetical order or estimate the top
three performers of the month by arranging the performance of the employees in descending order and extracting the details of the top
three.
6. Merge: Merge means to combine data elements of two sorted lists in order to form a single list of sorted data elements.
7. Create: Create is an operation used to reserve memory for the data elements of the program. We can perform this operation using a
declaration statement. The creation of data structure can take place either during the following:
a. Compile-time
b. Run-time
For example, the malloc() function is used in C Language to create data structure.
8. Selection: Selection means selecting a particular data from the available data. We can select any particular data by specifying conditions
inside the loop.
9. Update: The Update operation allows us to update or modify the data in the data structure. We can also update any particular data by
specifying some conditions inside the loop, like the Selection operation.
10. Splitting: The Splitting operation allows us to divide data into various subparts decreasing the overall process completion time.
Class 01 Page 6