1 / 15

Midterm 2 Review

Midterm 2 Review. Please grab a handout. Go ahead and start solving ReallyComplicatedGame. Easy way to check who wins a board winMap.get (new String(board));. The basics. You are allowed 1 sheet of notes

nenet
Download Presentation

Midterm 2 Review

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Midterm 2 Review Please grab a handout

  2. Go ahead and start solving ReallyComplicatedGame • Easy way to check who wins a board winMap.get(new String(board));

  3. The basics • You are allowed 1 sheet of notes • This is a tightly timed exam – be strategic about your time expenditure. Remember that all coding problems are worth an equal number of points. • My personal option: the hardest problems are recursive backtracking and stacks and queues

  4. The Straightforward Problems • Questions 1-3 • When adding nodes to a binary search tree, just add them one at a time and don’t move any existing nodes – that should give you a unique tree • Know how heaps work (handout on website) • Know preorder, postorder and inorder traversals

  5. Recurrence Relations • Recurrance relations – you need to use them not derive them • You don’t need to justify your BigO’s on the exam • I will give you these (you won’t need others) • T(n) = T(n/2) + O(1) → O(log n) • T(n) = T(n-1) + O(1) → O(n) • T(n) = 2T(n/2) + O(1) → O(n) • T(n) = 2T(n/2) + O(n) → O(n log n) • T(n) = T(n-1) + O(n) → O(n2)

  6. Big Os • Adding, removing, or searching a BST depends on its height. The height is O(n) if the tree is not height balanced (worst case), O(log n) if it is. • For priority queues, adding or removing lowest element is O(log n). Doing other stuff tends to be O(n) – priority queues are optimized for those 2 operations

  7. Very Hard Problems • Incomputablity and P/NP are both fair game • But it’s only worth 1 point!

  8. Linked List problems • Doubly linked lists are fair game • Be especially careful with removals. You don’t want to accidentally skip elements. (e.g. repeated 4s in the remove 4s example)

  9. Recursive Backtracking Two kinds of problems • 1st player/2nd player inversion problems • Map traversal problems

  10. 1st player/2nd player inversion problems • I can win if I can put the 2nd player in a situation where they CAN’T win • I try all the moves I can currently do and update the game state. Then I let the 2nd player go by making them the first player for this new game • If the second player can win, this is a BAD move for me • So I’ll try a different move • If I’ve tried every possible move and I can’t win, I’m gonna lose. So I return that. • I MUST always return the game state to what it was before I was called

  11. Map traversal problems • Check if you’re off the board • Check if you’re in an illegal position (e.g. an X, a square you’ve visited) • See if you’ve won • IF NOT – mark that this square has been visited (avoid infinite loop) • Then recursively call yourself on neighbors • When you’re finished UNMARK that this square has been visited

  12. Trees • Hopefully very straightforward

  13. Stack and Queue Problems • Always look like • Make a stack or queue • Add starting element to the stack/queue • While the queue is not empty • Grab some element off the stack/queue • Maybe add some more elements to the stack/queue • Sometimes it’s possible to do an end-run around these problems with recursion. Allowed, but can complicate things.

  14. Which structure? • QUEUES – useful when you want to visit some structure in distance order (e.g. everything that’s 1 away, followed by everything that’s 2 away, followed by…) • STACKS – useful for hierarchies where you deal with children before moving on to siblings • PRIORITY QUEUE – deal with certain elements first, based on a sort

  15. ALWAYS • Be calm and strategic. You don’t need to have a solution for every problem to do well on the exam. • Keep in mind the solution structures – that can get you partial points (sometimes) • Make sure you understand the solutions to the sample problems

More Related