Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Csc300 Computer Studies DFN Midterm Exam: Data Types, Algorithms, and Code Examples, Exams of Computer Science

A comprehensive overview of key concepts in computer science, including data types, abstract data types, algorithms, and code examples. It covers topics such as algorithm analysis, cost models, and the implementation of various algorithms in java. Suitable for students studying computer science at the university level.

Typology: Exams

2024/2025

Available from 12/22/2024

Martin-Ray-1
Martin-Ray-1 🇺🇸

5

(8)

6.1K documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Csc300 Computer Studies DFN midterm
Exam
data type - ✔✔A set of values and a set of operations on those values
Abstract data type (ADT) - ✔✔A data type whose representation is
hidden from the client.
Identity 4 ADTs we have discussed - ✔✔Int, double, boolean, string
Java Interface - ✔✔a collection of abstract methods and constants
Tilde approximation - ✔✔Throw away low-order terms that complicate
formulas and represent a negligible contribution to values of interest
Cost Model - ✔✔The basic operations used by algorithms we are
studying to solve the problem at hand.
What is the point if algorithm analysis? - ✔✔Required resources of an
algorithm to solve specific computational problem.
public static double valRange (double[] list) { - ✔✔double cmin = list[0];
double cmax = list[0];
pf3
pf4
pf5

Partial preview of the text

Download Csc300 Computer Studies DFN Midterm Exam: Data Types, Algorithms, and Code Examples and more Exams Computer Science in PDF only on Docsity!

Csc300 Computer Studies DFN midterm

Exam

data type - ✔✔A set of values and a set of operations on those values Abstract data type (ADT) - ✔✔A data type whose representation is hidden from the client. Identity 4 ADTs we have discussed - ✔✔Int, double, boolean, string Java Interface - ✔✔a collection of abstract methods and constants Tilde approximation - ✔✔Throw away low-order terms that complicate formulas and represent a negligible contribution to values of interest Cost Model - ✔✔The basic operations used by algorithms we are studying to solve the problem at hand. What is the point if algorithm analysis? - ✔✔Required resources of an algorithm to solve specific computational problem. public static double valRange (double[] list) { - ✔✔double cmin = list[0]; double cmax = list[0];

for (int i = 1; i < list.length; i++) { if (list[i] > cmax) cmax = list[i]; if (list[i] < cmin) cmin = list[i]; } return cmax - cmin; } public static int posOfLargestElementLtOeT( double limit, double[] list) {

  • ✔✔int cPos = - 1; for(int i = 0; i < list.length; i++) { if(list[i] <= limit) { if(cPos == - 1) { cPos = i; } else { if(list[i] > list[cPos]) { cPos = i; } } }

return false; public static int numDuplicates (char[] list) { - ✔✔int sum = 0; for(int i = 1; i < list.length; i++) { if(list[i] == list[i-1]) sum++; } return sum; public static char[] removeDuplicates (char[] list) { - ✔✔char[] ans = new char[list.length-numDuplicates(list)]; int counter = 0; for(int i = 0; i < list.length; i++) { if (i == 0 || list[i] != list[i-1]) { ans[counter++] = list[i]; } } return ans; public static int sumOfOdds (int[] a) { - ✔✔int result = 0; int i = 0; while (i < a.length) { if ( a[i] %2 == 1)

result = result + a[i]; i = i + 1; } return result; public static void reverseIterative (int[] a) { - ✔✔int hi = a.length - 1; int lo = 0; while (lo < hi) { int loVal = a[lo]; int hiVal = a[hi]; a[hi] = loVal; a[lo] = hiVal; lo = lo + 1; hi = hi - 1; public static void reverseArrayHelper(int[] a, int start, int end) { - ✔✔int temp; if(start>=end) return; temp = a[start]; a[start] = a[end]; a[end] = temp;

if (n == 0) // base case result = 0; else result = a[n] + sumOfArray(a[n-1]); return result; Reverse the queue of q1 - ✔✔Stack s1 = new Stack(); while(!q1.isEmpty()) { int item = q1.dequeue(); s1.push(item); } while(s1.isEmpty()) { int item = s1.pop(); q1.enqueue(item); }