VelocerUygulamayı aç

Velocer › Bilgi kartları › University of Minnesota Twin Cities › CSCI 1913: Intro to Algorithms and Data Structures · UMN

CSCI 1913: Intro to Algorithms and Data Structures · UMN

CSCI 1913 intro to algorithms and data structures flashcards. · dinkytown_decks tarafından · 146 kart

University of Minnesota Twin Cities

Bu desteyi çalış Göm

  1. What does 'spaced repetition' mean as a learning technique?Reviewing material at increasing intervals over time to strengthen long-term retention.
  2. What does 'deep processing' refer to in learning design?Engaging with material meaningfully (e.g., connecting ideas, explaining) rather than superficial memorization.
  3. Can every for loop be rewritten as a while loop?Yes, every for loop can be rewritten as a while, but not every while can become a for.
  4. Does Python have a do-while loop?No. Python has no do-while, so a while body may run zero times.
  5. What integers does range(start, stop, step) produce?Integers from start up to but not including stop, advancing by step.
  6. What sequence does range(5) produce?The integers 0, 1, 2, 3, 4 (0 through 4, excluding 5).
  7. What is a sequence in Python?An ordered collection that allows duplicate elements, supports zero-based indexing, and works with len().
  8. Which Python sequence types are immutable and which are mutable?Strings and tuples are immutable; lists are mutable.
  9. How do you write a one-item tuple in Python?Add a trailing comma, e.g. (50,). Without it, (50) is just an integer in parentheses.
  10. What does the tuple literal () represent?The empty tuple.
  11. What happens when you write bare comma-separated values like 1, 2, 3?They form a tuple.
  12. Which operators do tuples support for combining and repeating?+ for concatenation and * for repetition.
  13. How can a function return several values, and how does the caller receive them?It returns them as a tuple, and the caller can unpack them, e.g. lo, hi = min_max(nums).
  14. Which indexes does the slice s[1:4] include?Indexes 1, 2, and 3 (the stop index 4 is excluded).
  15. What are the two common ways to loop over a sequence?By index with for i in range(len(s)), or by element with for ch in s.
  16. Which loop style allows you to modify list items in place?Only the index style (for i in range(len(s))); the element style gives you copies of the values.
  17. What does list.append(x) do?Adds x to the end of the list.
  18. What does list.insert(i, x) do?Inserts x at index i, shifting later items to the right.
  19. What does list.remove(x) do?Deletes the first occurrence of x in the list.
  20. What does list.pop(i) do?Removes the item at index i and returns it.
  21. What does list.index(x) do if x is not in the list?It raises an error; it only finds the first match when present.
  22. How can you make a copy of a list?Use .copy() or the slice [:].
  23. What do list.sort() and list.reverse() return?They modify the list in place and return None.
  24. How do sorted() and [::-1] differ from .sort() and .reverse()?sorted() and [::-1] return new objects rather than modifying the original in place.
  25. What does x in collection test, and what does it return?It tests membership and returns a boolean.
  26. What does id(obj) return in Python?The object's identity, which in CPython is its memory address.
  27. Does modifying a list item or using += on a list change the list's id?No, the list keeps the same id because it is modified in place.
  28. What happens to the id when you use += on a tuple or an int?A new object is created with a new id, since tuples and ints are immutable.
  29. What is the difference between lst += other and lst = lst + other for a list?lst += other modifies the list in place (iadd); lst = lst + other builds a fresh list (add).
  30. After b = a where a is a list, what is the relationship between a and b?They are two names for the same object, so edits through b are visible through a.
  31. How does a function that builds and returns a new list differ from one that assigns into lst[i]?Returning a new list leaves the argument unchanged; assigning into lst[i] mutates the caller's list.
  32. Does for n in nums: n = n * 2 modify nums?No, rebinding the loop variable never touches the list.
  33. In a nested list people, what does people[1][0] select?Row 1, column 0 of the nested structure.
  34. Why is rows * [[0] * cols] a trap for building a grid?It repeats one inner list object, so changing one row changes all of them.
  35. What are two safe ways to build a grid of independent rows?Use a loop with append, or a list comprehension: [[0] * cols for _ in range(rows)].
  36. What does a shallow copy (.copy()) duplicate, and what does it share?It duplicates only the outer list; inner lists are still shared between the copies.
  37. How does copy.deepcopy() differ from a shallow copy?copy.deepcopy() duplicates every nested level, so no inner objects are shared.
  38. What does a dictionary store, and how is it looked up?A dictionary stores key-value pairs and is looked up by key, not by position.
  39. What restrictions apply to dictionary keys, and what about values?Keys must be immutable and unique; values may be any type. Mixed-type keys are allowed.
  40. What happens when you access a missing key with d[key]?It crashes (raises an error). Use d.get(key, default) to get a default instead.
  41. What does d[key] = value do if the key already exists versus if it doesn't?If the key exists, it replaces the existing value; if not, it adds a new pair and the length grows.
  42. How do del d[key] and d.pop(key, default) differ on a missing key?del d[key] crashes if the key is missing; d.pop(key, default) returns the default instead of crashing.
  43. What are the four common ways to loop over a dictionary?for k in d, for k in d.keys(), for v in d.values(), and for k, v in d.items().
  44. What is the dictionary counting pattern for tallying occurrences?counts[k] = counts.get(k, 0) + 1
  45. Why pre-fill every key with 0 when counting categories?It guarantees that categories with no occurrences still appear in the results.
  46. What are the key properties of a set?A set is mutable, unordered, has no duplicates, allows only immutable elements, and supports no indexing.
  47. How does .add(v) behave if v is already in the set?It does nothing—the set is unchanged since duplicates aren't allowed.
  48. How do .remove(v) and .discard(v) differ?.remove(v) raises an error if v is missing; .discard(v) does not.
  49. Which operators perform union, intersection, and difference on sets?Union is | (or .union()), intersection is & (or .intersection()), and difference is - (or .difference()).
  50. Why are set membership, insertion, and deletion fast?Sets are hash tables, so these operations are average O(1).
  51. What is an algorithm?A finite, ordered series of steps for solving a general class of problems or computing something. It is an idea, while code is one concrete realization of it in a specific language.
  52. What are the three levels of algorithm development?(1) Translate a specific problem directly into code; (2) problem description → specific problem → pseudocode → code; (3) recognize the generic problem and reuse a general algorithm.
  53. Why is wall-clock time a poor tool for comparing algorithms?It depends on hardware and implementation. Asymptotic analysis instead asks how cost grows as input size grows.
  54. What does Big-O describe?The growth rate of running time. You drop constants and lower-order terms, and it is usually stated for the worst case.
  55. What does O(N) mean in practical terms?Doubling the input roughly doubles the work.
  56. What is the Big-O of a single if statement?O(1), constant time.
  57. What is the Big-O of one pass over a list, even if it might return early?O(N).
  58. What is the Big-O of an algorithm that halves the list each round?O(log N).
  59. What is the Big-O of comparing every pair of elements?O(N^2), since (N-1) + ... + 1 = N(N-1)/2.
  60. What is the Big-O of a loop with an inner loop of fixed length 5?O(N), because the fixed inner loop is a constant factor.
  61. What is the Big-O of a counter that doubles until it reaches y?O(log y).
  62. What is the difference between an algorithm and code?An algorithm is the idea—a finite ordered series of steps; code is one concrete realization of it in a specific language.
  63. What is the search problem?Return the index of a value in a collection, or -1 if the value is absent.
  64. How does linear search work?It checks positions from the front and returns as soon as it finds a match.
  65. What is the worst-case time complexity of linear search?O(N), because in the worst case it visits all N items.
  66. What prerequisite does binary search require?The list must be sorted.
  67. How does binary search compute the middle index?mid = (low + high) // 2
  68. In binary search, what happens if the target is bigger than the middle value?Set low = mid + 1 to search the upper half.
  69. In binary search, what happens if the target is smaller than the middle value?Set high = mid - 1 to search the lower half.
  70. When does binary search stop and return -1?When low > high, meaning the target is not present.
  71. Why is binary search O(log N)?Each comparison discards half the remaining items; after k steps N/2^k remain, so k = log2 N.
  72. How does doubling the input size affect binary search versus linear search?Binary search needs just one more step, while linear search needs N more steps.
  73. What does binary search return when it finds the target?It returns mid, the index of the matching value.
  74. What is the difference between an in-place sort and one that returns a new sorted list?An in-place sort modifies the original list and returns nothing; the other returns a new sorted list, leaving the original unchanged.
  75. What is the ascending postcondition of a sort?Each element is at least as large as the element before it.
  76. How does selection sort work?For each position i, scan the unsorted part for the index of the smallest value and swap it into i. The sorted zone holds the smallest items, and the outer loop runs n−1 times.
  77. How does bubble sort work, and how can it exit early?Repeatedly walk the list swapping adjacent out-of-order pairs so the largest values drift to the end. A pass with no swaps proves the list is sorted, allowing early exit.
  78. How does insertion sort work?Grow a sorted prefix; take the next element and shift it left past larger neighbours until it fits. The outer loop starts at index 1.
  79. What is the Python idiom for swapping two list elements?a[i], a[j] = a[j], a[i]
  80. What is recursion?A function that calls itself on a smaller version of the same problem, trusting that the smaller call works (the "recursive leap of faith").
  81. What three rules must a correct recursive function follow?It needs at least one base case (returned directly, no recursive call), every recursive case must move toward a base case, and the combination must give the right answer.
  82. When is recursion a better choice than loops?Recursion shines on tree-shaped problems, such as in-order traversal of a binary tree; loops are usually faster and simpler for other problems.
  83. What does each call push onto the call stack?A frame holding its arguments, local variables, and return point.
  84. What error occurs if a recursive function never reaches a base case?RecursionError: maximum recursion depth exceeded.
  85. How does f(a, b) = a + f(a, b-1) with f(a, 0) = 0 compute multiplication?It computes \(a \times b\) by repeated addition.
  86. What are the base and recursive cases for recursive factorial?Base cases: \(0! = 1! = 1\); recursive case: \(n \cdot (n-1)!\).
  87. How does Java's approach to types differ from Python's?Java is statically and strongly typed and cares deeply about types, rejecting bugs Python would let through; Python rarely talks about types.
  88. What is the entry point method signature in Java?public static void main(String[] args).
  89. In public static void main(String[] args), what do public, static, and void mean?public is an access modifier, static means the method belongs to the class, and void means no return value.
  90. What does args represent in the main method?args is a String array holding command-line arguments.
  91. What does it mean that Java is statically and strongly typed?Every variable must be declared with a type before use, and type mismatches are rejected, e.g. int[] nums = new int[10];.
  92. What are the steps to run a Java program from source to output?MyProgram.java → javac → MyProgram.class → java → output.
  93. Do Java primitive types store the value itself or a reference?Primitive types (lower-case names) store the value itself.
  94. How is a char literal written in Java?With single quotes, and it represents a Unicode character (2 bytes).
  95. What happens when you divide two ints in Java?You get an int (there is no // operator); % gives the remainder.
  96. What naming and comment conventions does Java style use?camelCase names; // and /* */ comments; /** */ Javadoc with tags like @param and @return.
  97. How do you get the length of an array in Java?Use array.length, which is a field with no parentheses.
  98. What loop forms are available in Java?Counting for, enhanced for (int n : arr), and while.
  99. What does an object variable in Java actually hold?A reference (the location of an object), not the object itself. It defaults to null and behaves like a pointer.
  100. What is the difference between == and .equals() when comparing objects in Java?== compares references (whether they point to the same object), while .equals() compares contents.
  101. Are two objects created with new String("Hello") equal under == and .equals()?They are ==-different (distinct references) but .equals()-equal (same contents).
  102. What does it mean that String is immutable in Java?Once a String is created, its contents cannot be changed; operations like substring return new strings.
  103. Which Java object type has literal syntax, and what is an example?String is the only object with literal syntax, e.g. "Hello".
  104. What does the String method .length() return?The number of characters in the string.
  105. How do you get the character at index i of a Java String?Use .charAt(i).
  106. What does .substring(b, e) return for a Java String?The substring from index b up to but not including index e.
  107. What does .indexOf(s) return for a Java String?The index of the first occurrence of s, or -1 if not found.
  108. How do you read keyboard input in Java using Scanner?Create a Scanner(System.in) and call methods like nextLine() for text or nextInt() for integers.
  109. What simpler input option does JDK 25+ offer for reading a line from the keyboard?IO.readln, often combined with Integer.parseInt to convert text to an integer.
  110. What is object-oriented programming (OOP)?A way of organizing code into objects that bundle data (attributes) with behavior (methods). It helps represent complex things, enforce invariants, and hide messy details.
  111. What is the difference between a class and an object?A class is a blueprint; an object (instance) is a concrete thing built from it. Having a class does not mean any object exists.
  112. What does the new operator do?It finds memory, runs the constructor, and returns the object's location.
  113. What are the rules for a constructor?It has the same name as the class, has no return type, and initializes fields; at least one constructor should be public.
  114. What does this refer to in a class?It refers to the current object and can separate a field from a same-named parameter.
  115. What is a getter (accessor) method?A method that reads a private field and returns its value.
  116. What is a setter (mutator) method?A method that writes a private field, typically with validation.
  117. What is a helper method?A private support method used internally by a class to assist its other methods.
  118. What is encapsulation?Keeping fields private and exposing controlled access through methods. Fewer places that can touch the data means fewer bugs, easier testing, and safer refactoring.
  119. What is the difference between static and non-static members?static members belong to the class (utility methods, constants, shared values); non-static members belong to each object.
  120. What is the difference between a class's interface and its implementation?The interface is how outsiders use the object; the implementation is how it is built. They need not match.
  121. Which methods does every class inherit, and what should you often do with them?Every class inherits toString() and equals(Object). They exist but are usually worth overriding.
  122. What does the is-a relationship mean in inheritance?A subclass is a more specific kind of its superclass. For example, a Student is-a Person.
  123. What does class Student extends Person do?It makes Student a subclass of Person, giving Student the parent's fields and methods.
  124. What is the constructor rule for subclasses?Some constructor always runs before any method. A subclass constructor must call a parent constructor, either implicitly (the default) or explicitly with super(...) as its first line.
  125. How do you explicitly call a parent constructor from a subclass constructor?Use super(...) as the first line of the subclass constructor.
  126. What do super.method() and super.field do?They reach the parent class's members from within the subclass.
  127. What are the four access levels and their visibility scopes?public: class/package/subclass/world; protected: class/package/subclass; default: class/package; private: class only.
  128. Which access level is visible to subclasses but not the world?protected.
  129. Which access level is visible only within its own class?private.
  130. What access level is visible within the same package but not to subclasses elsewhere?default (package-private).
  131. What access levels should a well-designed parent class use for outside users, children, and itself?public for outside users, protected for children, and private for itself.
  132. What relationship does uses-a describe?One class uses another class, typically through a reference or method call, without inheriting from it.
  133. What relationship does has-a describe?One class contains or is composed of another class as a field.
  134. What is polymorphism?One interface, many implementations—the same method call can behave differently depending on the object's actual type.
  135. What is method overloading?Defining multiple methods with the same name but different parameter lists within one class; it is resolved at compile time (static/early binding).
  136. What is method overriding?Redefining a method with the same name and signature in a subclass; it is resolved at run time (dynamic/late binding).
  137. How are static and final methods bound?They bind statically (at compile time).
  138. Can final methods be overridden?No—final methods cannot be overridden.
  139. What does the @Override annotation do?It documents intent and lets the compiler check that the parent class has the method; it does not change behaviour.
  140. When writing equals(Object o), what should the first checks be?Return true if this == o; return false unless o is an instanceof the class.
  141. After the instanceof check in equals(Object o), what comes next?Cast o to the class type (e.g. (Polygon) o, or use pattern o instanceof Polygon p), then compare the fields that define equality.
  142. What is an abstract class?A class declared public abstract class X that exists only to be a parent; it cannot be instantiated with new.
  143. How is an abstract method declared?With the abstract keyword and no body—it ends with a semicolon—and it is allowed only in abstract classes.
  144. What must every concrete subclass of an abstract class do?It must implement all inherited abstract methods.
  145. What is the difference between overloading and overriding in binding time?Overloading is resolved at compile time (static/early binding); overriding is resolved at run time (dynamic/late binding).
  146. What is the difference between overloading and overriding in parameter lists?Overloading uses the same name with different parameter lists in one class; overriding uses the same name and signature redefined in a subclass.

Velocer ücretsizdir: aralıklı tekrar ve herhangi bir belgeden kendi kartlarınız.

PDF to flashcards · Lecture to flashcards · Practice exam · Syllabus study plan · Anki import

University of Minnesota Twin Cities için diğer desteler