Prelims Reviewer - Data Structures and Algorithm

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/105

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

106 Terms

1
New cards

Data Structure

Particular way of storing and organizing data in a computer so that it can be used efficiently

2
New cards

Data Structure

Based on the ability of a computer to fetch (retrieve) and store data at any place in its memory, specified by an address

3
New cards

Address

Bit string that can be itself stored in memory and manipulated by the program

4
New cards

Data Structure

Requires writing a set of procedures that create and manipulate instances of that structure

5
New cards

Data Structure Types

  • Primitive (ex. int, char)

  • Non-Primitive (ex. Array, Vector)

6
New cards

Data Structure Classification (Element)

  • Homogenous (Singular type, ex Array)

  • Heterogenous (Multiple type, ex Structure)

7
New cards

Data Structure Classification (Size)

  • Static (Immutable, ex. matrix)

  • Dynamic (Mutable, ex. list)

8
New cards

Data Structure Classification (Relationship)

  • Linear (ex. array)

  • Non-Linear (ex. tree)

9
New cards

Main Memory (RAM)

  • Where instructions (programs and data are stored

  • Volatile

10
New cards

Cache Memory

  • Used to store frequently used instructions and data that either is, will be, or has been used by the CPU

  • Fastest access speed

11
New cards

Register

  • Segment of CPU Cache

  • Small amount of memory that is used to temporarily store instructions and data

12
New cards

Persistent Storage

  • Used to store instructions and data in external devices such as a hard disk

  • Non-volatile, commonly used by the operating system as virtual memory

  • Slowest access speed

13
New cards

Reserving Memory

  • Data is stored in memory and manipulated by various data structure techniques

  • Organized into groups of eight bits called a byte, enabling 256 combinations of zeroes and ones that can store numbers from 0 through 255

  • Before storing, tell the computer how much space to reserve for data using an abstract data type

14
New cards

Abstract Data Type

Keyword of a programming language that specifies the amount of memory needed to store data and the kind of data that will be stored in that memory location

15
New cards

Abstract Data Type Examples

  • Java ADT

  • C & C++ ADT

16
New cards

Data Type Groups

  • Integers

    • byte - 8

    • short - 16

    • int - 32

    • long - 64

  • Characters

    • char - 16 (Unicode)

  • Floating-Point

    • float - 32

    • double - 64

  • Boolean

    • bool - 1

17
New cards

Algorithm

Step-by-step procedure, which defines a set of instructions to be executed in a certain order to get the desired output

18
New cards

Algorithm Categories

  • Search

  • Sort

  • Insert

  • Update

  • Delete

19
New cards

Algorithm Characteristics

  • Unambiguous

  • Input

  • Output

  • Finiteness

  • Feasibility

  • Independent

20
New cards

Algorithm Analysis Types

  • Priori

  • Posterior

21
New cards

Priori Analysis

Efficiency of an algorithm is measured by assuming that all other factors are constant and have no effect on the implementation

22
New cards

Posterior Analysis

Analysis where actual statistics like running time and space required, are collected

23
New cards

Algorithm Complexity Factors

  • Time factor

  • Space factor

24
New cards

Algorithm Complexity f(n)

Gives the running time and/or the storage space required by the algorithm in terms of n as the size of input data

25
New cards

Space Complexity

Represents the amount of memory space required by the algorithm in its life cycle

26
New cards

Space Complexity Parts

  • Fixed part

  • Variable part

27
New cards

Time Complexity T(n)

  • Amount of time required by the algorithm to run to completion

  • Measured as the number of steps, provided each step consumes constant time

28
New cards

Asymptotic Analysis

Defines the mathematical foundation/framing of its run-time performance

29
New cards

Asymptotic Analysis

Used to conclude the best case, average case, and worst-case scenario of an algorithm

30
New cards

Asymptotic Analysis

Computes the running time of any operation in mathematical units of computation

31
New cards

O Notation

Worst-case time complexity

32
New cards

Ω Notation

Best-case time complexity

33
New cards

θ Notation

Average-case time complexity

34
New cards

Common Asymptotic Notation

  • Constant - O(1)

  • Logarithmic - O(log n)

  • Linear - O(n)

  • n log n - O(n log n)

  • Quadratic - O(n2)

  • Cubic - O(n3)

  • Polynomial - nO(1)

  • Exponential - 2O(n)

35
New cards

Rate of Growth

How fast a function grows with input size

36
New cards

Data Abstraction

  • Simplify code by displaying only essential details to the user

37
New cards

Interface

  • Special block containing method signatures

  • Defines method signatures without body

  • Defines standard and public specification of class behavior

  • Allows classes, regardless of hierarchy, to implement common behaviors

  • May exhibit polymorphism

38
New cards

Abstract Class

  • Declared using “abstract”

  • No implementation

  • None, abstract, and/or concrete methods

39
New cards

Abstract Method

  • Redefined in subclass

  • Always overridden

  • Container class must be declared with “abstract”

  • No object

40
New cards

Interface vs Abstract Class

  • Interface

    • Methods have no body

    • Define constants

    • No direct inheritance

41
New cards

Tree

Which of the following is NOT a linear data structure?

42
New cards

Hiding implementation details and showing essential features

Abstraction in data structures means:

43
New cards

ArrayIndexOutOfBoundsException

What happens if you access an index of an array that is out of bounds in Java?

44
New cards

Abstract classes can have implemented methods, but interfaces cannot

In Java, which of the following statements about abstract classes and interfaces is true?

45
New cards

It reduces complexity by hiding implementation details

How does abstraction improve software development processes?

46
New cards

30

<p></p>
47
New cards

It initializes an array with 5 elements

knowt flashcard image
48
New cards

[0, 2, 4, 6, 8]

knowt flashcard image
49
New cards

It limits the number of iterations based on the array length

knowt flashcard image
50
New cards

The loop would access an invalid index

knowt flashcard image
51
New cards

System.out.print(numbers[i] + " ");

knowt flashcard image
52
New cards

Type

Integer is a primitive, while Array is a non-primitive. Under which classification of data structures does this fall?

53
New cards

1 2 3 4 5

knowt flashcard image
54
New cards

True

An algorithm is a step-by-step procedure, which defines a set of instructions to be executed in a certain order to get the desired output.

55
New cards

False

To implement a data structure, it requires writing set of array that create and manipulate instances of that structure.

56
New cards

Interfaces

In Java, which of the following can be used to implement multiple inheritance?

57
New cards

abstract void methodName();

Which of the following is the correct way to declare an abstract method in Java?

58
New cards

HU/M*ILI^-TY^+

CONVERT FROM INFIX TO POSTFIX:

H / U * M - (I ^ L I) + T ^ Y

59
New cards

CO+M-P*UTE^/R-

CONVERT FROM INFIX TO POSTFIX:

(C + O - M) * P / (U ^ T E) - R

60
New cards

((A+B)+(((C+(D*E))/(F-G))+H))

CONVERT FROM POSTFIX TO INFIX:

A B + C D E * + F G - / H ++

61
New cards
62
New cards

ArrayList

  • Part of collection framework and is present in java.util package

  • Provides a dynamic way of manipulating data

  • Slower than standard arrays but can be helpful in programs where lots of manipulation in the array is needed

63
New cards

ArrayList Characteristics

  • Inherits AbstractList class and implements List interface

  • Initialized by size, however, the size can increase if collection grows or shrunk if objects are removed from the collection

  • Allows random list access

  • Use a wrapper class if an ArrayList can not use primitive types, like int, char, etc.

  • Similar to a vector in C++

64
New cards

ArrayList Constructors

  • ArrayList() - empty array list

  • ArrayList(Collection c) - initialized with the elements from collection c

  • ArrayList(int capacity) - initial capacity being specified

65
New cards

ArrayList Methods

  • add(int index, Object element)

  • add(Object o)

  • addAll(Collection C)

  • addAll(int index, Collection C)

  • clear()

  • clone()

  • contains? (Object o)

  • ensureCapacity?(int minCapacity)

  • forEach?(Consumer<? super E> action)

  • get?(int index)

  • indexOf(Object O)

  • isEmpty?()

  • lastIndexOf(Object O)

  • listIterator?()

  • listIterator?(int index)

  • remove?(int index)

  • remove?(Object o)

  • removeAll?(Collection c)

  • removeIf?(Predicate filter)

  • removeRange?(int fromIndex, int toIndex)

  • retainAll?(Collection<?> c)

  • set?(int index, E element)

  • size?()

  • spliterator?()

  • subList?(int fromIndex, int toIndex)

  • toArray()

  • toArray(Object[] O)

  • trimToSize()

66
New cards

add(int index, Object element)

Insert a specific element at a specific position index in a list

67
New cards

add(Object o)

Append a specific element to the end of a list

68
New cards

addAll(Collection C)

Append all the elements from a specific collection to the end of the mentioned list

69
New cards

addAll(int index, Collection C)

Insert all of the elements starting at the specified position from a specific collection into the mentioned list

70
New cards

clear()

Used to remove all the elements from any list

71
New cards

clone()

Used to return a shallow copy of an ArrayList.

72
New cards

contains? (Object o)

Returns true if this list contains the specified element.

73
New cards

ensureCapacity?(int minCapacity)

Increases the capacity of this ArrayList instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument

74
New cards

forEach?(Consumer<? super E> action)

Performs the given action for each element of the Iterable until all elements have been processed or the action throws an exception

75
New cards

get?(int index)

Returns the element at the specified position in this list

76
New cards

indexOf(Object O)

The index the first occurrence of a specific element is either returned or -1 in case the element is not in the list

77
New cards

isEmpty?()

Returns true if this list contains no elements

78
New cards

lastIndexOf(Object O)

The index of the last occurrence of a specific element is either returned or -1 in case the element is not in the list

79
New cards

listIterator?()

Returns a list iterator over the elements in this list (in proper sequence)

80
New cards

listIterator?(int index)

Returns a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list

81
New cards

remove?(int index)

Removes the element at the specified position in this list

82
New cards

remove?(Object o)

Removes the first occurrence of the specified element from this list, if it is present

83
New cards

removeAll?(Collection c)

Removes from this list all of its elements that are contained in the specified collection

84
New cards

removeIf?(Predicate filter)

Removes all of the elements of this collection that satisfy the given predicate

85
New cards

removeRange?(int fromIndex, int toIndex)

Removes from this list all of the elements whose index is between fromIndex, inclusive, and toIndex, exclusive

86
New cards

retainAll?(Collection<?> c)

Retains only the elements in this list that are contained in the specified collection

87
New cards

set?(int index, E element)

Replaces the element at the specified position in this list with the specified element

88
New cards

size?()

Returns the number of elements in this list

89
New cards

spliterator?()

Creates a late-binding and fail-fast Spliterator over the elements in this list

90
New cards

subList?(int fromIndex, int toIndex)

Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive

91
New cards

toArray()

This method is used to return an array containing all of the elements in the list in the correct order

92
New cards

toArray(Object[] O)

It is also used to return an array containing all of the elements in this list in the correct order same as the previous method

93
New cards

trimToSize()

This method is used to trim the capacity of the instance of the ArrayList to the list’s current size

94
New cards

Stack

  • Way to group things together by placing one thing on top of another and then removing things one at a time from the top

  • Last-In, First-Out

95
New cards

push()

Adds to the top of the list

96
New cards

pop()

Removes an item from the top of the list and returns this value to the caller

97
New cards

Stack

Restricted data structure because only a small number of operations are performed on it

98
New cards

Stack

Linear data structure that follows a particular order in which the operations are performed

99
New cards

Stack

Extends Vector which implements the List interface

100
New cards
term image

Stack Hierarchy