(e) Algorithms for the main data structures

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

1/11

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.

12 Terms

1
New cards

Stack Push Operation

knowt flashcard image
2
New cards

Stack Pop Operation

knowt flashcard image
3
New cards

Queue Enque Operation

knowt flashcard image
4
New cards

Queue Dequeue Operation

knowt flashcard image
5
New cards

How do you perform a depth first (post order) traversal?

  1. visit all nodes from left of root node

  2. visit all nodes from right of root node

  3. visit root node

  4. repeat three points for each node visited

6
New cards

How do you perform a depth first (post order) traversal using a bubble around a tree?

  • draw bubble around tree

  • start from root node

  • mark the right side of each node in order

7
New cards

How do you perform a breadth first (pre order) traversal?

  • draw bubble around tree

  • start from root node

  • mark the left side of each node in order

8
New cards

What is an advantage of depth first (post-order) traversal?

  • requires less memory than breadth first

  • quicker when looking for deep parts of the tree

9
New cards

What is an disadvantage of depth first (post-order) traversal?

  • isn’t guaranteed to find the quickest solution + may never find solution

    • have to take precautionsnot to revisit previously visited nodes

10
New cards

How is backtracking used in depth first?

  • starts at root node

  • goes all the way down one branch to the bottom

  • stores which node been visitied/pushes nodes visited onto stack

  • when can’t go further

  • back tracks to previous nide

  • continues to backtrack until node reached w/ unvisitied child nodes

  • checks down that branch

11
New cards

Pseudocode for depth first (post-order) traversal on trees

knowt flashcard image
12
New cards

Pseudocode for breadth first (pre-order) traversal on trees

knowt flashcard image