This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Below are the Big O performance of common functions of different Java Collections. | |
| List | Add | Remove | Get | Contains | Next | Data Structure | |
| ---------------------|------|--------|------|----------|------|--------------- | |
| ArrayList | O(1) | O(n) | O(1) | O(n) | O(1) | Array | |
| LinkedList | O(1) | O(1) | O(n) | O(n) | O(1) | Linked List | |
| CopyOnWriteArrayList | O(n) | O(n) | O(1) | O(n) | O(1) | Array |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import random | |
| class TicTacToe: | |
| def __init__(self, playerX, playerO): | |
| self.board = [' ']*9 | |
| self.playerX, self.playerO = playerX, playerO | |
| self.playerX_turn = random.choice([True, False]) | |
| def play_game(self): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* MULTIPLIES A and B ============= | |
| using Strassen's O(n^2.81) method | |
| A = [1 3] B = [6 8] | |
| [7 5] [4 2] | |
| C = A * B = ? | |
| =================================*/ | |
| // Step 1: Split A and B into half-sized matrices of size 1x1 (scalars). |