Data Structure Unit-1
Data Structure Unit-1
UNIT-1
Unit: 1
• Algorithm specification
• Recursion
• Performance analysis
• Asymptotic Notation - The Big-O, Omega and Theta
notation
• Programming Style
• Refinement of Coding - Time-Space Trade Off
• Testing
• Data Abstraction
ACSBS0203.1 3 3 3 2 - 1 - 1 2 2 2 2
ACSBS0203.2 3 3 2 2 - 1 - 1 2 2 1 2
ACSBS0203.3 3 3 2 2 - 1 - 1 2 2 2 2
ACSBS0203.4 3 3 2 2 - 1 - 1 2 2 2 2
ACSBS0203.5 3 3 3 3 2 2 2 2 3 3 3 3
Average 3 3 2.4 2.2 0.4 1.2 0.4 1.2 2.2 2.2 2 2.2
• Interest
• Get Familiar with programming language ‘C’
• Start learn Data Structure and Algorithm daily.
• Practice ! Because practice makes you perfect.
• 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.
• Space complexity
– Its the amount of memory space required by the algorithm,
during the course of its execution.
– An algorithm generally requires space for following components
• Instruction Space
• Data Space
• Environment Space
• The notation Ο(n) is the formal way to express the upper bound of
an algorithm's running time. It measures the worst case time
complexity or the longest amount of time an algorithm can possibly
take to complete.
• k=n0
• For example, for a function f(n)
Ο(f(n)) = { g(n) : there exists c > 0 and n0 such that f(n) ≤ c.g(n) for all
n > n0. }
• The notation Ω(n) is the formal way to express the lower bound of
an algorithm's running time. It measures the best case time
complexity or the best amount of time an algorithm can possibly
take to complete.
• k=n0
• For example, for a function f(n)
Ω(f(n)) ≥ { g(n) : there exists c > 0 and n0 such that g(n) ≤ c.f(n) for all
n > n0. }
• The notation θ(n) is the formal way to express both the lower
bound and the upper bound of an algorithm's running time.
• k=n0
• For example, for a function f(n)
θ(f(n)) = { g(n) if and only if g(n) = Ο(f(n)) and g(n) = Ω(f(n)) for all n
> n0 . }
09/14/2021 Himani Bansal CSBS (DSA) Unit -1 20
Common Asymptotic Notations
constant Ο(1)
logarithmic Ο(log n)
linear Ο(n)
quadratic Ο(n2)
cubic Ο(n3)
polynomial nΟ(1)
exponential 2Ο(n)
• int marks[10] ;
• For example,
– float x[3][4];
• Here, x is a two-dimensional (2d) array. The array can hold
12 elements. You can think the array as a table with 3 rows
and each row has 4 columns as shown in figure.
1. Row-Major Order
2. Column-Major Order
• Example:
Consider following example in which a two dimensional array
consist of two rows and four columns is stored sequentially in row
major order as:
2000 A[0][0]
2002 A[0][1]
Row 0
2004 A[0][2]
2006 A[0][3]
2008 A[1][0]
2010 A[1][1]
Row 1
2012 A[1][2]
2014 A[1][3]
• Example:
Consider following example in which a two dimensional array
consist of two rows and four columns is stored sequentially in
Column Major Order as:
2000 A[0][0]
Column 0
2002 A[1][0]
2004 A[0][1]
Column 1
2006 A[1][1]
2008 A[0][2]
Column 2
2010 A[1][2]
2012 A[0][3]
Column 3
2014 A[1][3]
a b c d
51
Linked List Representation
head
A B C
struct node *head, *ptr;
ptr = (struct node *)malloc(sizeof(struct node *));
ptr = (struct node *) malloc(sizeof(struct node *));
ptr → data = item
• Make the link part of the new node pointing to the existing first node of the list.
ptr->next = head;
• At the last, we need to make the new node as the first node of the list
head = ptr;
ptr = head
head = NULL
free(ptr)
struct node
{
struct node *prev;
int data;
struct node *next;
}
Algorithm :
Step 1: IF ptr = NULL
Write OVERFLOW
Go to Step 9
[END OF IF]
Step 2: SET NEW_NODE = ptr
Step 3: SET ptr = ptr -> NEXT
Step 4: SET NEW_NODE -> DATA = VAL
Step 5: SET NEW_NODE -> PREV = NULL
Step 6: SET NEW_NODE -> NEXT = HEAD
Step 7: SET head -> PREV = NEW_NODE
Step 8: SET head = NEW_NODE
Step 9: EXIT
17. free(ptr)
18.
printf("\nNode Deleted\n");
19.
}
20.
else
21.
{
22.
ptr = temp -> next;
23.
temp -> next = ptr -> next;
24.
ptr -> next -> prev = temp;
25.
free(ptr);
26.
printf("\nNode Deleted\n");
27.
}
Himani Bansal CSBS (DSA) Unit
28.
}
09/14/2021
-1
108
Searching for a specific node
• Addition of polynomial
• Subtraction of polynomial
• Multiplication of polynomial
• In linked list each node contain minimum of two fields. One field is
data field to store the data second field is?
A. Pointer to character
B. Pointer to integer
C. Pointer to node
D. Node
• http://www.aktuonline.com/papers/btech-cs-3-sem-data-structure
s-kcs301-2020.html
• http://www.aktuonline.com/papers/btech-cs-3-sem-data-structure
s-rcs-305-2018-19.html
• http://www.aktuonline.com/papers/btech-cs-3-sem-data-structure
s-rcs-305-2017-18.html
• http://www.aktuonline.com/papers/btech-cs-3-sem-data-structure
s-using-c-ncs-301-2016-17.html