Breaking Posts

6/trending/recent

Hot Widget

Type Here to Get Search Results !

Introduction to Basic Data Structures and Algorithms

Introduction to Basic Data Structures and Algorithms


Basic types of Data Structures.
  • As previously stated, anything that can store data is referred to as a data structure, hence Integer, Float, Boolean, Char, and so on are all data structures. Primitive Data Structures are what they're called.
  • Then there are complicated Data Structures, which are used to store enormous amounts of data that are linked together. The following are some examples of Abstract Data Structure:
mskuthar
Basic types of Data Structures.

  1. Linked List
  2. Tree
  3. Graph
  4. Stack, Queue etc.
All of these data structures enable us to execute various data operations. We choose these data structures based on the sort of operation that will be performed. In subsequent courses, we will delve further into these data structures.

CharacteristicDescription
LinearIn Linear data structures, the data items are arranged in a linear sequence. Example: Array
Non-LinearIn Non-Linear data structures, the data items are not in sequence. Example: TreeGraph
HomogeneousIn homogeneous data structures, all the elements are of same type. Example: Array
Non-HomogeneousIn Non-Homogeneous data structure, the elements may or may not be of the same type. Example: Structures
StaticStatic data structures are those whose sizes and structures associated memory locations are fixed, at compile time. Example: Array
DynamicDynamic structures are those which expands or shrinks depending upon the program need and its execution. Also, their associated memory locations changes. Example: Linked List created using pointers
What is the definition of an algorithm?
  • An algorithm is a finite set of instructions or logic that must be written in a specific order to complete a set goals. An algorithm is not a complete programme or code; rather, it is the basic logic (solution) of a problem, which can be stated in a flowchart or as a high-level description in pseudocode.
The following properties must be met by every algorithm:

  1. Input- There should be 0 or more inputs given externally to the algorithm.
  2. Output- There should be at least 1 output as a result.
  3. Definiteness- Every step of the algorithm should be clear and well defined.
  4. Finiteness- The algorithm should have finite number of steps.
  5. Correctness- Every step of the algorithm must generate a correct output.

If an algorithm takes less time to perform and requires less memory space, it is said to be efficient and fast. The following properties are used to evaluate an algorithm's performance:

  1. Time Complexity.
  2. Space Complexity.
Time Complexity.
  • The term "time complexity" refers to the amount of time it takes for a programme to operate from start to finish. 
  • It's generally a good idea to attempt to minimize the time required to a bare minimum, so that our algorithm runs as quickly as feasible. In the next parts, we will go through Time Complexity in further depth.
NOTE: 
  • Before diving into data structures, you should have a solid understanding of programming, whether in C or C++, Java, Python, or another language.
Space Complexity.

  • It is the amount of memory space used by the algorithm while it is being executed. For multi-user systems and circumstances with limited memory, space complexity must be regarded seriously.

The following components of an algorithm typically demand space:

Instruction Space: 
  • This is the amount of space necessary to store the program's executable version. This space is constant, but it varies depending on how many lines of code are in the application.
Data Space: 
  • This is the amount of space needed to hold the values of all the constants and variables (including temporary variables).
Environment Space: 
  • This is the amount of space needed to store the environmental data required to resume the suspended function.
The Characteristics of Good Algorithms
  • Input and output must be well specified.
  • Each stage of the algorithm should be simple and straightforward.
  • Among the numerous various approaches to address an issue, algorithms should be the most effective.
  • Computer code should not be included in an algorithm. Rather, the algorithm should be designed in a way that allows it to be utilized in a variety of programming languages.
Algorithm 1: Add two numbers entered by the user
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 2: Find the largest number among three numbers
Step 1: Start
Step 2: Declare variables a,b and c.
Step 3: Read variables a,b and c.
Step 4: If a > b
           If a > c
              Display a is the largest number.
           Else
              Display c is the largest number.
        Else
           If b > c
              Display b is the largest number.
           Else
              Display c is the greatest number.  
Step 5: Stop

Algorithm 3: Find Root of the quadratic equation ax2 + bx + c = 0
Step 1: Start
Step 2: Declare variables a, b, c, D, x1, x2, rp and ip;
Step 3: Calculate discriminant
         D ← b2-4ac
Step 4: If D ≥ 0
              r1 ← (-b+√D)/2a
              r2 ← (-b-√D)/2a 
              Display r1 and r2 as roots.
        Else     
              Calculate real part and imaginary part
              rp ← -b/2a
              ip ← √(-D)/2a
              Display rp+j(ip) and rp-j(ip) as roots
Step 5: Stop      
       
Algorithm 4: Find the factorial of a number
Step 1: Start
Step 2: Declare variables n, factorial and i.
Step 3: Initialize variables
          factorial ← 1
          i ← 1
Step 4: Read value of n
Step 5: Repeat the steps until i = n
     5.1: factorial ← factorial*i
     5.2: i ← i+1
Step 6: Display factorial
Step 7: Stop

Algorithm 5: Check whether a number is prime or not
Step 1: Start
Step 2: Declare variables n, i, flag.
Step 3: Initialize variables
        flag ← 1
        i ← 2  
Step 4: Read n from the user.
Step 5: Repeat the steps until i=(n/2)
     5.1 If remainder of n÷i equals 0
            flag ← 0
            Go to step 6
     5.2 i ← i+1
Step 6: If flag = 0
           Display n is not prime
        else
           Display n is prime
Step 7: Stop 

Algorithm 6: Find the Fibonacci series till the term less than 1000
Step 1: Start 
Step 2: Declare variables first_term,second_term and temp. 
Step 3: Initialize variables first_term ← 0 second_term ← 1 
Step 4: Display first_term and second_term 
Step 5: Repeat the steps until second_term ≤ 1000 
     5.1: temp ← second_term 
     5.2: second_term ← second_term + first_term 
     5.3: first_term ← temp 
     5.4: Display second_term 
Step 6: Stop

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.