Data Structures. Chapter 8



Similar documents
CSE 326, Data Structures. Sample Final Exam. Problem Max Points Score 1 14 (2x7) 2 18 (3x6) Total 92.

5. A full binary tree with n leaves contains [A] n nodes. [B] log n 2 nodes. [C] 2n 1 nodes. [D] n 2 nodes.

Binary Search Trees CMPSC 122

Big O and Limits Abstract Data Types Data Structure Grand Tour.

Krishna Institute of Engineering & Technology, Ghaziabad Department of Computer Application MCA-213 : DATA STRUCTURES USING C

Scheduling. Getting Started. Scheduling 79

CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team

Graph Theory Problems and Solutions

Algorithms and Data Structures

Analysis of Algorithms, I

Data Structure [Question Bank]

International Journal of Advanced Research in Computer Science and Software Engineering

Data Structures and Algorithms Written Examination

Outline. NP-completeness. When is a problem easy? When is a problem hard? Today. Euler Circuits

Introduction to Data Structures and Algorithms

Lecture 2: Data Structures Steven Skiena. skiena

COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012

CSE373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks/Queues. Linda Shapiro Spring 2016

2) Write in detail the issues in the design of code generator.

Exam study sheet for CS2711. List of topics

APP INVENTOR. Test Review

International Journal of Software and Web Sciences (IJSWS)

Using Web-based Tools to Enhance Student Learning and Practice in Data Structures Course

The Union-Find Problem Kruskal s algorithm for finding an MST presented us with a problem in data-structure design. As we looked at each edge,

Social Media Mining. Graph Essentials

Euclidean Minimum Spanning Trees Based on Well Separated Pair Decompositions Chaojun Li. Advised by: Dave Mount. May 22, 2014

2. (a) Explain the strassen s matrix multiplication. (b) Write deletion algorithm, of Binary search tree. [8+8]

Computer Algorithms. NP-Complete Problems. CISC 4080 Yanjun Li

Introduction to Data Structures

Common Data Structures

GCE Computing. COMP3 Problem Solving, Programming, Operating Systems, Databases and Networking Report on the Examination.

Cost Model: Work, Span and Parallelism. 1 The RAM model for sequential computation:

I/O Management. General Computer Architecture. Goals for I/O. Levels of I/O. Naming. I/O Management. COMP755 Advanced Operating Systems 1

Intro to the Art of Computer Science

Computational Geometry Lab: FEM BASIS FUNCTIONS FOR A TETRAHEDRON

So today we shall continue our discussion on the search engines and web crawlers. (Refer Slide Time: 01:02)

Lecture 17 : Equivalence and Order Relations DRAFT

SHARP BOUNDS FOR THE SUM OF THE SQUARES OF THE DEGREES OF A GRAPH

MATHEMATICS Unit Decision 1

20-30 minutes, can be used within a longer activity

Chapter 19 Operational Amplifiers

Decision Mathematics D1 Advanced/Advanced Subsidiary. Tuesday 5 June 2007 Afternoon Time: 1 hour 30 minutes

Discrete Mathematics and Probability Theory Fall 2009 Satish Rao, David Tse Note 10

Cpt S 223. School of EECS, WSU

10CS35: Data Structures Using C

Chapter 8: Bags and Sets

Quiz 4 Solutions EECS 211: FUNDAMENTALS OF COMPUTER PROGRAMMING II. 1 Q u i z 4 S o l u t i o n s

Connectivity and cuts

Data Structures and Algorithm Analysis (CSC317) Intro/Review of Data Structures Focus on dynamic sets

MATHEMATICS Unit Decision 1

What Is Singapore Math?

DATA STRUCTURES USING C

6.080/6.089 GITCS Feb 12, Lecture 3

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

Course: Programming II - Abstract Data Types. The ADT Stack. A stack. The ADT Stack and Recursion Slide Number 1

Sequential Data Structures

Outline. Introduction Linear Search. Transpose sequential search Interpolation search Binary search Fibonacci search Other search techniques

