0% found this document useful (0 votes)
40 views12 pages

Data Structures and Algorithms

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views12 pages

Data Structures and Algorithms

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Data structures and

algorithms
Array Characteristics:
• Fixed size: Once initialized, the size of the
array cannot be changed.
• Fast access: Access time to an element in
the array is O(1), which is very fast.
• Homogenous storage: All elements in the
array must have the same data type.

How it works
• Initializing Array: An array students is
initialized with a fixed size of 100, to
store Student objects.
• Counting Students: The variable
student Count is used to keep track of
the number of students currently in the
array.
Array List
Characteristics:
Flexible Size: Array List can automatically resize when adding or
removing elements.
Fast Access: Access time to elements in Array List is also O(1).
Homogenous Storage: All elements in Array List must have the
same data type or Object data type.
Add Student
• This method adds a Student object to the students List.
• The method takes a parameter student then Calls the add
method of Array List, this method will add the student object to
the end of the students List.
Remove Student
• This method is responsible for removing a member from the list
based on the student member ID.
• The method takes an id parameter, which is the ID of the student
member you want to remove.
Print Student
This method is responsible for sorting the student list by ID and
printing the sorted list.
Bubble sort
Bubble sort
Bubble sort is a simple sorting algorithm that
repeatedly compares adjacent elements and swaps
them if they are in the wrong order, until the entire
list is sorted.

How it works
• Starting with the first element, compare it to the
next element.
• If the first element is larger than the second
element, swap them.
• Move to the next element and repeat step 2 until
you reach the last element.
• After each iteration, the largest element will "float"
to the bottom of the list.
• Repeat the process until no more swaps are needed.
Binary search tree
A binary search tree (BST) is a tree data structure in which each node
Binary search has a maximum of two children (left and right) and has the following
tree characteristics:
• Left child value: Always less than the parent.
• Right child value: Always greater than the parent.
• Recursive structure: Each node in a BST is also a binary search tree.

Insert
• Start at the root node.
• Compare the value to be inserted with the current node:
• If smaller, move left.
• If larger, move right.
• Repeat until a null node is encountered, at which point a new value is
inserted.
Search
Binary search • Start at the root node.
• Compare the value to be found with the current node:
tree • If equal, return the current node.
• If smaller, move left.
• If larger, move right.
• Continue until a value is found or a null node is
encountered.
Traversal
In-order Traversal: Traverse the tree in left - root - right order,
returning values ​in ascending order.
Array sort
Array sort How it works
• When the printStudentsSortedById() function is called, it will:
Arrays Sort is an algorithm used to sort the elements of an array. It can
• Sort the student array by student code.
sort both primitive data types (such as integers and characters) and
• Print the title “List of students (sorted by ID):”.
objects.
• Print a list of students sorted by ID.
This method usually sorts in ascending order and uses different
algorithms based on the data type of the array: Quick Sort for primitive
data types and Merge Sort for objects.
Compare two sort methods
Bubble Sort Arrays Sort
Algorithm: Bubble sort works by repeatedly swapping Algorithm: The Array sort algorithm,
the adjacent elements if they are in wrong order specifically referring to the Arrays. Sort()
Time Complexity: method in Java, utilizes Tim sort, which is a
• Best-case: O(n) hybrid sorting algorithm derived from merge
• Average-case: O(n^2) sort and insertion sort.
• Worst-case: O(n^2) Time Complexity:
• Space Complexity: O(1) • Best Case: O(n log n)
• Stability: Stable • Average Case: O(n log n)
• Use Cases: Bubble sort is suitable for small data sets or • Worst Case: O(n log n)
• nearly sorted data. • Space Complexity: O(n)
• Stability: Stable
Use Cases:
• Tim sort is particularly effective for:
• Large datasets where performance is critical.
• Datasets that are partially sorted, as it can
take advantage of existing order.
• Applications requiring stable sorting, such as
sorting objects with multiple fields.
Thanks for listening

You might also like