Works with the AI Agents you already use

    Data Structures, Algorithms & Design Patterns (Java)

    by Saud

    1

    Pick the right data structure, check Big O with the math, and learn the 23 GoF design patterns and secure coding.

    Free

    Security scanned
    Data Structures, Algorithms & Design Patterns (Java)

    Data Structures, Algorithms & Design Patterns (Java)

    Example session with this skill installed

    I need an LRU cache in Java with O(1) get and put. Explain why you chose these structures.

    • Read your context and instructions
    • Compiled the data structures algorithms

    Choice of structure

    An LRU cache needs two things in O(1): find a key, and know which key was used least recently. One structure cannot do both, so I combine two:

    • A hash map from key to node. It finds any key in O(1).
    • A doubly linked list ordered by recency. It moves or removes a known node in O(1).

    Two sentinel nodes (head and tail) remove all null checks at the ends of the list.

    Code (main methods)

    public V get(K key) {
        Node<K, V> node = index.get(key);
        if (node == null) return null;
        moveToFront(node);              // unlink + link at the front: O(1)
        return node.value;
    }
    
    public void put(K key, V value) {
        if (key == null || value == null) {
            throw new IllegalArgumentException("null keys and values are not allowed");
        }
        Node<K, V> node = index.get(key);
        if (node != null) {             // existing key: update and mark as recent
            node.value = value;
            moveToFront(node);
            return;
        }
        if (index.size() == capacity) { // full: evict the least recently used
            Node<K, V> lru = tail.prev;
            unlink(lru);
            index.remove(lru.key);
        }
        node = new Node<>(key, value);
        linkFront(node);
        index.put(key, node);
    }
    

    Big O

    OperationTimeSpace
    getO(1) expectedO(1)
    putO(1) expectedO(1)
    whole cache-O(capacity)

    "Expected" because the hash map is O(1) on average. The map is pre-sized so it never rehashes.

    Review notes

    • The cache is

    not thread-safe. If several threads share it, guard both get and put with one lock (get also changes the order).

    • The fixed capacity is a security feature: an unbounded cache is a memory leak and a denial-of-service risk (CWE-770).
    • In production you can also use LinkedHashMap with access order and removeEldestEntry.

    Next steps

    1. Test the cache against LinkedHashMap with random operations.
    2. Add a lock if the cache is shared between threads.
    3. Check references/security/index.md for the resource-limit rules.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    Pick the right data structure, check Big O with the math, and learn the 23 GoF design patterns and secure coding. The ideas are the same in any language. All examples are written in Java, because its syntax is close to C#, C++ and many other languages. Includes working Java 17 code with 263,000+ tests, 122 security weaknesses (each with a vulnerable and a fixed example), and a code review guide.

    Built while studying Data Structures at university. Every claim is backed by working code and 263,000+ automatic tests.

    Requires Java 17+. Diagrams require external rendering tools rather than ASCII. Scope limited to 122 specific security weaknesses and GoF patterns.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before buying a skill.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Free to use

    No account required to browse

    Trust & safety

    Security scan

    Security scan passed 12 days ago

    • Free with an Agensi account

    Software
    Java 17+ (to run the sample code)

    Permissions

    Read Files
    Write Files
    Network Access
    Listed12 days ago
    Updated5 days ago

    What's inside

    Frequently Asked Questions

    This skill goes beyond basic code generation by providing formal mathematical proofs for Big O, Omega, and Theta bounds, ensuring every algorithm choice is backed by rigorous complexity analysis.

    The skill is optimized for Java 17 and higher, utilizing modern features like Records, Sealed Classes, and updated Collections Framework standards to ensure your code is future-proof.

    Every implementation undergoes a security audit against 122 known weaknesses, specifically targeting high-risk areas like serialization vulnerabilities and hashing integrity.

    Yes, the skill is designed to refactor existing systems by applying Gang of Four design patterns and SOLID principles to improve maintainability and performance.

    You receive the full AI agent skill configuration, including the specialized logic for structure selection, security auditing protocols, and the GoF pattern implementation engine.

    While it provides deep analysis of data structures and algorithms, it does not currently generate ASCII art diagrams or provide memory model analysis for non-standard JVMs.

    New in Code Quality & Review

    Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Code Quality & Review.

    Free