# presentation27 - Collections Soheil Hassas Yeganeh Computer...

This preview shows pages 1–27. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Collections Soheil Hassas Yeganeh Computer Engineering Department Sharif University of Technology The problem 2 Size is unknown! The problem • We have a (unknown) number of objects and we want to store, access, and update them. 2 Size is unknown! A solution! 3 A solution! 1. Create an array of size K. 2. Insert into the array until its full . 3. When array is full, create another array doubled in size , and copy the old array elements into the new one. 4. Goto 2. 3 Resizable Array Lists 4 3 2 1 Obj1 Obj3 Obj4 Obj2 Resizable Array Lists 4 3 2 1 Obj1 Obj3 Obj4 Obj2 Obj6 Resizable Array Lists 4 3 2 1 Obj1 Obj3 Obj4 Obj2 Obj6 4 5 6 7 null null null Another solution! 5 First null Another solution! • We can create a linked list as follows 5 First null Another solution! • We can create a linked list as follows 5 First null Object Another solution! • We can create a linked list as follows 5 First null Object Another solution! • We can create a linked list as follows 5 First null Object Object Another solution! • We can create a linked list as follows 5 First null Object Object Another solution! • We can create a linked list as follows 5 First null Object Object Object Another solution! • We can create a linked list as follows 5 First null Object Object Object Searching a list (1) 6 Searching a list (1) • Let’s create a list and implement its search method. 6 Searching a list (2) 7 Searching a list (2) • In the worst case, we have to iteratively access the list from the Frst entry to the last one to search for an object. • What is the worst case scenario? 7 Searching a list (2) • In the worst case, we have to iteratively access the list from the Frst entry to the last one to search for an object. • What is the worst case scenario? 7 Searching for something that is not in the list! Set 8 Set • A list that does not have redundant items . • There is no item in a set that equals() another one. • So, we have to search the Set for each insert(). • It will be too slow to search the set every time. 8 Set • A list that does not have redundant items . • There is no item in a set that equals() another one. • So, we have to search the Set for each insert(). • It will be too slow to search the set every time. 8 H o w t o i m p r o v e t h e s e a r c h s p e e d ? Improving the search 9 Improving the search • Suppose we want to create a set just for numbers ....
View Full Document

## This note was uploaded on 11/21/2010 for the course COMPUTER S 003 taught by Professor Izadi during the Spring '10 term at Amirkabir University of Technology.

### Page1 / 90

presentation27 - Collections Soheil Hassas Yeganeh Computer...

This preview shows document pages 1 - 27. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online