CSE 373 Lecture Notes - Lecture 1: Linked List, Time Complexity, Binary Search Algorithm

52 views3 pages
CSE 373 Lecture 1
Implementing maps
- Using an array or a linked list
- Putting stuff in linked list more efficient b/c constant time
- Memory storage linked list more efficient
- Looking stuff up
o Array
If you know index, finding an item is constant time
If sorted, use binary search which is log(n) time
o Linked list lookup is linear time
o Array more efficient
Iterator java interface that dictates how a collection of data should be traversed
- hasNext() and next()
- Eclipse feature to add unimplemented methods
Testing your code
- Isolate by breaking code into small modules
- Build in increments
- Test as you go
- What to test
o Expected behavior
o Can user mess up (forbidden input) e.g., passing in null, illegal arguments
o Empty/null cases
o What about edge cases e.g., if you’re trying to add something to array when
it’s full
o Scale does it work at greater scale
- Tips
o Test behavior in combination
o Think about empty/error cases + boundary cases
- Example writing list interface implementation that stores integers in an array
o Expected behavior create new list, add some items to it, remove a couple of
them
o Forbidden input adding other data types, adding outside of array indices,
negative numbers, duplicates, really large numbers
o Empty/null remove when list is empty, adding to null list, size on a null list
Unlock document

This preview shows page 1 of the document.
Unlock all 3 pages and 3 million more documents.

Already have an account? Log in

Document Summary

Using an array or a linked list. Putting stuff in linked list more efficient b/c constant time. Memory storage linked list more efficient. If you know index, finding an item is constant time. If sorted, use binary search which is log(n) time: linked list lookup is linear time, array more efficient. Iterator java interface that dictates how a collection of data should be traversed. Tips: test behavior in combination, think about empty/error cases + boundary cases. Junit testing framework that works with ides: @test to indicate test code, assertions, assertequals(item1, item2, asserttrue(boolean, assertfalse(boolean, assertnotnull(item) Search array for value 42: o(n) linear. Best case scenario if value is first. Best case scenario if value is in middle. Finished when n/2^k = 1 k = log2n. Asymptotic analysis how runtime of an algorithm grows as the data grows (runtime grows as input grows)

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents