You are on page 1of 15

MC9214 : Data Structures

Unit 1 : Introduction to DS
Lesson 1 of 5 : Introduction to DS
Introduction to Data Structures
• Problem solving =
– Understanding the problem
+
– Designing a solution
+
– Implementing the solution

• What is a solution exactly?


– A solution = a program

(TM) (MCA)(2009-10/ ODD) (2009-2012)


Algorithm
An algorithm is a sequence of steps involved
in obtaining a solution (output) to a problem.
• An algorithm must be
– Correct: It should provide a correct solution
according to the specifications.
– Finite: It should terminate.
– General: It should work for every instance of a
problem.
– Efficient: It should use few resources (such as time
or memory).
(TM) (MCA)(2009-10/ ODD) (2009-2012)
Data Organization
• Any algorithm we come up with will have to
manipulate data in some way
– The way we choose to organize our data directly
affects the efficiency of our algorithm

• Solution = algorithm + data organization


– Both components are strongly interconnected.

(TM) (MCA)(2009-10/ ODD) (2009-2012)


Data structures and algorithms
• Data structure
– An organized collection of data.
– An arrangement of data in a computer’s memory.
– A representation of data and the operations allowed
on that data.
– E.g. Arrays, linked lists, stacks, trees, hash tables.
• Algorithms
– Manipulate the data in these structures in order to
accomplish some task.
– E.g. Inserting an item, search for an item, sorting.

(TM) (MCA)(2009-10/ ODD) (2009-2012)


How are Data structures used?
• As an actual way to store real-world data
– e.g., lists, trees
• As a tool to be used only within a program
(not visible to the user)
– E.g., stacks, queues, priority queues
• As a model of real-world situations
– e.g., graphs

(TM) (MCA)(2009-10/ ODD) (2009-2012)


Why different data structures?
• Each data structure has different advantages and
disadvantages, and will be useful for different
types of applications.
• Example: arrays
– Fast access: if we know the index of the item we are
looking for.
– Deletion is slow: Elements must be shifted after the
deletion.
– Size is fixed: Size of the array cannot be changed.
(TM) (MCA)(2009-10/ ODD) (2009-2012)
Abstract Data Types
• A data type is characterized by:
– a set of values.
– a data representation, which is common to all
these values.
– a set of operations, which can be applied
uniformly to all these values.
• An Abstract Data Type (ADT) is:
– a set of values.
– a set of operations .
– Abstract is keeping the more important parts.
(TM) (MCA)(2009-10/ ODD) (2009-2012)
Abstract Data Types contd…
• Specifies the logical properties of the data
type.
• ADT is a basic mathematical concept that
defines the data type.
• Example
– Arrays, stacks, queues…..

(TM) (MCA)(2009-10/ ODD) (2009-2012)


Summary
• Data Structure is an organized collection of
data.
• Various kinds of data structures are available
to suit various kinds of applications.
• ADT is a data structure which specifies the
operations rather than the representation.

(TM) (MCA)(2009-10/ ODD) (2009-2012)


Test your understanding
1. Which of the following is not correct with
the ADT
a) Set of Values
b) Data Representation
c) Set of Operations
d) None of the above
Ans: b

(TM) (MCA)(2009-10/ ODD) (2009-2012)


Complexity Analysis
Time Complexity is defined to be the time the
computer takes to run a program (or algorithm in our
case).

Space complexity is defined to be the amount of


memory the computer needs to run a program.
Complexity Analysis contd..
Complexity in general, measures the algorithms
efficiency in internal factors such as the time needed
to run an algorithm.

External Factors (not related to complexity):


•Size of the input of the algorithm
•Speed of the Computer
•Quality of the Compiler
Complexity Analysis contd..

•Average case complexity


–O(f(n))
•Best case complexity
–Ω(f(n))
•Worst case complexity
•Θ(f(n))
Common Big-Oh’s
Time Type Example
Complexity
O(1) constant Adding to the front of a linked list
O(log n) Log Finding an entry in a sorted array
O(n) Linear Finding an entry in an unsorted array
O(n log n) n - log - n Sorting n items by ‘divide-and-conquer’
O(n2) Quadratic Shortest path between two nodes in a
graph
O(n3) Cubic Simultaneous linear equations

(TM) (MCA)(2009-10/ ODD) (2009-2012)

You might also like