Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE 326: Data Structures Lecture #1 2 Degrees of List

Similar presentations


Presentation on theme: "CSE 326: Data Structures Lecture #1 2 Degrees of List"— Presentation transcript:

1 CSE 326: Data Structures Lecture #1 2 Degrees of List
Steve Wolfman Winter Quarter 2000

2 Today’s Outline Things Steve Forgot On Monday Lists Multi-Lists
Survey (remind me!)

3 Data Structures Trees Multi-D trees Heaps Up-trees Hash Tables
Binary search trees AVL trees Splay trees B-trees Multi-D trees BSP trees Quad trees Heaps skew heaps leftist heaps d heaps Up-trees Hash Tables Sparse Matrices Some people have expressed to me concern that the whole quarter will be review (like those stacks and queues). I can’t guarantee that it won’t be, but I _can_ give you a sample of what we’ll see. We’ll study each of these data structures, how they work, when to use them, and prove bounds on their time and space complexity.

4 Algorithms Depth First Search Simulation Sorting Primality testing
Voronoi diagram creation Compression 3-D Rendering Here’s a sampling of the algorithms which I hope we’ll see as well, although we may not reach all of these. Tell me if you have a particular interest in any of them.

5 I wanted to be remembered for my music!
List ADT List operations Create/Destroy Length Find Insert/Remove Next/Previous List properties Ai precedes Ai+1 for 1  i < n Ai succeeds Ai-1 for 1 < i  n Size 0 list is defined to be the empty list () ( A1 A2 … An-1 An ) length = n I wanted to be remembered for my music! Now, back to work! We’re going to talk about lists briefly and quickly get to an idea which I hope you haven’t seen. Lists are sets of values. The type of those values is arbitrary but fixed (can’t change from one to another in the same list). Each value is at a position, and those positions are totally ordered.

6 Applications Everything! Class list
compilers: list of functions in a program, statements in a function graphics: list of triangles to be drawn to the screen operating systems: list of programs running music: compose crazy hard transcendental études other data structures: queues, stacks!

7 List Operations Iteration operations (List methods):
ListItr<Object> first() ListItr<Object> kth(int) ListItr<Object> last() Iteration operations (ListItr methods): Object get()/void set(Object) void next()/void previous() bool isPastEnd()/bool isPastStart() bool isLast()/bool isFirst() I know I’ve just told you the operations we’ll perform on a list, but there’s a problem. How do we describe positions in a list? Where do we insert? Where do we remove? What do we return on a find? Here’s one solution to these problems, an oft-used device from the Standard Template Library, and it differs a bit from your text, so pay attention!

8 List Operations II Main operations (List methods):
ListItr<Object> find(Object) void insert(Object, ListItr<Object>) void remove(ListItr<Object>) bool isEmpty()

9 Array List Data Structure
Length List 4 2 3 11 7 x = L.find(11) x Length List 4 2 3 11 7 L.insert(5, x) x Length List 5 2 5 3 11 7 Why did the book choose to insert after? Why did the book not do remove with a position? L.remove(x) x Length List 4 2 5 11 7 x x.next() Length List 4 2 3 11 7

10 Linked List2 Data Structure
Length 4 2 3 11 7 x = L.find(11) x Length 4 2 3 11 7 L.insert(5, x) x Length 5 2 3 5 11 7 Now, there’s something I didn’t mention in yesterday’s analysis of arrays vs. linked lists, and I wasn’t entirely fair to arrays: Linked lists take more space per element! That’s OK, this is better done on the board, anyway. L.remove(x) x Length 4 2 3 11 7 x x.next() Length 4 2 3 11 7

11 Array vs. Linked List The Usual?

12 Application: Polynomial ADT
Ai is the coefficient of the xn-i term: 3x2 + 2x + 5 ( ) 8x + 7 ( 8 7 ) Here’s an application of the list abstract data type as a _data structure_ for another abstract data type. Is there a problem here? Why? x2 + 3 ( ) Problem?

13 x ( ) What is it about lists that makes this a problem here and not in stacks and queues? (Answer: kth(int)!) Is there a solution? Will we get anything but zeroes overwhelming this data structure?

