Joined projects

This commit is contained in:
Gašper Dobrovoljc
2024-11-29 13:11:09 +01:00
commit 74a510905e
24 changed files with 3536 additions and 0 deletions

31
izzivi/.gitignore vendored Normal file
View File

@@ -0,0 +1,31 @@
### IntelliJ IDEA ###
out/
!**/src/main/**/out/
!**/src/test/**/out/
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store
**.zip

8
izzivi/.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@@ -0,0 +1,12 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredIdentifiers">
<list>
<option value="tests.smoke.test_absences_sliding.TestAbsencesSliding.*" />
</list>
</option>
</inspection_tool>
</profile>
</component>

6
izzivi/.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_23" default="true" project-jdk-name="homebrew-23" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
izzivi/.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/aps1.iml" filepath="$PROJECT_DIR$/aps1.iml" />
</modules>
</component>
</project>

124
izzivi/.idea/uiDesigner.xml generated Normal file
View File

@@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

6
izzivi/.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

11
izzivi/aps1.iml Normal file
View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@@ -0,0 +1,61 @@
package izziv1;
public class Izziv1 {
public static void main(String[] args) {
System.out.println(" n | linearno | dvojisko |");
System.out.println("---------+--------------+------------------");
for (int i = 20000; i <= 1000000; i += 20000) {
System.out.printf(" %d | %d | %d\n", i, timeLinear(i), timeBinary(i));
}
}
static int[] generateTable(int n) {
int[] table = new int[n];
for (int i = 0; i < n; i++) {
table[i] = i + 1;
}
return table;
}
static int findLinear(int[] a, int v) {
for (int i = 0; i < a.length; i++) {
if (a[i] == v) {
return i;
}
}
return -1;
}
static int findBinary(int[] a, int l, int r, int v) {
int center = l + (r - l) / 2;
if (a[center] == v) {
return center;
}
if (a[center] > v) {
return findBinary(a, l, center, v);
}
return findBinary(a, center + 1, r, v);
}
static long timeLinear(int n) {
int[] table = generateTable(n);
long startTime = System.nanoTime();
for (int i = 0; i < 1000; i++) {
int num = (int)(Math.random() * n);
int _ = findLinear(table, num);
}
return (System.nanoTime() - startTime) / 1000;
}
static long timeBinary(int n) {
int[] table = generateTable(n);
long startTime = System.nanoTime();
for (int i = 0; i < 1000; i++) {
int num = (int)(Math.random() * n) + 1;
int _ = findBinary(table, 0, n - 1, num);
}
return (System.nanoTime() - startTime) / 1000;
}
}

View File

@@ -0,0 +1,23 @@
Zakaj so na časi pri vas drugačni kot v zgornji tabeli?
Ker sta procesorja različno zmogljiva in na računalnikih tečeju drugi procesi.
Kateri algoritem je hitrejši?
Binarni.
Kdaj bi lahko bil počasnejši algoritem hitrejši?
Če je iskan element na začetku tabele.
Kako je čas iskanja odvisen od velikosti naloge (linearno, kvadratno, ...)?
Linearno iskanje je linearno, binarno pa logaritemsko.
Je časovna odvisnost dvojiškega iskanja bližje linearni ali konstantni?
Konstantni.
Ali lahko napišemo boljši algoritem (za naš primer)?
Ja, ker so številke v tabeli od 1 do n, ne potrebujemo algoritma za iskanje ker je neka vrednost x na x-em mestu (4 je na 4. mestu, ...)
Katere so težave tovrstnega določanja časovne zahtevnosti?
Niso natančne.
Kako jih skušamo zaobiti?
Z večkratnim testiranjem in računanjem povprečja.

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

View File

