# Data Structures

**URL:** https://forum.codewithmosh.com/c/data-structures/14.md?page=1

[Latest](https://forum.codewithmosh.com/latest.md) · [Categories](https://forum.codewithmosh.com/categories.md)

**Page:** 2

---

## [What does it mean when f(n) is an element of O(g(n))?](https://forum.codewithmosh.com/t/what-does-it-mean-when-f-n-is-an-element-of-o-g-n/14494)

<div class="topic-metadata">

**Author:** [@Anon019](https://forum.codewithmosh.com/u/Anon019)\
**Replies:** 3\
**Last updated:** [August 17, 2022, 6:33pm UTC](https://forum.codewithmosh.com/t/what-does-it-mean-when-f-n-is-an-element-of-o-g-n/14494 "2022-08-17T18:33:54Z")

</div>

Hi! I know that f(n) = O(g(n)) means : 0 \< f(n) \<= c\*g(n) such that c\>0, n0\>0 and for any n\>= n0 but what does f(n) ∈ O(g(n)) mean? I’ve been given an example to solve: f(n) = 3log(n), g(n) = 9^n, f(n) ∈ O(g(n)) Coul…

---

## [Big-Oh Notation Demystified](https://forum.codewithmosh.com/t/big-oh-notation-demystified/14259)

<div class="topic-metadata">

**Author:** [@devashishbhor](https://forum.codewithmosh.com/u/devashishbhor)\
**Replies:** 1\
**Last updated:** [August 9, 2022, 3:39pm UTC](https://forum.codewithmosh.com/t/big-oh-notation-demystified/14259 "2022-08-09T15:39:19Z")

</div>

I recently started learning Data Structures and Algorithms. I cam across the mathematical definition of Big O notation. It was as follows, f(n)=O(g(n)) iff f(n)\<= C. g(n) for all n0 Now as the Big O says, it measures p…

---

## [LinkedList addLast method](https://forum.codewithmosh.com/t/linkedlist-addlast-method/12121)

<div class="topic-metadata">

**Author:** [@Pramod](https://forum.codewithmosh.com/u/Pramod)\
**Replies:** 5\
**Last updated:** [August 6, 2022, 5:50pm UTC](https://forum.codewithmosh.com/t/linkedlist-addlast-method/12121 "2022-08-06T17:50:17Z")

</div>

In the LinkedList exercise we are adding three numbers to LinkedList using AddLast() method. list.AddLast(1); list.AddLast(2); list.AddLast(3); Below is the implementation of the AddLast() method " var temp = new …

---

## [Shortest distance and shortest path in weighted graph? in python](https://forum.codewithmosh.com/t/shortest-distance-and-shortest-path-in-weighted-graph-in-python/11891)

<div class="topic-metadata">

**Author:** [@alisci](https://forum.codewithmosh.com/u/alisci)\
**Replies:** 1\
**Last updated:** [August 6, 2022, 5:19pm UTC](https://forum.codewithmosh.com/t/shortest-distance-and-shortest-path-in-weighted-graph-in-python/11891 "2022-08-06T17:19:47Z")

</div>

I am following the course The Ultimate Data Structures & Algorithms: Part 2. However, I got stuck in the videos from 6 to 8 in the undirected graphs section. 6- exercise- getting the shortest distance Is there any python…

---

## [Base condition Part 2 -11 last left node contains right node only](https://forum.codewithmosh.com/t/base-condition-part-2-11-last-left-node-contains-right-node-only/10989)

<div class="topic-metadata">

**Author:** [@Gary](https://forum.codewithmosh.com/u/Gary)\
**Replies:** 1\
**Last updated:** [August 6, 2022, 4:24pm UTC](https://forum.codewithmosh.com/t/base-condition-part-2-11-last-left-node-contains-right-node-only/10989 "2022-08-06T16:24:10Z")

</div>

I am converting examples to Delphi (No good classes in Delphi) so may be slightly different. All is fine with sample tree where all leaf’s line up even, however adding (3) to tree adds a right node to last left node, co…

---

## [JumpSearch Algorithm (BUG FOUND)](https://forum.codewithmosh.com/t/jumpsearch-algorithm-bug-found/8401)

<div class="topic-metadata">

**Author:** [@jack007](https://forum.codewithmosh.com/u/jack007)\
**Replies:** 2\
**Last updated:** [August 4, 2022, 2:13pm UTC](https://forum.codewithmosh.com/t/jumpsearch-algorithm-bug-found/8401 "2022-08-04T14:13:27Z")

</div>

public class JumpSearch { public int jumpsearch(int\[\]array, int target) { int blockSize = (int) Math.sqrt(array.length); int start = 0; int next = blockSize; while (start \< array.lengt…

---

## [Ternary Search Algorithm Implementation (BUG FOUND)](https://forum.codewithmosh.com/t/ternary-search-algorithm-implementation-bug-found/8398)

<div class="topic-metadata">

**Author:** [@jack007](https://forum.codewithmosh.com/u/jack007)\
**Replies:** 2\
**Last updated:** [August 4, 2022, 2:09pm UTC](https://forum.codewithmosh.com/t/ternary-search-algorithm-implementation-bug-found/8398 "2022-08-04T14:09:13Z")

</div>

public class TernarySearch { public int ternarySearch(int\[\] array, int target){ return ternarySearch(array,target,0,array.length-1); } private int ternarySearch(int\[\] array, int target, int left, in…

---

## [Array.intersect solution](https://forum.codewithmosh.com/t/array-intersect-solution/4470)

<div class="topic-metadata">

**Author:** [@Nagaeh](https://forum.codewithmosh.com/u/Nagaeh)\
**Replies:** 6\
**Last updated:** [August 4, 2022, 1:58pm UTC](https://forum.codewithmosh.com/t/array-intersect-solution/4470 "2022-08-04T13:58:58Z")

</div>

public Array intersect(Array other) { var intersection = new Array(count); for (int item : items) if (other.indexOf(item) \>= 0) intersection.insert(item); return intersection; } Can someone please explain the …

---

## [Building a LinkedList](https://forum.codewithmosh.com/t/building-a-linkedlist/6287)

<div class="topic-metadata">

**Author:** [@LashelleR](https://forum.codewithmosh.com/u/LashelleR)\
**Replies:** 4\
**Last updated:** [August 4, 2022, 1:56pm UTC](https://forum.codewithmosh.com/t/building-a-linkedlist/6287 "2022-08-04T13:56:44Z")

</div>

Hello Everyone, Am I the only that feels like every-time we come to an exercise part, we cannot execute the exercise? Im currently doing The Ultimate Data Structures & Algorithms: Part 1, Building a LikedList by scratc…

---

## [Priority Queue comapringInt](https://forum.codewithmosh.com/t/priority-queue-comapringint/1231)

<div class="topic-metadata">

**Author:** [@Syed0208](https://forum.codewithmosh.com/u/Syed0208)\
**Replies:** 3\
**Last updated:** [August 4, 2022, 12:08am UTC](https://forum.codewithmosh.com/t/priority-queue-comapringint/1231 "2022-08-04T00:08:22Z")

</div>

Dijkstra’s Algorithm: In the priority queue implemented (PriorityQueue queue = new PriorityQueue\<\>( Comparator.comparingInt(ne -\> ne.priority)):wink: , how does the comparingInt function place a node with minimum weigh…

---

## [This one might be wrong](https://forum.codewithmosh.com/t/this-one-might-be-wrong/1010)

<div class="topic-metadata">

**Author:** [@kmullick](https://forum.codewithmosh.com/u/kmullick)\
**Replies:** 4\
**Last updated:** [August 3, 2022, 10:35pm UTC](https://forum.codewithmosh.com/t/this-one-might-be-wrong/1010 "2022-08-03T22:35:40Z")

</div>

The marked Circle in red . Shouldn’t that be O(1) for Middle and End Deletion (Linked List)

---

## [Probable Mistake in Solution- First Repeated Character](https://forum.codewithmosh.com/t/probable-mistake-in-solution-first-repeated-character/891)

<div class="topic-metadata">

**Author:** [@pratik](https://forum.codewithmosh.com/u/pratik)\
**Replies:** 5\
**Last updated:** [August 3, 2022, 10:29pm UTC](https://forum.codewithmosh.com/t/probable-mistake-in-solution-first-repeated-character/891 "2022-08-03T22:29:18Z")

</div>

First things first, this is the best course purchase of my professional career. And that is the reason why I’m pointing out this tiny mistake in the hope to make it perfect. This will only work when the repeated chara…

---

## [Help with two stacks in one array exercise solution](https://forum.codewithmosh.com/t/help-with-two-stacks-in-one-array-exercise-solution/8662)

<div class="topic-metadata">

**Author:** [@DomingoGS](https://forum.codewithmosh.com/u/DomingoGS)\
**Replies:** 1\
**Last updated:** [August 3, 2022, 7:23pm UTC](https://forum.codewithmosh.com/t/help-with-two-stacks-in-one-array-exercise-solution/8662 "2022-08-03T19:23:59Z")

</div>

Hi, I am taking Part 1 of the Data Structures course and just wanted to ask about the exercise to implement two stacks in one array. I am quite puzzled about the solution provided in the TwoStacks.java file. I underta…

---

## [Graph Iterative vs Recursive](https://forum.codewithmosh.com/t/graph-iterative-vs-recursive/8395)

<div class="topic-metadata">

**Author:** [@Tarun](https://forum.codewithmosh.com/u/Tarun)\
**Replies:** 1\
**Last updated:** [August 3, 2022, 7:16pm UTC](https://forum.codewithmosh.com/t/graph-iterative-vs-recursive/8395 "2022-08-03T19:16:28Z")

</div>

Hi Mosh, why the output is different in Recursive and Iterative method in Graph lectures for the graph the solution for DFS in Recursive is ABDC DFS in Iterative is ACBD please suggest which one is correct or why th…

---

## [Error talking about Vector and multi-threaded app](https://forum.codewithmosh.com/t/error-talking-about-vector-and-multi-threaded-app/5901)

<div class="topic-metadata">

**Author:** [@bmedwar](https://forum.codewithmosh.com/u/bmedwar)\
**Replies:** 1\
**Last updated:** [August 3, 2022, 7:08pm UTC](https://forum.codewithmosh.com/t/error-talking-about-vector-and-multi-threaded-app/5901 "2022-08-03T19:08:11Z")

</div>

Hi, Great course! Thanks! The Ultimate Data Structures & Algorithms: Part 1 9- Dynamic Arrays “if you have a multi-threaded application where multiple threads are going to work with this collection then you’re not goi…

---

## [Can someone clarify this logic? (Hash table put method)](https://forum.codewithmosh.com/t/can-someone-clarify-this-logic-hash-table-put-method/5246)

<div class="topic-metadata">

**Author:** [@Nagaeh](https://forum.codewithmosh.com/u/Nagaeh)\
**Replies:** 1\
**Last updated:** [August 3, 2022, 7:04pm UTC](https://forum.codewithmosh.com/t/can-someone-clarify-this-logic-hash-table-put-method/5246 "2022-08-03T19:04:31Z")

</div>

In the above video, when Mosh is refactoring the put method (@ 6:20) he states that if we initialize a new linkedlist using the local variable “bucket” instead of using “entries\[index\]” then it won’t initialize that ce…

---

## [13- Solution- Building a Priority Queue](https://forum.codewithmosh.com/t/13-solution-building-a-priority-queue/5134)

<div class="topic-metadata">

**Author:** [@akarsh](https://forum.codewithmosh.com/u/akarsh)\
**Replies:** 1\
**Last updated:** [August 3, 2022, 6:59pm UTC](https://forum.codewithmosh.com/t/13-solution-building-a-priority-queue/5134 "2022-08-03T18:59:40Z")

</div>

Hi Mosh, I’m not able to understand the below mentioned code block, please help me. int j; for(j= count-1;j \>= 0; j--) { System.out.println("Current item--\>" +items\[j\]); System.out.println("J Count--\>" +…

---

## [Using Python for Data Structures Course](https://forum.codewithmosh.com/t/using-python-for-data-structures-course/4688)

<div class="topic-metadata">

**Author:** [@cgrahams](https://forum.codewithmosh.com/u/cgrahams)\
**Replies:** 1\
**Last updated:** [August 3, 2022, 6:56pm UTC](https://forum.codewithmosh.com/t/using-python-for-data-structures-course/4688 "2022-08-03T18:56:12Z")

</div>

Has anyone tried using Python for the Data Structures course? Some of the excersises work a bit differently since Python is dynamic and Java is static. I was just wondering if it makes sense to use Python for the excersi…

---

## [Implementing A trie using Array](https://forum.codewithmosh.com/t/implementing-a-trie-using-array/3624)

<div class="topic-metadata">

**Author:** [@akashreddy](https://forum.codewithmosh.com/u/akashreddy)\
**Replies:** 1\
**Last updated:** [August 3, 2022, 5:26pm UTC](https://forum.codewithmosh.com/t/implementing-a-trie-using-array/3624 "2022-08-03T17:26:02Z")

</div>

Quick question. The field size of Alphabet\_SIZE is declared as Static. My question is Is it mandatory to declare the variable static ? Can I just declare the variable without using static? Thank you

---

## [Algorithm logic flaw in AVLTree.insert()](https://forum.codewithmosh.com/t/algorithm-logic-flaw-in-avltree-insert/3067)

<div class="topic-metadata">

**Author:** [@Vikeman](https://forum.codewithmosh.com/u/Vikeman)\
**Replies:** 1\
**Last updated:** [August 3, 2022, 5:23pm UTC](https://forum.codewithmosh.com/t/algorithm-logic-flaw-in-avltree-insert/3067 "2022-08-03T17:23:20Z")

</div>

Mosh’s implementation of the insert method leaves out one important check - is value already in our tree. Duplicates are not permitted in a binary search tree and both bloat the size of your tree and slow down navigation…

---

## [Part 2 of This Course is BRUTAL](https://forum.codewithmosh.com/t/part-2-of-this-course-is-brutal/796)

<div class="topic-metadata">

**Author:** [@petrosy](https://forum.codewithmosh.com/u/petrosy)\
**Replies:** 4\
**Last updated:** [August 3, 2022, 5:08pm UTC](https://forum.codewithmosh.com/t/part-2-of-this-course-is-brutal/796 "2022-08-03T17:08:09Z")

</div>

How do I get good at this? I try to do the exercises without looking at the code but then I just stare at the screen for too long and no work gets done. Then I pretty much have no choice but to look at the solutions. Thi…

---

## [Probable mistake in Graph - 7. Removing Nodes and Edge](https://forum.codewithmosh.com/t/probable-mistake-in-graph-7-removing-nodes-and-edge/2333)

<div class="topic-metadata">

**Author:** [@Cowkiller](https://forum.codewithmosh.com/u/Cowkiller)\
**Replies:** 1\
**Last updated:** [August 3, 2022, 4:59pm UTC](https://forum.codewithmosh.com/t/probable-mistake-in-graph-7-removing-nodes-and-edge/2333 "2022-08-03T16:59:25Z")

</div>

I noticed that Mosh uses the node variable as parameter to remove from the 2 hash tables. I checked and the remove function only accept the Key as parameter. So “nodes.remove(node);” doesn’t work. “nodes.remove(label)…

---

## [Stacks: Reversing a string](https://forum.codewithmosh.com/t/stacks-reversing-a-string/1192)

<div class="topic-metadata">

**Author:** [@Kalhari](https://forum.codewithmosh.com/u/Kalhari)\
**Replies:** 1\
**Last updated:** [August 3, 2022, 2:14am UTC](https://forum.codewithmosh.com/t/stacks-reversing-a-string/1192 "2022-08-03T02:14:08Z")

</div>

Isn’t it a good idea to use a StringBuilder instead of a StringBuffer unless there is a specific need for things to be thread safe?

---

## [Stacks: BalancedExpressions](https://forum.codewithmosh.com/t/stacks-balancedexpressions/1195)

<div class="topic-metadata">

**Author:** [@Kalhari](https://forum.codewithmosh.com/u/Kalhari)\
**Replies:** 1\
**Last updated:** [August 3, 2022, 2:12am UTC](https://forum.codewithmosh.com/t/stacks-balancedexpressions/1195 "2022-08-03T02:12:28Z")

</div>

In the final solution there is a an assumption that 2 arrays should contain brackets in the given order. This isn’t maintainable. If someone changes order (which is not wrong) the code will break. Using a Map will be bet…

---

## [Data structure removeat](https://forum.codewithmosh.com/t/data-structure-removeat/13696)

<div class="topic-metadata">

**Author:** [@amjad-bar](https://forum.codewithmosh.com/u/amjad-bar)\
**Replies:** 3\
**Last updated:** [July 16, 2022, 6:36pm UTC](https://forum.codewithmosh.com/t/data-structure-removeat/13696 "2022-07-16T18:36:56Z")

</div>

I want to tell you that in the first part of Data Structures and Algorithms, specifically in the Arrays section of Video No. 7 removeAt() there is an error where the solution and the method you followed does not work if …

---

## [LinkedList printMiddle method](https://forum.codewithmosh.com/t/linkedlist-printmiddle-method/13321)

<div class="topic-metadata">

**Author:** [@ankita.soni03](https://forum.codewithmosh.com/u/ankita.soni03)\
**Replies:** 5\
**Last updated:** [July 5, 2022, 6:59am UTC](https://forum.codewithmosh.com/t/linkedlist-printmiddle-method/13321 "2022-07-05T06:59:17Z")

</div>

In printMiddle method (in case of even number of elements) Suppose there are 6 elements then the shared solution will give middle nodes as 4 & 5. Correct answer should be 3 and 4… right?? Can anyone help me to underst…

---

## [Why Stack and Queue have insertion operation O(1)?](https://forum.codewithmosh.com/t/why-stack-and-queue-have-insertion-operation-o-1/2216)

<div class="topic-metadata">

**Author:** [@Artem](https://forum.codewithmosh.com/u/Artem)\
**Replies:** 4\
**Last updated:** [June 28, 2022, 2:15pm UTC](https://forum.codewithmosh.com/t/why-stack-and-queue-have-insertion-operation-o-1/2216 "2022-06-28T14:15:40Z")

</div>

As was said in lectures, both Stack and Queue have insertion operation complexity O(1), BUT both of them have resize() function call if there is no free place left for new elements, so overall complexity should be O(n). …

---

## [Error: cannot find symbol](https://forum.codewithmosh.com/t/error-cannot-find-symbol/12937)

<div class="topic-metadata">

**Author:** [@johnsontempo](https://forum.codewithmosh.com/u/johnsontempo)\
**Replies:** 7\
**Last updated:** [June 16, 2022, 6:42pm UTC](https://forum.codewithmosh.com/t/error-cannot-find-symbol/12937 "2022-06-16T18:42:30Z")

</div>

I just started learning, and I follow what the video said to type out all the code, but I got the error message said cannot find the symbol. Is there anyone know why the Array symbol cannot be found? I create my own pack…

---

## [Why last node remove operation in array have O(n)?](https://forum.codewithmosh.com/t/why-last-node-remove-operation-in-array-have-o-n/5518)

<div class="topic-metadata">

**Author:** [@ni3.net](https://forum.codewithmosh.com/u/ni3.net)\
**Replies:** 4\
**Last updated:** [June 14, 2022, 4:09pm UTC](https://forum.codewithmosh.com/t/why-last-node-remove-operation-in-array-have-o-n/5518 "2022-06-14T16:09:43Z")

</div>

Why removing the last node in the array is O(n) since we don’t traverse the array while removing the last node and there is no left shit.

---

## [Part 1 Array 7-Solution-removeAt()](https://forum.codewithmosh.com/t/part-1-array-7-solution-removeat/7991)

<div class="topic-metadata">

**Author:** [@Lindaaa](https://forum.codewithmosh.com/u/Lindaaa)\
**Replies:** 1\
**Last updated:** [June 6, 2022, 4:14am UTC](https://forum.codewithmosh.com/t/part-1-array-7-solution-removeat/7991 "2022-06-06T04:14:10Z")

</div>

Hi, when I run the removeAt() part code with 3 items in the array, I run into an ArrayIndexOutOfBoundsException, I think in the for loop of removeAt(), we should use i \< count-1, instead of i\<count, does this make sens…

[Previous page](https://forum.codewithmosh.com/c/data-structures/14.md)

[Next page](https://forum.codewithmosh.com/c/data-structures/14.md?page=2)