Planar Graphs. Complement to Chapter 2, The Villas of the Bellevue

Decision Analysis. Here is the statement of the problem:

DATA ANALYSIS II. Matrix Algorithms

1 Symmetries of regular polyhedra

Heaps & Priority Queues in the C++ STL 2-3 Trees

The ID Technology. Introduction to GS1 Barcodes

IE 680 Special Topics in Production Systems: Networks, Routing and Logistics*

Solving simultaneous equations using the inverse matrix

Static Load Balancing

The number of marks is given in brackets [ ] at the end of each question or part question. The total number of marks for this paper is 72.

Binary Risk Analysis

Matrix Multiplication

Chapter 6: Graph Theory

Abstract Data Type. EECS 281: Data Structures and Algorithms. The Foundation: Data Structures and Abstract Data Types

An Introduction to The A* Algorithm

Count the Dots Binary Numbers

Data Structures Fibonacci Heaps, Amortized Analysis

6.3 Conditional Probability and Independence

Network (Tree) Topology Inference Based on Prüfer Sequence

Any two nodes which are connected by an edge in a graph are called adjacent node.

Page 18. Using Software To Make More Money With Surveys. Visit us on the web at:

PES Institute of Technology-BSC QUESTION BANK

Advanced Computer Architecture-CS501. Computer Systems Design and Architecture 2.1, 2.2, 3.2

What Is Recursion? Recursion. Binary search example postponed to end of lecture

Chinese postman problem

A Review And Evaluations Of Shortest Path Algorithms

Organizing image files in Lightroom part 2

Christopher Seder Affiliate Marketer

Connie LeFevre. 22 Texas Home & Living September/October 2009

Symbol Tables. Introduction

CAD Algorithms. P and NP

QUEUES. Primitive Queue operations. enqueue (q, x): inserts item x at the rear of the queue q

Portfolio management tools. Why and when are they used?

Load balancing Static Load Balancing

CompSci-61B, Data Structures Final Exam

One platform for all your print, scan and device management

AI: A Modern Approach, Chpts. 3-4 Russell and Norvig

Level 2 Routing: LAN Bridges and Switches

Linear Programming Notes VII Sensitivity Analysis

Load Balancing and Termination Detection

Transcription:

Chapter 8 Data Structures Computer has to process lots and lots of data. To systematically process those data efficiently, those data are organized as a whole, appropriate for the application, called a data structure. The important issue is that different kinds of data structures are suited to different kinds of applications, and some are highly specialized to specific tasks. 1

An example When we talked about algorithms, we looked at the example of 555-1212, where the phone records are organized as tables, i.e., a list of phone records. We also saw that if we use a table where the phone records are not alphabetically sorted, only the sequential search algorithm can be applied. On the other hand, if those records are sorted, then the much faster binary search approach can be followed. 2

One of the two It is long recognized that there is a close relationship between algorithms and data structure, indeed, as stated in Worth s famous book, Algorithms + Data Structures = Programs Hence, data structures are used in every nontrivial program or software system. In many cases, an efficient algorithm is based on a cleverly designed data structure. An appropriate data structure is also the key to manage huge amounts of data, such as large databases, the bloodline of today s information age. We now look at several simple, but often used, data structures. 3

Array As we already discussed, the backbone of the 555-1212 system is a table of phone records. Technically, we call such a data structure as an array of data. Array is perhaps one of the most used data structure. This data structure is also used in our daily life. The following figure shows an array of telescopes. 4

Stack We once discussed in the topic of Analytical Engine about the concept of sub-routine, a group of steps that can be used as a whole. For example, when we want to dosomething, we will use the Advisor, which uses Aspect A, then Aspect B, which again dosomething before it completes. When Aspect B completes, we continue run Aspect A, then return to the Advisor, finally come back to dosomething until it is over. Question: What is buried here? 5