@@ -0,0 +1,250 @@
package izziv2;
public class Izziv2 {
public static void main(String[] args) throws CollectionException {
System.out.println("Stack: ");
Stack<Integer> stack = new ArrayDeque<>();
int i = 0;
while (!stack.isFull()) {
stack.push(i++);
}
System.out.println(stack);
assert stack.top() == i;
while (!stack.isEmpty()) {
System.out.println(stack.pop());
}
System.out.println("Deque: ");
Deque<Integer> deque = new ArrayDeque<>();
// enqueue and dequeueBack are the same as push and pop
i = 0;
while (!deque.isFull()) {
deque.enqueueFront(i++);
}
System.out.println(deque);
assert deque.front() == i;
assert deque.back() == 0;
while (!deque.isEmpty()) {
System.out.println(deque.dequeue());
}
System.out.println("Sequence: ");
Sequence<Integer> sequence = new ArrayDeque<>();
i = 0;
while (!sequence.isFull()) {
sequence.add(i++);
}
System.out.println(sequence);
for (int j = 0; j < sequence.size(); j++) {
System.out.println(sequence.get(j));
}
}
}
class CollectionException extends Exception {
public CollectionException(String msg) {
super(msg);
}
}
interface Collection {
static final String ERR_MSG_EMPTY = "Collection is empty.";
static final String ERR_MSG_FULL = "Collection is full.";
boolean isEmpty();
boolean isFull();
int size();
String toString();
}
interface Stack<T> extends Collection {
T top() throws CollectionException;
void push(T x) throws CollectionException;
T pop() throws CollectionException;
}
interface Deque<T> extends Collection {
T front() throws CollectionException;
T back() throws CollectionException;
void enqueue(T x) throws CollectionException;
void enqueueFront(T x) throws CollectionException;
T dequeue() throws CollectionException;
T dequeueBack() throws CollectionException;
}
interface Sequence<T> extends Collection {
static final String ERR_MSG_INDEX = "Wrong index in sequence.";
T get(int i) throws CollectionException;
void add(T x) throws CollectionException;
}
class ArrayDeque<T> implements Deque<T>, Stack<T>, Sequence<T> {
private static final int DEFAULT_CAPACITY = 64;
private final T[] array;
private int front, back, size;
public ArrayDeque() {
//noinspection unchecked
array = (T[]) new Object[DEFAULT_CAPACITY];
front = back = size = 0;
}
private int index(int i) {
return (front + i) % DEFAULT_CAPACITY;
}
private int next(int i) {
return (i + 1) % DEFAULT_CAPACITY;
}
private int prev(int i) {
return (i + DEFAULT_CAPACITY - 1) % DEFAULT_CAPACITY;
}
@Override
public T front() throws CollectionException {
if (isEmpty()) {
throw new CollectionException(ERR_MSG_EMPTY);
}
return array[front];
}
@Override
public T back() throws CollectionException {
if (isEmpty()) {
throw new CollectionException(ERR_MSG_EMPTY);
}
return array[back];
}
@Override
public void enqueue(T x) throws CollectionException {
this.push(x);
}
@Override
public void enqueueFront(T x) throws CollectionException {
if (isFull()) {
throw new CollectionException(ERR_MSG_FULL);
}
front = this.prev(front);
size++;
array[front] = x;
}
@Override
public T dequeue() throws CollectionException {
if (isEmpty()) {
throw new CollectionException(ERR_MSG_EMPTY);
}
T x = array[front];
array[front] = null;
front = this.next(front);
size--;
return x;
}
@Override
public T dequeueBack() throws CollectionException {
return this.pop();
}
@Override
public T get(int i) throws CollectionException {
if (isEmpty()) {
throw new CollectionException(ERR_MSG_EMPTY);
}
if (i < 0 || i >= size) {
throw new CollectionException(ERR_MSG_INDEX);
}
return array[index(i)];
}
@Override
public void add(T x) throws CollectionException {
this.push(x);
}
@Override
public T top() throws CollectionException {
return this.back();
}
@Override
public void push(T x) throws CollectionException {
if (isFull()) {
throw new CollectionException(ERR_MSG_FULL);
}
array[back] = x;
back = this.next(back);
size++;
}
@Override
public T pop() throws CollectionException {
if (isEmpty()) {
throw new CollectionException(ERR_MSG_EMPTY);
}
back = this.prev(back);
T x = array[back];
array[back] = null;
size--;
return x;
}
@Override
public boolean isEmpty() {
return size == 0;
}
@Override
public boolean isFull() {
return size == DEFAULT_CAPACITY;
}
@Override
public int size() {
return size;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("[");
if (size > 0) {
sb.append(array[front].toString());
}
for (int i = 0; i < size - 1; i++) {
sb.append(", ").append(array[this.next(front + i)].toString());
}
sb.append("]");
return sb.toString();
}
}

View File

@@ -0,0 +1,112 @@
package izziv3;
import java.util.ArrayList;
public class Izziv3 {
public static void main(String[] args) {
// int size = Integer.parseInt(args[0]);
int size = 20;
StdDraw.setCanvasSize(1500, 800);
StdDraw.setXscale(-1, size);
StdDraw.setYscale((int) (Math.log(size + 1) / Math.log(2)) + 1, -1);
CompleteBinaryTreeDrawer ctd = new CompleteBinaryTreeDrawer(size);
ctd.drawLevelorder();
}
}
class CompleteBinaryTreeDrawer {
char[] data;
int[] x, y;
ArrayList<Integer> inorder;
final int size;
public CompleteBinaryTreeDrawer(int size) {
this.size = size;
data = new char[size];
x = new int[size];
y = new int[size];
inorder = new ArrayList<>();
inorder(0);
for (int i = 0; i < size; i++) {
data[i] = (char) ('A' + i);
x[i] = inorder.indexOf(Integer.valueOf(i));
y[i] = (int) (Math.log(i + 1) / Math.log(2));
}
}
void inorder(int i) {
if (2 * i + 1 < size) {
inorder(i * 2 + 1);
}
inorder.add(Integer.valueOf(i));
if (2 * i + 2 < size) {
inorder(2 * i + 2);
}
}
void drawNode(int i) {
StdDraw.filledCircle(x[i], y[i], 0.1);
}
void drawEdgeToNode(int i) {
int o = (i - 1) / 2;
StdDraw.line(x[o], y[o], x[i], y[i]);
}
void drawLevelorder() {
drawNode(0);
for (int i = 0; i < size; i++) {
drawEdgeToNode(i);
drawNode(i);
}
}
void drawPreorder(int i) {
drawEdgeToNode(i);
drawNode(i);
if (2 * i + 1 < size) {
drawInorder(i * 2 + 1);
}
if (2 * i + 2 < size) {
drawInorder(2 * i + 2);
}
}
void drawInorder(int i) {
if (2 * i + 1 < size) {
drawInorder(i * 2 + 1);
}
drawEdgeToNode(i);
drawNode(i);
if (2 * i + 2 < size) {
drawInorder(2 * i + 2);
}
}
void drawPostorder(int i) {
if (2 * i + 1 < size) {
drawInorder(i * 2 + 1);
}
if (2 * i + 2 < size) {
drawInorder(2 * i + 2);
}
drawEdgeToNode(i);
drawNode(i);
}
int traverse(int i, int x, int y) {
if (2 * i + 1 < size) {
x = traverse(2 * i + 1, x, y + 1);
}
this.x[i] = x;
this.y[i] = y;
if (2 * i + 2 < size) {
x = traverse(2 * i + 2, x + 1, y + 1);
}
return x + 1;
}
}

File diff suppressed because it is too large Load Diff