Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[pull] master from amejiarosario:master #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
pull merged 3 commits into lalittolani:master from amejiarosario:master
Jul 28, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion book/content/part02/array.asc
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ endif::[]
=== Array
(((Array)))
(((Data Structures, Linear, Array)))
Arrays are one of the most used data structures. You probably have used it a lot but are you aware of the runtimes of `splice`, `shift`, `indexOf` and other operations? In this chapter, we are going deeper into the most common operations and their runtimes.
Arrays are one of the most used data structures. You probably have used it a lot but are you aware of the runtimes of `splice`, `shift`, `indexOf` and other operations? In this chapter, we are going deeper into the most common operations and their runtimes.

==== Array Basics

Expand Down Expand Up @@ -274,3 +274,47 @@ To sum up, the time complexity of an array is:
| splice ^| O(n) | Insert and remove from anywhere.
|===
//end::table

==== Array Exercises

1) Implement an efficient algorithm that rotate an array `a` an `k` number of times.

[source, javascript]
----
/**
* Rotate an array left by k number of times.
*
* @example
* rotateLeft([1,2,3], 1); // [2,3,1]
* rotateLeft([1,2,3,4,5], 4); // [5,1,2,3,4]
*
* rotateLeft(Array(1e6).fill(1), 1e4); // <scale testing>
*
* @param a - The array
* @param k - The number of times the array is rotated
*/
function rotateLeft(a, k) {
// write you code and test with examples
}
----


2) Implement an algorithm that takes two arrays of numbers and return a new array with the sum.

[source, javascript]
----
/**
* Return the sum of two arrays as a new array.
*
* @example
* sum([1,2,3], [1,1,1]); // [2,3,4]
* sum([1], [9,9,9]); // [1,0,0,0]
*
* @param {number[]} a - Array of numbers.
* @param {number[]} b - Array of numbers.
* @returns {number[]} the sum array.
*/
function sum(a, b) {
// write you code and test with examples
}
----
4 changes: 4 additions & 0 deletions book/content/part02/linked-list.asc
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,7 @@ Use a doubly linked list when:
* You want to save some memory when dealing with possibly large data sets. Arrays pre-allocate a large chunk of contiguous memory on initialization. Lists are more "grow as you go".

For the next two linear data structures <<part02-linear-data-structures#stack>> and <<part02-linear-data-structures#queue>>, we are going to use a doubly linked list to implement them. We could use an array as well, but since inserting/deleting from the start performs better with linked-lists, we are going use that.

==== Linked List Exercises

1) Merge two sorted lists into one (and keep them sorted)
15 changes: 15 additions & 0 deletions lab/exercises/01-arrays/rotate-array-left.js
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Rotate an array left by k number of times.
*
* @example
* rotateLeft([1,2,3], 1); // [2,3,1]
* rotateLeft([1,2,3,4,5], 4); // [5,1,2,3,4]
*
* rotateLeft(Array(1e6).fill(1), 1e4); // <scale testing>
*
* @param a - The array
* @param k - The number of times the array is rotated
*/
function rotateLeft(a, k) {
// write you code and test with examples
}
13 changes: 13 additions & 0 deletions lab/exercises/01-arrays/sum-arrays.js
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Return the sum of two arrays as a new array.
*
* @example
* sum([1,2,3], [1,1,1]); // [2,3,4]
* sum([1], [9,9,9]); // [1,0,0,0]
*
* @param {number[]} a - Array of numbers.
* @param {number[]} b - Array of numbers.
* @returns {number[]} the sum array.
*/
function sum(a, b) {
}

AltStyle によって変換されたページ (->オリジナル) /