Skip to content

Commit

Permalink
algorithms lesson #2 + hw init
Browse files Browse the repository at this point in the history
  • Loading branch information
biblelamp committed Jun 25, 2023
1 parent 8f9f0b0 commit 7214990
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
59 changes: 59 additions & 0 deletions BerlinTelran/Algorithms/src/homework2/Homework2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package homework2;

/**
* Algorithms. Homework #2
*
* @author Sergey Iryupin
* @version 25 Jun 2023
*/

/**
* 2. Task #1
* START
* READ number n
* IF n == 1 THEN return
* FOR i = 1, i <= n, i++
* FOR j = 1; j <= n, j++
* print "*"
* BREAK
* END
*/

/**
* 2. Task #2
* START
* READ number n
* numbers i = 0, j = 0, a = 0
* FOR i = n/2, i <= n; i++
* FOR j = 2, j <= n, j * 2
* a = a + n / 2
* END
*/

/**
* 2. Task #3
* START
* READ number n
* number a = 0
* FOR i = 0, i < n, i++
* FOR j = n, j > i, j--
* a = a + i + j
* END
*/

/**
* 2. Task #4
* START
* READ number n
* numbers a = 0, i = n
* WHILE i > 0
* a = a + i
* i = i / 2
* END
*/

public class Homework2 {
public static void main(String[] args) {

}
}
32 changes: 32 additions & 0 deletions BerlinTelran/Algorithms/src/lesson2/Lesson2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package lesson2;

import java.util.Arrays;

public class Lesson2 {
public static void main(String[] args) {
int[] array = {1, 4, 5, 6, 9};

// сложность алгоритма O(1)
int a = array[1];

// сложность алгоритма O(N)
int sum = 0;
for (int item : array) {
sum += item;
}
System.out.println(Arrays.toString(array));
System.out.println(sum);

// сложность алгоритма O(log N)
int idx = Arrays.binarySearch(array, 4);

// сложность алгоритма O(N log N)
// сортировка слиянием и быстрая сортировка

// сложность алгоритма O(N ^ 2)
// пузырьковая сортировка

// сложность алгоритма O(N!)
// задача коммивояжёра
}
}

0 comments on commit 7214990

Please sign in to comment.