I'm working hard to be someone I'll be proud of.
--Your friends at LectureNotes

Note for Data Structure using C - DS by pawan kumar

  • Data Structure using C - DS
  • Note
  • Ranchi University - Ru
  • Master of Computer Applications
  • MCA
  • 11 Topics
  • 1 Offline Downloads
  • Uploaded 1 year ago
Pawan Kumar
Pawan Kumar
0 User(s)
Download PDFOrder Printed Copy

Share it with your friends

Leave your Comments

Text from page-2

The data structures can also be classified on the basis of the following characteristics: Characterstic Description In Linear data structures,the data items are arranged in a linear sequence. Linear Example: Array In Non-Linear data structures,the data items are not in sequence. Example: Non-Linear Tree, Graph In homogeneous data structures,all the elements are of same type. Example: Homogeneous Array NonIn Non-Homogeneous data structure, the elements may or may not be of the Homogeneous same type. Example: Structures Static data structures are those whose sizes and structures associated Static memory locations are fixed, at compile time. Example: Array Dynamic structures are those which expands or shrinks depending upon the Dynamic program need and its execution. Also, their associated memory locations changes. Example: Linked List created using pointers What is an Algorithm ? An algorithm is a finite set of instructions or logic, written in order, to accomplish a certain predefined task. Algorithm is not the complete code or program, it is just the core logic(solution) of a problem, which can be expressed either as an informal high level description as pseudocode or using a flowchart. Every Algorithm must satisfy the following properties: 1. Input- There should be 0 or more inputs supplied externally to the algorithm.

Text from page-3

2. 3. 4. 5. Output- There should be atleast 1 output obtained. Definiteness- Every step of the algorithm should be clear and well defined. Finiteness- The algorithm should have finite number of steps. Correctness- Every step of the algorithm must generate a correct output. An algorithm is said to be efficient and fast, if it takes less time to execute and consumes less memory space. The performance of an algorithm is measured on the basis of following properties : 1. Time Complexity 2. Space Complexity Space Complexity Its the amount of memory space required by the algorithm, during the course of its execution. Space complexity must be taken seriously for multi-user systems and in situations where limited memory is available. An algorithm generally requires space for following components :    Instruction Space: Its the space required to store the executable version of the program. This space is fixed, but varies depending upon the number of lines of code in the program. Data Space: Its the space required to store all the constants and variables(including temporary variables) value. Environment Space: Its the space required to store the environment information needed to resume the suspended function. To learn about Space Complexity in detail, jump to the Space Complexity tutorial. Time Complexity Time Complexity is a way to represent the amount of time required by the program to run till its completion. It's generally a good practice to try to keep the time required minimum, so that our algorithm completes it's execution in the minimum time possible. We will study about Time Complexity in details in later sections. NOTE: Before going deep into data structure, you should have a good knowledge of programming either in C or in C++ or Java or Python etc.

Text from page-4

Asymptotic Notations When it comes to analysing the complexity of any algorithm in terms of time and space, we can never provide an exact number to define the time required and the space required by the algorithm, instead we express it using some standard notations, also known as Asymptotic Notations. When we analyse any algorithm, we generally get a formula to represent the amount of time required for execution or the time required by the computer to run the lines of code of the algorithm, number of memory accesses, number of comparisons, temporary variables occupying memory space etc. This formula often contains unimportant details that don't really tell us anything about the running time. Let us take an example, if some algorithm has a time complexity of T(n) = (n2 + 3n + 4), which is a quadratic equation. For large values of n, the 3n + 4 part will become insignificant compared to the n2 part. For n = 1000, n2 will be 1000000 while 3n + 4 will be 3004. Also, When we compare the execution times of two algorithms the constant coefficients of higher order terms are also neglected. An algorithm that takes a time of 200n2 will be faster than some other algorithm that takes n3 time, for any value of n larger than 200. Since we're only interested in the asymptotic behavior of the growth of the function, the constant factor can be ignored too. What is Asymptotic Behaviour The word Asymptotic means approaching a value or curve arbitrarily closely (i.e., as some sort of limit is taken). Remember studying about Limits in High School, this is the same. The only difference being, here we do not have to find the value of any expression where n is approaching any finite number or infinity, but in case of Asymptotic notations, we use the same model to ignore the constant factors and insignificant parts of an expression, to device a

Text from page-5

better way of representing complexities of algorithms, in a single coefficient, so that comparison between algorithms can be done easily. Let's take an example to understand this: If we have two algorithms with the following expressions representing the time required by them for execution, then: Expression 1: (20n2 + 3n - 4) Expression 2: (n3 + 100n - 2) Now, as per asymptotic notations, we should just worry about how the function will grow as the value of n(input) will grow, and that will entirely depend on n2 for the Expression 1, and on n3 for Expression 2. Hence, we can clearly say that the algorithm for which running time is represented by the Expression 2, will grow faster than the other one, simply by analysing the highest power coeeficient and ignoring the other constants(20 in 20n2) and insignificant parts of the expression(3n - 4 and 100n - 2). The main idea behind casting aside the less important part is to make things manageable. All we need to do is, first analyse the algorithm to find out an expression to define it's time requirements and then analyse how that expression will grow as the input(n) will grow. Types of Asymptotic Notations We use three types of asymptotic notations to represent the growth of any algorithm, as input increases: 1. Big Theta (Θ) 2. Big Oh(O) 3. Big Omega (Ω) Tight Bounds: Theta When we say tight bounds, we mean that the time compexity represented by the Big-Θ notation is like the average value or range within which the actual time of execution of the algorithm will be. For example, if for some algorithm the time complexity is represented by the expression 3n2 + 5n, and we use the Big-Θ notation to represent this, then the time complexity would be Θ(n2), ignoring the constant coefficient and removing the insignificant part, which is 5n.

Lecture Notes