File
File
Syllabus
UNIT 1:
Introduction to Linear Data Structures:
Linked List: Dynamic Memory versus Static Memory Allocation, Types and
Operations Singly Linked List, Doubly Linked List, Header Linked List, Circular
Linked List, Applications Polynomial Arithmetic.
An abstract data type is an abstraction of data structure that provides only the
interface to which the data structure must adhere. The interface does not give
any specific details about something, should be implemented or in what
programming language. The reason for not having implementation details is
that every programming language has a different implementation strategy. For
example: A list is an abstract data type that is implemented using a dynamic
array and linked list. A queue is implemented using linked list based queue,
array based queue, and stack based queue.
Introduction to Algorithms
An algorithm is a process or a set of rules required to perform calculations or
some other problem solving operations especially by a computer. It is just a
logic of a program, which can be represented either as an informal description
using a flowchart or pseudo code.
Characteristics of Algorithms
Input: An algorithm has some input values. We can pass 0 or some input
value to an algorithm.
Asymptotic Analysis
The time required by an algorithm comes under three types:
Worst Case: It defines the input for which the algorithm takes more time.
Best Case: It defines the input for which the algorithm takes less time.
Asymptotic Notations
2. Theta Notation(θ): This notation is the formal way to express both the
lower bound and the upper bound of an algorithm’s running time. It mainly
describes average case.
3. Omega Notation(Ω): This notation is the formal way to express the lower
bound of an algorithm’s running time. It measures the best case or best
amount of time an algorithm can possible take to complete.
Algorithm Complexity
sum = 0;
// suppose we have to calculate the sum of n numbers
for i = 1 to n
sum = sum + i;
In the above code, the time complexity of the loop statement will be atleast
n, and if value of n increases, then time complexity also increases. TC:
O(n)
// O(1)
int arr = [1,2,3,4,5];
print(arr[2]); // 3
------------------------
// O(log n)
void operation(int n){
for (int i = 1; i <= n; i *=2){ // doubles i in eac
h step
printf("%d ", i);
}
}
int main(){
operation(16); // output: 1 -> 2 -> 4 -> 8 -> 16
return 0;
}