14 Sparse List Data Structure (?): x2001 + 1
( <1 2001> <1 0> ) Linked List vs Array This slide is made possible in part by the sparse list data structure. Now, two questions: 1) Is a sparse list really a data structure or an abstract data type? (Answer: It depends but I lean toward data structure. YOUR ANSWER MUST HAVE JUSTIFICATION!) 2) Which list data structure should we use to implement it? Linked Lists or Arrays? 1 2001 1 2001

15 Other Data Structures for Lists
Doubly Linked List Circular List 7 11 3 2 Advantages/disadvantages (previous for doubly linked list) your book also describes header nodes. Are they just a hack? I’m not going to go into these, but: You should be able to (for a test) add and delete nodes in all these types of list; not to mention for your daily coding needs! c d e f

16 MultiLists (Way More Lists)
Many applications use multiple linked lists graphs (2D) relations (multi-D) matrices (2-D, usually) multivariate polynomials (multi-D) radix sort (2-D) Why does this differ from just a list of lists? Because higher dimensionality tends to impose some interesting new constraints on the data structure. For one thing, a length 100 list with 100 entries in each list suddenly has 10,000 entries. The effect is, of course, more extreme for higher dimensionality (1,000,000 for 3-D!). So, just “allocating enough space” in an array becomes an expensive prospect. Therefore, we tend to use one of three types of data structures for multi-d lists:

17 MultiList Data Structures
Array of linked lists Linked list of linked lists Cross list Here’s three data structures for multilists. I’ll mention an application that leans on each of them.

18 Array of Linked Lists: Adjacency List for Graphs
1 3 2 5 4 G Graphs are a very important data type. You might think as you read about your project if there are any graphs there. Here, we’re implementing graphs with adjacency lists. The reason is that this is a sparse graph. We want to have every node in an array (so we can find the first edge quickly), but we just need the edges around. Array G of unordered linked lists Each list entry corresponds to an edge in the graph 1 5 2 2 4 3 5 3 1 4 4 5 4 5

19 Reachability by Marking
Suppose we want to mark all the nodes in the graph which are reachable from a given node k. Let G[1..n] be the adjacency list rep. of the graph Let M[1..n] be the mark array, initially all falses. void mark(int i) M[i] = true; x = G[i] while (x != NULL) { if (M[x->node] == false) mark(G[x->node]) x = x->next } Here’s an algorithm that works on our adj list graph.

20 1 3 2 5 4 M G 1 5 2 2 4 3 5 Let’s work out the example 3 1 4 4 5 4 5

21 Thoughts on Reachability
The marking algorithm visits each node and each edge at most once. Why? This marking algorithm uses Depth First Search. DFS uses a stack to track nodes. Where? Graph reachability is closely related to garbage collection the nodes are blocks of memory marking starts at all global and active local variables the marked blocks are reachable from a variable unmarked blocks are garbage Each node once because after once, it’s marked. Each edge once because we visit each node once and edges are stored under nodes.

22 Linked Lists of Linked Lists: Multivariate Polynomials
y + xy10 + xy5 + 3x12 + 4x12y10 = ( y)x0 + (y5 + y10)x1 + (3 + 4y10)x12 Here, we need sort of a sparse list of sparse lists.

23 Cross Lists: Enrollment ADT
Registry ADT for UW - stores which students are taking which courses Supported operations: int TakingCourse(int UWID, int SLN) tells if the student is taking the course specified by SLN void PrintSchedule(int UWID) print a list of all the courses this student is taking void PrintCourseList(int SLN) print a list of all the students in this course What’s different here?

24 Enrollment Cross List Stefan Bjarni Sigurdsson (B) Steve Hanks (H)
CSE326 CSE473 Steve Hanks (H) CSE370 CSE501 Stephen Soderland (S) Steve Tanimoto (T) CSE326 CSE473 CSE501 Steve Wolfman (W) CSE370

25 Matrices Matrix

26 To Do Sign up on the mailing list, darn it!
Pick a partner for Project I Read Project I Read Chapter 2 in the book Get questions ready for Zasha doubly linked lists logs, exponents, sums, series cross lists anything else?

27 Coming Up Asymptotic Analysis
Priority Qs (these are very different from plain Qs) First homework assignment A day off (January 17th)!


Download ppt "CSE 326: Data Structures Lecture #1 2 Degrees of List"

Similar presentations


Ads by Google