Data Structures and Algorithms IIIT Delhi Winter 2018

  • Slides: 48
Download presentation
Data Structures and Algorithms IIIT Delhi Winter 2018 Semester 1

Data Structures and Algorithms IIIT Delhi Winter 2018 Semester 1

Instructor Name: Rahul Purandare n Email: purandare@iiitd. ac. in n Office: A-503 n Office

Instructor Name: Rahul Purandare n Email: purandare@iiitd. ac. in n Office: A-503 n Office hours: By appointment n 2

Academic Integrity Policy n n Zero tolerance in this section Any act of plagiarism,

Academic Integrity Policy n n Zero tolerance in this section Any act of plagiarism, copying, cheating, etc. , will lead to Failing this course. n This is independent of what policy other section adopts 3

Familiar structures 4

Familiar structures 4

Dictionary: sorted data 5

Dictionary: sorted data 5

Data organized in columns 6

Data organized in columns 6

Organization structure of an institution 7

Organization structure of an institution 7

Road Map: geo-spatial data 8

Road Map: geo-spatial data 8

Social network 9

Social network 9

Hard disk directory 10

Hard disk directory 10

Why Data Structures? n n n Data is just the raw material for information,

Why Data Structures? n n n Data is just the raw material for information, analytics, business intelligence, advertising, etc Computational efficient ways of analyzing, storing, searching, modeling data For the purpose of this course, need for efficient data structures comes down to: n Linear search does not scale for querying large databases 2 2 n N processing or N storage infeasible n Smart data structures offer an intelligent tradeoff n Perform sub-linear preprocessing so that queries can be answered in much better than linear time 11

What is this Course About? Clever ways to organize information in order to enable

What is this Course About? Clever ways to organize information in order to enable efficient computation n What do we mean by clever? n What do we mean by efficient? 12

Clever? Efficient? Lists, Stacks, Queues Heaps Binary Search Trees AVL Trees Hash Tables Graphs

Clever? Efficient? Lists, Stacks, Queues Heaps Binary Search Trees AVL Trees Hash Tables Graphs Disjoint Sets Data Structures Insert Delete Find Merge Shortest Paths Union Algorithms

Data Structures A data structure is a scheme for organizing data in the memory

Data Structures A data structure is a scheme for organizing data in the memory of a computer. The way in which the data is organized affects the performance of a program for different tasks. Computer programmers decide which data structures to use based on the nature of the data and the processes that need to be performed on that data.

Concept of Abstract Data Type (ADT) 15

Concept of Abstract Data Type (ADT) 15

16

16

Implementation view 17

Implementation view 17

Abstract view of a TV set n n n Select a program Play a

Abstract view of a TV set n n n Select a program Play a program Store a program Add an app (to select a network) Remove an app 18

ADT An abstract model of a data structure together with the operations (can be

ADT An abstract model of a data structure together with the operations (can be treated as a form of algorithms) processed on the data structure. n In C++ or Java, an ADT can be implemented as a class. 19

Example: A Queue A queue is an example of commonly used simple data structure.

Example: A Queue A queue is an example of commonly used simple data structure. A queue has beginning and end, called the front and rear of the queue. Data enters the queue at one end and leaves at the other. Because of this, data exits the queue in the same order in which it enters the queue, like people in a checkout line at a supermarket.

Queue ADT n n Add an element Delete an element Get size of the

Queue ADT n n Add an element Delete an element Get size of the queue Check if queue is empty 21

Choosing Data Structures By comparing the queue with the binary tree, you can see

Choosing Data Structures By comparing the queue with the binary tree, you can see how the structure of the data affects what can be done efficiently with the data.

Choosing Data Structures A queue is a good data structure to use for storing

Choosing Data Structures A queue is a good data structure to use for storing things that need to be kept in order, such as a set of documents waiting to be printed on a network printer. .

Choosing Data Structures The jobs will be printed in the order in which they

Choosing Data Structures The jobs will be printed in the order in which they are received. Most network print servers maintain such a print queue. .

Choosing Data Structures A binary tree is a good data structure to use for

Choosing Data Structures A binary tree is a good data structure to use for searching sorted data. The middle item from the list is stored in the root node, with lesser items to the left and greater items to the right.

Choosing Data Structures A search begins at the root. The computer either find the

Choosing Data Structures A search begins at the root. The computer either find the data, or moves left or right, depending on the value for which you are searching. Each move down the tree cuts the remaining data in half.

Choosing Data Structures Items can be located very quickly in a tree. Telephone directory

Choosing Data Structures Items can be located very quickly in a tree. Telephone directory assistance information is stored in a tree, so that a name and phone number can be found quickly.

Choosing Data Structures For some applications, a queue is the best data structure to

Choosing Data Structures For some applications, a queue is the best data structure to use. For others, a binary tree is better. Programmers choose from among many data structures based on how the data will be used by the program.

What we are planning to cover in the course 29

What we are planning to cover in the course 29

n n Sorting techniques ( sorted data easier to handle) Recursion revision ( most

n n Sorting techniques ( sorted data easier to handle) Recursion revision ( most algos in Data Structures are recursive) Evaluating efficiency of algorithms Data structures n n n n Linked lists Stacks and queues Trees Hash tables Disjoint sets ………… . 30

Queues n n n Processing jobs sent to printer Computer simulation of waiting queues

Queues n n n Processing jobs sent to printer Computer simulation of waiting queues at bank counters, car wash, air traffic control, Transport and operations research where various entities are stored and held to be processed later i. e. the queue performs the function of a buffer. 31

Queue for processor scheduling 32

Queue for processor scheduling 32

Stacks n n undoredo operation in word processors, Expression evaluation and syntax parsing, many

Stacks n n undoredo operation in word processors, Expression evaluation and syntax parsing, many virtual machines like JVM are stack oriented. 33

Heap n n n Priority queues process scheduling in the kernel (shortest jobs first)

Heap n n n Priority queues process scheduling in the kernel (shortest jobs first) Simulation of priority passengers on waiting list 34

Trees n n Trees - Parsers, Filesystem Directory traversal 35

Trees n n Trees - Parsers, Filesystem Directory traversal 35

Tree data structure 36

Tree data structure 36

Symbol table 37

Symbol table 37

Expression tree: { [4+3*7]-[5/(3+4)] }+6 38

Expression tree: { [4+3*7]-[5/(3+4)] }+6 38

Hash Tables n n used for fast data lookup – symbol table for n

Hash Tables n n used for fast data lookup – symbol table for n n compilers, database indexing, caches, Unique data representation. 39

Hash function leads to data location 40

Hash function leads to data location 40

Graphs n n n Connections/relations in social networking sites, Routing , networks of communication,

Graphs n n n Connections/relations in social networking sites, Routing , networks of communication, data organization etc. 41

Course grading plan 42

Course grading plan 42

n Tentative Grading Components: n Labs: 20% Quizzes: 10% Mid-sem Exam: 20% Mid-sem Lab

n Tentative Grading Components: n Labs: 20% Quizzes: 10% Mid-sem Exam: 20% Mid-sem Lab Exam: 10% End-sem Exam: 25% End-sem Lab Exam: 10% Tutorial: 5% More details on backpack 43

Social network as graph data structure 44

Social network as graph data structure 44

Road network 45

Road network 45

Trie n n dictionary, such as one found on a mobile telephone for auto-completion

Trie n n dictionary, such as one found on a mobile telephone for auto-completion and spellchecking. 46

stru 47

stru 47

structure struggle 48

structure struggle 48