UIL CS: Collections & Algorithms
This is part of the UIL CS study series. See also:
Main topic list: https://www.uiltexas.org/files/academics/UILCS-JavaTopicList2526.pdf
7. Regex Patterns (most common + how used)
In Java:
s.matches(regex)must match entire string- Use
PatternandMatcherfor searching
String s = "insert regex pattern here";
String t = "match me to a regex";
Pattern pattern = Pattern.compile(s);
Matcher matcher = pattern.matcher(t);
Common patterns
| Pattern | Meaning |
|---|---|
. | any char |
\d | digit |
\D | not digit |
\w | word char [A-Za-z0-9_] |
\W | not word |
\s | whitespace |
\S | not whitespace |
\b | word boundary (position between \w and \W) |
| | alternation (matches before and after, like a logical OR) |
(?:...) | non-capturing group |
(?=...) | positive lookahead |
(?!...) | negative lookahead |
(?<=...) | positive lookbehind |
(?<!...) | negative lookbehind |
Note: ? after a quantifier (*, +, ?) is non-greedy/lazy.
Examples
"12345".matches("\\d+"); // true
"12a45".matches("\\d+"); // false
"abc".matches("[a-z]{3}"); // true
"ABC".matches("[a-z]{3}"); // false
"hello@gmail.com".matches("\\w+@\\w+\\.com"); // true-ish (simplified)
" ".matches("\\s+"); // true
14. Collections & Common Methods
List / ArrayList
- Add/insert:
add(E)/add(index, E). - Access:
get(index). - Remove:
remove(index)orremove(Object). - Size:
size(). - Example: Removing and adding values changes order.
Stack
- Push:
push(E)oradd(E)on a Stack. - Pop:
pop(). - Peek:
peek()returns top. - LIFO behavior.
Collections Utility Methods
- Rotate lists:
Collections.rotate(list, k). - Remove by condition:
removeIf(predicate).
Maps and Sets
- Basic behaviors:
HashMap,TreeMap,HashSet,TreeSet. - Key methods:
put(key, value),get(key),containsKey(key),contains(),size().
16. Trees & Graphs
Binary Search Trees: Insert order affects shape. Tree properties: internal nodes vs leaves, diameter. Complexity: worst-case search in unbalanced BST is .
17. Postfix notation (Reverse Polish) with example
Polish notation reference: https://www.uilexas.org/files/academics/UILCS-PolishNotation-Examples.pdf
Definition
Postfix places operators after operands.
- Infix:
- Postfix:
Evaluate using a stack:
- push numbers
- when operator appears: pop two operands, apply, push result
Example
Evaluate postfix:
Steps:
- push
- push
- push
- : pop and
- : pop and
- push
- : pop and
Answer:
18. Algorithms/Complexity
- Understand basic time complexity (e.g., BFS, simple loops).
- Recognize inefficiencies (e.g., nested loops ).
- Recognize linear vs logarithmic vs polynomial behavior.
19. Miscellaneous
- String methods:
length(),substring(),split(),toLowerCase(),matches(). - Math class:
ceil,floor,pow,min,max. - Scanner: input parsing:
nextInt(),nextLine().