So, we have to write a C program that creates and traverses the singly linked list. Take care while handling the pointers in the program, because there are a lot of pointer movements. Also read: Singly Linked List Declaring a Singly Linked List: So, we know that we can declare…
ManOrInfinity Posts
A singly linked list consists of elements that are called ‘nodes’. Every element contains data and a link to the next element in the linked list. Singly linked list contains a number of elements that are linked sequentially with the help of pointers. These elements or nodes are generally self…
Linked list is a linear data structure like array. In array data structure, elements are stored in contiguous memory location but in linked list data structure, elements are not necessarily stored in contiguous memory location. The elements in the linked list are connected with pointers. Array v/s Liked List: Array…
Master Theorem:
Master Theorem is a cookbook method for determining solutions to recurrence equations of a specific form.
So, in the first step you should match your recurrence equation with the equation given below and determine the value of some constants (a,b,k and p) then select the appropriate case-
T(n) = a T(n/b) + Θ(nk logpn)
Where a≥1, b>1, k≥0 and p∈R(real numbers). These conditions are important. Why? Because these condition help to check the properties the given constants (a, b, k, p). That helps to determine the time complexity using Master theorem.
CASE-1: if a > bk , then T(n)=Θ(nlogba)
CASE-2: if a = bk ,
a) If p>-1, then T(n)=Θ(nlogba logp+1n)
b) If p=-1, then T(n)=Θ(nlogba log(logn))
c) If p<-1, then T(n)=Θ(nlogba)
CASE-3: if a < bk ,
a) If p≥0, then T(n)=Θ(nklogpn)
b) If p<0, then T(n)=O(nk)
For,
Substitution Method click here!
Recursion tree method click here!
Example-1: Solve the given recurrence using Master theorem-
T(n) = 4T(n/2) + n2
Simply, compared with the above equation given in the Master theorem.
Hence,
a=4, b=2, k=2, p=0
Now, identifying the matching case-
a = bk
Why?
a = bk => 4 = 22 => 4 = 4
and
p>-1
Why?
Because, p=0
Hence, CASE 2.a is applied here!
T(n) = Θ(nlogba logp+1n)
T(n) = Θ(nlog24 log0+1n)
T(n) = Θ(n2.logn)
Example-2: Solve the given recurrence using Master theorem-
T(n) = 4T(n/2) + nlogn
Simply, compared with the above equation given in the Master theorem.
Hence,
a=4, b=2, k=1, p=1
Now, identifying the matching case-
a > bk
Why?
a > bk => 4 > 21 => 4 > 2
Hence, CASE 1 is applied here!
T(n) = Θ(nlogba)
T(n) = Θ(nlog24)
T(n) = Θ(n2)
Example-3: Solve the given recurrence using Master theorem-
T(n) = 5T(n/3) + n
Simply, compared with the above equation given in the Master theorem.
Hence,
a=5, b=3, k=1, p=0
Now, identifying the matching case-
a > bk
Why?
a > bk => 5 > 31 => 5 > 3
Hence, CASE 1 is applied here!
T(n) = Θ(nlogba)
T(n) = Θ(nlog35)
Example-4: Solve the given recurrence using Master theorem-
T(n) = 4T(n/2) + n3
Simply, compared with the above equation given in the Master theorem.
Hence,
a=4, b=2, k=3, p=0
Now, identifying the matching case-
a < bk
Why?
a < bk => 4 < 23 => 4 < 8
and
p≥0
Why?
Because, p=0
Hence, CASE 3.a is applied here!
T(n) = Θ(n3log0n)
T(n) = Θ(n3)
Example-5: Solve the given recurrence using Master theorem-
T(n) = 3n T(n/2) + nn
Here, values of a and k are not constant, so the Master theorem cannot apply here.
As, a=3n , b=2 , k=n, p=0
Example-6: Solve the given recurrence using Master theorem-
T(n) = 2T(n/4) + n0.55
Simply, compared with the above equation given in the Master theorem.
Hence,
a=2, b=4, k=0.55, p=0
Now, identifying the matching case-
a < bk
Why?
a < bk => 2 < 40.55 => 40.50 < 40.55
and
p≥0
Why?
Because, p=0
Hence, CASE 3.a is applied here!
T(n) = Θ(n0.55log0n)
T(n) = Θ(n0.55)
Circular Linked list is a sequence of nodes in which every node connects to its next node in the sequence, by the pointer. The last node also connects to the first node in the sequence. Hence a circular linked list is similar to the singly linked list with an extra…
Circular doubly linked list is a mixture or combination of doubly linked list and circular linked list. In a circular doubly linked list two successive nodes are linked by previous pointer and next pointer. The first node points to the last node by the previous pointer and the last node…
OnePlus Nord CE 5G is the successor to the original OnePlus Nord. In short, it’s better and cheaper than the original Nord making it a better value for money device. The Focus of every smartphone company is shifting to mid-range smartphones because 60% of smartphone sales fall in the mid-range.…
In C language when a structure is referring or pointing to the structure of the same type, then it is called ‘self referential structure’. Example of a structure- Example of a self referential structure- Here, *link is a pointer to the structure of type ‘manu’. Hence, it is a self…
Dynamic Memory Allocation: When we need to change the size of data structure at runtime, then we use dynamic memory allocation. C language provides some functions for dynamic memory allocation. There are 4 library functions in C language that are defined under the ‘stdlib.h’ header file to facilitate dynamic memory…
Population or Query Population in mongoose is a process of automatically replacing paths with other documents from other collections in a single document, multiple documents, objects, multiple objects. That’s the official definition of the population by a mongoose. But, most of us would understand this one: “Population is simply a…