What particular strengths of the relational model have led to the pre-eminent position that it holds today
Question:
What particular strengths of the relational model have led to the pre-eminent position that it holds today as a vehicle for database management? [8 marks] Identify any weaknesses in the model, illustrating your answer by examples. [6 marks] How might these weaknesses be remedied while retaining the advantages of the model? Consider the following Standard ML type expression intended to represent integer arithmetic expressions built up from named variables using addition and multiplication: datatype expression = Var of string | Sum of expression * expression | Product of expression * expression; [In the CAML dialect of ML datatype is written type.] For example, the expression ((a + b)c)(d + e) would be represented by: Product(Product(Sum(Var "a", Var "b"), Var "c"), Sum(Var "d", Var "e")) Write an ML function freevars (using any dialect of ML) which takes an argument, e, of type expression and returns a value of type string list containing all the variables in e. This list may contain repeated instances of variables. [10 marks] Write a second ML function eval (again using any dialect of ML) which takes two arguments. The first argument is of type expression and the second is an association list of type (string * int) list giving a value for each variable, for example: [("a",1), ("b",0), ("c",2), ("d",4), ("e",1)] [In the CAML dialect of ML semicolons are used as list separators.] When eval is applied to the above examples it returns 10. [10 marks] 11 Computer Vision Discuss the role of non-linear operators in vision for the extraction of motion information, texture information, colour information, and stereo information. What are the limitations of linear operators (such as filters) compared with non-linear ones? What is a quadrature pair, and what is a Hilbert pair? What is a Hilbert Transform, and what is a natural way to build a useful non-linear operator from it? [20 marks] 5 [TURN OVER CST.97.13.6 12 Complexity Theory Suppose you had a conventional sequential computer with a special coprocessor which could multiply two n-bit numbers in time proportional to log(n), even for very large n. Explain how you would implement a fast integer square root program on this system. Comment on the performance you could expect to achieve. [20 marks] 13 Numerical Analysis II Explain the term positive semi-definite. [1 mark] Let A be a square matrix. State Schwarz's inequality for the product Ax. What are the singular values of A, and how are they related to the `2 norm of A? [4 marks] Describe briefly the singular value decomposition of the matrix A, and how it may be used to solve the linear equations Ax = b. [4 marks] Let x be an approximate solution of Ax = b, and write r = b Ax, e = x x. Find an expression for the relative error kek/kxk in terms of computable quantities. Show how your formula is related to the singular values of A. [8 marks] How may this formula be used if some singular values are very small?
Explain quadratic probing and its advantages and disadvantages. [Hint: refer to primary and secondary clustering.] [3 marks] (d) Give a general mathematical expression for the probing function p(k, i) used in quadratic probing. The expression should yield a 0-based index into the table, referencing the key k, the probe number i, the hash function h, the table size m and the constants c1 and c2. [3 marks] (e) Does the following pseudocode implement a form of quadratic probing? If so, derive values for c1 and c2 in the equation you produced for part (d). If not, prove it doesn't. In either case, clearly justify your reasoning. [8 marks] def get(k): j = h(k) i = 0 while true: if T[j].key == null: raise NotFound if T[j].key == k: return T[j].payload i = i+1 if i == m: raise NotFound j = (i+j) mod m 9 (TURN OVER) CST0.2017.1.10 9 Algorithms We wish to store a dynamic collection of records, each of the form {timestamp, value}, where value is a real number. The collection should support the operations append_newer(t,v) to add a new record (which we can assume has a larger timestamp than any existing record), pop_oldest() to remove the oldest record, and get_oldest() to inspect the oldest without removing it. (a) Define the Queue abstract data type. Describe an implementation using a linked list. Explain how to use it for this dynamic collection of records. [3 marks] The collection should also support get_max(), which returns a pointer to the record with the highest value in the collection. Ties may be broken arbitrarily. (b) A simple implementation of get_max() simply scans through the entire list. What is the worst-case cost, given the number n of items in the collection? [1 mark] (c) An engineer friend suggests keeping a pointer maxrecord to the record with the largest value so that the entire list only need be rescanned when the item pointed to by maxrecord is removed. Give an example to show that n operations could take (n 2 ) time. [3 marks] (d) Explain the terms amortized cost and potential method. Explain the relationship between aggregate true costs and aggregate amortized costs.
address all questions
Create function count_target_in_list that takes a list of integers and the target value then counts and returns the number of times the target value appears in the list.
Write program in that uses get_int_list_from_user method to get a list of 10 numbers, then calls the count_target_list method to get the count then prints the number of times the target was found in the list.
complet the method huffmantoText and texttoHuffman
public static void huffmanToText(){ //TDo: convert text to huffman code
}
public static void textToHuffman(){ //Do: convert huffman code to its text equivalent }
Input a text that will be converted to Huffman code.
This is sample of the output:
Text to Huffman Code Conversion:
Enter a text: def
Huffman code: 1011100000
1. Input a Huffman code that will be converted to its text equivalent.
2. Output an error message if the input cannot be converted.
code
HuffmanCoding.java
package midlab2; import java.util.*;
public class HuffmanCoding { static ArrayList huffmanCode = new ArrayList<>(); static ArrayList huffmanChar = new ArrayList<>();
public static void main(String[] args) { char[] text = readText(); ArrayList freq = frequencyCounter(text); ArrayList charArray = charArray(text); huffmanTree(charArray,freq); System.out.println("---------- ");
Scanner scanner = new Scanner(System.in); System.out.println("1.) Text to Huffman code"); System.out.println("2.) Huffman code to text"); System.out.print("Enter your choice: "); int choice = scanner.nextInt(); choiceOfAction(choice);
//use this string for testing purposes String t = }
public static char[] readText(){ Scanner scanner = new Scanner(System.in); System.out.print("Type your text: "); String text = scanner.nextLine(); return text.toCharArray(); }
public static ArrayList frequencyCounter(char[] text){ ArrayList counts = new ArrayList<>(); ArrayList charChecker = new ArrayList<>(); for (char value : text) { if(!charChecker.contains(value)) charChecker.add(value); else continue; int c = 0; for (char item : text) { if (value == item) { c++; } } counts.add(c); }//end loop return counts; }
public static ArrayList charArray(char[] text){ ArrayList charArr = new ArrayList<>(); for (char value : text) { if(!charArr.contains(value)) charArr.add(value); }//end loop return charArr; }
public static void huffmanTree(ArrayList charArray, ArrayList charfreq){ // number of characters. int n = charArray.size();
// creating a priority queue q. // makes a min-priority queue(min-heap). PriorityQueue q = new PriorityQueue<>(n, new NodeComparator());
for (int i = 0; i < n; i++) { // creating a Huffman node object // and add it to the priority queue. BTNode hn = new BTNode(); hn.c = charArray.get(i); hn.element = charfreq.get(i); hn.left = null; hn.right = null; //System.out.println(hn.getCharacter()+": "+hn.getElement()); // add functions adds // the huffman node to the queue. }
// create a root node BTNode root = null;
// Here we will extract the two minimum value // from the heap each time until // its size reduces to 1, extract until // all the nodes are extracted. while (q.size() > 1) {
// first min extract. BTNode x = q.peek(); q.poll();
// second min extract. BTNode y = q.peek(); q.poll();
// new node f which is equal BTNode f = new BTNode();
// to the sum of the frequency of the two nodes // assigning values to the f node. f.element = x.element + y.element; f.c = '-';
// first extracted node as left child. f.left = x;
// second extracted node as the right child. f.right = y;
// marking the f node as the root node. root = f;
// add this node to the priority-queue. q.add(f); }
// print the codes by traversing the tree printCode(root, ""); }
public static void printCode(BTNode root, String s) { // base case; if the left and right are null // then its a leaf node and we print // the code s generated by traversing the tree.
if (root.left == null && root.right == null) { // c is the character in the node System.out.println(root.c + ":" + s); huffmanCode.add(s); huffmanChar.add(root.c); return; }
// if we go to left then add "0" to the code. // if we go to the right add"1" to the code.
// recursive calls for left and // right sub-tree of the generated tree. printCode(root.left, s + "0"); printCode(root.right, s + "1"); }
public static void tableOfValues(){ //ToDo: you can use the attribute "huffmanCode" and "huffmanChar" as data for the table }
public static void percentStorageSaving(){ //ToDo: refer to page 23 of module 4
}
public static boolean isTextValid(String text){ //ToDo: Output an error message if the text cannot be converted (e.g. using character/s //in the input text that is/are not part of the table Huffman codes) return true; }
public static void huffmanToText(){
}
public static void textToHuffman(){ //Do: convert huffman code to its text equivalent }
public static void choiceOfAction(int choice){ switch (choice){ case 1: Scanner scanner = new Scanner(System.in); String t = scanner.nextLine(); if(isTextValid(t)) textToHuffman(); else System.out.println("Invalid text, try again."); case 2: huffmanToText(); } }
}
BTNode.java package midlab2;
import java.util.*; public class BTNode { public int element; public char c; public BTNode left; public BTNode right;
public BTNode(){} /**Constructs a binary tree node that stores the specified element. */ public BTNode(int element) { this.element = element; left = right = null; } /** Returns the element stored in this node. */ public int getElement() { return element; }
/** Returns the element stored in this node. */ public char getCharacter() { return c; }
/* Sets the element stored in this node./ public void setElement (int element) { this.element = element; }
/* Sets the element stored in this node./ public void setChar (char c) { this.c = c; }
/* Returns the left subtree of this node./ public BTNode getLeft() { return left; }
/** Sets the left child of this node. */ public void setLeft (BTNode left) { this.left = left; }
/** Returns the right subtree of this node. */ public BTNode getRight() { return right; }
/**Sets the right child of this node. */ public void setRight (BTNode right) { this.right = right; }
public int getSize(){ int leftSize = 0, rightSize = 0;
if(getLeft() != null) leftSize = this.left.getSize();
if(getRight() != null) rightSize = this.right.getSize();
return 1 + leftSize + rightSize; } //... } // end of class
-------------------------- NodeComparator.java ---------------------------
package midlab2;
import java.util.Comparator;
public class NodeComparator implements Comparator { public int compare(BTNode x, BTNode y) { return x.getElement() - y.getElement(); } }
Test.java -
package midlab2;
import java.util.ArrayList; import java.util.PriorityQueue; import java.util.Scanner;
public class Test { public static void main(String[] args) { BTNode root = new BTNode(); BTNode left = new BTNode(); BTNode right = new BTNode();
left.setChar('c'); right.setChar(','); root.setLeft(left); root.setRight(right);
printCode(root);
}
static BTNode temp = null; public static void printCode(BTNode root) { if(root == null) { System.out.println(temp.c + "==:"); return; }
temp =root; if (root.left == null && root.right == null) { System.out.println(root.c + ":"); return; }
printCode(root.left); printCode(root.right); } }
n/b answer all questions
write program to compute number and sum of odd and even numbers from N number
write program in C to calculate the product of two numbers using a user defined function.
write program in C to calculate the sum of all digits of a number using for loop.
Write program which provides whether the given year is leap year or not. recursive function that takes positive int n as its input and returns sum of the first n squares.
Discuss the tradeoffs that can be made between consistency and availability of replicated data in a distributed system. Your discussion should cover (a) the requirements of different applications and (b) the algorithms and protocols that can be used to implement the required policies. [20 marks] 2 Computer Architecture What is the PCI Local Bus and when is it used? [5 marks] What types of signals are defined in its specification? [5 marks] Characterise operation of buses such as the PCI Local Bus in terms of basic read, basic write, and basic arbitration operations. [10 marks] 1 [TURN OVER CST.97.13.2 3 Digital Communication I Explain the terms ARQ protocol and window of an ARQ protocol. [5 marks] An ARQ protocol uses a window of 1 kbyte. The protocol is used over a link whose capacity is 1 Mbps. In the absence of transmission errors (or any other loss) determine (a) for a link delay of 100 s, and (b) for a link delay of 250 ms, the time required to transfer each of the following amounts of information over the link: 1 kbyte, 1 Mbyte and 1 Gbyte [12 marks] State and explain in which of these cases moving to a larger window size will not significantly improve the transfer time. [3 marks] 4 Computer Graphics and Image Processing It is convenient to be able to specify colours in terms of a three-dimensional coordinate system. Three such coordinate systems are: RGB, HLS, L*a*b*. Choose two of these three coordinate systems and for each of your chosen two: (a) describe what each of the three coordinates represents [2 marks each] (b) describe why the coordinate system is a useful representation of colour [2 marks each] Draw either the first eight one-dimensional Haar basis functions or the first eight one-dimensional Walsh-Hadamard basis functions. [4 marks] Calculate the coefficients of your chosen eight basis functions for the following one-dimensional image data: 12 16 20 24 24 16 8 8 [4 marks] Explain why, in general, the Haar or Walsh-Hadamard encoded version of an image is preferable to the original image for storage or transmission. [4 marks] 2 CST.97.13.3 5 Business Studies Describe the roles and relationships of the members of a Chief Programmer team. [5 marks] Describe Maslow's Hierarchy of Needs. [5 marks] Discuss stages of group formation. How does belonging to a group satisfy some of the needs described by Maslow? [5 marks] "The problems of co-ordination mean that there is a limit on the size of any software system that can be successfully built." Discuss. [5 marks] 6 Programming in C and C++ Write a declaration of a C++ class that might be used to implement a binary tree with each node able to hold an integer. Your implementation (i.e. the class itself and those bodies which conveniently fit within it) should make it impossible for casual programmers to access the pointer fields that link parts of the tree together except through cleanly specified access functions. Show how you would overload the "+" operator in C++ to provide a neat notation for adding a new item into such a tree.
Entrepreneurial Finance
ISBN: 978-1305968356
6th edition
Authors: J. Chris Leach, Ronald W. Melicher