Free Data Structures and Algorithms Course with C# | Complete Course with in-depth Concepts and implementations
We will be going through the following topics in this entire course of data structures and algorithm:
- Algorithms basics
- Sorting algorithm
- Searching algorithm
- Data structures
- Arrays
- Enumerations
- Structs
- Other
- Standard collections
- Specialized collections
- Generics
- Creating and using generics
But for the part 01 of the course, we will be going through the following in depth:
- Algorithms basics
- Sorting algorithm
- Searching algorithm
ALGORITHMS
Algorithms are involved in our daily lives which we are not noticing. For instance, the processes and instructions involved to completely prepare a recipe is also an algorithm. Algorithm defined as the group of steps and processes to successfully complete a task.In fact, the appropriate outcomes specify, whether it is an algorithm or not. Lets say, you make a scheduled for tomorrow and align your tasks to done in a particular order. What if you didn't have breakfast before going to school? Would it be an appropriate algorithm or successful plan, as per your tasks steps? It is required in an algorithm to solve the certain problem by taking certain steps.
Lets take an another example, now are asked the total number of apples in the 5 baskets if each basket has 5 apples. Most probably, you would do any of the following calculation:
- Multiply 5 apples to the number of baskets (5)
- Add 5 apples of each basket until get the total amount
This is what algorithm is! you produced successful or appropriate outcome, no matter what method you used.
BUBBLE SORTING ALGORITHM
Bubble sorting algorithm is based on comparing values with each other. Sorting refers to the process of differentiating between different values and aligning them appropriately. Bubble sorting works and sorts the values in an ascending order.Lets say that we have a set of unsorted number (3,1,5,6,4,7). The bubble sorting algorithm would work by comparing the values with each other. On comparing first two values, it will recognize that a larger number(3) is before a smaller number(1).
Bubble sorting algorithm works with the help of two things.
- Comparing
- Swapping
Therefore, it will swap first two numbers and arrange them in ascending order. Then, from 1 to 6, there is no need to swap as elements are already sorted. And finally, it will repeat the process for 4 to be sorted and swapped on the index before 5 and after 3.
BUBBLE SORTING WITH C#
Now, when the concept and algorithm of bubble sorting is clear, lets have a look on its implementation using C#:BUBBLE SORTING CODE:
int[] num = {6,11,4,3,5};
bool change;
do
{
change = false;
for(int i = 0; i < num.length - 1; i++) {
if(num[i] > num[i+1]) {
int tem = num[i+1];
num[i+1] = num[i];
num[i] = tem;
change = true;
}
}
}
while(changed == true);
for(int i = 0; i < num.length; i++) {
Console.Writeline("{0} ", num[i]);
}
Console.ReadKey();
OUTPUT:
Bubble Sorting |
SEARCHING ALGORITHM
Searching algorithm is defined as, retrieving required information from a certain source. These sources includes any data structure such as collection or array. Searching algorithm requires some certain criteria for searching:- Outcome of the searching must be appropriate always
- It is required to be significant for information needs and sources.
- Searching speed is also an important factor for searching algorithm as per the requirements.
LINEAR SEARCH WITH C#
Linear search or one way search is useful method for searching in C#. Practical implementation of linear search in C# is discussed below:BINARY SEARCH WITH C#
Binary Search or two way searching is a quite practical and faster method of searching as compared with linear searching in C#. The clip below shows the code for binary search in C#.
To be Continued ...
0 Comments
Your comments and interesting view make our day!