Lec1 Introduction
Lec1 Introduction
Data Structures
and
Algorithms
Sraban Kumar Mohanty
Slides and figures have been collected from various publicly available Internet sources for
preparing the lecture slides of IT2001 course. I acknowledge and thank all the original authors
for their contribution to prepare the content.
Introduction
2
Data Structures and Algorithms
■ Study of Data Structures & Algorithms:
Fundamental to Computer Science
■ Not only Computer Science and Engineering, but also other
allied engineering disciplines such as
❑ Computer Integrated Manufacturing,
❑ Product Design,
❑ Commerce, and
❑ Communication Engineering, to list a few
3
Data Structures and Algorithms
4
Data Structures
■ How does Google find the documents matching your query
so fast?
❑ Uses sophisticated algorithms to create index structures, which
are just data structures.
■ With the amount of data created by the new technologies,
the need to organize, search, and update MASSIVE amounts
of information FAST is more severe than ever before.
5
What is data?
▪ Data
▪ A collection of facts from which conclusion may be drawn.
▪ e.g., Temperature 35°C; Conclusion: It is hot.
▪ Types of data
▪ Textual: name
▪ Numeric: Roll no
▪ Audio: your voice
▪ Visual data: images and videos
6
Data Types & Data Structures
❑ Applications/programs read data, store data temporarily, process it
and finally output results.
❑ It plays a vital role in enhancing the performance of a software or a
program as the main function of the software is to store and retrieve
the user’s data as fast as possible
Application/ Data
Data
Program
7
Data Types & Data Structures
■ Data is classified into data types. e.g., char, float, int, etc.
■ A data type is
❑ a domain of allowed values and
❑ set of operations on these values.
■ Compiler signals an error if wrong operation is performed
on data of a certain type.
❑ For example, char x,y,z; z = x*y is not allowed.
8
Data Types & Data Structures
Data Type Domain Operations
boolean 0,1 and, or, =, etc.
char ASCII =, <>, <, etc.
integer -maxint to +maxint +, _, =, ==, <>, <, etc.
21 3.14 ‘a’
9
What is data structure?
■ A particular way of storing and organizing data in a
computer so that it can be used efficiently and
effectively.
■ Data structure is the logical or mathematical model
of a particular organization of data.
■ A group of data elements grouped together under one
name.
❑ For example, an array of integers
What the course is About
▪ Data Structures
▪ Data Structures define how data is stored in RAM
11
Data Structures and Algorithms
■ Efficient problem-solving using computers, irrespective of
the discipline or application, calls for the design of efficient
algorithms
■ Inclusion of appropriate data structures is of critical importance
to the design of efficient algorithms
■ In other words, good algorithm design must go hand in
hand with appropriate data structures for efficient program
design to solve a problem
12
Example Algorithms
■ Two algorithms for computing the Factorial
■ Which one is better?
13
Examples of famous algorithms
■ Euclid algorithm
■ Newton's root finding
■ Fast Fourier Transform
■ Compression (Huffman, Lempel-Ziv, GIF, MPEG)
■ DES, RSA encryption
■ Simplex algorithm for linear programming
■ Shortest Path Algorithms (Dijkstra, Bellman-Ford)
■ Error correcting codes (CDs, DVDs)
■ TCP congestion control, IP routing
■ Pattern matching (Genomics)
■ Search Engines
14
Role of algorithms in the modern world
15
Why study data structures (and algorithms)
■ Using a computer?
❑ Solve computational problems?
❑ Want it to go faster?
❑ Ability to process more data?
■ Technology vs. Performance/cost factor
❑ Technology can improve things by a constant factor
❑ Good algorithm design can do much better and may be cheaper
❑ Supercomputer cannot rescue a bad algorithm
■ Data structures and algorithms as a field of study
❑ Old enough to have basics known
❑ New discoveries
❑ Rapidly increasing application areas
16
Data Structures
⮚ The representation of a particular data structure in the main
memory of a computer is called as storage structure.
⮚ The storage structure representation in auxiliary memory is called
as file structure.
⮚ Algorithm + Data Structure = Program
⮚ Data Structure study covers the following points
1) Representation of data in memory
2) Operations performs on data
3) Amount of memory require to store
4) Amount of time require to process
17
Operation on Data Structures
⮚Design of efficient data structure must take operations to be performed
on the DS into account. The most commonly used operations on DS are
broadly categorized into following types
➢ Create: This operation results in reserving memory for program
elements.
➢ Creation of DS may take place either during compile-time or run-time.
➢ Delete: This operation destroys memory space allocated for specified
data structure .
➢ Selection: This operation deals with accessing a particular data within a
data structure.
➢ Update: It updates or modifies the data in the data structure.
➢ Search: It finds the presence of desired data item in the list of items
Operation on Data Structures
➢ Design of efficient data structure must take operations to be performed
on the DS into account. The most commonly used operations on DS are
broadly categorized into following types
➢ Sorting: This is a process of arranging all data items in a DS in particular
order, for example either ascending order or in descending order.
➢ Splitting: It is a process of partitioning single list to multiple list.
➢ Merging: It is a process of combining data items of two different sorted
list into single sorted list.
➢ Traversing: It is a process of visiting each and every node of a list in
systematic manner.
Source: https://www.researchgate.net/publication/347303319_Data_Structure_Ppt
Types Of DS
2) Non primitive
2) Nonlinear DS
Primitive Data Types
■ Primitive Data Structure are basic structure and directly operated upon
by machine instructions.
■ Primitive data structures have different representations on different
computers.
■ These data types are available in most programming languages as built-
in type.
❑ Integer: It is a data type which allows all values without fraction part.
❑ Float: It is a data type which is use for storing fraction numbers.
❑ Character: It is a data type which is used for character values.
❑ Pointer: A variable that hold memory address of another variable are called
pointer.
Non-Primitive Data Type
■ These are more sophisticated data structures.
■ These are derived from primitive data structure.
Array: An array is a fixed size sequenced collection of elements of the same data
type.
List: An ordered set containing variable number of elements is called as List.
File: A file is a collection of logically related information. It can be viewed as a
large list of records consisting of various fields.
Course Structure
■ Notion of Algorithm, Space and Time Complexity, Analyzing algorithms
■ Static & Dynamic Memory Management: Arrays, Stacks, Queues, Linked Lists
■ Trees, Binary Trees, Tree Traversals, Applications of Binary Tree
■ Graphs and their representations, Graph Traversal Algorithms, Minimum
Spanning Tree, Shortest Paths
■ Searching Algorithms: Sequential Search, Binary Search
■ Sorting Algorithms: Quick sort, Merge sort, Insertion sort, Selection sort, Heap &
Heap sort
■ Binary Search Tree, Balanced Tree, AVL Tree
■ Files, Indexing: Hashing, Tree Indexing: B-tree
■ Basic Algorithm Design Paradigms: Divide & Conquer, Greedy method, Dynamic
Programming, Back tracking, Branch and Bound [Discussion with the help of
some example which are already discussed].
23
Text Books
■ Textbook
❑ Introduction to Algorithms, Cormen, Leiserson, and Rivest, MIT Press/McGraw-Hill,
Cambridge (Theory)
❑ Fundamentals of Data Structures by Ellis Horowitz, Sartaj Sahni, Galgotia Booksource
■ References
❑ Data Structures and Algorithm Analysis in C or C++ by Mark Allen Weiss
❑ Data Structures by Seymour Lipschutz, Schaum’s Outlines, TMH
❑ The C Programming language, Kernigham & Ritchie
❑ Other material will be posted
24
Grading Scheme
■ Assignments: for your practice only
■ Quiz1: 10%
■ Quiz2:10%
■ Mid Sem: 25%
■ End Sem: 35%
■ Lab work: 20%
25
Algorithm
■ An algo is a sequence of computational steps that transform the input
into output
❑ The statement of the problem specifies in general terms the desired
input/output relationship
❑ The algo describes a specific computational procedure for achieving that
input/output relationship
■ An algorithm can be specified
❑ in natural language like English,
❑ as a computer program, or
❑ as a hardware design
26
Algorithm
■ Example: sorting
❑ Fundamental operation in CS; a number of sorting algorithms are available
❑ Which algorithm is best for a given application depends on a number of factors:
■ The number of items to be sorted
■ The extent to which the items are already sorted
■ Possible restrictions on the item values
■ The kind of storage device to be used
■ Goal: To learn techniques of algorithm design and analysis so that you
can
❑ Develop algorithms on your own
❑ Show that they give the correct answer, and
❑ Understand their efficiency
27
Algorithm as a Technology
■ Suppose computers are infinitely fast and computer memory is free
■ would you have any reason to study algorithms?
■ You would still like to demonstrate that your solution method terminates and
does so with the correct answer
■ Of course, computers may be fast, but not infinitely fast and memory
may be cheap, but it is not free
■ Computing time and memory space: bounded resources
■ These resources should be used wisely, and algorithms that are
efficient in terms of time/space will help you do so
■ Algorithms devised to solve the same problem often differ dramatically
in their efficiency
■ These differences can be much more significant than differences due to
h/w and s/w
28
Algorithm as a Technology: Efficiency
No matter how much
■ Consider two sorting methods: smaller c1 is than c2,
there will always be a
❑ Insertion sort crossover point
■ Takes time roughly equal to c1n2 to sort n items beyond which merge
sort is faster
■ c1 is a constant that does not depend on n
❑ Merge sort
■ The constant factors are far less significant in the running time than the input
size n
■ Insertion sort is usually faster than merge sort for small input sizes, but once
the input size n becomes large enough, merge sort’s advantage of log2n Vs n
will more than compensate for the difference in constant factors
29
Algorithm as a Technology: Efficiency
❑ Computer A: faster: running insertion sort
Insertion sort takes approx 2.3 days
❑ speed: 1 billion instructions/sec (109 inst/sec)
❑ Computer B: slower: running merge sort
merge sort takes under 20 mins
❑ speed: 10 million instructions/sec (107 inst/sec)
❑ Input size: n= 1 million numbers
❑ To make the difference even more dramatic
31
Algorithms and other Technologies
■ Moreover, even an application that does not require algorithmic content at
the application level relies heavily upon algorithms
■ Does the application rely on fast h/w?
The h/w design used algorithm
32
Algorithms and other Technologies
33
References:
■ Slides and figures have been collected from various Internet
sources for preparing the lecture slides of IT2001 course.
■ I acknowledge and thank all the authors for the same.
■ It is difficult to acknowledge all the sources though.
❑ https://www.researchgate.net/publication/347303319_Data_Struct
ure_Ppt
34