-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!) | ||
// задача коммивояжёра | ||
} | ||
} |