Commit 1a7727b

mo khan <mo.khan@gmail.com>
2020-06-15 02:10:01
Start work on assignment
1 parent 56746a7
Changed files (2)
assignments/01/01_a_priority_queue.rb
@@ -0,0 +1,34 @@
+require 'bundler/inline'
+
+gemfile do
+  source 'https://rubygems.org'
+
+  gem 'minitest'
+end
+
+require 'minitest/autorun'
+
+=begin
+Describe the meaning of the essential methods `add(x)`, `deleteMin()`, and `size()` that are supported by the priority queue interface.
+Implement those methods using a singly-linked list.
+Analyze the running time of the `add(x)` and `deletMin()` operations based on this implementation.
+=end
+
+class Example < Minitest::Test
+  def dyck_word?(stack)
+    sum = 0
+    stack.each do |item|
+      return if sum.negative?
+      sum += item
+    end
+    true
+  end
+
+  def test_valid_word
+    assert dyck_word?([1, -1, 1, -1])
+  end
+
+  def test_invalid_word
+    refute dyck_word?([1, -1, -1, 1])
+  end
+end
assignments/01/README.md
@@ -3,8 +3,15 @@
 Answer question 1, question 2, and any other 2 questions from questions 3 to 6 – maximum 100 marks.
 You must score at least 50 to pass the assignment.
 
-1. You have learned some fundamental data structure concepts such as array, queue and priority queue, stack, list and linked list, sequence, and unordered set, and you understand the concept of interface or abstract data type that defines the set of operations supported by a data structure and the semantics, or meaning, of those operations. You can use the interface of one particular data structure to define or implement the operations of a different data structure.
-  * a. Describe the meaning of the essential methods `add(x)`, `deleteMin()`, and `size()` that are supported by the priority queue interface. Implement those methods using a singly-linked list. Analyze the running time of the `add(x)` and `deletMin()` operations based on this implementation.
+1. You have learned some fundamental data structure concepts such as array,
+  queue and priority queue, stack, list and linked list, sequence,
+  and unordered set, and you understand the concept of interface or abstract data type that defines the set of operations supported by a data structure and the semantics, or meaning, of those operations.
+  You can use the interface of one particular data structure to define or implement the operations of a different data structure.
+  * a. Describe the meaning of the essential methods `add(x)`, `deleteMin()`, and `size()` that are supported by the priority queue interface.
+    Implement those methods using a singly-linked list. Analyze the running time of the `add(x)` and `deletMin()` operations based on this implementation.
+    * The `add(x)` method is used to add an element to the queue with a priority.
+    * The `deleteMin()` method is used to remove the element with the lowest priority from the queue and return it.
+    * The `size()` method is used to determine how many items are in the queue.
   * b. Implement the stack methods `push(x)` and `pop()` using two queues. Analyze the running time of the `push(x)` and `pop()` operations based on this implementation.
 2. Swap two adjacent elements in a list by adjusting only the links (and not the data) using:
   * a. singly-linked list.