Sunteți pe pagina 1din 40

T o

H ow
ACSL
Contest #3
Contest 3 Topics

Intermediate Senior
Boolean (no XOR) - 2 Boolean (inc. XOR) - 2
Data structures (no Data structures (inc.
heaps/path lengths) - 2 heaps/path len) -2
Regex (No FSA) - 1 Regex and FSAs -1
Boolean Algebra
Boolean algebra notation can be used to represent digital
electronic circuits
Uses letters and operands to represent circuit operations
* equals AND, + equals OR
To solve:
Use properties on following slide
Use order of operations: NOT; AND and NAND;
XOR and EQUIV; OR and NOR
Boolean Algebra Properties
Commutative: A+B=B+A A*B=B*A
Associative: A+(B+C)=(A+B)+C A*(B*C)=(A*B)*C
Distributive: A*(B+C)=A*B+A*C

DeMorgans
Law
Boolean Algebra Properties
DeMorgans Law
Boolean Algebra Properties

Many of these later complex properties are derived from the earlier
simpler properties
So if you dont remember these properties, you can derive them or
work out the solution using other methods
However, memorizing these will save you time and effort on the test
Boolean Algebra
Boolean Algebra
Data Structures
- Algorithms and data structures are at the heart of every
computer program
- There are four basic structures tested in ACSL:
Stacks, Queues, Binary Search Trees, and Priority Queues
Data Structures
- Stacks: (Literally think like a stack of books)
- Follows last in, first out or LIFO order
- Has two operations PUSH and POP
- PUSH(A) puts key A at top of stack
- POP(X) removes top item from stack and stores in variable X (if the
stack is empty, NIL is stored to X)
Data Structures
- Queues: Think of coin machines. Coins are added to the
top, and removed from the bottom.
- First-in, First-out or FIFO stack
- The element that was placed in first is the next one to be
retrieved
- Same set of operation names as a stack
Data Structures
- E.g. PUSH(A), PUSH(M), PUSH(E), POP(X), PUSH(R),
POP(X), PUSH(I), POP(X), POP(X), POP(X),POP(X),
PUSH(C), PUSH(A), PUSH(N)
- Stacks have pop values of E,R,I,M,A, and NIL , with three
items left in the stack N at top (next to be popped), C at
bottom
- Queues have pop values of A,M,E,R,I, and NIL , with three
elements left N at top and C at bottom (next to be popped)
Data Structures
- Binary Search Trees - These trees have nodes with two
children, a left and right node
- Property: Key is less than keys of left child and
descendants, and greater than keys of right child and
descendants

Binary search tree


from keys:
A, M, E, R, I, C, A, N
Data Structures
- Root (First node) = A
- Duplicates are considered less
than their root key
- Depth = 3
- # of layers below the root
Data Structures
- Nodes with no children
are leaf nodes (4 leaf
nodes in example)
- External nodes are
places where new nodes
could be attached to the
tree (9 in previous
example)
Data Structures
- Internal path length =
Sum of depths of all nodes
- 0+2(1)+2(2)+3(3) = 15
- External path length =
Sum of depths of all
external nodes
- 2(2)+3+6(4) = 31
OR
internal path length + 2 * #
Senior division only!! But learning
internal nodes for life is cool too.
Data Structures
Inorder traversal
Left child Root Right child
- Recursive so you must
go to the deepest node
(A,A,C,E,I,M,N,R)
- Lists elements in order
Data Structures
Preorder traversal
Root Left child Right child
A,A,M,E,C,I,R,N
Data Structures
Postorder traversal
Left child right child root
- A,C,I,E,N,R,M,A
Data Structures
- Binary search trees have three operations: insert, delete,
and search
- It does these three very efficiently due to the nature of the
structure
- Pseudocode for searching for a node (left) and deleting a
node (right)
Data Structures
- Priority Queues - Tree structure, but only the smallest item
can be deleted and searched for
- Can be done in O(log(n)) time
- Uses a heap, which is a tree where each node has two
children, but the node is larger than both children
- The tree has no holes, and all levels are completely filled
except the bottom, which is filled from left to right
Data Structures
Data Structures
Data Structures
Data Structures

Be careful! A binary tree is a tree where each node has at


most 2 children. A binary search tree is a binary tree with
the additional property that the letter of each node is greater
than the values of all nodes in its left subtree, and less than
the values of all nodes in its right subtree. The valid trees
are: (a), (b), and (d).
Data Structures
Data Structures
Regex
- Regular expressions, or regex, condense
multiple strings into a general form
- Combination of regular characters and
special operands
- You can identify it because it looks like gibberish
Regex - Common Operands
Operation What it does Example

. Matches any character A. Aa, AA, Ab...

[] Matches single character [abc] a, b, c


in brackets

[^] Matches not brackets [^abc] char not a, b, c

* Preceding char 0 or more A* , A, AA, AAA...


times

+ Match 1 or more times A+ A, AA but not


Regex - Common Operands
Operation What it does Example

{int, int} Match between ints A{1,3} A, AA, AAA

{char, int} Char <= int times {a,2} a, aa not aaa

Supplement:
https://www.cheatography.com/davechild/cheat-sheets/regular-expression
s/
https://regexone.com/
FSAs
- Basically a more complicated version of regex
- Four components:
- Input alphabet (defined legal input)
- Transition rules (how to get to next state)
- Start (marked by incoming arrow)
- End (double circle)
RULES

END
START

REGEX
Regex/FSA
- Rules for reg expression (RE):
- Null string = RE
- If string A is in input alpha, its an RE
- If both strings A and B are REs, follow the
following
- Concatenation: ab = a then b
- Union: aUb = a or b
- Closure: a* = zero or more times
Regex/FSA
- Order of operations
- Closure Concatenation Union
- Star goes right to left; everything else is left to right
- Problem types:
- Convert FSA to regex
- Simplify FSA
- Create FSA/regex to accept strings
Regex/FSA
Regex/FSA
Regex/FSA
Regex/FSA
Regex/FSA
Regex/FSA
Regex/FSA

S-ar putea să vă placă și