Answer: The issue here is that we take off from dosomething first, but will come back to this as the last step. Similarly, we come to the Aspect B as the last step of the whole sequence, but finishes it off as the first one. When we use a data structure to manage such a sequence of FirstOut- LastIn or LastInFirstOut, we will use the Stack data structure. Stack is actually a restricted version of a list, but when we either add in something into a Stack, or remove something from it, we always do it in only one of the two ends. A general list represents a sequence where we can either add something in, or take something out, anywhere. 6

No just here... Stack is also used in our daily life. For example, when we want to take a dish out of a deck of plates, as shown in the following figure, which one do you take? Although you can take out any one, I bet you must take the one at the top. On the other hand, when we want to put a dish back to such a deck, where do you put it back to? Again at the top. Thus, such a deck of dish is really a stack. 7

Queue Queue is another very simple but useful data structure. In a computer lab when one printer is shared by all the computers in that lab, what happens if five people want to print out their papers? The answer is very simple: they take in turns. What happens is that those papers will be put into a queue according to the order they arrive, then wait there until it comes to the front. Queue is also a restricted list where we add things in one end, and remove from the other. It is actually called FirstInFirstOut or LastIn- LastOut list. 8

Not just here again... Queue is certainly also used quite a bit in our daily life. For example, in a civilized society, we would wait in a line for our turns, but not cut in as some of the students did when buying tickets for the Drake show in last year s Spring Fling weekend. 9

Tree Array, stack and queue are examples of linear data structures, where everything is lined up. Tree is an example of a more complicated data structure. Indeed, everything inside the computer is organized as a tree. For example, the following figure shows the composition of a web site: The folder galleries contains a few folders, one of which is called gal100, which contains a few folders and a few documents, one being pioneer.html. A key property of using the tree structure to organize such data is that we can provide a unique path for the computer to find the pioneer.html file. 10

Tree structure is also widely used in our life. For example, the following figure shows the relationship among persons in a family. 11

Graph Graph is the most complicated data structure. The following shows a simple graph that connects five vertices with nice edges. In the above graph, we represent the association between various vertices as well as some information attached to such association. 12

Graph representation Usually, a graph can be represented as either an adjacency matrix, or an adjacency list. The adjacency matrix of an n vertex directed graph, G, is an n n matrix, such that, A(i, j) = { 1 if (i, j) E 0 otherwise. An alternative approach is to use a linked list to represent, for every vertex, all the vertices it is adjacent. 13

Applications The graph data structure is used in many real applications. For example, before you do any travel, you want to google a shortest way to get there, where a map is always represented as a graph. Internet is also organized as a graph. Whatever we do with the computer network, we have to rely on this graph structure to come up with algorithms, such as topological sort, shortest paths, minimum spanning tree, maximum network flow, etc.. 14

Course registration It is about time for us to register courses for Spring 2011. How could we make sure that all the prerequisite courses will be taken first? For examples, the following graph represents the prerequisite structure of part of a curriculum. Course v 1 is a prerequisite of both v 2 and v 4, and v 1, v 2 and v 5 are all prerequisites of v 4, etc.. 15

Topological sort The following is an algorithm looking for a topological sorting in G, where we label all the vertices to come up with an order in which these courses will be taken: 1. Set n to 1 2. Wile not all vertices labeled yet 3. Find v, s.t. there is no edge coming into v; 4. Label v with n; 5. n<-n+1 6. Retract v together with all the edges outgoing from v; Let s apply this algorithm to the above graph. 16

Minimum spanning tree Let s assume that we want to hook up a collection of sites, houses, buildings on a campus, with Internet lines, each connection comes at different cost. How could we do it with minimum cost? 17

Activities 1. Find out other examples of applications of the data structures that we have discussed here, i.e., stack, queue, list, tree, graph, etc., in our lives. 2. Find out examples and applications of other data structures that people have been using with computers applications. 3. How do you organize data, in the most general sense, in your life? For example, how do you organize all the clothing in your closet so that it will take you little time to find out the one that you want? 18