0% found this document useful (0 votes)
4 views2 pages

Data Structure and Algorithm Notes

Uploaded by

nogok13611
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
4 views2 pages

Data Structure and Algorithm Notes

Uploaded by

nogok13611
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 2

7/19/24, 3:11 AM OneNote

Intro to Data Structure


Friday, June 30, 2023 9:07 PM

Why do we need more data structures than the programming language provide?

Common operations:
• Accessing a value
• Searching for a value
• Inserting a value
• Deleting a value

Creating another data structure on our own --> Linked List

Covering area -->


• Implementing sorting algorithm on two different data structures and explore how the
implementation of one algorithm can differ based on the data structure that we use.
• How the choice of a data structure potentially influences the runtime of the algorithm

Array

What is a data structure?


A data structure is way/format of storing data when programming. It's not just the collection of
values and the format they are stored in, but the relationship between the values in the
collection as well as the operations applied on the data stored in the structure.

Array >>
Contiguous data structure..
Analogy of an array compared with train.

C, Java and Swift >> Arrays are homogenous containers.. Stored same type of values..
When an array is created, since the compiler knows the type of value is homogeneous, it can
choose a contiguous block of memory that fix the array size and values it created. It allocates
contiguous memory of same size.

Advantage of contiguous memory


• Access data is almost constant time O(1)

In python as it is not homogenous it cannot do that. It allocates contiguous block of memory, but
inside that, it stores the reference, not the values.

Array operation
a. Insert. Insert can be divided into 3 sub-categories:
1. Insert --> Linear Runtime. Every index value has to be changed
2. Append --> Constant runtime. Simply end of the last index a new value added
3. Extend --> another list to add (concatenation) --> O(K) .. k is the number of item of 2nd
list
b. Delete --> Linear Runtime. O(n). Every index value has to be shifted left like the opposite
of Insert operation.

In python array data structure is handled by List type. If we see how python's append operation
in details turned out:
• Every time appending list resize is not done.
• The growth pattern of python's list type is: 0, 4, 8, 16, 25, 35, 46 …. which means as list
size approaches this specific values, resize is called again.
• In the append operation some operation don't increase spaces and others do, So in
average all of them out, append operation takes constant space. We say it has an
Ammortized Constant Space Complexity.

Extend: Extend effectively makes a series of append calls, on each of the item in the new list
until all of the item have been appended to the original list.

Building Linked List


Why custom data structure: because we have seen the built in data structure given with the
language in python has some drawbacks. We have seen that inserting has linear runtime. So,
it’s efficiency can be improved by using Linked List.

A Linked list is a linear data structure where each element in the list is contained in a separate
object called Node.
Node contains two information: value and reference/memory address for the next node.

https://digigate360-my.sharepoint.com/:o:/r/personal/sarker_mahmud_technonext_com/_layouts/15/Doc.aspx?sourcedoc=%7B5… 1/2
7/19/24, 3:11 AM OneNote
The first node is called the Head. Last node is called the tail. The list only maintains the
reference to the Head. In some implementations information of Tail are kept as well.

Two Types:
a. Singly Linked List: Each node references next node
b. Doubly Linked List: Each node references both before and after node.

3 types of insert
• Prepend (heads are changing)
• Append (tails are changing)
• Insert

The first two ones are the constant time operation. But inserting new element is linear time
operation.

https://digigate360-my.sharepoint.com/:o:/r/personal/sarker_mahmud_technonext_com/_layouts/15/Doc.aspx?sourcedoc=%7B5… 2/2

You might also like