• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 2 out of 6 pages
Exam (elaborations)

Data Structures and Algorithms Python Questions and Answers

Document preview thumbnail
Preview 2 out of 6 pages

Data Structures and Algorithms Python Name Every Data Structure (There are 8 Main Ones) - Answer- 1. Array 2. Stack 3. Queue 4. Linked Lists 5. Hash Table 6. BST 7. B-Tree, Red Black Trees 8. Heaps Name Every Python Super Basic Datastructure - Answer- 1. List 2. Tuples 3. Sets 4. Strings 5. Arrays (you must use numpy) Strings - Answer- 1. They are immutable 2. Access characters in strings like you do for arrays/lists 3. empty strings are false, non empty are true. 4. | and & don't work on strings Slicing - Answer- string_name[beginning:end:step] *end is not inclusive *works for strings, lists, and tuples Useful String Methods - Answer- 1. s[3] 2. s + t 3. len(s) 4. s in t 5. () 6. swith(prefix) 7. ith(suffix) 8. (substring, beg, end) - returns the first position where substring is found. 9. (substring, beg,end) - returns the position of the last occurrence of string 10. () - changes case 11. () - changes case 12. ase() - changes to other case Python List - Answer- 1. not always homogenous 2. mutable 3. used to implement stacks and queues Python List Methods - Answer- 1. append(x) 2. extend(x) 3. insert(i, x) 4. min(list) 5. max(list)

Content preview

Data Structures and Algorithms Python
Name Every Data Structure (There are 8 Main Ones) - Answer- 1. Array
2. Stack
3. Queue
4. Linked Lists
5. Hash Table
6. BST
7. B-Tree, Red Black Trees
8. Heaps

Name Every Python Super Basic Datastructure - Answer- 1. List
2. Tuples
3. Sets
4. Strings
5. Arrays (you must use numpy)

Strings - Answer- 1. They are immutable
2. Access characters in strings like you do for arrays/lists
3. empty strings are false, non empty are true.
4. | and & don't work on strings

Slicing - Answer- string_name[beginning:end:step]
*end is not inclusive
*works for strings, lists, and tuples

Useful String Methods - Answer- 1. s[3]
2. s + t
3. len(s)
4. s in t
5. s.strip()
6. s.startswith(prefix)
7. s.endswith(suffix)
8. s.find(substring, beg, end) - returns the first position where substring is found.
9. s.rfind(substring, beg,end) - returns the position of the last occurrence of string
10. s.lower() - changes case
11. s.upper() - changes case
12. s.swapcase() - changes to other case

Python List - Answer- 1. not always homogenous
2. mutable
3. used to implement stacks and queues

Python List Methods - Answer- 1. append(x)
2. extend(x)
3. insert(i, x)
4. min(list)
5. max(list)

, 6. del a[i:j]
7. a.reverse()
8. a.sort()
9. B = copy.deepcopy(A)
10. b = copy.copy(A)
11. remove(index)

Tuples - Answer- 1. collection of python objects separated by commas
2. immutable
3. use () to create

Tuples Methods - Answer- 1. len(tuple_name)
2. tuple(list_name)
3. cmp() - returns 0 if matched. 1 when not matched and longer, -1 when not
matched and shorter
4. max() - returns max el
5. min() - returns min el

Python Sets - Answer- 1. unordered collection data type that is iterable, mutable, and
has no duplicate elements
2. based on datastructure known as hash table
3. highly optimized for checking contains
4. to create a set you need to use set(list)
*Only instances of immutable types can be added to python set

Methods - Answer- 1. add(x)
2. union(other)
3. intersect(other)
4. difference(other)
5. clear()
6. set(list) - create a set

Arrays - Answer- 1. There is no built in support.
2. Use numpy arrays
3. To create: np.array([][][]) where each list is its own row

Numpy Array Methods - Answer- ?

Python Dictionaries - Answer- 1. To construct: {key:value,key:value ...}
2. To add key,value pair: dic[new_key] = new_value

Dictionaries Methods - Answer- 1. str(dic) - string of key value pairs
2. items() - returns list of all dictionary keys
3. len() - number of key entries
4. clear()
5. fromkeys(seq, value) - declare new dic form sequence, initialize dic with values

Linked List - Answer- Similar to lists but use it when inserting and deleting a lot.

Linked List Implementation - Answer- class LinkedList():

Document information

Uploaded on
August 18, 2024
Number of pages
6
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers
$10.99

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
Freshy
3.6
(11)
Sold
65
Followers
4
Items
6964
Last sold
1 day ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions