/
Cse  373 September  29  – Cse  373 September  29  –

Cse 373 September 29 – - PowerPoint Presentation

anastasia
anastasia . @anastasia
Follow
66 views
Uploaded On 2023-06-22

Cse 373 September 29 – - PPT Presentation

Stacks and queues Design Decisions Shopping list Design Decisions Shopping list What sorts of behavior do shoppers exhibit What constraints are there on a shopper What improvements would make a better shopping list ID: 1001449

queue stack element circular stack queue circular element data object behavior expect enqueue returns adtwhat list queues problems dictionary

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "Cse 373 September 29 –" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

1. Cse 373September 29 – Stacks and queues

2. Design DecisionsShopping list?

3. Design DecisionsShopping list?What sorts of behavior do shoppers exhibit?What constraints are there on a shopper?What improvements would make a better shopping list?

4. Design DecisionsShopping list?Stack?

5. Design DecisionsShopping list?Stack?What sorts of behavior does the ‘stack’ support?What constraints are there on a stack user?(Is there a change in certainty?)What improvements would make a better stack?(What problems might arise in a stack?)

6. Stack ADTImportant to know exactly what we expect from a stack.

7. Stack ADTImportant to know exactly what we expect from a stack.Push(Object a) returns null; (other options?)Pop() returns Object a: where a is the element on ‘top’ of the stack; also removes a from the stackTop() returns Object a: where a is the element on ‘top’ of the stack without removing that element from the stack

8. Stack ADTImportant to know exactly what we expect from a stack.Push(Object a) returns null; (other options?)Pop() returns Object a: where a is the element on ‘top’ of the stack; also removes a from the stackTop() returns Object a: where a is the element on ‘top’ of the stack without removing that element from the stackHow long will these operations take?

9. Stack ADTImportant to know exactly what we expect from a stack.Push(Object a) returns null; (other options?)Pop() returns Object a: where a is the element on ‘top’ of the stack; also removes a from the stackTop() returns Object a: where a is the element on ‘top’ of the stack without removing that element from the stackHow long will these operations take?That depends on the Data Structure and Implementation

10. queue ADTWhat behavior do we expect from the queue?

11. queue ADTWhat behavior do we expect from the queue?enqueue(Object toInsert):dequeue(): front():

12. queue ADTWhat behavior do we expect from the queue?enqueue(Object toInsert): adds to the queuedequeue(): removes the ‘next’ element from the queuefront(): peeks at the ‘next’ element

13. queue ADTWhat behavior do we expect from the queue?enqueue(Object toInsert): adds to the queuedequeue(): removes the ‘next’ element from the queuefront(): peeks at the ‘next’ elementWhich element is ‘next’?

14. queue ADTWhat behavior do we expect from the queue?enqueue(Object toInsert): adds to the queuedequeue(): removes the ‘next’ element from the queuefront(): peeks at the ‘next’ elementWhich element is ‘next’?FIFO – ‘first in, first out’ ordering

15. Stack and Queue ADTStacks and Queues both support the same functionsinsert: push() and enqueue()remove: pop() and dequeue()peek: top() and front()

16. Stack and Queue ADTStacks and Queues both support the same functionsinsert: push() and enqueue()remove: pop() and dequeue()peek: top() and front()This isn’t sufficient to distinguish them, their behavior is also a critical part of their ADT. Which element do we expect to be ‘removed’?FIFO v LIFO

17. Stack and Queue ADTThe ADT describes the methods provided and the behavior we expect from themThe Data Structure is a theoretical arrangement of the data that supports the functionality of the ADT

18. Stack and Queue ADTWhat Data Structures might we use for Stacks and Queues?

19. Stack and Queue ADTWhat Data Structures might we use for Stacks and Queues?Arrays

20. Stack and Queue ADTWhat Data Structures might we use for Stacks and Queues?ArraysHow many ways can we use arrays?

21. Stack and Queue ADTWhat Data Structures might we use for Stacks and Queues?ArraysHow many ways can we use arrays?Which ways are efficient?

22. queue ADTArray implementationUnique problems?

23. queue ADTArray implementationUnique problems? What if the array is full?

24. queue ADTArray implementationUnique problems? What if the array is full? What if we alternate enqueue() and dequeue()?

25. queue ADTArray implementationUnique problems?End of ArrayUnique solutions?

26. queue ADTArray implementationUnique problems?End of ArrayUnique solutions?Resizing (costly!)Circular Array (?)

27. Circular Queues

28. Circular QueuesFrontBack

29. Circular QueuesFrontBack

30. Circular QueuesFrontBackWhy this way?What function to front and back serve?

31. Circular QueuesFrontBackenqueue(4)

32. Circular Queues4FrontBackWhich operations will move what pointers?

33. Circular Queues4FrontBackLet’s do several enqueues

34. Circular Queues4592316FrontBackWhat happens now, on enqueue(7)?

35. Circular Queues45923167FrontBackProblems here?How to implement?

36. Circular Queues45923167FrontBackThe queue is full, but it is the same situation (front == back) as when the queue is empty. This is a boundary condition.

37. Circular Queues45923167FrontBackWe have to resize the list (or deny the add) if we get another enqueue.

38. Circular Queues45923167FrontBackWhat if we dequeue some items?

39. Circular Queues5923167FrontBackDequeue() outputs 4

40. Circular Queues5923167FrontBackDequeue() outputs 4Is the 4 really “deleted”?

41. Circular Queues923167FrontBackOutput 5

42. Circular Queues923167FrontBackNow we’ve freed up some space and can enqueue more

43. Circular Queues5923167FrontBackenqueue(5)

44. Circular QueuesBy moving the front and back pointers, we can utilize all of the space in the arrayAdvantages over a linked list?

45. Circular QueuesBy moving the front and back pointers, we can utilize all of the space in the arrayAdvantages over a linked list?Fixed number of itemsSmall data (Memory efficiency)From Wednesday: What is the memory overhead of the linked list?

46. TestingImplementation is great if it works on the first try

47. TestingImplementation is great if it works on the first tryIn a large implementation, what is causing the problem?Data structure?Client?Wrapper?

48. TestingImplementation is great if it works on the first tryIn a large implementation, what is causing the problem?Object oriented programming allows modularity – good testing can pinpoint bugs to particular modules

49. TestingTwo primary types of testing

50. TestingTwo primary types of testingBlack boxBehavior only, no peeking into the codeThis usually tests ADT behaviorCan test performance/efficiency by using a timer

51. TestingTwo primary types of testingWhite box (or clear box)Where there is an understanding of the implementation that can be leveraged for testingIf you’re writing your own DS, you can peek into attributes that you would normally refuse access to the client

52. TestingIsolate the problem

53. TestingIsolate the problemWrite specific testsRunning the whole program doesn’t help narrow down problems

54. TestingIsolate the problem Write specific testsRunning the whole program doesn’t help narrow down problemsWhat are expected test cases?

55. TestingIsolate the problem Write specific testsRunning the whole program doesn’t help narrow down problems

56. TestingMany test cases (and large ones)You can prove that an algorithm is correct, but you cannot necessarily prove an arbitrary implementation is correct

57. TestingMany test cases (and large ones)You can prove that an algorithm is correct, but you cannot necessarily prove an arbitrary implementation is correctMore inputs can increase certaintyAdversarial testingThe client is not your friend

58. TestingGood things to testExpected behavior (at multiple sizes)Forbidden inputEmpty/NullSide effectsBoundary/Edge Cases

59. New ADTStacks and Queues are great, but they’re very simple.Data structures is about storing and managing data, but S/Q restrict access to that dataWhat sort of behavior would be more general?

60. Dictionary ADTOperates on two data typesa key, our lookup data typea value, the related data stored in the structureSupports three main functionsinsert(K key, V value)delete(K key)find(K key)

61. Dictionary ADTExampleEnglish Language Dictionary

62. Dictionary ADTExampleEnglish Language DictionaryWhat are keys and values?

63. Dictionary ADTExampleEnglish Language DictionaryKeys here are words (Strings)Values are definitions (Strings)

64. Dictionary ADTExampleEnglish Language DictionaryKeys here are words (Strings)Values are definitions (Strings)Keys and Values can be the same data type

65. Dictionary ADTExampleEnglish Language DictionaryKeys here are words (Strings)Values are definitions (Strings)Keys and Values can be the same data typefind(String word) will return the definition of the word – provided that the <word,definition> pair was added to the dictionary

66. Next weekDictionary/Map behavior and ADTSimple ImplementationsAnalyzing behavior, what do we mean when we say an algorithm is efficient?