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
Find the number of times f() is called as a function of the input size n. | |
a. for (i = n; i > 1; i /= 2) | |
f() | |
a. O(log n) | |
b. for (i = 0; i * i < n; i++) | |
f() | |
b. O(sqrt n) |
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
public static void main(String[] args) { | |
long startTime = System.currentTimeMillis(); | |
int n = 100 * 1000; | |
long res = compute(n); | |
long endTime = System.currentTimeMillis(); | |
System.out.println(res); | |
// 2.2 GHz ~ 2.2 * 10^9 op/sec |
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
# f(x) = x*x*x + a*x + b; a, b > 0, x - integer | |
# find x0, such that f(x0) = c, c > 0 | |
| |
# Для начала найдем левую границу, выберем произвольную отрицательную точку (например -1). | |
# Будем удваивать ее до тех пор, пока значение в ней будет больше заданного значения. | |
# | |
# Для того, чтобы найти правую границу, выберем произвольную положительную точку (например 1). | |
# Будем удваивать ее до тех пор, пока значение функции в этой точке меньше заданного. | |
| |
def findLeftBoard(C): |
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
static void insertionSort(int[] a) { | |
for(int i = 1; i < a.length; ++i) { | |
// invariant x[0:i-1] sorted | |
// shift i_th element to its proper place | |
for(int j = i; j > 0 && a[j-1] > a[j]; --j) { | |
swap(a, j-1, j); | |
} | |
} | |
} | |
|
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
from typing import List, Optional, Set, Tuple | |
class Heap: | |
def __init__(self, arr: Optional[List[int]] = None): | |
self._to_delete: Set[int] = set() | |
if arr: | |
self.__heapify(arr) | |
else: | |
self.__arr: List[int] = [] |
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
changed: [localhost] => (item={u'folder': u'org/jenkins-ci/ui', u'version': u'1.1', u'name': u'ace-editor'}) | |
failed: [localhost] (item={u'version': u'2.28.1', u'name': u'allure-jenkins-plugin'}) => {"changed": true, "cmd": ["java", "-jar", "/opt/jenkins-cli.jar", "-i", "/var/lib/jenkins/.ssh/jenkins_deploy_key", "-s", "http://localhost:8080/", "-remoting", "install-plugin", "https://repo.jenkins-ci.org/releases/org/jenkins-ci/plugins/allure-jenkins-plugin/2.28.1/allure-jenkins-plugin-2.28.1.hpi", "-name", "allure-jenkins-plugin"], "delta": "0:00:02.250731", "end": "2019-10-22 15:36:35.991978", "item": {"name": "allure-jenkins-plugin", "version": "2.28.1"}, "msg": "non-zero return code", "rc": 1, "start": "2019-10-22 15:36:33.741247", "stderr": "\nERROR: Unexpected exception occurred while performing install-plugin command.\njava.io.FileNotFoundException: https://repo.jenkins-ci.org/releases/org/jenkins-ci/plugins/allure-jenkins-plugin/2.28.1/allure-jenkins-plugin-2.28.1.hpi\n\tat sun.net.www.protocol.http.Htt |
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
from collections import deque | |
from dataclasses import dataclass | |
class LRUCache: | |
@dataclass | |
class Node: | |
"""Doubly Linked List (DLL) Node class to store value to be cached""" | |
key: int = None | |
val: int = None |
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
void bubbleSort(int[] a) | |
{ | |
int n = a.length; | |
for (int j = 0; j < n - 1; ++j) | |
{ | |
for (int i = 0; i < n - j - 1; ++i) | |
{ | |
if (a[i] > a[i+1]) | |
{ | |
swap(a, i, i+1); |
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
import bisect | |
# very useful for the following kind of data: | |
# https://taxfoundation.org/2016-tax-brackets/ | |
cuts = [60, 70, 80, 90] | |
grades = 'FDCBA' | |
[grades[bisect.bisect(cuts, score)] for score in [32, 64, 70, 85, 90, 99, 100]] |
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
def read_tokens(): | |
return input().strip().split() | |
def read_ints(): | |
return [int(s) for s in read_tokens()] | |
a, = read_ints() # 1 int | |
a, b, c = read_ints() # several |