• Congratulations to the Class of 2024 on your results!
    Let us know how you went here
    Got a question about your uni preferences? Ask us here

help!!!! (1 Viewer)

KelvinHSC

New Member
Joined
Mar 14, 2013
Messages
7
Gender
Undisclosed
HSC
N/A
Just wondering if a person could master algorithms (understanding and writing one) in the time period of 7 weeks, practising everyday? I have no knowledge in writing one even the simple ones. :(
 

GoldyOrNugget

Señor Member
Joined
Jul 14, 2012
Messages
583
Gender
Male
HSC
2012
Understanding an algorithm? It's pretty much a description of a process, like a recipe. Try to translate it into English in your head. E.g. this is a linear search algorithm

Code:
Index = 1
Found = FALSE
WHILE Index <= Length of Array DO
    IF Array[Index] = Query THEN
        PRINT "Found!"
        Found = TRUE
    ENDIF
ENDWHILE

IF Found == FALSE THEN
    PRINT "Element is not in array"
ENDIF
So you start at the beginning of the array. You then go through each element of the array, checking if it matches the element you're querying for. If you find the element, output that you found it. If by the end of the program, you haven't found your element, then output that it's not in the array.

Pretty much do this for any algorithm you're given.
 
Last edited:

KelvinHSC

New Member
Joined
Mar 14, 2013
Messages
7
Gender
Undisclosed
HSC
N/A
Understanding an algorithm? It's pretty much a description of a process, like a recipe. Try to translate it into English in your head. E.g. this is a linear search algorithm

Code:
Index = 1
Found = FALSE
WHILE Index <= Length of Array DO
    IF Array[Index] = Query THEN
        PRINT "Found!"
        Found = TRUE
    ENDIF
ENDWHILE

IF Found == FALSE THEN
    PRINT "Element is not in array"
ENDIF
So you start at the beginning of the array. You then go through each element of the array, checking if it matches the element you're querying for. If you find the element, output that you found it. If by the end of the program, you haven't found your element, then output that it's not in the array.

Pretty much do this for any algorithm you're given.
In sam davis textbox, is "Index" like "Count" and "Query" is "ItemToFind"? I understand most algorithms logic, but writing one from scratch is very hard for me :(
 

GoldyOrNugget

Señor Member
Joined
Jul 14, 2012
Messages
583
Gender
Male
HSC
2012
The specific names used are interchangeable, so yes, "Index" is like "Count" and "Query" is like "ItemToFind".

What do you have trouble with? The pseudocode syntax? Or how to translate an abstract solution into an algorithm? To write one from scratch, think about how you'd carry it out by hand. E.g. for a linear search, think about having a bunch of items in front of you, and going through them one by one. That's what I do.
 

KelvinHSC

New Member
Joined
Mar 14, 2013
Messages
7
Gender
Undisclosed
HSC
N/A
The specific names used are interchangeable, so yes, "Index" is like "Count" and "Query" is like "ItemToFind".

What do you have trouble with? The pseudocode syntax? Or how to translate an abstract solution into an algorithm? To write one from scratch, think about how you'd carry it out by hand. E.g. for a linear search, think about having a bunch of items in front of you, and going through them one by one. That's what I do.
"The pseudocode syntax? Or how to translate an abstract solution into an algorithm?" and interpretation of the question is the hardest part for me and of course writing one from scratch (insertion,bubble,selection) just makes me have a headache just thinking about it.
 

GoldyOrNugget

Señor Member
Joined
Jul 14, 2012
Messages
583
Gender
Male
HSC
2012
Do you have any examples of questions you can't do? It'll be easier to help you on a concrete case.

For all the standard algorithms like the sorts, just think about what they do.

* Insertion sort goes through each element sequentially and shifts it backwards until it's in its right position.

* Bubble sort repeatedly goes through the whole array and swaps out-of-order adjacent terms. It keeps doing this until the list is sorted.

* Selection sort goes through each spot in the sorted list and linear searches for the element that should go in that spot. It then puts the element in that spot.
 

KelvinHSC

New Member
Joined
Mar 14, 2013
Messages
7
Gender
Undisclosed
HSC
N/A
Do you have any examples of questions you can't do? It'll be easier to help you on a concrete case.

For all the standard algorithms like the sorts, just think about what they do.

* Insertion sort goes through each element sequentially and shifts it backwards until it's in its right position.

* Bubble sort repeatedly goes through the whole array and swaps out-of-order adjacent terms. It keeps doing this until the list is sorted.

* Selection sort goes through each spot in the sorted list and linear searches for the element that should go in that spot. It then puts the element in that spot.
Post up some questions and i will try to answer them to best of my ability.
 

GoldyOrNugget

Señor Member
Joined
Jul 14, 2012
Messages
583
Gender
Male
HSC
2012
1. Write an algorithm that takes as input an array of integers and outputs the maximum and minimum values in that array.

2. Write an algorithm that takes as input an array of integers and outputs the sum of all the even-indexed elements in the array (i.e. elements at positions 0,2,4,...)

3. Write an algorithm that takes as input 3 integers and returns the median of the integers.

4. John tries to program a standard integer sorting algorithm (to sort in ascending order), and produces the following (see below). a) What algorithm did John try to program? b) John messed up the algorithm. Correct the pseudocode to make the algorithm correct.

Code:
INPUT Array // 0-indexed
IsSorted := FALSE
WHILE IsSorted = FALSE DO
    i := 0
    IsSorted = TRUE
    WHILE i < length of Array DO
        IF Array[i] < Array[i+1] THEN
            Temp := Array[i]
            Array[i] := Array[i+1]
            Array[i+1] := Temp
            IsSorted := FALSE
        ENDIF
        i := i + 1
    ENDWHILE
ENDWHILE
5. A database of movies is ordered alphabetically. Which of the following is the most effective algorithm to search for a movie released on a particular date? a) Binary search b) Selection search c) Linear search d) Indexed search
 
Last edited:

hanif

New Member
Joined
Jul 30, 2012
Messages
11
Gender
Male
HSC
2013
No offense, but why do you call it an "algorithm" when it's CLEARLY pseudo-code?
 

GoldyOrNugget

Señor Member
Joined
Jul 14, 2012
Messages
583
Gender
Male
HSC
2012
Pseudocode is a method for representing the logic of an algorithm. It would not make sense to say "What pseudocode did John try to program?" (and indeed, the answer I expect is the name of an algorithm). "John messed up the pseudocode" would also be misleading, as it suggests the issue is syntactical rather than algorithmic.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top