CS : Data Structures
|
|
- Roy Grant
- 5 years ago
- Views:
Transcription
1 CS : Data Structures Michael Schatz Oct 7, 2016 Lecture 15: More Machine Code Optimization ;-)
2 Assignment 5: Due Sunday Oct 10pm Remember: javac Xlint:all & checkstyle *.java & JUnit Solutions should be independently written!
3 Bit Hacking $ xxd -b -c 9 solutions.txt cut -f d ' ' : : : b: : d: : f: : : a: : c: : e: : : : a2: ab: b4: bd: c6: cf: d8: e1: ea: f3: fc:
4 Bit Hacking $ xxd -b -c 9 solutions.txt cut -f d ' ' : : : b: : d: : f: : : a: : c: : No peeking J e: : : : a2: ab: b4: bd: c6: cf: d8: e1: ea: f3: fc:
5 Midterm Review
6 Midterm Review *You are not responsible for knowing the k-d tree
7 ADT: Arrays n-3 n-2 n-1 a: t t t t t t get(2) put(n-2, X) Fixed length data structure Constant time get() and put() methods Definitely needs to be generic J
8 Accessing RAM myarray[0] 0x0000 0x0001 0x0002 0x0003 0x0004 0x0005 0x0006 0x0007 0x0008 0x0009 0x000A 0x000B 0x000C 0x000D 0x000E 0x000F 0x0010 0x0011 0x0012 0x0013 0x0014 0x0015 0x0016 0x0017 0x0018 0x0019 0x001A 0x001B 0x001C 0x001D 0x001E 0x001F Byte [] myarray = new myarray[5000]; // myarray now starts at 0x0004 myarray[5] => offset for myarray + 5 * (sizeof type) => 0x04 + 0x05 * 1 => movl 0x09, %eax
9 Array Growing If the array size starts at 1, how expensive will it be to grow to 1M if we copy one element at a time? M push()s will require a total of ,999 copies = 0.5MM steps! O(n 2 ) performance L 5 6
10 Array Doubling If the array size starts at 1, how expensive will it be to grow to 1M? How many doublings will it take? How many times will an item be copied? How many rounds of doubling? lg(1m) = 20 How many total copies? k = 1M Whats the total runtime for n pushes? O(n) J This single push was O(n), but the next O(n) pushes are O(1) J 32
11 Sums of Powers of Two , ,048, ,048,575
12 ADT: Linked List (Singly Linked List) Node Node Node Node Node list data 0 data 1 data 2 data n-2 data n-1 null next next next next next Variable length data structure Constant time to head of list Linear time seek
13 ADT: Linked List (Singly Linked List) Node Node Node Node Node list data 0 data 1 data 2 data n-2 data n-1 null next next next next next Variable length data structure Constant time to head of list Linear time seek
14 Doubly Linked List List Node Node Node Node first 1 next prev 2 next prev 3 next prev 4 next prev null last null Very similar to a singly linked list, except each node has a reference to both the next and previous node in the list A little more overhead, but significantly increased flexibility: supports insertfront, insertback, removefront, removeback, insertbefore, removemiddle
15 Stacks Stacks are very simple but surprisingly useful data structures for storing a collection of information Any number of items can be stored, but you can only manipulate the top of the stack: Push: adds a new element to the top Pop: takes off the top element Top: Lets you peek at top element s value without removing it from stack Many Applications In hardware call stack Memory management systems Parsing arithmetic instructions: ((x+3) / (x+9)) * (42 * sin(x)) Back-tracing, such as searching within a maze
16 ListStack vs ArrayStack ListStack Node Node Node Node head value next value next value next value next null ArrayStack int [] arr int top
17 ArrayStack versus ListStack ListStack has some nice properties: Unbounded: keep adding items to the stack until you run out of memory Push, pop, and top are all constant time (Pretty) Simple implementation But also has significant overhead: You may end up dedicating more memory to node references (8 bytes each) than to the values that you are storing (4 bytes per int, 1 byte for char, etc) The values may be distributed all over RAM which can incur a penalty on some hardware See computer architecture class for details ArrayStack has some nice properties: Minimal overhead to storing items: 8 bytes for a reference to the entire array with N elements (Pretty) simple implementation: pop just decrements one number, top is a quick array lookup But also has a significant challenge/limitation Sometimes push() may be impossible (throw a StackOverflow exception), or expensive (copy entire array to a new larger array)
18 Queue Applications Whenever a resource is shared among multiple jobs: accessing the CPU accessing the disk Fair scheduling (ticketmaster, printing) Whenever data is transferred asynchronously (data not necessarily received at same rate as it is sent): Sending data over the network Working with UNIX pipes:./slow./fast./medium Also many applications to searching graphs (see 3-4 weeks) FIFO: First-In-First-Out Add to back + Remove from front
19 ListQueue vs ArrayQueue ListQueue Node Node Node Node first value next value next value next value next null last ArrayQueue int [] arr int top Many of the same tradeoffs as ListStack vs ArrayStack
20 ArrayQueue ArrayQueue int [] arr int top = 1 1 queue.enqueue(1);
21 ArrayQueue ArrayQueue int [] arr int top = queue.enqueue(1); queue.enqueue(2);
22 ArrayQueue ArrayQueue int [] arr int top = queue.enqueue(1); queue.enqueue(2); queue.enqueue(3);
23 ArrayQueue ArrayQueue int [] arr int top = queue.enqueue(1); queue.enqueue(2); queue.enqueue(3); queue.enqueue(4);
24 ArrayQueue ArrayQueue int [] arr int top = queue.dequeue()
25 ArrayQueue ArrayQueue int [] arr int top = queue.dequeue()
26 ArrayQueue ArrayQueue int [] arr int top = Whats wrong with copying? How could we fix it?
27 ArrayQueue ArrayQueue int [] arr int f = 0 int b = 0 f b Use a separate index for the front and back of the queue We know the queue is empty when f == b
28 ArrayQueue ArrayQueue int [] arr int f = 0 int b = 1 1 f b queue.enqueue(1);
29 ArrayQueue ArrayQueue int [] arr int f = 0 int b = f b queue.enqueue(1); queue.enqueue(2);
30 ArrayQueue ArrayQueue int [] arr int f = 0 int b = f b queue.enqueue(1); queue.enqueue(2); queue.enqueue(3);
31 ArrayQueue ArrayQueue int [] arr int f = 0 int b = f b Notice: queuelen = b - f queue.enqueue(1); queue.enqueue(2); queue.enqueue(3); queue.enqueue(4);
32 ArrayQueue ArrayQueue int [] arr int f = 1 int b = f b queue.dequeue() Hooray, enqueue and dequeue are O(1) J We don t even need to clear out the old front of the list
33 ArrayQueue ArrayQueue int [] arr int f = 13 int b = f b What happens when we get to the end of the array? Queuelen = = 4 J
34 ArrayQueue ArrayQueue int [] arr int f = 13 int b = f b queue.enqueue(17); Should we double the array? Nah, the array is mostly empty. Lets use it up first!
35 ArrayQueue ArrayQueue int [] arr int f = 13 int b = b f queue.enqueue(17);
36 ArrayQueue ArrayQueue int [] arr int f = 13 int b = b f queue.enqueue(17); queue.enqueue(18);
37 ArrayQueue ArrayQueue int [] arr int f = 14 int b = b f queue.dequeue()
38 ArrayQueue ArrayQueue int [] arr int f = 15 int b = b f queue.dequeue() queue.dequeue()
39 ArrayQueue ArrayQueue int [] arr int f = 16 int b = b f queue.dequeue() queue.dequeue() queue.dequeue()
40 ArrayQueue ArrayQueue int [] arr int f = 0 int b = f b How can we implement the wrap around? queue.dequeue() queue.dequeue() queue.dequeue() queue.dequeue()
41 Mod.java Modular Arithmetic m = a % b means to set m to be the remainder when dividing a by b m is guaranteed to fall between 0 and b public class Mod { public static void main(string [] args){ System.out.println("i\ti%2\ti%5\ti%10\ti%16"); } } for (int i = 0; i < 20; i++) { System.out.println(i + "\t" + i % 2 + "\t" + i % 5 + "\t" + i % 10 + "\t" + i % 16); } back = (back + 1) % arr.length How do we compute length or know when it is full? Use a separate counter. When array is totally full, double the size and copy into new array starting at 0 $ java Mod i i%2 i%5 i%10 i%
42 Dequeues insertfront() insertback() front back removefront() removeback() Dynamic Data Structure used for storing sequences of data Insert/Remove at either end in O(1) If you exclusively add/remove at one end, then it becomes a stack If you exclusive add to one end and remove from other, then it becomes a queue Many other applications: browser history: deque of last 100 webpages visited
43 ListDeque vs ArrayDeque ListDeque Node Node Node Node first value next value next value next value next null last ArrayDeque int [] arr int f int b Many of the same tradeoffs as ListQueue vs ArrayQueue
44 ArrayDequeue ArrayDeque int [] arr int f = 0 int b = 0 f b deque = new ArrayDequeue();
45 ArrayDequeue ArrayDeque int [] arr int f = 0 int b = 1 1 f b deque = new ArrayDequeue(); deque.insertback(1);
46 ArrayDequeue ArrayDeque int [] arr int f = 0 int b = f b deque = new ArrayDequeue(); deque.insertback(1); deque.insertback(2);
47 ArrayDequeue ArrayDeque int [] arr int f = 0 int b = f b deque = new ArrayDequeue(); deque.insertback(1); deque.insertback(2); deque.insertfront(3);
48 ArrayDequeue ArrayDeque int [] arr int f = 16 int b = b f deque = new ArrayDequeue(); deque.insertback(1); deque.insertback(2); deque.insertfront(3);
49 ArrayDequeue ArrayDeque int [] arr int f = 15 int b = Inserting at front usually means subtract, but gets tricky when we wrap around. f = (f-1) % arr.length; // depends on how this is implemented for negative numbers f = (f -1+arr.length) % arr.length; // does the right thing b deque = new ArrayDequeue(); deque.insertback(1); deque.insertback(2); deque.insertfront(3); deque.insertfront(4); f
50 Advanced Data Structure #1: K-d tree Balanced Binary Search Tree invented by Jon Louis Bentley in 1975 Generalization of the ubiquitous binary search tree Very fast to build & search almost any type of spatial data
51 Complexity Analysis How long will the algorithm take when run on inputs of different sizes: If it takes X seconds to process 1000 items, how long will it take to process twice as many (2000 items) or ten times as many (10,000 items)? Generally looking for an order of magnitude estimate: Constant time O(1): It takes the same amount of time to do it for 1 or for 1 million items Example: Getting a value from any position in an array Linear time O(n): If you double the number of elements it will take twice as long Example: scanning a linked list Logarithmic time O(lg(n)): Doubling the number of elements only makes it a tiny bit harder because the total number of steps is log(n) Example: Finding the nearest Pokemon stop using a k-d tree Also very important for space characterization: Sometimes doubling the number of elements will more than double the amount of space needed
52 FindMax Analysis public static int findmaximum(int [] myarray) { int max = myarray[0]; for (int i = 1; i < myarray.length; i++) { if (myarray[i] > max) { max = myarray[i]; } } } return max; $ java ArrayFind Scanning the array of size: 10,000,000 The max is: Search took: 11,666,963 nanoseconds $ java ArrayFind Scanning the array of size: 100,000,000 The max is: Search took: 71,270,945 nanoseconds Why isnt ArrayFind 100M exactly 10 times longer than ArrayFind 10M?
53 FindMax Analysis public static int findmaximum(int [] myarray) { int max = myarray[0]; for (int i = 1; i < myarray.length; i++) { if (myarray[i] > max) { max = myarray[i]; } } } return max; How many comparisons are done? i < myarray.length n myarray[i] > max n-1 C(n) = 2n-1 How many assignments are done (worst case)? max = myarray[0] 1 for i =1; i < myarray.length; i++ n val = myarray[i] n-1 max = myarray[i] n-1 A(n) = 1+ n + 2(n-1) = 3n-1
54 FindMax Analysis public static int findmaximum(int [] myarray) { int max = myarray[0]; for (int i = 1; i < myarray.length; i++) { if (myarray[i] > max) { max = myarray[i]; } } } return max; What is the total amount of work done? T(n) = C(n) + A(n) = (2n-2) + (3n 1) = 5n-3 Should we worry about the -3? Nah, for sufficiently large inputs will make a tiny difference Should we worry about the 5n? Nah, the runtime is linearly proportional to the length of the array
55 Big-O Notation Formally, algorithms that run in O(X) time means that the total number of steps (comparisons and assignments) is a polynomial whose largest term is X, aka asymptotic behavior f(x) O(g(x)) if there exists c > 0 (e.g., c = 1) and x 0 (e.g., x 0 = 5) such that f(x) cg(x) whenever x x 0 T(n) = 33 => O(1) T(n) = 5n-2 => O(n) T(n) = 37n n 8 => O(n 2 ) T(n) = 99n n n + 2 => O(n 3 ) T(n) = 127n log (n) + log(n) + 16 => O(n lg n) T(n) = 33 log (n) + 8 => O(lg n) T(n) = 900*2 n + 12n n + 54 => O(2 n ) Informally, you can read Big-O(X) as On the order of X O(1) => On the order of constant time O(n) => On the order of linear time O(n 2 ) => On the order of quadratic time O(n 3 ) => On the order of cubic time O(lg n) => On the order of logarithmic time O(n lg n) => On the order of n log n time
56 Growth of functions x^2 5x x A quadratic function isnt necessarily larger than a linear function for all possible inputs, but eventually will be x That largest term defines the Big-O complexity
57 Growth of functions
58 Trying every possible permutation Growth of functions Trying every possible subset Processing every element in a square array, Comparing every element to every other element Finding the nearest Pokemon stop from every other stop with a k-d tree Linear Search Finding an element in a balanced tree, Simple arithmetic, simple comparison, array access
59 Part 2: Midterm Review!
60 Next Steps 1. Reflect on the magic and power of Sentinels! 2. Work on Assignment 5: Due Sunday Oct 10:00 pm 3. Start to review for Midterm on Monday Oct Your notes from class 2. Lecture Notes on Piazza 3. Slides on course webpage 4. Online & printed textbooks 5. Sample Midterm!!!
61 Welcome to CS Questions?
CS : Data Structures Michael Schatz. Oct Lecture 18. Midterm review 2
CS 600.226: Data Structures Michael Schatz Oct 10 2018 Lecture 18. Midterm review 2 Midterm Topics Topics 01.Intro (kd-tree) 02.Interfaces 03.ArraysGenericsExceptions 04.Lists 05.Iterators 06.Complexity
More informationCS : Data Structures
CS 600.226: Data Structures Michael Schatz Sept 21, 2016 Lecture 8: Sorting Assignment 3: Due Sunday Sept 25 @ 10pm Remember: javac Xlint:all & checkstyle *.java Solutions should be independently written!
More informationCS : Data Structures
CS 600.226: Data Structures Michael Schatz Sept 18, 2016 Lecture 7: JUnit and Complexity Analysis Assignment 2: Due Sunday Sept 18 @ 10pm Remember: javac Xlint:all & checkstyle *.java Solutions should
More informationCS : Data Structures
CS 600.226: Data Structures Michael Schatz Sept 23, 2016 Lecture 9: Stacks Assignment 3: Due Sunday Sept 25 @ 10pm Remember: javac Xlint:all & checkstyle *.java & JUnit Solutions should be independently
More informationCS : Data Structures
CS 600.226: Data Structures Michael Schatz Oct 3, 2016 Lecture 13: More Lists Assignment 4: Due Sunday Oct 2 @ 10pm Remember: javac Xlint:all & checkstyle *.java & JUnit Solutions should be independently
More informationCS : Data Structures Michael Schatz. Sept Lecture 7. More Complexity
CS 600.226: Data Structures Michael Schatz Sept 14 2018 Lecture 7. More Complexity Agenda 1. Review HW1 2. Introduce HW 2 3. Recap & continuation on complexity Assignment 1: Due Friday Sept 14 @ 10pm https://github.com/schatzlab/datastructures2018/blob/master/assignments/assignment01/assignment01.md
More informationCS : Data Structures
CS 600.226: Data Structures Michael Schatz Oct 3, 2016 Lecture 14: Machine Code Optimization Assignment 5: Due Sunday Oct 9 @ 10pm Remember: javac Xlint:all & checkstyle *.java & JUnit Solutions should
More informationCH ALGORITHM ANALYSIS CH6. STACKS, QUEUES, AND DEQUES
CH4.2-4.3. ALGORITHM ANALYSIS CH6. STACKS, QUEUES, AND DEQUES ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN JAVA, GOODRICH, TAMASSIA AND GOLDWASSER
More informationCS : Data Structures
CS 600.226: Data Structures Michael Schatz Nov 30, 2016 Lecture 35: Topological Sorting Assignment 10: Due Monday Dec 5 @ 10pm Remember: javac Xlint:all & checkstyle *.java & JUnit Solutions should be
More informationToday s Outline. CSE 326: Data Structures Asymptotic Analysis. Analyzing Algorithms. Analyzing Algorithms: Why Bother? Hannah Takes a Break
Today s Outline CSE 326: Data Structures How s the project going? Finish up stacks, queues, lists, and bears, oh my! Math review and runtime analysis Pretty pictures Asymptotic analysis Hannah Tang and
More informationCS : Data Structures Michael Schatz. Sept Lecture 10. Stacks and JUnit
CS 600.226: Data Structures Michael Schatz Sept 21 2018 Lecture 10. Stacks and JUnit Agenda 1. Review HW2 2. Introduce HW3 3. Recap on Stacks 4. Queues Assignment 2: Due Friday Sept 21 @ 10pm https://github.com/schatzlab/datastructures2018/blob/master/assignments/assignment02/readme.md
More informationThe questions will be short answer, similar to the problems you have done on the homework
Introduction The following highlights are provided to give you an indication of the topics that you should be knowledgeable about for the midterm. This sheet is not a substitute for the homework and the
More informationHOWDY! WELCOME TO CSCE 221 DATA STRUCTURES AND ALGORITHMS
HOWDY! WELCOME TO CSCE 221 DATA STRUCTURES AND ALGORITHMS SYLLABUS ABSTRACT DATA TYPES (ADTS) An abstract data type (ADT) is an abstraction of a data structure An ADT specifies: Data stored Operations
More informationCourse Review for. Cpt S 223 Fall Cpt S 223. School of EECS, WSU
Course Review for Midterm Exam 1 Cpt S 223 Fall 2011 1 Midterm Exam 1 When: Friday (10/14) 1:10-2pm Where: in class Closed book, closed notes Comprehensive Material for preparation: Lecture slides & in-class
More informationComputer Science 210 Data Structures Siena College Fall Topic Notes: Linear Structures
Computer Science 210 Data Structures Siena College Fall 2018 Topic Notes: Linear Structures The structures we ve seen so far, Vectors/ArrayLists and linked list variations, allow insertion and deletion
More informationCS : Data Structures Michael Schatz. Sept Lecture 5: Iterators
CS 600.226: Data Structures Michael Schatz Sept 10 2018 Lecture 5: Iterators Agenda 1. Review HW1 2. References and Linked Lists 3. Nested Classes and Iterators Assignment 1: Due Friday Sept 14 @ 10pm
More informationCOS 226 Algorithms and Data Structures Fall Midterm
COS 226 Algorithms and Data Structures Fall 2017 Midterm This exam has 10 questions (including question 0) worth a total of 55 points. You have 0 minutes. This exam is preprocessed by a computer, so please
More informationComputer Science 62. Bruce/Mawhorter Fall 16. Midterm Examination. October 5, Question Points Score TOTAL 52 SOLUTIONS. Your name (Please print)
Computer Science 62 Bruce/Mawhorter Fall 16 Midterm Examination October 5, 2016 Question Points Score 1 15 2 10 3 10 4 8 5 9 TOTAL 52 SOLUTIONS Your name (Please print) 1. Suppose you are given a singly-linked
More informationCSE 146. Asymptotic Analysis Interview Question of the Day Homework 1 & Project 1 Work Session
CSE 146 Asymptotic Analysis Interview Question of the Day Homework 1 & Project 1 Work Session Comparing Algorithms Rough Estimate Ignores Details Or really: independent of details What are some details
More informationCS 231 Data Structures and Algorithms Fall Algorithm Analysis Lecture 16 October 10, Prof. Zadia Codabux
CS 231 Data Structures and Algorithms Fall 2018 Algorithm Analysis Lecture 16 October 10, 2018 Prof. Zadia Codabux 1 Agenda Algorithm Analysis 2 Administrative No quiz this week 3 Algorithm Analysis 4
More informationCS 261: Data Structures. Dynamic Array Queue
CS 261: Data Structures Dynamic Array Queue Dynamic Array -- Review Positives: Each element easily accessed Grows as needed The user unaware of memory management 2 Stack as Dynamic Array -- Review Remove
More informationCS 261. List Bag List Queue List Deque. by Tim Budd Ron Metoyer Sinisa Todorovic
CS 261 List Bag List Queue List Deque by Tim Budd Ron Metoyer Sinisa Todorovic List Bag struct { TYPE value; struct *; ; struct ListBag { struct *sentinel; List Bag Init, Add operations are similar to
More informationLecture 2: Implementing ADTs
Lecture 2: Implementing ADTs Data Structures and Algorithms CSE 373 SP 18 - KASEY CHAMPION 1 Warm Up Discuss with your neighbors! From last lecture: - What is an ADT? - What is a data structure? From CSE
More informationCPSC 221: Algorithms and Data Structures Lecture #1: Stacks and Queues
CPSC 221: Algorithms and Data Structures Lecture #1: Stacks and Queues Alan J. Hu (Slides borrowed from Steve Wolfman) Be sure to check course webpage! http://www.ugrad.cs.ubc.ca/~cs221 1 Lab 1 is available.
More informationCS : Data Structures
CS 600.226: Data Structures Michael Schatz Oct 12, 2016 Lecture 17: Trees Assignment 5: Due Sunday Oct 9 @ 10pm Remember: javac Xlint:all & checkstyle *.java & JUnit Solutions should be independently written!
More informationCpt S 223 Fall Cpt S 223. School of EECS, WSU
Course Review Cpt S 223 Fall 2012 1 Final Exam When: Monday (December 10) 8 10 AM Where: in class (Sloan 150) Closed book, closed notes Comprehensive Material for preparation: Lecture slides & class notes
More informationCourse Review. Cpt S 223 Fall 2010
Course Review Cpt S 223 Fall 2010 1 Final Exam When: Thursday (12/16) 8-10am Where: in class Closed book, closed notes Comprehensive Material for preparation: Lecture slides & class notes Homeworks & program
More informationComputer Science 210 Data Structures Siena College Fall Topic Notes: Linear Structures
Computer Science 210 Data Structures Siena College Fall 2017 Topic Notes: Linear Structures The structures we ve seen so far, Vectors/ArrayLists and linked lists, allow insertion and deletion of elements
More information[2:3] Linked Lists, Stacks, Queues
[2:3] Linked Lists, Stacks, Queues Helpful Knowledge CS308 Abstract data structures vs concrete data types CS250 Memory management (stack) Pointers CS230 Modular Arithmetic !!!!! There s a lot of slides,
More informationAdam Blank Lecture 1 Winter 2017 CSE 332. Data Abstractions
Adam Blank Lecture 1 Winter 2017 CSE 332 Data Abstractions CSE 332: Data Abstractions Welcome to CSE 332! Outline 1 Administrivia 2 A Data Structures Problem 3 Review of Stacks & Queues What Am I Getting
More informationCS : Data Structures
CS 600.226: Data Structures Michael Schatz Sept 7, 2016 Lecture 2: Introduction to Interfaces Course Webpage: Course Discussions: Welcome! http://www.cs.jhu.edu/~cs226/ http://piazza.com Office Hours:
More informationinfix expressions (review)
Outline infix, prefix, and postfix expressions queues queue interface queue applications queue implementation: array queue queue implementation: linked queue application of queues and stacks: data structure
More informationData Structures Lecture 8
Fall 2017 Fang Yu Software Security Lab. Dept. Management Information Systems, National Chengchi University Data Structures Lecture 8 Recap What should you have learned? Basic java programming skills Object-oriented
More informationCE204 Data Structures and Algorithms Part 2
CE204 Data Structures and Algorithms Part 2 14/01/2018 CE204 Part 2 1 Abstract Data Types 1 An abstract data type is a type that may be specified completely without the use of any programming language.
More informationDiscussion 2C Notes (Week 3, January 21) TA: Brian Choi Section Webpage:
Discussion 2C Notes (Week 3, January 21) TA: Brian Choi (schoi@cs.ucla.edu) Section Webpage: http://www.cs.ucla.edu/~schoi/cs32 Abstraction In Homework 1, you were asked to build a class called Bag. Let
More informationCS24 Week 4 Lecture 2
CS24 Week 4 Lecture 2 Kyle Dewey Overview Linked Lists Stacks Queues Linked Lists Linked Lists Idea: have each chunk (called a node) keep track of both a list element and another chunk Need to keep track
More informationProgramming II (CS300)
1 Programming II (CS300) Chapter 08 : Algorithm Analysis MOUNA KACEM mouna@cs.wisc.edu Fall 2018 Algorithm Analysis 2 Introduction Running Time Big-Oh Notation Keep in Mind Introduction Algorithm Analysis
More informationECE 2400 Computer Systems Programming Fall 2018 Topic 8: Complexity Analysis
ECE 2400 Computer Systems Programming Fall 2018 Topic 8: Complexity Analysis School of Electrical and Computer Engineering Cornell University revision: 2018-10-11-00-23 1 Analyzing Algorithms 2 1.1. Linear
More informationAlgorithms in Systems Engineering IE172. Midterm Review. Dr. Ted Ralphs
Algorithms in Systems Engineering IE172 Midterm Review Dr. Ted Ralphs IE172 Midterm Review 1 Textbook Sections Covered on Midterm Chapters 1-5 IE172 Review: Algorithms and Programming 2 Introduction to
More informationCourse Review for Finals. Cpt S 223 Fall 2008
Course Review for Finals Cpt S 223 Fall 2008 1 Course Overview Introduction to advanced data structures Algorithmic asymptotic analysis Programming data structures Program design based on performance i.e.,
More informationComputer Science 210 Data Structures Siena College Fall Topic Notes: Complexity and Asymptotic Analysis
Computer Science 210 Data Structures Siena College Fall 2017 Topic Notes: Complexity and Asymptotic Analysis Consider the abstract data type, the Vector or ArrayList. This structure affords us the opportunity
More informationStandard ADTs. Lecture 19 CS2110 Summer 2009
Standard ADTs Lecture 19 CS2110 Summer 2009 Past Java Collections Framework How to use a few interfaces and implementations of abstract data types: Collection List Set Iterator Comparable Comparator 2
More informationRepresentation of Information
Representation of Information CS61, Lecture 2 Prof. Stephen Chong September 6, 2011 Announcements Assignment 1 released Posted on http://cs61.seas.harvard.edu/ Due one week from today, Tuesday 13 Sept
More informationITI Introduction to Computing II
ITI 1121. Introduction to Computing II Queues ArrayQueue Marcel Turcotte School of Electrical Engineering and Computer Science Version of March 10, 2014 Abstract These lecture notes are meant to be looked
More informationCS350 - Exam 1 (100 Points)
Spring 2013 Name CS350 - Exam 1 (100 Points) 1.(25 points) Stacks and Queues (a) (5) For the values 4, 8, 2, 5, 7, 3, 9 in that order, give a sequence of push() and pop() operations that produce the following
More informationCS : Data Structures
CS 600.226: Data Structures Michael Schatz Oct 20, 2016 Lecture 21: Graphs and Sets Assignment 6: Due Monday Oct 24 @ 10pm Remember: javac Xlint:all & checkstyle *.java & JUnit Solutions should be independently
More informationCS 216 Exam 1 Fall SOLUTION
CS 216 Exam 1 Fall 2004 - SOLUTION Name: Lab Section: Email Address: Student ID # This exam is closed note, closed book. You will have an hour and fifty minutes total to complete the exam. You may NOT
More informationPostfix (and prefix) notation
Postfix (and prefix) notation Also called reverse Polish reversed form of notation devised by mathematician named Jan Łukasiewicz (so really lü-kä-sha-vech notation) Infix notation is: operand operator
More informationData Structures. Outline. Introduction Linked Lists Stacks Queues Trees Deitel & Associates, Inc. All rights reserved.
Data Structures Outline Introduction Linked Lists Stacks Queues Trees Introduction dynamic data structures - grow and shrink during execution Linked lists - insertions and removals made anywhere Stacks
More informationKeeping Order:! Stacks, Queues, & Deques. Travis W. Peters Dartmouth College - CS 10
Keeping Order:! Stacks, Queues, & Deques 1 Stacks 2 Stacks A stack is a last in, first out (LIFO) data structure Primary Operations: push() add item to top pop() return the top item and remove it peek()
More informationSection 05: Solutions
Section 05: Solutions 1. Memory and B-Tree (a) Based on your understanding of how computers access and store memory, why might it be faster to access all the elements of an array-based queue than to access
More informationIT 4043 Data Structures and Algorithms
IT 4043 Data Structures and Algorithms Budditha Hettige Department of Computer Science 1 Syllabus Introduction to DSA Abstract Data Types Arrays List Operation Using Arrays Recursion Stacks Queues Link
More information1/18/12. Chapter 5: Stacks, Queues and Deques. Stacks. Outline and Reading. Nancy Amato Parasol Lab, Dept. CSE, Texas A&M University
Chapter 5: Stacks, ueues and Deques Nancy Amato Parasol Lab, Dept. CSE, Texas A&M University Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich,
More informationCS 106B Lecture 5: Stacks and Queues
CS 106B Lecture 5: Stacks and Queues Monday, July 3, 2017 Programming Abstractions Summer 2017 Stanford University Computer Science Department Lecturer: Chris Gregg reading: Programming Abstractions in
More informationRevision Statement while return growth rate asymptotic notation complexity Compare algorithms Linear search Binary search Preconditions: sorted,
[1] Big-O Analysis AVERAGE(n) 1. sum 0 2. i 0. while i < n 4. number input_number(). sum sum + number 6. i i + 1 7. mean sum / n 8. return mean Revision Statement no. of times executed 1 1 2 1 n+1 4 n
More informationSummer Final Exam Review Session August 5, 2009
15-111 Summer 2 2009 Final Exam Review Session August 5, 2009 Exam Notes The exam is from 10:30 to 1:30 PM in Wean Hall 5419A. The exam will be primarily conceptual. The major emphasis is on understanding
More informationCPSC 221: Algorithms and Data Structures ADTs, Stacks, and Queues
CPSC 221: Algorithms and Data Structures ADTs, Stacks, and Queues Alan J. Hu (Slides borrowed from Steve Wolfman) Be sure to check course webpage! http://www.ugrad.cs.ubc.ca/~cs221 1 Lab 1 available very
More informationASYMPTOTIC COMPLEXITY
Simplicity is a great virtue but it requires hard work to achieve it and education to appreciate it. And to make matters worse: complexity sells better. - Edsger Dijkstra ASYMPTOTIC COMPLEXITY Lecture
More informationEC8393FUNDAMENTALS OF DATA STRUCTURES IN C Unit 3
UNIT 3 LINEAR DATA STRUCTURES 1. Define Data Structures Data Structures is defined as the way of organizing all data items that consider not only the elements stored but also stores the relationship between
More informationCS : Data Structures
CS 600.226: Data Structures Michael Schatz Nov 7, 2016 Lecture 28: HashTables Assignment 8: Due Thursday Nov 10 @ 10pm Remember: javac Xlint:all & checkstyle *.java & JUnit Solutions should be independently
More informationCS : Data Structures
CS 600.226: Data Structures Michael Schatz Oct 14, 2016 Lecture 18: Tree Implementation Assignment 5: Due Sunday Oct 9 @ 10pm Remember: javac Xlint:all & checkstyle *.java & JUnit Solutions should be independently
More informationASYMPTOTIC COMPLEXITY
Simplicity is a great virtue but it requires hard work to achieve it and education to appreciate it. And to make matters worse: complexity sells better. - Edsger Dijkstra ASYMPTOTIC COMPLEXITY Lecture
More informationAsymptotic Analysis of Algorithms
Asymptotic Analysis of Algorithms EECS2030 B: Advanced Object Oriented Programming Fall 2018 CHEN-WEI WANG Algorithm and Data Structure A data structure is: A systematic way to store and organize data
More informationCS 261. Dynamic Array Queue by Tim Budd Ron Metoyer Sinisa Todorovic
CS 261 Dynamic Array Queue by Tim Budd Ron Metoyer Sinisa Todorovic Dynamic Array -- Review Positives: Each element easily accessed Grows as needed The user unaware of memory management Stack as Dynamic
More informationModule 1: Asymptotic Time Complexity and Intro to Abstract Data Types
Module 1: Asymptotic Time Complexity and Intro to Abstract Data Types Dr. Natarajan Meghanathan Professor of Computer Science Jackson State University Jackson, MS 39217 E-mail: natarajan.meghanathan@jsums.edu
More informationInformation Science 2
Information Science 2 - Basic Data Structures- Week 02 College of Information Science and Engineering Ritsumeikan University Today s class outline l Basic data structures: Definitions and implementation
More information10/5/2016. Comparing Algorithms. Analyzing Code ( worst case ) Example. Analyzing Code. Binary Search. Linear Search
10/5/2016 CSE373: Data Structures and Algorithms Asymptotic Analysis (Big O,, and ) Steve Tanimoto Autumn 2016 This lecture material represents the work of multiple instructors at the University of Washington.
More informationCS : Data Structures Michael Schatz. Oct 22, 2018 Lecture 22. Ordered Sets
CS 600.226: Data Structures Michael Schatz Oct 22, 2018 Lecture 22. Ordered Sets HW5 Assignment 5: Six Degrees of Awesome Out on: October 17, 2018 Due by: October 26, 2018 before 10:00 pm Collaboration:
More informationCourse Review. Cpt S 223 Fall 2009
Course Review Cpt S 223 Fall 2009 1 Final Exam When: Tuesday (12/15) 8-10am Where: in class Closed book, closed notes Comprehensive Material for preparation: Lecture slides & class notes Homeworks & program
More informationArrays. https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html
1 Arrays Arrays in Java an array is a container object that holds a fixed number of values of a single type the length of an array is established when the array is created 2 https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html
More informationCSE373: Data Structures & Algorithms Lecture 12: Amortized Analysis and Memory Locality. Lauren Milne Spring 2015
CSE373: Data Structures & Algorithms Lecture 12: Amortized Analysis and Memory Locality Lauren Milne Spring 2015 Announcements Homework 3 due on Wednesday at 11pm Catie back Monday Spring 2015 CSE 373
More informationLecture 2: Stacks and Queues
Lecture 2: Stacks and Queues CSE 373: Data Structures and Algorithms CSE 373 19 WI - KASEY CHAMPION 1 Warm Up 1. Grab a worksheet 2. Introduce yourself to your neighbors J 3. Discuss the answers 4. Log
More informationCSE373 Fall 2013, Second Midterm Examination November 15, 2013
CSE373 Fall 2013, Second Midterm Examination November 15, 2013 Please do not turn the page until the bell rings. Rules: The exam is closed-book, closed-note, closed calculator, closed electronics. Please
More informationby Marina Cholakyan, Hyduke Noshadi, Sepehr Sahba and Young Cha
CS 111 Scribe Notes for 4/11/05 by Marina Cholakyan, Hyduke Noshadi, Sepehr Sahba and Young Cha Processes What is a process? A process is a running instance of a program. The Web browser you're using to
More informationHow to Win Coding Competitions: Secrets of Champions. Week 2: Computational complexity. Linear data structures Lecture 5: Stack. Queue.
How to Win Coding Competitions: Secrets of Champions Week 2: Computational complexity. Linear data structures Lecture 5: Stack. Queue. Deque Pavel Krotkov Saint Petersburg 2016 General overview Stack,
More informationCS/COE 1501
CS/COE 1501 www.cs.pitt.edu/~nlf4/cs1501/ Introduction Meta-notes These notes are intended for use by students in CS1501 at the University of Pittsburgh. They are provided free of charge and may not be
More informationCS 11 C track: lecture 8
CS 11 C track: lecture 8 n Last week: hash tables, C preprocessor n This week: n Other integral types: short, long, unsigned n bitwise operators n switch n "fun" assignment: virtual machine Integral types
More informationCS/COE 1501 cs.pitt.edu/~bill/1501/ Introduction
CS/COE 1501 cs.pitt.edu/~bill/1501/ Introduction Meta-notes These notes are intended for use by students in CS1501 at the University of Pittsburgh. They are provided free of charge and may not be sold
More informationAbstract vs concrete data structures HEAPS AND PRIORITY QUEUES. Abstract vs concrete data structures. Concrete Data Types. Concrete data structures
10/1/17 Abstract vs concrete data structures 2 Abstract data structures are interfaces they specify only interface (method names and specs) not implementation (method bodies, fields, ) HEAPS AND PRIORITY
More informationCS : Data Structures
CS 600.226: Data Structures Michael Schatz Oct 17, 2016 Lecture 19: Trees and Graphs Assignment 6: Due Sunday Oct 23 @ 10pm Remember: javac Xlint:all & checkstyle *.java & JUnit Solutions should be independently
More informationAbout this exam review
Final Exam Review About this exam review I ve prepared an outline of the material covered in class May not be totally complete! Exam may ask about things that were covered in class but not in this review
More informationWe don t have much time, so we don t teach them [students]; we acquaint them with things that they can learn. Charles E. Leiserson
Homework 3 CS 321 - Data Structures Fall 2018 Dec 6, 2018 Name: Collaborators: We don t have much time, so we don t teach them [students]; we acquaint them with things that they can learn. Charles E. Leiserson
More informationLecture 3: Queues, Testing, and Working with Code
Lecture 3: Queues, Testing, and Working with Code Data Structures and Algorithms CSE 373 SU 18 BEN JONES 1 Clearing up Stacks CSE 373 SU 18 BEN JONES 2 Clearing up Stacks CSE 373 SU 18 BEN JONES 3 Clearing
More informationDNHI Homework 3 Solutions List, Stacs and Queues
Solutions List, Stacs and Queues Problem 1 Given the IntegerQueue ADT below state the return value and show the content of the, initially empty, queue of Integer objects after each of the following operations.
More informationCS 261: Data Structures. Dynamic Array Queue
CS 261: Data Structures Dynamic Array Queue Dynamic Array -- Review Positives: Each element easily accessed Grows as needed The user unaware of memory management 2 Stack as Dynamic Array -- Review Remove
More informationCS61, Fall 2012 Midterm Review Section
CS61, Fall 2012 Midterm Review Section (10/16/2012) Q1: Hexadecimal and Binary Notation - Solve the following equations and put your answers in hex, decimal and binary. Hexadecimal Decimal Binary 15 +
More informationData Structures Question Bank Multiple Choice
Section 1. Fundamentals: Complexity, Algorthm Analysis 1. An algorithm solves A single problem or function Multiple problems or functions Has a single programming language implementation 2. A solution
More informationHeaps, stacks, queues
Heaps, stacks, queues Dan S. Wallach and Mack Joyner, Rice University Copyright 216 Dan Wallach, All Rights Reserved Where was Prof. Wallach on Tuesday? Two hours of scintillating Congressional testimony:
More information1 P age DS & OOPS / UNIT II
UNIT II Stacks: Definition operations - applications of stack. Queues: Definition - operations Priority queues - De que Applications of queue. Linked List: Singly Linked List, Doubly Linked List, Circular
More informationCOSC160: Data Structures: Lists and Queues. Jeremy Bolton, PhD Assistant Teaching Professor
COSC160: Data Structures: Lists and Queues Jeremy Bolton, PhD Assistant Teaching Professor Outline I. Queues I. FIFO Queues I. Usage II. Implementations II. LIFO Queues (Stacks) I. Usage II. Implementations
More informationAlgorithm Efficiency & Sorting. Algorithm efficiency Big-O notation Searching algorithms Sorting algorithms
Algorithm Efficiency & Sorting Algorithm efficiency Big-O notation Searching algorithms Sorting algorithms Overview Writing programs to solve problem consists of a large number of decisions how to represent
More informationAssume you are given a Simple Linked List (i.e. not a doubly linked list) containing an even number of elements. For example L = [A B C D E F].
Question Assume you are given a Simple Linked List (i.e. not a doubly linked list) containing an even number of elements. For example L = [A B C D E F]. a) Draw the linked node structure of L, including
More informationCS 537: Introduction to Operating Systems Fall 2015: Midterm Exam #1
CS 537: Introduction to Operating Systems Fall 2015: Midterm Exam #1 This exam is closed book, closed notes. All cell phones must be turned off. No calculators may be used. You have two hours to complete
More information8/19/2014. Most algorithms transform input objects into output objects The running time of an algorithm typically grows with input size
1. Algorithm analysis 3. Stacks 4. Queues 5. Double Ended Queues Semester I (2014) 1 Most algorithms transform input objects into output objects The running time of an algorithm typically grows with input
More informationCS 310: Order Notation (aka Big-O and friends)
CS 310: Order Notation (aka Big-O and friends) Chris Kauffman Week 1-2 Logistics At Home Read Weiss Ch 1-4: Java Review Read Weiss Ch 5: Big-O Get your java environment set up Compile/Run code for Max
More informationCOMP 250 Winter stacks Feb. 2, 2016
Stack ADT You are familiar with stacks in your everyday life. You can have a stack of books on a table. You can have a stack of plates on a shelf. In computer science, a stack is an abstract data type
More informationPlot SIZE. How will execution time grow with SIZE? Actual Data. int array[size]; int A = 0;
How will execution time grow with SIZE? int array[size]; int A = ; for (int i = ; i < ; i++) { for (int j = ; j < SIZE ; j++) { A += array[j]; } TIME } Plot SIZE Actual Data 45 4 5 5 Series 5 5 4 6 8 Memory
More informationComputer Science 501 Data Structures & Algorithms The College of Saint Rose Fall Topic Notes: Linear Structures
Computer Science 501 Data Structures & Algorithms The College of Saint Rose Fall 2015 Topic Notes: Linear Structures The structures we ve seen so far, Vectors and linked lists, allow insertion and deletion
More informationYou must include this cover sheet. Either type up the assignment using theory4.tex, or print out this PDF.
15-122 Assignment 4 Page 1 of 12 15-122 : Principles of Imperative Computation Fall 2012 Assignment 4 (Theory Part) Due: Thursday, October 18, 2012 at the beginning of lecture Name: Andrew ID: Recitation:
More informationCOE428 Lecture Notes Week 1 (Week of January 9, 2017)
COE428 Lecture Notes: Week 1 1 of 10 COE428 Lecture Notes Week 1 (Week of January 9, 2017) Table of Contents COE428 Lecture Notes Week 1 (Week of January 9, 2017)...1 Announcements...1 Topics...1 Informal
More information