{"id":16184404,"url":"https://github.com/cbl/algorithm-analyzer","last_synced_at":"2025-03-19T02:31:15.022Z","repository":{"id":48406758,"uuid":"376029977","full_name":"cbl/algorithm-analyzer","owner":"cbl","description":"A tool to analyze various sorting algorithms, graphs or binary trees.","archived":false,"fork":false,"pushed_at":"2021-07-27T17:55:23.000Z","size":41394,"stargazers_count":4,"open_issues_count":3,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-08T09:03:00.084Z","etag":null,"topics":["algorithms","data-structures","java"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cbl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-11T13:12:46.000Z","updated_at":"2024-10-26T06:31:49.000Z","dependencies_parsed_at":"2022-08-24T14:38:34.189Z","dependency_job_id":null,"html_url":"https://github.com/cbl/algorithm-analyzer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cbl%2Falgorithm-analyzer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cbl%2Falgorithm-analyzer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cbl%2Falgorithm-analyzer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cbl%2Falgorithm-analyzer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cbl","download_url":"https://codeload.github.com/cbl/algorithm-analyzer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243960434,"owners_count":20375101,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithms","data-structures","java"],"created_at":"2024-10-10T07:10:04.138Z","updated_at":"2025-03-19T02:31:14.604Z","avatar_url":"https://github.com/cbl.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# algorithm-analyzer\n\nA tool to analyze various sorting algorithms, graphs or binary trees. The repository contains implementations for algorithms that where taught by Prof. Dr. rer. nat. Karsten Weicker in the Sommersemester 2021 at the Htwk Leipzig.\n\nThis is a community project with the aim to exchange experiences among students. It is also designed to better understand the algorithms and how they work.\n\n## Contributing\n\nEveryone is welcome to contribute, please read the [contribution guideline](./.github/CONTRIBUTING.md) if you want to know how this works.\n\n## Table Of Contents\n\n-   [Usage](#usage)\n    -   [Setup](#setup)\n    -   [Run](#run)\n    -   [Build](#build)\n    -   [Test](#test)\n    -   [Formatting Code](#formatting-code)\n-   [Sorting Algorithms](sorting)\n    -   [Bubblesort](#bubblesort)\n    -   [Insertionsort](#insertionsort)\n    -   [Quicksort](#quicksort)\n    -   [Shellsort](#shellsort)\n    -   [Selectionsort](#selectionsort)\n    -   [Heapsort](#heapsort)\n    -   [Radixsort](#radixsort)\n-   [Data Structures](#data-structures)\n    -   [Binary Search](#binary-search)\n    -   [AVL Tree](#avl-tree)\n    -   [Skiplist](#skiplist)\n-   [Graph Algorithms](graphs)\n    -   [Deepsearch (Tiefensuche)](#deepsearch)\n    -   [Breath-First Search (Breitensuche)](#breath-first-search)\n    -   [Dijkstra](#dijkstra)\n    -   [Floyd–Warshall Algorithm](#floyd-warhsall)\n    -   [Traveling Salesman (Rundreise)](#tsm)\n-   [Hash Tables](#hash-tables)\n    -   [Closed Hash Table](#closed-hash-table)\n    -   [Double Hash Table](#double-hash-table)\n    -   [Brent Hash Table](#brent-hash-table)\n    -   [Coalesced Hash Table](#coalesced-hash-table)\n-   [Runtime](#runtime)\n\n\u003ca name=\"usage\"\u003e\u003c/a\u003e\n\n## Usage\n\n\u003ca name=\"setup\"\u003e\u003c/a\u003e\n\n### Requirements\n\n-   JDK `16` or newer\n-   Maven `3.8.x` or newer\n\n### Setup\n\n`mvn clean install`\n\n\u003ca name=\"run\"\u003e\u003c/a\u003e\n\n### Run\n\n`mvn exec:java`\n\n\u003ca name=\"build\"\u003e\u003c/a\u003e\n\n### Build\n\nCompile to run directly in the terminal:\n\n`mvn compile`\n\nPackage compiled source code into an executable jar file:\n\n`mvn package`\n\nOutputs to `target/algorithm-analyzer-x.x.x.jar`\n\n\u003ca name=\"test\"\u003e\u003c/a\u003e\n\n### Test\n\n`mvn test`\n\n\u003ca name=\"formatting-code\"\u003e\u003c/a\u003e\n\n### Formatting Code\n\n`/bin/sh bin/format.sh`\n\nCalls google-code-formatter locally.\n\n\u003ca name=\"sorting\"\u003e\u003c/a\u003e\n\n## Sorting Algorithms\n\n\u003ca name=\"bubblesort\"\u003e\u003c/a\u003e\n\n### Bubblesort\n\n```java\nfinal Integer[] array = {15, 48, 22, 34, 27, 35, 14};\n\nfinal Algorithm\u003cEvent, BubbleSort.Data\u003cInteger\u003e\u003e a = new BubbleSort\u003cInteger\u003e();\nfinal EventConsumer\u003cEvent\u003e ec = new GeneralEventConsumer();\n\na.run(ec, new BubbleSort.Data\u003c\u003e(array));\n\nec.visitEvents(new LogEventVisitor());\n```\n\n\u003ca name=\"insertionsort\"\u003e\u003c/a\u003e\n\n### Insertionsort\n\n```java\nfinal Integer[] array = {15, 48, 22, 34, 27, 35, 14};\n\nfinal Algorithm\u003cEvent, InsertionSort.Data\u003cInteger\u003e\u003e a = new InsertionSort\u003cInteger\u003e();\nfinal EventConsumer\u003cEvent\u003e ec = new GeneralEventConsumer();\n\na.run(ec, new InsertionSort.Data\u003c\u003e(array));\n\nec.visitEvents(new LogEventVisitor());\n```\n\n\u003ca name=\"quicksort\"\u003e\u003c/a\u003e\n\n### Quicksort\n\n```java\nfinal Integer[] array = {20, 54, 28, 31, 5, 24, 39, 14, 1, 15};\n\nfinal Algorithm\u003cEvent, Quicksort.Data\u003cInteger\u003e\u003e a = new Quicksort\u003cInteger\u003e();\nfinal EventConsumer\u003cEvent\u003e ec = new GeneralEventConsumer();\n\na.run(ec, new Quicksort.Data\u003c\u003e(array));\n\nec.visitEvents(new LogEventVisitor());\n```\n\n\u003ca name=\"shellsort\"\u003e\u003c/a\u003e\n\n### Shellsort\n\n```java\nfinal Integer[] array = {6, 5, 4, 3, 2, 1};\n\nfinal Algorithm\u003cEvent, Shellsort.Data\u003cInteger\u003e\u003e a = new Shellsort\u003cInteger\u003e();\nfinal EventConsumer\u003cEvent\u003e ec = new GeneralEventConsumer();\n\na.run(ec, new Shellsort.Data\u003c\u003e(array));\n\nec.visitEvents(new LogEventVisitor());\n```\n\n\u003ca name=\"selectionsort\"\u003e\u003c/a\u003e\n\n### Selectionsort\n\n```java\nfinal Integer[] array = {64, 25, 12, 22, 11};\n\nfinal Algorithm\u003cEvent, Selectionsort.Data\u003cInteger\u003e\u003e a = new Selectionsort\u003cInteger\u003e();\nfinal EventConsumer\u003cEvent\u003e ec = new GeneralEventConsumer();\n\na.run(ec, new Selectionsort.Data\u003c\u003e(array));\n\nec.visitEvents(new LogEventVisitor());\n```\n\n\u003ca name=\"heapsort\"\u003e\u003c/a\u003e\n\n### Heapsort\n\n```java\nfinal Integer[] array = {20, 54, 28, 31, 5, 24, 39, 14, 1, 15};\n\nfinal Algorithm\u003cEvent, HeapSort.Data\u003cInteger\u003e\u003e a = new HeapSort\u003cInteger\u003e();\nfinal EventConsumer\u003cEvent\u003e ec = new GeneralEventConsumer();\n\na.run(ec, new HeapSort.Data\u003c\u003e(array));\n\nec.visitEvents(new LogEventVisitor());\n\n```\n\n\u003ca name=\"countingsort\"\u003e\u003c/a\u003e\n\n### Countingsort\n\n```java\nfinal Integer[] array = {2, 4, 2, 1, 1, 4, 2, 1, 4, 2};\n\nfinal Algorithm\u003cEvent, Countingsort.Data\u003cInteger\u003e\u003e a = new Countingsort\u003cInteger\u003e();\nfinal EventConsumer\u003cEvent\u003e ec = new GeneralEventConsumer();\n\na.run(ec, new Countingsort.Data\u003c\u003e(array));\n\nec.visitEvents(new LogEventVisitor());\n```\n\n\u003ca name=\"radixsort\"\u003e\u003c/a\u003e\n\n### Radixsort\n\nSee: [Countingsort](#countingsort)\n\n```java\n// Todo...\n```\n\n\u003ca name=\"data-structures\"\u003e\u003c/a\u003e\n\n## Data Structures\n\n\u003ca name=\"binary-search\"\u003e\u003c/a\u003e\n\n### Binary Search\n\n```java\nfinal Integer[] array = {21, 25, 32, 33, 26, 40, 52, 53, 57, 60, 65, 66, 67, 78};\nfinal Integer searchedValue = 60;\n\nfinal Algorithm\u003cEvent, BinarySearch.Data\u003cInteger\u003e\u003e a = new BinarySearch\u003c\u003e();\nfinal EventConsumer\u003cEvent\u003e ec = new GeneralEventConsumer();\n\na.run(ec, new BinarySearch.Data\u003cInteger\u003e(array, searchedValue));\n\nec.visitEvents(new LogEventVisitor());\n```\n\n\u003ca name=\"avl\"\u003e\u003c/a\u003e\n\n### AVL Tree\n\n```java\nAVLTree\u003cInteger\u003e t = new AVLTree\u003cInteger\u003e(Comparator.naturalOrder());\nEventConsumer\u003cEvent\u003e ec = new GeneralEventConsumer();\nt.onEvent(ec);\n\nt.insert(4);\nt.insert(2);\nt.insert(5);\nt.insert(1);\nt.insert(3);\nt.insert(6);\nt.insert(10);\nt.insert(15);\nt.remove(2);\nt.insert(13);\nt.remove(3);\n\nec.visitEvents(new LogEventVisitor());\n```\n\n\u003ca name=\"skiplist\"\u003e\u003c/a\u003e\n\n### Skiplist\n\n```java\n// Todo ...\n```\n\n\u003ca name=\"graphs\"\u003e\u003c/a\u003e\n\n## Graph Algorithms\n\n\u003ca name=\"deepsearch\"\u003e\u003c/a\u003e\n\n### Deepsearch (Tiefensuche)\n\n```java\nint size = 4;\nString[] nodeNames = {\"A\", \"B\", \"C\", \"D\"};\nWeightFreeGraph\u003cInteger\u003e graph = new AdjacentMatrixGraph(size);\n\ngraph.setEdge(1, 0);\ngraph.setEdge(0, 3);\ngraph.setEdge(0, 2);\ngraph.setEdge(2, 1);\ngraph.setEdge(2, 3);\ngraph.setEdge(3, 1);\ngraph.setEdge(3, 2);\n\nfinal Algorithm\u003cEvent, Deepsearch.Data\u003e a = new Deepsearch();\nfinal EventConsumer\u003cEvent\u003e ec = new GeneralEventConsumer();\n\na.run(ec, new Deepsearch.Data(graph, nodeNames));\n\nec.visitEvents(new LogEventVisitor());\n```\n\n\u003ca name=\"breath-first-search\"\u003e\u003c/a\u003e\n\n### Breath-First Search (Breitensuche)\n\n```java\nString start = \"v1\";\nCollection\u003cEdge\u003cString, Integer\u003e\u003e edges = Set.of(\n    Edge.of(\"v1\", \"v2\", 7),\n    Edge.of(\"v1\", \"v3\", 4),\n    Edge.of(\"v1\", \"v4\", 2),\n    Edge.of(\"v2\", \"v3\", 3),\n    Edge.of(\"v2\", \"v5\", 3),\n    Edge.of(\"v3\", \"v4\", 1),\n    Edge.of(\"v3\", \"v5\", 5),\n    Edge.of(\"v4\", \"v5\", 8)\n);\nGraph\u003cString, Integer\u003e graph = new LinkedGraph\u003c\u003e(edges);\nfor (Edge\u003cString, Integer\u003e e : edges) {\n    graph.setEdge(e.to(), e.from(), e.weight());\n}\n\nfinal Algorithm\u003cEvent, BreathFirst.Data\u003e a = new BreathFirst();\nfinal EventConsumer\u003cEvent\u003e ec = new GeneralEventConsumer();\n\na.run(ec, new BreathFirst.Data\u003cString\u003e(graph, start));\n\nec.visitEvents(new LogEventVisitor());\n```\n\n\u003ca name=\"dijkstra\"\u003e\u003c/a\u003e\n\n### Dijkstra\n\n```java\nGraph\u003cCharacter, Integer\u003e costs = new LinkedGraph\u003c\u003e(Set.of(\n    Edge.of('A', 'B', 100),\n    Edge.of('A', 'C', 50),\n    Edge.of('B', 'C', 100),\n    Edge.of('B', 'D', 100),\n    Edge.of('B', 'E', 250),\n    Edge.of('C', 'E', 250),\n    Edge.of('D', 'E', 50)\n));\n\nfinal Algorithm\u003cEvent, Dijkstra.Data\u003cCharacter\u003e\u003e a = new Dijkstra\u003c\u003e();\nfinal EventConsumer\u003cEvent\u003e ec = new GeneralEventConsumer();\n\na.run(ec, new Dijkstra.Data\u003cCharacter\u003e(costs, 'A'));\n\nec.visitEvents(new LogEventVisitor());\n```\n\n\u003ca name=\"floyd-warshall\"\u003e\u003c/a\u003e\n\n### Floyd–Warshall Algorithm\n\n```java\nGraph\u003cCharacter, Integer\u003e costs = new LinkedGraph\u003c\u003e(Set.of(\n    Edge.of('v', 'x', 2),\n    Edge.of('w', 'v', 10),\n    Edge.of('w', 'x', 5),\n    Edge.of('x', 'v', 3),\n    Edge.of('x', 'y', 2),\n    Edge.of('y', 'v', 10),\n    Edge.of('y', 'w', 1)\n));\n\nAlgorithm\u003cEvent, FloydWarshall.Data\u003cCharacter\u003e\u003e alg = new FloydWarshall\u003c\u003e();\nfinal EventConsumer\u003cEvent\u003e ec = new GeneralEventConsumer();\nalg.run(ec, new FloydWarshall.Data\u003c\u003e(costs));\n\nec.visitEvents(new LogEventVisitor());\n```\n\n\u003ca name=\"tsm\"\u003e\u003c/a\u003e\n\n### Traveling Salesman (Rundreise)\n\n```java\nCollection\u003cEdge\u003cCharacter, Integer\u003e\u003e edges = Set.of(\n    Edge.of('A', 'B', 7),\n    Edge.of('A', 'C', 5),\n    Edge.of('A', 'D', 8),\n    Edge.of('A', 'E', 12),\n    Edge.of('B', 'C', 5),\n    Edge.of('B', 'D', 9),\n    Edge.of('B', 'E', 8),\n    Edge.of('C', 'D', 4),\n    Edge.of('C', 'E', 7),\n    Edge.of('D', 'E', 9)\n);\n\nGraph\u003cCharacter, Integer\u003e graph = new LinkedGraph\u003c\u003e(edges);\nfor (Edge\u003cCharacter, Integer\u003e e : edges) {\n    graph.setEdge(e.to(), e.from(), e.weight());\n}\n\nfinal Algorithm\u003cEvent, TravelingSalesman.Data\u003cCharacter\u003e\u003e a = new TravelingSalesman\u003c\u003e();\nfinal EventConsumer\u003cEvent\u003e ec = new GeneralEventConsumer();\n\na.run(ec, new TravelingSalesman.Data\u003cCharacter\u003e(graph));\n\nec.visitEvents(new LogEventVisitor());\n```\n\n\u003ca name=\"hash-tables\"\u003e\u003c/a\u003e\n\n## Hash Tables\n\n\u003ca name=\"closed-hash-table\"\u003e\u003c/a\u003e\n\n### Closed Hash Table\n\n```java\nint startSize = 11;\nEventConsumer\u003cEvent\u003e ec = new GeneralEventConsumer();\nClosedHashTable.Hashing hashing = (int key, int p) -\u003e {\n    return key % p;\n};\nClosedHashTable.Probing probing = (int key, int j, int p) -\u003e {\n    return (key % p) + j;\n};\nClosedHashTable table = new ClosedHashTable(ec, startSize, hashing, probing);\ntable.resizeFactor = 3 / 2; // Resize by next prime to 3/2 of size.\ntable.resizeAtOccupation = 0.9; // Resize at 90% occupation.\n\ntable.insert(29);\ntable.insert(12);\ntable.insert(7);\ntable.insert(19);\ntable.insert(30);\ntable.insert(40);\ntable.insert(11);\ntable.remove(7);\ntable.insert(18);\n\nec.visitEvents(new LogEventVisitor());\n```\n\n\u003ca name=\"double-hash-table\"\u003e\u003c/a\u003e\n\n### Double Hash Table\n\n```java\nint size = 11;\nEventConsumer\u003cEvent\u003e ec = new GeneralEventConsumer();\nDoubleHashTable.Hashing hashing = (int key) -\u003e {\n    return key % 11;\n};\nDoubleHashTable.Hashing doubleHashing = (int key) -\u003e {\n    return (1 + (key % (11 - 1)));\n};\nDoubleHashTable table = new DoubleHashTable(ec, size, hashing, doubleHashing);\n\ntable.insert(29);\ntable.insert(12);\ntable.insert(7);\ntable.insert(19);\ntable.insert(30);\ntable.insert(40);\ntable.insert(11);\n\nec.visitEvents(new LogEventVisitor());\n```\n\n\u003ca name=\"brent-hash-table\"\u003e\u003c/a\u003e\n\n### Brent Hash Table\n\n```java\nint size = 11;\nEventConsumer\u003cEvent\u003e ec = new GeneralEventConsumer();\nBrentHashTable.Hashing hashing =(int key) -\u003e {\n    return key % 11;\n};\nBrentHashTable.Hashing doubleHashing = (int key) -\u003e {\n    return (1 + (key % (11 - 1)));\n};\nBrentHashTable table = new BrentHashTable(ec, size, hashing, doubleHashing);\n\ntable.insert(29);\ntable.insert(12);\ntable.insert(7);\ntable.insert(19);\ntable.insert(30);\ntable.insert(40);\ntable.insert(11);\n\nec.visitEvents(new LogEventVisitor());\n```\n\n\u003ca name=\"coalesced-hash-table\"\u003e\u003c/a\u003e\n\n### Coalesced Hash Table\n\n```java\nint mod = 10;\nint reserved = 2;\nEventConsumer\u003cEvent\u003e ec = new GeneralEventConsumer();\nCoalescedHashTable table = new CoalescedHashTable(ec, mod, reserved);\n\ntable.insert(29);\ntable.insert(12);\ntable.insert(7);\ntable.insert(19);\ntable.insert(30);\ntable.insert(40);\ntable.insert(2);\ntable.insert(39);\ntable.insert(8);\n\nec.visitEvents(new LogEventVisitor());\n```\n\n\u003ca name=\"runtime\"\u003e\u003c/a\u003e\n\n## Runtime\n\n| Algorithm     | Best Case  | Worst Case | Expected Case           |\n| ------------- | ---------- | ---------- | ----------------------- |\n| Shellsort     | O(n log n) | O(n²)      | Depends on gap sequence |\n| Selectionsort | O(n²)      | O(n²)      | O(n²)                   |\n| dijkstra      | O(n²)      | O(n²)      | O(n²)                   |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcbl%2Falgorithm-analyzer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcbl%2Falgorithm-analyzer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcbl%2Falgorithm-analyzer/lists"}