Dataset Viewer
Auto-converted to Parquet Duplicate
question
stringlengths
6
3.53k
text
stringlengths
17
2.05k
source
stringclasses
1 value
Consider the following contains function defined on Iterable (in particular, it accepts both Vector and List). def contains[A](l: Iterable[A], elem: A): Boolean = val n = l.size if n <= 5 then for i <- l do if i == elem then return true false else val (p0, p1) = parallel( contains(l.take(n / 2), elem), contains(l.drop(n / 2), elem) ) p0 || p1 Let $n$$n$ be the size of l. Assume that drop and take run in $\Theta(1)$ on Vector and $\Theta(n)$ on List. What is the asymptotic depth of contains if it is called on a List?
This can happen for at most 2K(x,y)-l = 2k different strings. These strings can be enumerated given k,l and hence x can be specified by its index in this enumeration. The corresponding program for x has size k + O(1). Theorem proved.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
Consider the following contains function defined on Iterable (in particular, it accepts both Vector and List). def contains[A](l: Iterable[A], elem: A): Boolean = val n = l.size if n <= 5 then for i <- l do if i == elem then return true false else val (p0, p1) = parallel( contains(l.take(n / 2), elem), contains(l.drop(n / 2), elem) ) p0 || p1 Let $n$$n$ be the size of l. Assume that drop and take run in $\Theta(1)$ on Vector and $\Theta(n)$ on List. What is the asymptotic depth of contains if it is called on a List?
The earliest result may be found directly from elementary probability theory. Suppose we model the above process taking L {\displaystyle L} and G {\displaystyle G} as the fragment length and target length, respectively. The probability of "covering" any given location on the target with one particular fragment is then L / G {\displaystyle L/G} . (This presumes L ≪ G {\displaystyle L\ll G} , which is valid often, but not for all real-world cases.)
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
What is the asymptotic work of <code>parGroupyBy2</code>?
{\displaystyle {\begin{aligned}\mathbb {A} :\ \sum _{i\in \mathbb {A} }2^{i}&=n-k,\\\mathbb {B} :\ \sum _{j\in \mathbb {B} }2^{j}&=\left\lfloor {\dfrac {k-1}{2}}\right\rfloor .\\\end{aligned}}} One can mimic a bitwise AND operation by intersecting these two sets: { n k } mod 2 = { 0 , A ∩ B ≠ ∅ ; 1 , A ∩ B = ∅ ; {\displaystyle {\begin{Bmatrix}n\\k\end{Bmatrix}}\,{\bmod {\,}}2={\begin{cases}0,&\mathbb {A} \cap \mathbb {B} \neq \emptyset ;\\1,&\mathbb {A} \cap \mathbb {B} =\emptyset ;\end{cases}}} to obtain the parity of a Stirling number of the second kind in O(1) time. In pseudocode: { n k } mod 2 := ; {\displaystyle {\begin{Bmatrix}n\\k\end{Bmatrix}}\,{\bmod {\,}}2:=\left;} where {\displaystyle \left} is the Iverson bracket. The parity of a central Stirling number of the second kind { 2 n n } {\displaystyle \textstyle \left\{{2n \atop n}\right\}} is odd if and only if n {\displaystyle n} is a fibbinary number, a number whose binary representation has no two consecutive 1s.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
What is the asymptotic work of <code>parGroupyBy2</code>?
Asymptotically, this probability is λ {\displaystyle \lambda } . More precisely, λ = lim n → ∞ Prob { P 2 ( n ) ≤ P 1 ( n ) } {\displaystyle \lambda =\lim _{n\to \infty }{\text{Prob}}\left\{P_{2}(n)\leq {\sqrt {P_{1}(n)}}\right\}} where P 2 ( n ) {\displaystyle P_{2}(n)} is the second largest prime factor n. The Golomb-Dickman constant also arises when we consider the average length of the largest cycle of any function from a finite set to itself.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
We have a collection of rectangles in a plane, whose sides are aligned with the coordinate axes. Each rectangle is represented by its lower left corner $(x_1,y_1)$ and its upper right corner $(x_2,y_2)$. All coordinates are of type Long. We require $x_1 \le x_2$ and $y_1 \le y_2$. Define a case class Rectangle storing two corners.
In the case of d = 2 {\displaystyle d=2} the rectangle is represented by ( ( x m i n , y m i n ) , ( x m a x , y m a x ) ) {\displaystyle \,((x_{min},y_{min}),(x_{max},y_{max}))} and the MBR thus four corners ( x m i n , y m i n , x m a x , y m a x ) {\displaystyle \,(x_{min},y_{min},x_{max},y_{max})} .
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
We have a collection of rectangles in a plane, whose sides are aligned with the coordinate axes. Each rectangle is represented by its lower left corner $(x_1,y_1)$ and its upper right corner $(x_2,y_2)$. All coordinates are of type Long. We require $x_1 \le x_2$ and $y_1 \le y_2$. Define a case class Rectangle storing two corners.
Dominating rectangles, or box representation, maps the points on the lower of the two lines of the trapezoid representation as lying on the x-axis and that of the upper line as lying on the y-axis of the Euclidean plane. Each trapezoid then corresponds to an axis-parallel box in the plane. Using the notion of a dominance order (In RK, x is said to be dominated by y, denoted x < y, if xi is less than yi for i = 1, …, k), we say that a box b dominates a box b’ if the lower corner of b dominates the upper corner of b’.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
Which of the following scheduler policies are preemptive?
The scheduler will delay preemption as long as possible if there are unused logical CPUs. If a task is marked idle priority policy, it cannot preempt at all even other idle policy marked tasks but rather use cooperative multitasking. : ln 2341–2344
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
Which of the following scheduler policies are preemptive?
Fixed-priority preemptive scheduling is a scheduling system commonly used in real-time systems. With fixed priority preemptive scheduling, the scheduler ensures that at any given time, the processor executes the highest priority task of all those tasks that are currently ready to execute. The preemptive scheduler has a clock interrupt task that can provide the scheduler with options to switch after the task has had a given period to execute—the time slice. This scheduling system has the advantage of making sure no task hogs the processor for any time longer than the time slice.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
Which of the following are correct implementation for acquire function ? Assume 0 means UNLOCKED and 1 means LOCKED. Initially l->locked = 0.
The first blocked lock for operation in the queue is acquired as soon as the existing blocking lock is removed from the object, and then its respective operation is executed. If a lock for operation in the queue is not blocked by any existing lock (existence of multiple compatible locks on a same object is possible concurrently), it is acquired immediately. Comment: In some publications, the table entries are simply marked "compatible" or "incompatible", or respectively "yes" or "no".
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
Which of the following are correct implementation for acquire function ? Assume 0 means UNLOCKED and 1 means LOCKED. Initially l->locked = 0.
So when P1 tries to acquire the lock it immediately succeeds and next_ticket is incremented to 1 (Row 2). When P3 tries to acquire the lock it gets 1 for its my_ticket, next ticket is incremented to 2, and it must wait since now_serving is still 0 (Row 3). Next, when P2 attempts to acquire the lock it gets 2 for its my_ticket, next_ticket is incremented to 3, and it must also wait due to now_serving still being 0 (Row 4).
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
In this week's lecture, you have been introduced to the aggregate method of ParSeq[A] (and other parallel data structures). It has the following signature: def aggregate[B](z: B)(f: (B, A) => B, g: (B, B) => B): B Discuss, as a group, what aggregate does and what its arguments represent. Consider the parallel sequence xs containing the three elements x1, x2 and x3. Also consider the following call to aggregate: xs.aggregate(z)(f, g) The above call might potentially result in the following computation: f(f(f(z, x1), x2), x3) But it might also result in other computations. Come up with at least two other computations in terms of f and g that may result from the above call to aggregate. Below are other examples of calls to aggregate. In each case, check if the call can lead to different results depending on the strategy used by aggregate to aggregate all values contained in data down to a single value. You should assume that data is a parallel sequence of values of type BigInt. 1. data.aggregate(1)(_ + _, _ + _)
Aggregate functions present a bottleneck, because they potentially require having all input values at once. In distributed computing, it is desirable to divide such computations into smaller pieces, and distribute the work, usually computing in parallel, via a divide and conquer algorithm. Some aggregate functions can be computed by computing the aggregate for subsets, and then aggregating these aggregates; examples include COUNT, MAX, MIN, and SUM. In other cases the aggregate can be computed by computing auxiliary numbers for subsets, aggregating these auxiliary numbers, and finally computing the overall number at the end; examples include AVERAGE (tracking sum and count, dividing at the end) and RANGE (tracking max and min, subtracting at the end).
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
In this week's lecture, you have been introduced to the aggregate method of ParSeq[A] (and other parallel data structures). It has the following signature: def aggregate[B](z: B)(f: (B, A) => B, g: (B, B) => B): B Discuss, as a group, what aggregate does and what its arguments represent. Consider the parallel sequence xs containing the three elements x1, x2 and x3. Also consider the following call to aggregate: xs.aggregate(z)(f, g) The above call might potentially result in the following computation: f(f(f(z, x1), x2), x3) But it might also result in other computations. Come up with at least two other computations in terms of f and g that may result from the above call to aggregate. Below are other examples of calls to aggregate. In each case, check if the call can lead to different results depending on the strategy used by aggregate to aggregate all values contained in data down to a single value. You should assume that data is a parallel sequence of values of type BigInt. 1. data.aggregate(1)(_ + _, _ + _)
Many parallel databases use distributed parallel processing to execute the queries. While executing an aggregate function such as sum, the following strategy is used: Compute a partial sum locally and concurrently at each processor using the data present in the associated disk partition with it. Add these local subtotals to get the final result.The final result may contain some rounding error as each processor independently rounds-off local results. One test is to ensure that such errors do not occur.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
Freshly graduated from EPFL, you have been hired as contractors for a successful and rapidly growing bank. The bank has been experiencing problems with their money management system recently, which is written in Scala, and so they hired the best and brightest young engineer they could find: you! The system had been working perfectly fine so far, they tell you. In the past days, due to an increased number of customers, they had to switch from a single-threaded sequential execution environment to a multi-threaded concurrent one, in which the threads may perform transactions concurrently. That's when problems started, your manager says... Here is the code responsible to withdraw money from the account from and transfer it to the account to, within the same bank: def transfer(from: Account, to: Account, amount: BigInt): Unit = { require(amount >= 0) val balanceFrom = from.balance if (balanceFrom >= amount) { from.balance = balanceFrom - amount val balanceTo = to.balance to.balance = balanceTo + amount } } For the bank, it is very important that the following two properties hold after any sequence of completed transfer transactions: The balance of an account never goes below 0. The total sum of money held by the bank is constant. Does the transfer method above respect the two properties in a sequential execution environment, that is, when there is only one thread in the program?
One of lock-based programming's biggest problems is that "locks don't compose": it is hard to combine small, correct lock-based modules into equally correct larger programs without modifying the modules or at least knowing about their internals. Simon Peyton Jones (an advocate of software transactional memory) gives the following example of a banking application: design a class Account that allows multiple concurrent clients to deposit or withdraw money to an account; and give an algorithm to transfer money from one account to another. The lock-based solution to the first part of the problem is: class Account: member balance: Integer member mutex: Lock method deposit(n: Integer) mutex.lock() balance ← balance + n mutex.unlock() method withdraw(n: Integer) deposit(−n) The second part of the problem is much more complicated. A transfer routine that is correct for sequential programs would be function transfer(from: Account, to: Account, amount: Integer) from.withdraw(amount) to.deposit(amount) In a concurrent program, this algorithm is incorrect because when one thread is halfway through transfer, another might observe a state where amount has been withdrawn from the first account, but not yet deposited into the other account: money has gone missing from the system. This problem can only be fixed completely by taking locks on both account prior to changing any of the two accounts, but then the locks have to be taken according to some arbitrary, global ordering to prevent deadlock: function transfer(from: Account, to: Account, amount: Integer) if from < to // arbitrary ordering on the locks from.lock() to.lock() else to.lock() from.lock() from.withdraw(amount) to.deposit(amount) from.unlock() to.unlock() This solution gets more complicated when more locks are involved, and the transfer function needs to know about all of the locks, so they cannot be hidden.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
Freshly graduated from EPFL, you have been hired as contractors for a successful and rapidly growing bank. The bank has been experiencing problems with their money management system recently, which is written in Scala, and so they hired the best and brightest young engineer they could find: you! The system had been working perfectly fine so far, they tell you. In the past days, due to an increased number of customers, they had to switch from a single-threaded sequential execution environment to a multi-threaded concurrent one, in which the threads may perform transactions concurrently. That's when problems started, your manager says... Here is the code responsible to withdraw money from the account from and transfer it to the account to, within the same bank: def transfer(from: Account, to: Account, amount: BigInt): Unit = { require(amount >= 0) val balanceFrom = from.balance if (balanceFrom >= amount) { from.balance = balanceFrom - amount val balanceTo = to.balance to.balance = balanceTo + amount } } For the bank, it is very important that the following two properties hold after any sequence of completed transfer transactions: The balance of an account never goes below 0. The total sum of money held by the bank is constant. Does the transfer method above respect the two properties in a sequential execution environment, that is, when there is only one thread in the program?
Consider a banking application as an example, and a transaction in it—the transfer function, which takes money from one account, and puts it into another account. In the IO monad, this might look like: This causes problems in concurrent situations where multiple transfers might be taking place on the same account at the same time. If there were two transfers transferring money from account from, and both calls to transfer ran line (A) before either of them had written their new values, it is possible that money would be put into the other two accounts, with only one of the amounts being transferred being removed from account from, thus creating a race condition.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
In which of the following cases does JOS acquire the big kernel lock?
In operating systems, a giant lock, also known as a big-lock or kernel-lock, is a lock that may be used in the kernel to provide concurrency control required by symmetric multiprocessing (SMP) systems. A giant lock is a solitary global lock that is held whenever a thread enters kernel space and released when the thread returns to user space; a system call is the archetypal example. In this model, threads in user space can run concurrently on any available processors or processor cores, but no more than one thread can run in kernel space; any other threads that try to enter kernel space are forced to wait. In other words, the giant lock eliminates all concurrency in kernel space.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
In which of the following cases does JOS acquire the big kernel lock?
The Linux kernel had a big kernel lock (BKL) since the introduction of SMP, until Arnd Bergmann removed it in 2011 in kernel version 2.6.39, with the remaining uses of the big lock removed or replaced by finer-grained locking. Linux distributions at or above CentOS 7, Debian 7 (Wheezy) and Ubuntu 11.10 are therefore not using BKL. As of September 2022, Linux kernel still has console_lock which is sometimes referred as BKL and its removal is in progress.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
There are N philosphers sitting around a circular table eating spaghetti and discussing philosphy. The problem is that each philosopher needs two forks to eat, and there are only $N$ forks, one between each pair of philosophers. We want to design an algorithm that the philosophers can use, that ensures that no one starves as long as each philosopher eventually stops eating, and such that the maximum number of philosophers can eat at once. Lecture 5 provides one possible solution which uses a central arbiter. Can you write the philospherTurn function without a central arbiter? You may modify the provided class Fork if required. class Fork() { var inUse: Boolean = false } def philosopherTurn(l: Fork, r: Fork): Boolean = ??? // your implementation here // your implementation here def run() = val n = 5 val forks = new Array[Fork](n) val philosophers = new Array[Thread](n) for p <- 0 to n - 1 do forks(p) = new Fork() for p <- 0 to n - 1 do philosophers(p) = new Thread { override def run() = { while (!philosopherTurn(forks(p % n), forks((p + 1) % n))) { /* wait */ } } } philosophers(p).start for p <- 0 to n - 1 do philosophers(p).join() Hint: Use the deadlock prevention technique introduced in the lecture.
Each philosopher can only alternately think and eat. Moreover, a philosopher can only eat their spaghetti when they have both a left and right fork. Thus two forks will only be available when their two nearest neighbors are thinking, not eating. After an individual philosopher finishes eating, they will put down both forks. The problem is how to design a regimen (a concurrent algorithm) such that no philosopher will starve; i.e., each can forever continue to alternate between eating and thinking, assuming that no philosopher can know when others may want to eat or think (an issue of incomplete information).
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
There are N philosphers sitting around a circular table eating spaghetti and discussing philosphy. The problem is that each philosopher needs two forks to eat, and there are only $N$ forks, one between each pair of philosophers. We want to design an algorithm that the philosophers can use, that ensures that no one starves as long as each philosopher eventually stops eating, and such that the maximum number of philosophers can eat at once. Lecture 5 provides one possible solution which uses a central arbiter. Can you write the philospherTurn function without a central arbiter? You may modify the provided class Fork if required. class Fork() { var inUse: Boolean = false } def philosopherTurn(l: Fork, r: Fork): Boolean = ??? // your implementation here // your implementation here def run() = val n = 5 val forks = new Array[Fork](n) val philosophers = new Array[Thread](n) for p <- 0 to n - 1 do forks(p) = new Fork() for p <- 0 to n - 1 do philosophers(p) = new Thread { override def run() = { while (!philosopherTurn(forks(p % n), forks((p + 1) % n))) { /* wait */ } } } philosophers(p).start for p <- 0 to n - 1 do philosophers(p).join() Hint: Use the deadlock prevention technique introduced in the lecture.
A solution presented by William Stallings is to allow a maximum of n-1 philosophers to sit down at any time. The last philosopher would have to wait (for example, using a semaphore) for someone to finish dining before they "sit down" and request access to any fork. This guarantees at least one philosopher may always acquire both forks, allowing the system to make progress.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
In an x86 multiprocessor with JOS, how many Bootstrap Processors (BSP) is it possible to have at most? And how many Application Processors (AP) at most?
A symmetric multiprocessor (SMP) is a computer system with multiple identical processors that share memory and connect via a bus. Bus contention prevents bus architectures from scaling. As a result, SMPs generally do not comprise more than 32 processors. Because of the small size of the processors and the significant reduction in the requirements for bus bandwidth achieved by large caches, such symmetric multiprocessors are extremely cost-effective, provided that a sufficient amount of memory bandwidth exists.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
In an x86 multiprocessor with JOS, how many Bootstrap Processors (BSP) is it possible to have at most? And how many Application Processors (AP) at most?
Symmetric multiprocessing or shared-memory multiprocessing (SMP) involves a multiprocessor computer hardware and software architecture where two or more identical processors are connected to a single, shared main memory, have full access to all input and output devices, and are controlled by a single operating system instance that treats all processors equally, reserving none for special purposes. Most multiprocessor systems today use an SMP architecture. In the case of multi-core processors, the SMP architecture applies to the cores, treating them as separate processors. Professor John D. Kubiatowicz considers traditionally SMP systems to contain processors without caches.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
In this week's lecture, you have been introduced to the aggregate method of ParSeq[A] (and other parallel data structures). It has the following signature: def aggregate[B](z: B)(f: (B, A) => B, g: (B, B) => B): B Discuss, as a group, what aggregate does and what its arguments represent. Under which condition(s) on z, f, and g does aggregate always lead to the same result? Come up with a formula on z, f, and g that implies the correctness of aggregate. Hint: You may find it useful to use calls to foldLeft(z)(f) in your formula(s).
For the algorithm to be correct, all steps that identify n must be correct. Steps 1, 3 and 4 are trivially correct, since they are based on direct tests of the divisibility of n. Step 5 is also correct: since (2) is true for any choice of a coprime to n and r if n is prime, an inequality means that n must be composite. The difficult part of the proof is showing that step 6 is true. Its proof of correctness is based on the upper and lower bounds of a multiplicative group in Z n {\displaystyle \mathbb {Z} _{n}} constructed from the (X + a) binomials that are tested in step 5.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
In this week's lecture, you have been introduced to the aggregate method of ParSeq[A] (and other parallel data structures). It has the following signature: def aggregate[B](z: B)(f: (B, A) => B, g: (B, B) => B): B Discuss, as a group, what aggregate does and what its arguments represent. Under which condition(s) on z, f, and g does aggregate always lead to the same result? Come up with a formula on z, f, and g that implies the correctness of aggregate. Hint: You may find it useful to use calls to foldLeft(z)(f) in your formula(s).
Therefore, fg is also in M(S, G), i.e. M(S, G) is closed. M(S, G) is associative because ((fg)h)(x) = (fg)(x)h(x) = (f(x)g(x))h(x) = f(x)(g(x)h(x)) = f(x)(gh)(x) = (f(gh))(x). And there is a map i such that i(x) = e where e is the identity element of G. The map i is such that for all f in M(S, G) we have fi = if = f, i.e. i is the identity element of M(S, G). Thus, M(S, G) is actually a group. If G is abelian then (fg)(x) = f(x)g(x) = g(x)f(x) = (gf)(x), and therefore so is M(S, G).
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
We have a collection of rectangles in a plane, whose sides are aligned with the coordinate axes. Each rectangle is represented by its lower left corner $(x_1,y_1)$ and its upper right corner $(x_2, y_2)$. All coordinates are of type Long. We require $x_1 \le x_2$ and $y_1 \le y_2$. Define a function hull that, given an Array[Rectangle], computes the smallest rectangle containing each of the elements of the array, using one of the collection operations mentioned in Week 02 videos.
For a finite set of points in the plane the lower bound on the computational complexity of finding the convex hull represented as a convex polygon is easily shown to be the same as for sorting using the following reduction. For the set x 1 , … , x n {\displaystyle x_{1},\dots ,x_{n}} numbers to sort consider the set ( x 1 , x 1 2 ) , … , ( x n , x n 2 ) {\displaystyle (x_{1},x_{1}^{2}),\dots ,(x_{n},x_{n}^{2})} of points in the plane. Since they lie on a parabola, which is a convex curve it is easy to see that the vertices of the convex hull, when traversed along the boundary, produce the sorted order of the numbers x 1 , … , x n {\displaystyle x_{1},\dots ,x_{n}} .
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
We have a collection of rectangles in a plane, whose sides are aligned with the coordinate axes. Each rectangle is represented by its lower left corner $(x_1,y_1)$ and its upper right corner $(x_2, y_2)$. All coordinates are of type Long. We require $x_1 \le x_2$ and $y_1 \le y_2$. Define a function hull that, given an Array[Rectangle], computes the smallest rectangle containing each of the elements of the array, using one of the collection operations mentioned in Week 02 videos.
Let C be a set of n axis-parallel rectangles in the plane. The following algorithm finds a disjoint set with a size of at least | M D S ( C ) | log ⁡ n {\displaystyle {\frac {|MDS(C)|}{\log {n}}}} in time O ( n log ⁡ n ) {\displaystyle O(n\log {n})}: INITIALIZATION: sort the horizontal edges of the given rectangles by their y-coordinate, and the vertical edges by their x-coordinate (this step takes time O(n log n)). STOP CONDITION: If there are at most n ≤ 2 shapes, compute the MDS directly and return. RECURSIVE PART: Let x m e d {\displaystyle x_{\mathrm {med} }} be the median x-coordinate.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
In this week's lecture, you have been introduced to the aggregate method of ParSeq[A] (and other parallel data structures). It has the following signature: def aggregate[B](z: B)(f: (B, A) => B, g: (B, B) => B): B Discuss, as a group, what aggregate does and what its arguments represent. Consider the parallel sequence xs containing the three elements x1, x2 and x3. Also consider the following call to aggregate: xs.aggregate(z)(f, g) The above call might potentially result in the following computation: f(f(f(z, x1), x2), x3) But it might also result in other computations. Come up with at least two other computations in terms of f and g that may result from the above call to aggregate. Below are other examples of calls to aggregate. In each case, check if the call can lead to different results depending on the strategy used by aggregate to aggregate all values contained in data down to a single value. You should assume that data is a parallel sequence of values of type BigInt. 2. data.aggregate(0)((acc, x) => x - acc, _ + _)
Aggregate functions present a bottleneck, because they potentially require having all input values at once. In distributed computing, it is desirable to divide such computations into smaller pieces, and distribute the work, usually computing in parallel, via a divide and conquer algorithm. Some aggregate functions can be computed by computing the aggregate for subsets, and then aggregating these aggregates; examples include COUNT, MAX, MIN, and SUM. In other cases the aggregate can be computed by computing auxiliary numbers for subsets, aggregating these auxiliary numbers, and finally computing the overall number at the end; examples include AVERAGE (tracking sum and count, dividing at the end) and RANGE (tracking max and min, subtracting at the end).
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
In this week's lecture, you have been introduced to the aggregate method of ParSeq[A] (and other parallel data structures). It has the following signature: def aggregate[B](z: B)(f: (B, A) => B, g: (B, B) => B): B Discuss, as a group, what aggregate does and what its arguments represent. Consider the parallel sequence xs containing the three elements x1, x2 and x3. Also consider the following call to aggregate: xs.aggregate(z)(f, g) The above call might potentially result in the following computation: f(f(f(z, x1), x2), x3) But it might also result in other computations. Come up with at least two other computations in terms of f and g that may result from the above call to aggregate. Below are other examples of calls to aggregate. In each case, check if the call can lead to different results depending on the strategy used by aggregate to aggregate all values contained in data down to a single value. You should assume that data is a parallel sequence of values of type BigInt. 2. data.aggregate(0)((acc, x) => x - acc, _ + _)
Many parallel databases use distributed parallel processing to execute the queries. While executing an aggregate function such as sum, the following strategy is used: Compute a partial sum locally and concurrently at each processor using the data present in the associated disk partition with it. Add these local subtotals to get the final result.The final result may contain some rounding error as each processor independently rounds-off local results. One test is to ensure that such errors do not occur.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
Assume a user program executes following tasks. Select all options that will use a system call.
There are two techniques by which a program executing in user mode can request the kernel's services: System call Message passingOperating systems are designed with one or the other of these two facilities, but not both. First, assume that a user process wishes to invoke a particular target system function. For the system call approach, the user process uses the trap instruction. The idea is that the system call should appear to be an ordinary procedure call to the application program; the OS provides a library of user functions with names corresponding to each actual system call.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
Assume a user program executes following tasks. Select all options that will use a system call.
In computing, a system call (commonly abbreviated to syscall) is the programmatic way in which a computer program requests a service from the operating system on which it is executed. This may include hardware-related services (for example, accessing a hard disk drive or accessing the device's camera), creation and execution of new processes, and communication with integral kernel services such as process scheduling. System calls provide an essential interface between a process and the operating system. In most systems, system calls can only be made from userspace processes, while in some systems, OS/360 and successors for example, privileged system code also issues system calls.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
What is the content of the inode?
The inodes area. Each file or directory is represented as an inode, which records metadata including type (file, directory, block, char, pipe), IDs for user and group, three timestamps that record the date and time of last access, last modification and last status change. An inode also contains a list of addresses that point to the zones in the data area where the file or directory data is actually stored. The data area is the largest component of the file system, using the majority of the space. It is where the actual file and directory data are stored.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
What is the content of the inode?
LED is located in diode section.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
In x86, what are the possible ways to transfer arguments when invoking a system call? For example, in the following code, string and len are sys_cputs’s arguments.
Some arguments can contain megabytes of data, all of which must be copied and transmitted to the receiving object. Traditional procedure calls differ from message-passing in terms of memory usage, transfer time and locality. Arguments are passed to the receiver typically by general purpose registers requiring no additional storage nor transfer time, or in a parameter list containing the arguments' addresses (a few bits).
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
In x86, what are the possible ways to transfer arguments when invoking a system call? For example, in the following code, string and len are sys_cputs’s arguments.
Modern x86 operating systems are transitioning away from CALL FAR call gates. With the introduction of x86 instructions for system call (SYSENTER/SYSEXIT by Intel and SYSCALL/SYSRET by AMD), a new faster mechanism was introduced for control transfers for x86 programs. As most other architectures do not support call gates, their use was rare even before these new instructions, as software interrupts or traps were preferred for portability, even though call gates are significantly faster than interrupts. Call gates are more flexible than the SYSENTER/SYSEXIT and SYSCALL/SYSRET instructions since unlike the latter two, call gates allow for changing from an arbitrary privilege level to an arbitrary (albeit higher or equal) privilege level. The fast SYS* instructions only allow control transfers from ring 3 to 0 and vice versa.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
What is the worst case complexity of listing files in a directory? The file system implements directories as hash-tables.
Each position in this table corresponds to a specific directory entry record. The hash table, being one sector in length, can index a maximum of 256 directory records or files. The directory itself is sized according to disk capacity by being a maximum of one cylinder (up to 34 sectors).
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
What is the worst case complexity of listing files in a directory? The file system implements directories as hash-tables.
When a file is to be opened for access, the system needs to search the directory for its directory record. Search time is minimized by using a hashing technique to reduce the 11-character string formed from the file name and extension to a one byte value. The hash code for each file is stored in a Hash Index Table (HIT) which is the second sector of the directory.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
In this week's lecture, you have been introduced to the aggregate method of ParSeq[A] (and other parallel data structures). It has the following signature: def aggregate[B](z: B)(f: (B, A) => B, g: (B, B) => B): B Discuss, as a group, what aggregate does and what its arguments represent. Implement aggregate using the task and/or parallel constructs seen in the first week and the Splitter[A] interface seen in this week's lecture. The Splitter interface is defined as: trait Splitter[A] extends Iterator[A]: def split: Seq[Splitter[A]] def remaining: Int You can assume that the data structure you are defining aggregate for already implements a splitter method which returns an object of type Splitter[A]. Your implementation of aggregate should work in parallel when the number of remaining elements is above the constant THRESHOLD and sequentially below it. Hint: Iterator, and thus Splitter, implements the foldLeft method.
Thus for any list homomorphism h, there exists a parallel implementation. That implementation cuts the list into chunks, which are assigned to different computers; each computes the result on its own chunk. It is those results that transit on the network and are finally combined into one. In any application where the list is enormous and the result is a very simple type – say an integer – the benefits of parallelisation are considerable. This is the basis of the map-reduce approach.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
In this week's lecture, you have been introduced to the aggregate method of ParSeq[A] (and other parallel data structures). It has the following signature: def aggregate[B](z: B)(f: (B, A) => B, g: (B, B) => B): B Discuss, as a group, what aggregate does and what its arguments represent. Implement aggregate using the task and/or parallel constructs seen in the first week and the Splitter[A] interface seen in this week's lecture. The Splitter interface is defined as: trait Splitter[A] extends Iterator[A]: def split: Seq[Splitter[A]] def remaining: Int You can assume that the data structure you are defining aggregate for already implements a splitter method which returns an object of type Splitter[A]. Your implementation of aggregate should work in parallel when the number of remaining elements is above the constant THRESHOLD and sequentially below it. Hint: Iterator, and thus Splitter, implements the foldLeft method.
Many parallel databases use distributed parallel processing to execute the queries. While executing an aggregate function such as sum, the following strategy is used: Compute a partial sum locally and concurrently at each processor using the data present in the associated disk partition with it. Add these local subtotals to get the final result.The final result may contain some rounding error as each processor independently rounds-off local results. One test is to ensure that such errors do not occur.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
Consider an operation we will call scanRight1 that, given a function $f$ of two arguments, and a sequence $a_1, \ldots, a_N$, computes a sequence $b_1, \ldots, b_N$ such that: $b_N = a_N$ $b_i = f(a_{i}, b_{i+1})$, for $0 < i < N$ Define similarly scanLeft1 in a manner similar to scanRight1: Given a function $f$ of two arguments, and a sequence $a_1, \ldots, a_N$, scanLeft1 computes a sequence $b_1, \ldots, b_N$ such that: $b_i = f(b_{i-1}, a_{i})$, for $0 < i \leq N$ Suppose that $f$ is associative. is the result of scanRight1 same as the result of scanLeft1?
Given two sets A , B ⊆ N {\displaystyle A,B\subseteq \mathbb {N} } of natural numbers, we say A {\displaystyle A} is Turing reducible to B {\displaystyle B} and write A ≤ T B {\displaystyle A\leq _{T}B} if and only if there is an oracle machine that computes the characteristic function of A when run with oracle B. In this case, we also say A is B-recursive and B-computable. If there is an oracle machine that, when run with oracle B, computes a partial function with domain A, then A is said to be B-recursively enumerable and B-computably enumerable. We say A {\displaystyle A} is Turing equivalent to B {\displaystyle B} and write A ≡ T B {\displaystyle A\equiv _{T}B\,} if both A ≤ T B {\displaystyle A\leq _{T}B} and B ≤ T A .
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
Consider an operation we will call scanRight1 that, given a function $f$ of two arguments, and a sequence $a_1, \ldots, a_N$, computes a sequence $b_1, \ldots, b_N$ such that: $b_N = a_N$ $b_i = f(a_{i}, b_{i+1})$, for $0 < i < N$ Define similarly scanLeft1 in a manner similar to scanRight1: Given a function $f$ of two arguments, and a sequence $a_1, \ldots, a_N$, scanLeft1 computes a sequence $b_1, \ldots, b_N$ such that: $b_i = f(b_{i-1}, a_{i})$, for $0 < i \leq N$ Suppose that $f$ is associative. is the result of scanRight1 same as the result of scanLeft1?
In functional programming terms, the prefix sum may be generalized to any binary operation (not just the addition operation); the higher order function resulting from this generalization is called a scan, and it is closely related to the fold operation. Both the scan and the fold operations apply the given binary operation to the same sequence of values, but differ in that the scan returns the whole sequence of results from the binary operation, whereas the fold returns only the final result. For instance, the sequence of factorial numbers may be generated by a scan of the natural numbers using multiplication instead of addition:
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
As a group, write a function called minMax, which should take a non-empty array as input and return a pair containing the smallest and the largest element of the array. def minMax(a: Array[Int]): (Int, Int) = ??? Now write a parallel version of the function. You may use the constructs task and/or parallel, as seen in the lectures.
For the variant of the problem which disallows empty subarrays, best_sum should be initialized to negative infinity instead and also in the for loop current_sum should be updated as max(x, current_sum + x). In that case, if the input contains no positive element, the returned value is that of the largest element (i.e., the value closest to 0), or negative infinity if the input was empty. For correctness, an exception should be raised when the input array is empty, since an empty array has no maximum nonempty subarray. If the array is non-empty, its first element can be used in place of negative infinity, if needed to avoid mixing numeric and non-numeric values.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
As a group, write a function called minMax, which should take a non-empty array as input and return a pair containing the smallest and the largest element of the array. def minMax(a: Array[Int]): (Int, Int) = ??? Now write a parallel version of the function. You may use the constructs task and/or parallel, as seen in the lectures.
The following pseudocode rearranges the elements between left and right, such that for some value k, where left ≤ k ≤ right, the kth element in the list will contain the (k − left + 1)th smallest value, with the ith element being less than or equal to the kth for all left ≤ i ≤ k and the jth element being larger or equal to for k ≤ j ≤ right: // left is the left index for the interval // right is the right index for the interval // k is the desired index value, where array is the (k+1)th smallest element when left = 0 function select(array, left, right, k) is while right > left do // Use select recursively to sample a smaller set of size s // the arbitrary constants 600 and 0.5 are used in the original // version to minimize execution time. if right − left > 600 then n := right − left + 1 i := k − left + 1 z := ln(n) s := 0.5 × exp(2 × z/3) sd := 0.5 × sqrt(z × s × (n − s)/n) × sign(i − n/2) newLeft := max(left, k − i × s/n + sd) newRight := min(right, k + (n − i) × s/n + sd) select(array, newLeft, newRight, k) // partition the elements between left and right around t t := array i := left j := right swap array and array if array > t then swap array and array while i < j do swap array and array i := i + 1 j := j − 1 while array < t do i := i + 1 while array > t do j := j − 1 if array = t then swap array and array else j := j + 1 swap array and array // Adjust left and right towards the boundaries of the subset // containing the (k − left + 1)th smallest element. if j ≤ k then left := j + 1 if k ≤ j then right := j − 1
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
In this week's lecture, you have been introduced to the aggregate method of ParSeq[A] (and other parallel data structures). It has the following signature: def aggregate[B](z: B)(f: (B, A) => B, g: (B, B) => B): B Discuss, as a group, what aggregate does and what its arguments represent. Consider the parallel sequence xs containing the three elements x1, x2 and x3. Also consider the following call to aggregate: xs.aggregate(z)(f, g) The above call might potentially result in the following computation: f(f(f(z, x1), x2), x3) But it might also result in other computations. Come up with at least two other computations in terms of f and g that may result from the above call to aggregate.
Aggregate functions present a bottleneck, because they potentially require having all input values at once. In distributed computing, it is desirable to divide such computations into smaller pieces, and distribute the work, usually computing in parallel, via a divide and conquer algorithm. Some aggregate functions can be computed by computing the aggregate for subsets, and then aggregating these aggregates; examples include COUNT, MAX, MIN, and SUM. In other cases the aggregate can be computed by computing auxiliary numbers for subsets, aggregating these auxiliary numbers, and finally computing the overall number at the end; examples include AVERAGE (tracking sum and count, dividing at the end) and RANGE (tracking max and min, subtracting at the end).
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
In this week's lecture, you have been introduced to the aggregate method of ParSeq[A] (and other parallel data structures). It has the following signature: def aggregate[B](z: B)(f: (B, A) => B, g: (B, B) => B): B Discuss, as a group, what aggregate does and what its arguments represent. Consider the parallel sequence xs containing the three elements x1, x2 and x3. Also consider the following call to aggregate: xs.aggregate(z)(f, g) The above call might potentially result in the following computation: f(f(f(z, x1), x2), x3) But it might also result in other computations. Come up with at least two other computations in terms of f and g that may result from the above call to aggregate.
Many parallel databases use distributed parallel processing to execute the queries. While executing an aggregate function such as sum, the following strategy is used: Compute a partial sum locally and concurrently at each processor using the data present in the associated disk partition with it. Add these local subtotals to get the final result.The final result may contain some rounding error as each processor independently rounds-off local results. One test is to ensure that such errors do not occur.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
In this week's lecture, you have been introduced to the aggregate method of ParSeq[A] (and other parallel data structures). It has the following signature: def aggregate[B](z: B)(f: (B, A) => B, g: (B, B) => B): B Discuss, as a group, what aggregate does and what its arguments represent. Consider the parallel sequence xs containing the three elements x1, x2 and x3. Also consider the following call to aggregate: xs.aggregate(z)(f, g) The above call might potentially result in the following computation: f(f(f(z, x1), x2), x3) But it might also result in other computations. Come up with at least two other computations in terms of f and g that may result from the above call to aggregate. Below are other examples of calls to aggregate. In each case, check if the call can lead to different results depending on the strategy used by aggregate to aggregate all values contained in data down to a single value. You should assume that data is a parallel sequence of values of type BigInt. 4. data.aggregate(1)((acc, x) => x * x * acc, _ * _)
Aggregate functions present a bottleneck, because they potentially require having all input values at once. In distributed computing, it is desirable to divide such computations into smaller pieces, and distribute the work, usually computing in parallel, via a divide and conquer algorithm. Some aggregate functions can be computed by computing the aggregate for subsets, and then aggregating these aggregates; examples include COUNT, MAX, MIN, and SUM. In other cases the aggregate can be computed by computing auxiliary numbers for subsets, aggregating these auxiliary numbers, and finally computing the overall number at the end; examples include AVERAGE (tracking sum and count, dividing at the end) and RANGE (tracking max and min, subtracting at the end).
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
In this week's lecture, you have been introduced to the aggregate method of ParSeq[A] (and other parallel data structures). It has the following signature: def aggregate[B](z: B)(f: (B, A) => B, g: (B, B) => B): B Discuss, as a group, what aggregate does and what its arguments represent. Consider the parallel sequence xs containing the three elements x1, x2 and x3. Also consider the following call to aggregate: xs.aggregate(z)(f, g) The above call might potentially result in the following computation: f(f(f(z, x1), x2), x3) But it might also result in other computations. Come up with at least two other computations in terms of f and g that may result from the above call to aggregate. Below are other examples of calls to aggregate. In each case, check if the call can lead to different results depending on the strategy used by aggregate to aggregate all values contained in data down to a single value. You should assume that data is a parallel sequence of values of type BigInt. 4. data.aggregate(1)((acc, x) => x * x * acc, _ * _)
Many parallel databases use distributed parallel processing to execute the queries. While executing an aggregate function such as sum, the following strategy is used: Compute a partial sum locally and concurrently at each processor using the data present in the associated disk partition with it. Add these local subtotals to get the final result.The final result may contain some rounding error as each processor independently rounds-off local results. One test is to ensure that such errors do not occur.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
Imagine that the data structure you are given, instead of an Array[A], is one called ParSeq[A]. This class offers the two following methods, which work in parallel: def map[B](f: A => B): ParSeq[B] def reduce(f: (A, A) => A): A Can you write the following minMax function in terms of map and/or reduce operations ? def minMax(data: ParSeq[Int]): (Int, Int) = ???
Thus for any list homomorphism h, there exists a parallel implementation. That implementation cuts the list into chunks, which are assigned to different computers; each computes the result on its own chunk. It is those results that transit on the network and are finally combined into one. In any application where the list is enormous and the result is a very simple type – say an integer – the benefits of parallelisation are considerable. This is the basis of the map-reduce approach.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
Imagine that the data structure you are given, instead of an Array[A], is one called ParSeq[A]. This class offers the two following methods, which work in parallel: def map[B](f: A => B): ParSeq[B] def reduce(f: (A, A) => A): A Can you write the following minMax function in terms of map and/or reduce operations ? def minMax(data: ParSeq[Int]): (Int, Int) = ???
To increase efficiency, a number of data sets have this operation applied to them simultaneously, before the data is structured together again at the end. ‘Forks’ are similar to ‘maps’ but they use a different operation for certain data types. This is known as multiple data parallelism. ‘Reduces’ or ‘scans’ are used to apply prefixes to a set of data, before then applying an operation upon the data. These are different to ‘maps’ as they have a set of partial results during the runtime of the method itself.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
In JOS, suppose one Env sends a page to another Env. Is the page copied?
Post-copy sends each page exactly once over the network whereas pre-copy can transfer the same page multiple times if the page is dirtied repeatedly at the source during migration. On the other hand, pre-copy retains an up-to-date state of the VM at the source during migration, whereas during post-copy, the VM's state is split across the source and the destination. If the destination fails during live migration, pre-copy can recover the VM, whereas post-copy cannot.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
In JOS, suppose one Env sends a page to another Env. Is the page copied?
The child borrows the memory management unit setup from the parent and memory pages are shared among the parent and child process with no copying done, and in particular with no copy-on-write semantics; hence, if the child process makes a modification in any of the shared pages, no new page will be created and the modified pages are visible to the parent process too. Since there is absolutely no page copying involved (consuming additional memory), this technique is an optimization over plain fork in full-copy environments when used with exec. In POSIX, using vfork for any purpose except as a prelude to an immediate call to a function from the exec family (and a select few other operations) gives rise to undefined behavior.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
In JOS and x86, please select all valid options for a system call.
select is a system call and application programming interface (API) in Unix-like and POSIX-compliant operating systems for examining the status of file descriptors of open input/output channels. The select system call is similar to the poll facility introduced in UNIX System V and later operating systems. However, with the c10k problem, both select and poll have been superseded by the likes of kqueue, epoll, /dev/poll and I/O completion ports.One common use of select outside of its stated use of waiting on filehandles is to implement a portable sub-second sleep. This can be achieved by passing NULL for all three fd_set arguments, and the duration of the desired sleep as the timeout argument.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
In JOS and x86, please select all valid options for a system call.
Most work in the monolithic kernel is done via system calls. These are interfaces, usually kept in a tabular structure, that access some subsystem within the kernel such as disk operations. Essentially calls are made within programs and a checked copy of the request is passed through the system call.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
Concatenating two conc-trees of heights $h_1$ and $h_2$ yields a conc-tree with height $h$ where
An H tree can be constructed by starting with a line segment of arbitrary length, drawing two shorter segments at right angles to the first through its endpoints, and continuing in the same vein, reducing (dividing) the length of the line segments drawn at each stage by 2 {\displaystyle {\sqrt {2}}} . A variant of this construction could also be defined in which the length at each iteration is multiplied by a ratio less than 1 / 2 {\displaystyle 1/{\sqrt {2}}} , but for this variant the resulting shape covers only part of its bounding rectangle, with a fractal boundary.An alternative process that generates the same fractal set is to begin with a rectangle with sides in the ratio 1: 2 {\displaystyle 1:{\sqrt {2}}} , and repeatedly bisect it into two smaller silver rectangles, at each stage connecting the two centroids of the two smaller rectangles by a line segment. A similar process can be performed with rectangles of any other shape, but the 1: 2 {\displaystyle 1:{\sqrt {2}}} rectangle leads to the line segment size decreasing uniformly by a 2 {\displaystyle {\sqrt {2}}} factor at each step while for other rectangles the length will decrease by different factors at odd and even levels of the recursive construction.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
Concatenating two conc-trees of heights $h_1$ and $h_2$ yields a conc-tree with height $h$ where
There are bijective correspondences between recursive trees of size n and permutations of size n − 1.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
What are the drawbacks of non-preemptive scheduling compared to preemptive scheduling?
The no preemption condition may also be difficult or impossible to avoid as a process has to be able to have a resource for a certain amount of time, or the processing outcome may be inconsistent or thrashing may occur. However, the inability to enforce preemption may interfere with a priority algorithm. Preemption of a "locked out" resource generally implies a rollback, and is to be avoided since it is very costly in overhead.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
What are the drawbacks of non-preemptive scheduling compared to preemptive scheduling?
However this low-level scheduling has its drawbacks. A process that seldom needs to interact with peripherals or other processes would simply hog processor resource until it completed or was halted by manual intervention. The result, particularly for interactive systems running tasks that frequently interact with the outside world, is that the system is sluggish and slow to react in a timely manner.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
Select valid answers about file descriptors (FD):
In Unix and Unix-like computer operating systems, a file descriptor (FD, less frequently fildes) is a process-unique identifier (handle) for a file or other input/output resource, such as a pipe or network socket. File descriptors typically have non-negative integer values, with negative values being reserved to indicate "no value" or error conditions. File descriptors are a part of the POSIX API. Each Unix process (except perhaps daemons) should have three standard POSIX file descriptors, corresponding to the three standard streams:
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
Select valid answers about file descriptors (FD):
Now suppose that the user program successfully executes the following statement: The variable fd now contains the index of a file descriptor in the process's file descriptor table. This file descriptor is a capability. Its existence in the process's file descriptor table is sufficient to show that the process does indeed have legitimate access to the object. A key feature of this arrangement is that the file descriptor table is in kernel memory and cannot be directly manipulated by the user program.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
What is the default block size for a traditional file system, e.g. ext3/4?
Because file size references are stored in eight instead of four bytes, the file size limit has increased to 16 exabytes (EB) (264 − 1 bytes, or about 1019 bytes, which is otherwise limited by a maximum volume size of 128 PB, or 257 − 1 bytes), raised from 4 GB (232 − 1 bytes) in a standard FAT32 file system. Therefore, for the typical user, this enables seamless interoperability between Windows and macOS platforms for files in excess of 4 GB. Other specifications, features, and requirements of the exFAT file system include: Scalability to large disk sizes: about 128 PB (257 − 1 bytes) maximum, 512 TB (249 − 1 bytes) recommended maximum, raised from the 32-bit limit (2 TB for a sector size of 512 bytes) of standard FAT32 partitions. Support for up to 2,796,202 files per directory.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
What is the default block size for a traditional file system, e.g. ext3/4?
File systems have traditionally divided the disk into equally sized blocks to simplify their design and limit the worst-case fragmentation. Block sizes are typically multiples of 512 bytes due to the size of hard disk sectors. When files are allocated by some traditional file systems, only whole blocks can be allocated to individual files.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
Suppose a file system used only for reading immutable files in random fashion. What is the best block allocation strategy?
In some scenarios where the majority of files are shorter than half the block size, such as in a folder of small source code files or small bitmap images, tail packing can increase storage efficiency even more than twofold, compared to file systems without tail packing.This not only translates into conservation of disk space, but may also introduce performance increases, as due to higher locality of reference, less data has to be read, also translating into higher page cache efficiency. However, these advantages can be negated by the increased complexity of implementation.As of 2015, the most widely used read-write file systems with support for block suballocation are Btrfs and FreeBSD UFS2 (where it is called "block level fragmentation"). ReiserFS and Reiser4 also support tail packing. Several read-only file systems do not use blocks at all and are thus implicitly using space as efficiently as suballocating file systems; such file systems double as archive formats.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
Suppose a file system used only for reading immutable files in random fashion. What is the best block allocation strategy?
Deciding from benchmarking results, when used with relatively small number of servers (15), the file system achieves reading performance comparable to that of a single disk (80–100 MB/s), but has a reduced write performance (30 MB/s), and is relatively slow (5 MB/s) in appending data to existing files. The authors present no results on random seek time. As the master node is not directly involved in data reading (the data are passed from the chunk server directly to the reading client), the read rate increases significantly with the number of chunk servers, achieving 583 MB/s for 342 nodes. Aggregating multiple servers also allows big capacity, while it is somewhat reduced by storing data in three independent locations (to provide redundancy).
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
Consider the following contains function defined on Iterable (in particular, it accepts both Vector and List). def contains[A](l: Iterable[A], elem: A): Boolean = val n = l.size if n <= 5 then for i <- l do if i == elem then return true false else val (p0, p1) = parallel( contains(l.take(n / 2), elem), contains(l.drop(n / 2), elem) ) p0 || p1 Let $n$ be the size of l. Assume that drop and take run in $\Theta(1)$ on Vector and $\Theta(n)$ on List. What is the asymptotic depth of contains if it is called on a Vector?
Suppose the set of vertices of K is given as an input, so that K = conv ( v 1 , … , v k ) = {\displaystyle K={\text{conv}}(v_{1},\ldots ,v_{k})=} the convex hull of its vertices. Then, deciding whether y is in K requires to check whether y is a convex combination of the input vectors, that is, whether there exist coefficients z1,...,zk such that:: 49 z 1 ⋅ v 1 + ⋯ + z k ⋅ v k = y {\displaystyle z_{1}\cdot v_{1}+\cdots +z_{k}\cdot v_{k}=y} ; 0 ≤ z i ≤ 1 {\displaystyle 0\leq z_{i}\leq 1} for all i in 1,...,k.This is a linear program with k variables and n equality constraints (one for each element of y). If y is not in K, then the above program has no solution, and the separation oracle needs to find a vector c such that c ⋅ y > c ⋅ v i {\displaystyle c\cdot y>c\cdot v_{i}} for all i in 1,...,k.Note that the two above representations can be very different in size: it is possible that a polytope can be represented by a small number of inequalities, but has exponentially many vertices (for example, an n-dimensional cube). Conversely, it is possible that a polytope has a small number of vertices, but requires exponentially many inequalities (for example, the convex hull of the 2n vectors of the form (0,...,±1,...,0).
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
Consider the following contains function defined on Iterable (in particular, it accepts both Vector and List). def contains[A](l: Iterable[A], elem: A): Boolean = val n = l.size if n <= 5 then for i <- l do if i == elem then return true false else val (p0, p1) = parallel( contains(l.take(n / 2), elem), contains(l.drop(n / 2), elem) ) p0 || p1 Let $n$ be the size of l. Assume that drop and take run in $\Theta(1)$ on Vector and $\Theta(n)$ on List. What is the asymptotic depth of contains if it is called on a Vector?
This can happen for at most 2K(x,y)-l = 2k different strings. These strings can be enumerated given k,l and hence x can be specified by its index in this enumeration. The corresponding program for x has size k + O(1). Theorem proved.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
Consider the following contains function defined on Iterable (in particular, it accepts both Vector and List). def contains[A](l: Iterable[A], elem: A): Boolean = val n = l.size if n <= 5 then for i <- l do if i == elem then return true false else val (p0, p1) = parallel( contains(l.take(n / 2), elem), contains(l.drop(n / 2), elem) ) p0 || p1 Let $n$ be the size of l. Assume that drop and take run in $\Theta(1)$ on Vector and $\Theta(n)$ on List. What is the asymptotic work of contains if it is called on a Vector?
It will first check if the element is at the middle of the vector. If not, then it will check if the middle element is greater or lesser than the sought element. At this point, half of the vector can be discarded, and the algorithm can be run again on the other half. The number of comparisons will be given by c 1 = 1 {\displaystyle c_{1}=1} c n = 1 + c n / 2 {\displaystyle c_{n}=1+c_{n/2}} the time complexity of which will be O ( log 2 ⁡ ( n ) ) {\displaystyle O(\log _{2}(n))} .
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
Consider the following contains function defined on Iterable (in particular, it accepts both Vector and List). def contains[A](l: Iterable[A], elem: A): Boolean = val n = l.size if n <= 5 then for i <- l do if i == elem then return true false else val (p0, p1) = parallel( contains(l.take(n / 2), elem), contains(l.drop(n / 2), elem) ) p0 || p1 Let $n$ be the size of l. Assume that drop and take run in $\Theta(1)$ on Vector and $\Theta(n)$ on List. What is the asymptotic work of contains if it is called on a Vector?
An exact cover problem is defined by the binary relation "contains" between subsets in S and elements in X. There are different equivalent ways to represent this relation.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
Which of the following operations would switch the user program from user space to kernel space?
Kernel space can be accessed by user-mode only through the use of system calls. End user programs like the UNIX shell or other GUI-based applications are part of user space. These applications interact with hardware through kernel supported functions.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
Which of the following operations would switch the user program from user space to kernel space?
The term user space (or userland) refers to all code that runs outside the operating system's kernel. User space usually refers to the various programs and libraries that the operating system uses to interact with the kernel: software that performs input/output, manipulates file system objects, application software, etc. Each user space process normally runs in its own virtual memory space, and, unless explicitly allowed, cannot access the memory of other processes. This is the basis for memory protection in today's mainstream operating systems, and a building block for privilege separation.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
We have a collection of rectangles in a plane, whose sides are aligned with the coordinate axes. Each rectangle is represented by its lower left corner $(x_1,y_1)$ and its upper right corner $(x_2,y_2)$. All coordinates are of type Long. We require $x_1 \le x_2$ and $y_1 \le y_2$. How can the result be computed in parallel? Which properties of hull2 need to hold to make the solution correct? Prove these properties for hull2.
In computational geometry, a number of algorithms are known for computing the convex hull for a finite set of points and for other geometric objects. Computing the convex hull means constructing an unambiguous, efficient representation of the required convex shape. Output representations that have been considered for convex hulls of point sets include a list of linear inequalities describing the facets of the hull, an undirected graph of facets and their adjacencies, or the full face lattice of the hull. In two dimensions, it may suffice more simply to list the points that are vertices, in their cyclic order around the hull.For convex hulls in two or three dimensions, the complexity of the corresponding algorithms is usually estimated in terms of n {\displaystyle n} , the number of input points, and h {\displaystyle h} , the number of points on the convex hull, which may be significantly smaller than n {\displaystyle n} .
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
We have a collection of rectangles in a plane, whose sides are aligned with the coordinate axes. Each rectangle is represented by its lower left corner $(x_1,y_1)$ and its upper right corner $(x_2,y_2)$. All coordinates are of type Long. We require $x_1 \le x_2$ and $y_1 \le y_2$. How can the result be computed in parallel? Which properties of hull2 need to hold to make the solution correct? Prove these properties for hull2.
Let C be a set of n axis-parallel rectangles in the plane, all with the same height but with varying lengths. There is an algorithm that finds a disjoint set with a size of at least |MDS(C)|/(1 + 1/k) in time O(n2k−1), for every constant k > 1.The algorithm is an improvement of the above-mentioned 2-approximation, by combining dynamic programming with the shifting technique of Hochbaum and Maass.This algorithm can be generalized to d dimensions. If the labels have the same size in all dimensions except one, it is possible to find a similar approximation by applying dynamic programming along one of the dimensions. This also reduces the time to n^O(1/e).
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
Consider an operation we will call scanRight1 that, given a function $f$ of two arguments, and a sequence $a_1, \ldots, a_N$, computes a sequence $b_1, \ldots, b_N$ such that: $b_N = a_N$ $b_i = f(a_{i}, b_{i+1})$, for $0 < i < N$ Define similarly scanLeft1 in a manner similar to scanRight1: Given a function $f$ of two arguments, and a sequence $a_1, \ldots, a_N$, scanLeft1 computes a sequence $b_1, \ldots, b_N$ such that: $b_1 = a_1$ $b_i = f(b_{i-1}, a_{i})$, for $0 < i \leq N$ Suppose that $f$ is associative. is the result of scanRight1 the same same as the result of scanLeft1 on the reversed sequence $a_N, \ldots, a_1$$a_N, \ldots, a_1$ ?
Given two sets A , B ⊆ N {\displaystyle A,B\subseteq \mathbb {N} } of natural numbers, we say A {\displaystyle A} is Turing reducible to B {\displaystyle B} and write A ≤ T B {\displaystyle A\leq _{T}B} if and only if there is an oracle machine that computes the characteristic function of A when run with oracle B. In this case, we also say A is B-recursive and B-computable. If there is an oracle machine that, when run with oracle B, computes a partial function with domain A, then A is said to be B-recursively enumerable and B-computably enumerable. We say A {\displaystyle A} is Turing equivalent to B {\displaystyle B} and write A ≡ T B {\displaystyle A\equiv _{T}B\,} if both A ≤ T B {\displaystyle A\leq _{T}B} and B ≤ T A .
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
Consider an operation we will call scanRight1 that, given a function $f$ of two arguments, and a sequence $a_1, \ldots, a_N$, computes a sequence $b_1, \ldots, b_N$ such that: $b_N = a_N$ $b_i = f(a_{i}, b_{i+1})$, for $0 < i < N$ Define similarly scanLeft1 in a manner similar to scanRight1: Given a function $f$ of two arguments, and a sequence $a_1, \ldots, a_N$, scanLeft1 computes a sequence $b_1, \ldots, b_N$ such that: $b_1 = a_1$ $b_i = f(b_{i-1}, a_{i})$, for $0 < i \leq N$ Suppose that $f$ is associative. is the result of scanRight1 the same same as the result of scanLeft1 on the reversed sequence $a_N, \ldots, a_1$$a_N, \ldots, a_1$ ?
In functional programming terms, the prefix sum may be generalized to any binary operation (not just the addition operation); the higher order function resulting from this generalization is called a scan, and it is closely related to the fold operation. Both the scan and the fold operations apply the given binary operation to the same sequence of values, but differ in that the scan returns the whole sequence of results from the binary operation, whereas the fold returns only the final result. For instance, the sequence of factorial numbers may be generated by a scan of the natural numbers using multiplication instead of addition:
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
What is the complexity of concatenation of two conc-trees with heights $h_1$ and $h_2$?
Thus the group G exhibits a large gap between the growth of its Dehn function and the complexity of its word problem. The conjugacy problem in G is known to be decidable, but the only known worst-case upper bound estimate for the complexity of the conjugacy problem, due to Janis Beese, is elementary recursive. It is conjectured that this estimate is sharp, based on some reductions to power circuit division problems. There is a strongly generically polynomial time solution of the conjugacy problem for G.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
What is the complexity of concatenation of two conc-trees with heights $h_1$ and $h_2$?
There are bijective correspondences between recursive trees of size n and permutations of size n − 1.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
What property does the function f passed to reduce need to satisfy in order to have the same result regardless on how reduce groups the applications of the operation f to the elements of the data structure? Prove that your function f indeed satisfies that property.
Let P1 and P2 be two problems in FNP, with associated verification algorithms A1, A2. A reduction P1 and P2 is defined as two efficiently-computable functions, f and g, such that f maps inputs x to P1 to inputs f(x) to P2 ; g maps outputs y to P2 to outputs g(y) to P1 ; For all x and y: if A2(f(x),y) returns true, then A1(x, g(y)) returns true; For all x: if A2(f(x),y) returns false, then A1(x, g(y)) returns false for all y.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
What property does the function f passed to reduce need to satisfy in order to have the same result regardless on how reduce groups the applications of the operation f to the elements of the data structure? Prove that your function f indeed satisfies that property.
Functional interpretations also provide a way to extract constructive information from proofs in the reduced theory. As a direct consequence of the interpretation one usually obtains the result that any recursive function whose totality can be proven either in I or in C is represented by a term of F. If one can provide an additional interpretation of F in I, which is sometimes possible, this characterization is in fact usually shown to be exact. It often turns out that the terms of F coincide with a natural class of functions, such as the primitive recursive or polynomial-time computable functions.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
To support very large scale neural networks in limited amount of memory, one may want to use floating point numbers with very few bits. Here we consider substantially simplified operations on such numbers, Float8. A value Float8(mant,exp) represents the non-negative integer mant * 2^exp. We call mant a mantissa (which gives significant digits) whereas exp is the exponent. This allows us to represent both smaller and larger integers, keeping a similar number of significant digits. (The larger integers can only be represented up to a given power of two.) In our simple example, we use only four bits for both mantissa and the exponent, and we assume they are both non-negative. final case class Float8(mant: Int, exp: Int): require(0 <= mant && mant <= 15 && 0 <= exp && exp <= 15) def value: Int = mant << exp val a = Float8(15, 8) val b = Float8(5, 10) We look at the operation plus, of adding such numbers. When the exponent is smaller than another one, the operation shifts mantissa and then performs addition. If mantissa gets too large, we reduce it an increase the exponent. extension (x: Float8) def +(y: Float8): Float8 = if x.exp <= y.exp then val shift = y.exp - x.exp val mant = (x.mant >> shift) + y.mant if mant < 16 then Float8(mant, y.exp) else val exp1 = y.exp + 1 if exp1 < 16 then Float8(mant / 2, y.exp + 1) else Float8(15, 15) else y + x Is this operation commutative? Prove or give a counterexample.
A 2-bit float with 1-bit exponent and 1-bit mantissa would only have 0, 1, Inf, NaN values. If the mantissa is allowed to be 0-bit, a 1-bit float format would have a 1-bit exponent, and the only two values would be 0 and Inf. The exponent must be at least 1 bit or else it no longer makes sense as a float (it would just be a signed number).
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
To support very large scale neural networks in limited amount of memory, one may want to use floating point numbers with very few bits. Here we consider substantially simplified operations on such numbers, Float8. A value Float8(mant,exp) represents the non-negative integer mant * 2^exp. We call mant a mantissa (which gives significant digits) whereas exp is the exponent. This allows us to represent both smaller and larger integers, keeping a similar number of significant digits. (The larger integers can only be represented up to a given power of two.) In our simple example, we use only four bits for both mantissa and the exponent, and we assume they are both non-negative. final case class Float8(mant: Int, exp: Int): require(0 <= mant && mant <= 15 && 0 <= exp && exp <= 15) def value: Int = mant << exp val a = Float8(15, 8) val b = Float8(5, 10) We look at the operation plus, of adding such numbers. When the exponent is smaller than another one, the operation shifts mantissa and then performs addition. If mantissa gets too large, we reduce it an increase the exponent. extension (x: Float8) def +(y: Float8): Float8 = if x.exp <= y.exp then val shift = y.exp - x.exp val mant = (x.mant >> shift) + y.mant if mant < 16 then Float8(mant, y.exp) else val exp1 = y.exp + 1 if exp1 < 16 then Float8(mant / 2, y.exp + 1) else Float8(15, 15) else y + x Is this operation commutative? Prove or give a counterexample.
NaN values have the highest exponent, with a non-zero value for the mantissa. A float with 1-bit sign and 3-bit mantissa has 2 × ( 2 3 − 1 ) = 14 {\displaystyle 2\times (2^{3}-1)=14} NaN values. s 1111 mmm = NaN (if mmm ≠ 000)
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
We have a collection of rectangles in a plane, whose sides are aligned with the coordinate axes. Each rectangle is represented by its lower left corner $(x_1,y_1)$ and its upper right corner $(x_2,y_2)$. All coordinates are of type Long. We require $x_1 \le x_2$ and $y_1 \le y_2$. Define an operation hull2 that takes two Rectangles, r1 and r2, and computes as the result the smallest Rectangle containing both r1 and r2.
Let C be a set of n axis-parallel rectangles in the plane. The following algorithm finds a disjoint set with a size of at least | M D S ( C ) | log ⁡ n {\displaystyle {\frac {|MDS(C)|}{\log {n}}}} in time O ( n log ⁡ n ) {\displaystyle O(n\log {n})}: INITIALIZATION: sort the horizontal edges of the given rectangles by their y-coordinate, and the vertical edges by their x-coordinate (this step takes time O(n log n)). STOP CONDITION: If there are at most n ≤ 2 shapes, compute the MDS directly and return. RECURSIVE PART: Let x m e d {\displaystyle x_{\mathrm {med} }} be the median x-coordinate.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
We have a collection of rectangles in a plane, whose sides are aligned with the coordinate axes. Each rectangle is represented by its lower left corner $(x_1,y_1)$ and its upper right corner $(x_2,y_2)$. All coordinates are of type Long. We require $x_1 \le x_2$ and $y_1 \le y_2$. Define an operation hull2 that takes two Rectangles, r1 and r2, and computes as the result the smallest Rectangle containing both r1 and r2.
In this variant, there are multiple instances of a single rectangle of size (l,w), and a bigger rectangle of size (L,W). The goal is to pack as many small rectangles as possible into the big rectangle without overlap between any rectangles (small or large). Common constraints of the problem include limiting small rectangle rotation to 90° multiples and requiring that each small rectangle is orthogonal to the large rectangle. This problem has some applications such as loading of boxes on pallets and, specifically, woodpulp stowage. As an example result: it is possible to pack 147 small rectangles of size (137,95) in a big rectangle of size (1600,1230).
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
Review the notion of depth seen in the lecture. What does it represent? Below is a formula for the depth of a divide and conquer algorithm working on an array segment of size $L$, as a function of $L$. The values $c$, $d$ and $T$ are constants. We assume that $L>0$ and $T>0$. $$ D(L) = \begin{cases} c \cdot L &\text{if}\ L \leq T \\ \text{max}\left( D\left(\left\lfloor \frac L2 \right\rfloor \right), D\left(L - \left\lfloor \frac L2 \right\rfloor \right)\right) + d &\text{otherwise} \end{cases} $$ Below the threshold T, the algorithm proceeds sequentially and takes time c to process each single element. Above the threshold, the algorithm is applied recursively over the two halves of the array. The results are then merged using an operation that takes d units of time. Prove a logarithmic upper bound on $D(L)$. That is, prove that $D(L)$ is in $O(log(L))$ by finding specific constants $a$, $b$$b$ such that $D(L) \leq a \times log_2(L) + b$. Hint: The proof is more complex that it might seem. One way to make it more manageable is to define and use a function $D'(L)$that has the property described in question 1, and is greater or equal to $D(L)$. We suggest you use: $$D'(L) = \begin{cases} c \cdot L &\text{if}\ L \leq T \\ \text{max}\left( D'\left(\left\lfloor \frac L2 \right\rfloor \right), D'\left(L - \left\lfloor \frac L2 \right\rfloor \right)\right) + d + \underline{\underline{c \cdot T}} &\text{otherwise} \end{cases}$$ Also remark that computing $D'(L)$ when $L$ is a power of 2 is easy. Also remember that there always exists a power of 2 between any positive integer and its double.
The separator phase of the algorithm breaks the graph into components which are at most 1 / 2 {\displaystyle 1/2} the size of the original graph, resulting in a logarithmic recursion depth. At each level of the recursion, only linear work is needed to identify the separators as well as the connections possible between vertices. The overall result is O ( n log ⁡ n ) {\displaystyle O(n\log n)} preprocessing time with only O ( log ⁡ n ) {\displaystyle O(\log {n})} additional information stored for each vertex.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
Review the notion of depth seen in the lecture. What does it represent? Below is a formula for the depth of a divide and conquer algorithm working on an array segment of size $L$, as a function of $L$. The values $c$, $d$ and $T$ are constants. We assume that $L>0$ and $T>0$. $$ D(L) = \begin{cases} c \cdot L &\text{if}\ L \leq T \\ \text{max}\left( D\left(\left\lfloor \frac L2 \right\rfloor \right), D\left(L - \left\lfloor \frac L2 \right\rfloor \right)\right) + d &\text{otherwise} \end{cases} $$ Below the threshold T, the algorithm proceeds sequentially and takes time c to process each single element. Above the threshold, the algorithm is applied recursively over the two halves of the array. The results are then merged using an operation that takes d units of time. Prove a logarithmic upper bound on $D(L)$. That is, prove that $D(L)$ is in $O(log(L))$ by finding specific constants $a$, $b$$b$ such that $D(L) \leq a \times log_2(L) + b$. Hint: The proof is more complex that it might seem. One way to make it more manageable is to define and use a function $D'(L)$that has the property described in question 1, and is greater or equal to $D(L)$. We suggest you use: $$D'(L) = \begin{cases} c \cdot L &\text{if}\ L \leq T \\ \text{max}\left( D'\left(\left\lfloor \frac L2 \right\rfloor \right), D'\left(L - \left\lfloor \frac L2 \right\rfloor \right)\right) + d + \underline{\underline{c \cdot T}} &\text{otherwise} \end{cases}$$ Also remark that computing $D'(L)$ when $L$ is a power of 2 is easy. Also remember that there always exists a power of 2 between any positive integer and its double.
In the most balanced case, each time we perform a partition we divide the list into two nearly equal pieces. This means each recursive call processes a list of half the size. Consequently, we can make only log2 n nested calls before we reach a list of size 1. This means that the depth of the call tree is log2 n. But no two calls at the same level of the call tree process the same part of the original list; thus, each level of calls needs only O(n) time all together (each call has some constant overhead, but since there are only O(n) calls at each level, this is subsumed in the O(n) factor). The result is that the algorithm uses only O(n log n) time.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
In this week's lecture, you have been introduced to the aggregate method of ParSeq[A] (and other parallel data structures). It has the following signature: def aggregate[B](z: B)(f: (B, A) => B, g: (B, B) => B): B Discuss, as a group, what aggregate does and what its arguments represent. Implement aggregate using the methods map and/or reduce of the collection you are defining aggregate for.
There are no readily available heuristics available that are accurate with large databases. This method has only been used by Ringe's group.In these two methods there are often several trees found with the same score so the usual practice is to find a consensus tree via an algorithm. A majority consensus has bipartitions in more than half of the input trees while a greedy consensus adds bipartitions to the majority tree.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
In this week's lecture, you have been introduced to the aggregate method of ParSeq[A] (and other parallel data structures). It has the following signature: def aggregate[B](z: B)(f: (B, A) => B, g: (B, B) => B): B Discuss, as a group, what aggregate does and what its arguments represent. Implement aggregate using the methods map and/or reduce of the collection you are defining aggregate for.
The elements of aggregates (SET, BAG, LIST, ARRAY) are given in parentheses, separated by ",". Care has to be taken for select data types based on defined data types. Here the name of the defined data type gets mapped too. See also "Mapping of Express to Java" for more details of this.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
Which flag prevents user programs from reading and writing kernel data?
However, this variant requires that the operating system itself be prevented from writing to read-only pages (through the setting of a global processor flag), and not all kernels are designed this way; more recent kernels in fact are, since this is the same basic mechanism used for implementing copy-on-write. Additional workarounds other than the official ones from Intel have been proposed; in many cases these proved as effective and much easier to implement.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
Which flag prevents user programs from reading and writing kernel data?
These programs do not run under the control of an operating system
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
In JOS, after finishing the execution of a user-level page fault handler, how is the program control flow transferred back to the program? (You may get insights from the code snippet of _pagefault_upcall.)
Some interrupts are handled transparently to the program - for example, the normal resolution of a page fault is to make the required page accessible in physical memory. But in other cases such as a segmentation fault the operating system executes a process callback. On Unix-like operating systems this involves sending a signal such as SIGSEGV, SIGBUS, SIGILL or SIGFPE, which may either call a signal handler or execute a default action (terminating the program). On Windows the callback is made using Structured Exception Handling with an exception code such as STATUS_ACCESS_VIOLATION or STATUS_INTEGER_DIVIDE_BY_ZERO.In a kernel process, it is often the case that some types of software interrupts are not supposed to happen. If they occur nonetheless, an operating system crash may result.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
In JOS, after finishing the execution of a user-level page fault handler, how is the program control flow transferred back to the program? (You may get insights from the code snippet of _pagefault_upcall.)
Fault are induced by signals in POSIX compliant systems, and these signals originate from API calls, from the operating system, and from other applications. Any signal that does not have handler code becomes a fault that causes premature application termination. The handler is a function that is performed on-demand when the application receives a signal. This is called exception handling.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
What is the content of the superblock in the JOS file system?
The superblock maintains information about the entire file system and includes the following fields: Size of the file system Number of data blocks in the file system A flag indicating the state of the file system Allocation group sizes File system block size
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
What is the content of the superblock in the JOS file system?
The Berkeley Fast File System superblock format is identified as either 19 54 01 19 or 01 19 54 depending on version; both represent the birthday of the author, Marshall Kirk McKusick. The Master Boot Record of bootable storage devices on almost all IA-32 IBM PC compatibles has a code of 55 AA as its last two bytes. Executables for the Game Boy and Game Boy Advance handheld video game systems have a 48-byte or 156-byte magic number, respectively, at a fixed spot in the header.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
Consider an operation we will call scanRight1 that, given a function $f$ of two arguments, and a sequence $a_1, \ldots, a_N$, computes a sequence $b_1, \ldots, b_N$ such that: $b_N = a_N$ $b_i = f(a_{i}, b_{i+1})$, for $0 < i < N$ Define similarly scanLeft1 in a manner similar to scanRight1: Given a function $f$ of two arguments, and a sequence $a_1, \ldots, a_N$, scanLeft1 computes a sequence $b_1, \ldots, b_N$ such that: $b_1 = a_1$ $b_i = f(b_{i-1}, a_{i})$, for $0 < i \leq N$ Suppose that $f$ is associative. is the result of doing scanLeft1 and then reversing the sequence the same as first reversing the sequence and then doing scanRight1? Illustrate your answer on a sequence of three elements where each $a_i$ is a list and f(x,y) = x ::: y is concatenation.
Were the function f to refer to its second argument first here, and be able to produce some part of its result without reference to the recursive case (here, on its left i.e., in its first argument), then the recursion would stop. This means that while foldr recurses on the right, it allows for a lazy combining function to inspect list's elements from the left; and conversely, while foldl recurses on the left, it allows for a lazy combining function to inspect list's elements from the right, if it so chooses (e.g., last == foldl (\a b->b) (error "empty list")). Reversing a list is also tail-recursive (it can be implemented using rev = foldl (\ys x -> x: ys) ).
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
Consider an operation we will call scanRight1 that, given a function $f$ of two arguments, and a sequence $a_1, \ldots, a_N$, computes a sequence $b_1, \ldots, b_N$ such that: $b_N = a_N$ $b_i = f(a_{i}, b_{i+1})$, for $0 < i < N$ Define similarly scanLeft1 in a manner similar to scanRight1: Given a function $f$ of two arguments, and a sequence $a_1, \ldots, a_N$, scanLeft1 computes a sequence $b_1, \ldots, b_N$ such that: $b_1 = a_1$ $b_i = f(b_{i-1}, a_{i})$, for $0 < i \leq N$ Suppose that $f$ is associative. is the result of doing scanLeft1 and then reversing the sequence the same as first reversing the sequence and then doing scanRight1? Illustrate your answer on a sequence of three elements where each $a_i$ is a list and f(x,y) = x ::: y is concatenation.
Let V, R, and O be types, and i be any natural number, representing a sequence of parameters taken from V. Then the function sequence f of functions fn from Vi+n → R to O is defined by bar recursion from the functions Ln: R → O and B with Bn: ((Vi+n → R) x (Vn → R)) → O if: fn((λα:Vi+n)r) = Ln(r) for any r long enough that Ln+k on any extension of r equals Ln. Assuming L is a continuous sequence, there must be such r, because a continuous function can use only finitely much data. fn(p) = Bn(p, (λx:V)fn+1(cat(p, x))) for any p in Vi+n → R.Here "cat" is the concatenation function, sending p, x to the sequence which starts with p, and has x as its last term. (This definition is based on the one by Escardó and Oliva.)
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
Freshly graduated from EPFL, you have been hired as contractors for a successful and rapidly growing bank. The bank has been experiencing problems with their money management system recently, which is written in Scala, and so they hired the best and brightest young engineer they could find: you! The system had been working perfectly fine so far, they tell you. In the past days, due to an increased number of customers, they had to switch from a single-threaded sequential execution environment to a multi-threaded concurrent one, in which the threads may perform transactions concurrently. That's when problems started, your manager says... Here is the code responsible to withdraw money from the account from and transfer it to the account to, within the same bank: def transfer(from: Account, to: Account, amount: BigInt): Unit = { require(amount >= 0) val balanceFrom = from.balance if (balanceFrom >= amount) { from.balance = balanceFrom - amount val balanceTo = to.balance to.balance = balanceTo + amount } } For the bank, it is very important that the following two properties hold after any sequence of completed transfer transactions: The balance of an account never goes below 0. The total sum of money held by the bank is constant. For each of the proposed implementations of transfer below, check which of the two properties hold. Additionally, check if the system is vulnerable to deadlocks. Variant 1: def transfer1(from: Account, to: Account, amount: Long): Unit = { require(amount >= 0) val balanceFrom = from.balance if (balanceFrom >= amount) { from.synchronized { from.balance = balanceFrom - amount } to.synchronized { val balanceTo = to.balance to.balance = balanceTo + amount } } } Variant 2: def transfer2(from: Account, to: Account, amount: Long): Unit = { require(amount >= 0) from.synchronized { val balanceFrom = from.balance if (balanceFrom >= amount) { from.balance = balanceFrom - amount to.synchronized { val balanceTo = to.balance to.balance = balanceTo + amount } } } } Variant 3 object lock // Global object def transfer3(from: Account, to: Account, amount: Long): Unit = { require(amount >= 0) lock.synchronized { val balanceFrom = from.balance if (balanceFrom >= amount) { from.balance = balanceFrom - amount val balanceTo = to.balance to.balance = balanceTo + amount } } }
One of lock-based programming's biggest problems is that "locks don't compose": it is hard to combine small, correct lock-based modules into equally correct larger programs without modifying the modules or at least knowing about their internals. Simon Peyton Jones (an advocate of software transactional memory) gives the following example of a banking application: design a class Account that allows multiple concurrent clients to deposit or withdraw money to an account; and give an algorithm to transfer money from one account to another. The lock-based solution to the first part of the problem is: class Account: member balance: Integer member mutex: Lock method deposit(n: Integer) mutex.lock() balance ← balance + n mutex.unlock() method withdraw(n: Integer) deposit(−n) The second part of the problem is much more complicated. A transfer routine that is correct for sequential programs would be function transfer(from: Account, to: Account, amount: Integer) from.withdraw(amount) to.deposit(amount) In a concurrent program, this algorithm is incorrect because when one thread is halfway through transfer, another might observe a state where amount has been withdrawn from the first account, but not yet deposited into the other account: money has gone missing from the system. This problem can only be fixed completely by taking locks on both account prior to changing any of the two accounts, but then the locks have to be taken according to some arbitrary, global ordering to prevent deadlock: function transfer(from: Account, to: Account, amount: Integer) if from < to // arbitrary ordering on the locks from.lock() to.lock() else to.lock() from.lock() from.withdraw(amount) to.deposit(amount) from.unlock() to.unlock() This solution gets more complicated when more locks are involved, and the transfer function needs to know about all of the locks, so they cannot be hidden.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
Freshly graduated from EPFL, you have been hired as contractors for a successful and rapidly growing bank. The bank has been experiencing problems with their money management system recently, which is written in Scala, and so they hired the best and brightest young engineer they could find: you! The system had been working perfectly fine so far, they tell you. In the past days, due to an increased number of customers, they had to switch from a single-threaded sequential execution environment to a multi-threaded concurrent one, in which the threads may perform transactions concurrently. That's when problems started, your manager says... Here is the code responsible to withdraw money from the account from and transfer it to the account to, within the same bank: def transfer(from: Account, to: Account, amount: BigInt): Unit = { require(amount >= 0) val balanceFrom = from.balance if (balanceFrom >= amount) { from.balance = balanceFrom - amount val balanceTo = to.balance to.balance = balanceTo + amount } } For the bank, it is very important that the following two properties hold after any sequence of completed transfer transactions: The balance of an account never goes below 0. The total sum of money held by the bank is constant. For each of the proposed implementations of transfer below, check which of the two properties hold. Additionally, check if the system is vulnerable to deadlocks. Variant 1: def transfer1(from: Account, to: Account, amount: Long): Unit = { require(amount >= 0) val balanceFrom = from.balance if (balanceFrom >= amount) { from.synchronized { from.balance = balanceFrom - amount } to.synchronized { val balanceTo = to.balance to.balance = balanceTo + amount } } } Variant 2: def transfer2(from: Account, to: Account, amount: Long): Unit = { require(amount >= 0) from.synchronized { val balanceFrom = from.balance if (balanceFrom >= amount) { from.balance = balanceFrom - amount to.synchronized { val balanceTo = to.balance to.balance = balanceTo + amount } } } } Variant 3 object lock // Global object def transfer3(from: Account, to: Account, amount: Long): Unit = { require(amount >= 0) lock.synchronized { val balanceFrom = from.balance if (balanceFrom >= amount) { from.balance = balanceFrom - amount val balanceTo = to.balance to.balance = balanceTo + amount } } }
If line 3 in both operations executes before line 5 both operations will find that balance >= withdrawal evaluates to true, and execution will proceed to subtracting the withdrawal amount. However, since both processes perform their withdrawals, the total amount withdrawn will end up being more than the original balance. These sorts of problems with shared resources benefit from the use of concurrency control, or non-blocking algorithms.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
In which of the following cases does the TLB need to be flushed?
Flushing of the TLB can be an important security mechanism for memory isolation between processes to ensure a process can't access data stored in memory pages of another process. Memory isolation is especially critical during switches between the privileged operating system kernel process and the user processes – as was highlighted by the Meltdown security vulnerability. Mitigation strategies such as kernel page-table isolation (KPTI) rely heavily on performance-impacting TLB flushes and benefit greatly from hardware-enabled selective TLB entry management such as PCID.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
In which of the following cases does the TLB need to be flushed?
On an address-space switch, as occurs when context switching between processes (but not between threads), some TLB entries can become invalid, since the virtual-to-physical mapping is different. The simplest strategy to deal with this is to completely flush the TLB. This means that after a switch, the TLB is empty, and any memory reference will be a miss, so it will be some time before things are running back at full speed. Newer CPUs use more effective strategies marking which process an entry is for.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
Select all valid answers about UNIX-like shell.
sqsh, a shell available with some SQL implementations for database queries and other tasks. Google Shell, a browser-based front-end for Google Search
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
Select all valid answers about UNIX-like shell.
Many later command-line interpreters have been inspired by the Unix shell. A fundamental simplifying assumption of Unix was its focus on newline-delimited text for nearly all file formats. There were no "binary" editors in the original version of Unix – the entire system was configured using textual shell command scripts.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
Review the notion of depth seen in the lecture. What does it represent? Below is a formula for the depth of a divide and conquer algorithm working on an array segment of size $L$, as a function of $L$. The values $c$, $d$ and $T$ are constants. We assume that $L>0$ and $T>0$. $$ D(L) = \begin{cases} c \cdot L &\text{if}\ L \leq T \\ \text{max}\left( D\left(\left\lfloor \frac L2 \right\rfloor \right), D\left(L - \left\lfloor \frac L2 \right\rfloor \right)\right) + d &\text{otherwise} \end{cases} $$ Below the threshold T, the algorithm proceeds sequentially and takes time c to process each single element. Above the threshold, the algorithm is applied recursively over the two halves of the array. The results are then merged using an operation that takes d units of time. Is it the case that for all $1 \leq L_1 \leq L_2$ we have $D(L_1) \leq D(L_2)$? If it is the case, prove the property by induction on $L$. If it is not the case, give a counterexample showing values of $L_1$, $L_2$, $c$, and $d$for which the property does not hold.
The depth (defined as the maximal length of a regular M-sequence; also referred to as the grade of M) provides a sharp lower bound, i.e., it is the smallest integer n such that H I n ( M ) ≠ 0. {\displaystyle H_{I}^{n}(M)\neq 0.} These two bounds together yield a characterisation of Cohen–Macaulay modules over local rings: they are precisely those modules where H m n ( M ) {\displaystyle H_{\mathfrak {m}}^{n}(M)} vanishes for all but one n.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
Review the notion of depth seen in the lecture. What does it represent? Below is a formula for the depth of a divide and conquer algorithm working on an array segment of size $L$, as a function of $L$. The values $c$, $d$ and $T$ are constants. We assume that $L>0$ and $T>0$. $$ D(L) = \begin{cases} c \cdot L &\text{if}\ L \leq T \\ \text{max}\left( D\left(\left\lfloor \frac L2 \right\rfloor \right), D\left(L - \left\lfloor \frac L2 \right\rfloor \right)\right) + d &\text{otherwise} \end{cases} $$ Below the threshold T, the algorithm proceeds sequentially and takes time c to process each single element. Above the threshold, the algorithm is applied recursively over the two halves of the array. The results are then merged using an operation that takes d units of time. Is it the case that for all $1 \leq L_1 \leq L_2$ we have $D(L_1) \leq D(L_2)$? If it is the case, prove the property by induction on $L$. If it is not the case, give a counterexample showing values of $L_1$, $L_2$, $c$, and $d$for which the property does not hold.
For computing ⌊ n ⌋ {\displaystyle \lfloor {\sqrt {n}}\rfloor } for very large integers n, one can use the quotient of Euclidean division for both of the division operations. This has the advantage of only using integers for each intermediate value, thus making the use of floating point representations of large numbers unnecessary. It is equivalent to using the iterative formula By using the fact that one can show that this will reach ⌊ n ⌋ {\displaystyle \lfloor {\sqrt {n}}\rfloor } within a finite number of iterations. In the original version, one has x k ≥ n {\displaystyle x_{k}\geq {\sqrt {n}}} for k ≥ 1 {\displaystyle k\geq 1} , and x k > x k + 1 {\displaystyle x_{k}>x_{k+1}} for x k > n {\displaystyle x_{k}>{\sqrt {n}}} .
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
In x86, select all synchronous exceptions?
Asynchronous exceptions are events raised by a separate thread or external process, such as pressing Ctrl-C to interrupt a program, receiving a signal, or sending a disruptive message such as "stop" or "suspend" from another thread of execution. Whereas synchronous exceptions happen at a specific throw statement, asynchronous exceptions can be raised at any time. It follows that asynchronous exception handling can't be optimized out by the compiler, as it cannot prove the absence of asynchronous exceptions. They are also difficult to program with correctly, as asynchronous exceptions must be blocked during cleanup operations to avoid resource leaks.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
In x86, select all synchronous exceptions?
Structured exception handling. Proceedings of the 2nd ACM SIGACT-SIGPLAN symposium on Principles of programming languages - POPL '75. pp.
https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus
End of preview. Expand in Data Studio

This dataset has been created by retrieving, for each question, the top 2 documents of https://www.kaggle.com/datasets/conjuring92/wiki-stem-corpus using BAAI/bge-small-en-v1.5 of the EPFL dataset

Downloads last month
13