Lecture 01 - Complexity Time-Space Tradeoff
Lecture 01 - Complexity Time-Space Tradeoff
CSE 4303
Data Structure
Asaduzzaman Herok
Lecturer | CSE | IUT
[email protected]
What is Data Structure?
Data: Simply values or sets of values, raw facts or figure without any specific
meaning.
Data Structure: The logical or mathematical model of a particular organization of
data.
➢ Computer file system ( Data structure maps file names onto hard drive sectors)
➢ Google and other search engines (Data structure maps keywords on web pages containing those
keywords)
➢ What is the longest common subsequence of two DNA can be found?
➢ Geographic systems (Data structure find data relevant to the current view/location)
➢ Finding large Prime Numbers
➢ Block chain (Linked list)
➢ Google Map (Finding shortest distances in terms of distance and time)
➢ Data Compression (Huffman’s encoding)
➢ Natural Language Processing (Strings)
➢ ……………
Many problems are solved efficiently just using the right data structure …
Linear Stacks
Queues
Trees
Non Primitive Data Structure
Non Linear
Graphs
➢ Contiguous
Example: arrays
➢ Linked
Example: linked lists
➢ Indexed
Example: array of pointers.
➔ Random access to any data apart from the beginning is not possible since the address of a
particular data is only stored to its previous data.
Graph
A rooted tree is similar to a linked
list but with multiple next pointers
Tree
adjacency matrix adjacency list
Asaduzzaman Herok, Lecturer
21 August, 2023 10
Department of Computer Science and Engineering, IUT
Complexity, Time-space tradeoff
➢ A function that estimates the running time/space with respect to the input size.
➢ Less time and space requirement is a blessing!
➢ Deals with large input size.
➢ Tradeoff: Increased amount of space to store data can sometimes reduce time requirement
(or vice-versa).
Why Do We Care?
● Define mathematical bound of how the time (or space) taken by an algorithm increases with
the input size.
● An algorithm that is asymptotically more efficient will be the best choice for all but very small
inputs.
[Generally, the term ‘asymptotic’ means approaching but never connecting with a line or curve.]
if (condition) {
// true body
} Runtime of a conditional statement =
else { The runtime of the condition (the test) +
// false body The runtime of the body
}
Middle Loop
Outer Loop
Assume the case we are looking for is in the list and equally likely distributed.
If the list is of size n, then there is a 1/n chance of it being in the ith location :
So its O(n)
Asaduzzaman Herok, Lecturer
21 August, 2023 37
Department of Computer Science and Engineering, IUT
Acknowledgement
Rafsanjany Kushol
PhD Student, Dept. of Computing Science,
University of Alberta
Sabbir Ahmed
Assistant Professor
Department of CSE, IUT